Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/moody-buttons-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': major
---

Dialog no longer accepts styled-system props. Please use the `sx` prop to extend Primer component styling instead. See also https://primer.style/react/overriding-styles for information about `sx` and https://primer.style/react/system-props for context on the removal.
33 changes: 15 additions & 18 deletions docs/content/Dialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,22 @@ You can also pass any non-text content into the header:
</State>
```

## System props

<Note variant="warning">

System props are deprecated in all components except [Box](/Box). Please use the [`sx` prop](/overriding-styles) instead.

</Note>
## Component props

`Dialog` components get the `COMMON` and `LAYOUT` categories of system props. `Dialog.Header` components get `COMMON`, `LAYOUT`, and `FLEX` system props. Read our [System Props](/system-props) doc page for a full list of available props.
### Dialog

## Component props
| Prop name | Type | Default | Description |
| :-------------- | :---------------- | :------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| isOpen | Boolean | | Set whether or not the dialog is shown |
| onDismiss | Function | | A user-provided function that should close the dialog |
| returnFocusRef | React ref | | The element to restore focus back to after the `Dialog` is closed |
| initialFocusRef | React ref | | Element inside of the `Dialog` you'd like to be focused when the Dialog is opened. If nothing is passed to `initialFocusRef` the close button is focused. |
| aria-labelledby | string | | Pass an id to use for the aria-label. Use either a `aria-label` or an `aria-labelledby` but not both. |
| aria-label | string | | Pass a label to be used to describe the Dialog. Use either a `aria-label` or an `aria-labelledby` but not both. |
| sx | SystemStyleObject | {} | Style to be applied to the component |

| Prop name | Type | Description |
| :-------------- | :-------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| isOpen | Boolean | Set whether or not the dialog is shown |
| onDismiss | Function | A user-provided function that should close the dialog |
| returnFocusRef | React ref | The element to restore focus back to after the `Dialog` is closed |
| initialFocusRef | React ref | Element inside of the `Dialog` you'd like to be focused when the Dialog is opened. If nothing is passed to `initialFocusRef` the close button is focused. |
| aria-labelledby | string | Pass an id to use for the aria-label. Use either a `aria-label` or an `aria-labelledby` but not both. |
| aria-label | string | Pass a label to be used to describe the Dialog. Use either a `aria-label` or an `aria-labelledby` but not both. |
### Dialog.Header

`Dialog.Header` does not take any non-system props.
| Prop name | Type | Default | Description |
| :-------- | :---------------- | :------ | :----------------------------------- |
| sx | SystemStyleObject | {} | Style to be applied to the component |
8 changes: 2 additions & 6 deletions src/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {forwardRef, useRef} from 'react'
import styled from 'styled-components'
import ButtonClose from './Button/ButtonClose'
import {COMMON, get, LAYOUT, SystemCommonProps, SystemLayoutProps} from './constants'
import {get} from './constants'
import Box from './Box'
import useDialog from './hooks/useDialog'
import sx, {SxProp} from './sx'
Expand All @@ -14,9 +14,7 @@ const noop = () => null
type StyledDialogBaseProps = {
narrow?: boolean
wide?: boolean
} & SystemLayoutProps &
SystemCommonProps &
SxProp
} & SxProp

const DialogBase = styled.div<StyledDialogBaseProps>`
box-shadow: ${get('shadows.shadow.large')};
Expand All @@ -39,8 +37,6 @@ const DialogBase = styled.div<StyledDialogBaseProps>`
height: 100vh;
}

${LAYOUT};
${COMMON};
${sx};
`

Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/Dialog.types.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'
import Dialog from '../Dialog'

export function shouldAcceptCallWithNoProps() {
return <Dialog />
}

export function shouldNotAcceptSystemProps() {
// @ts-expect-error system props should not be accepted
return <Dialog backgroundColor="thistle" />
}