Skip to content

Commit 40a1b68

Browse files
committed
Dialog2 no longer accepts styled system props
1 parent 22483b9 commit 40a1b68

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

.changeset/old-taxis-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/components': major
3+
---
4+
5+
Dialog2 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.

docs/content/Dialog2.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ By default, the Dialog component implements the design and interactions defined
8787
| role | `"dialog" │ "alertdialog"` | `"dialog"` | The ARIA role given to the dialog element. More info: [dialog](https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal), [alertdialog](https://www.w3.org/TR/wai-aria-practices-1.1/#alertdialog) |
8888
| width | `"small" │ "medium" │ "large" │ "xlarge"` | `"xlarge"` | The fixed width of the dialog. |
8989
| height | `"small" │ "large" │ "auto"` | `"auto"` | The fixed height of the dialog, or, auto to adjust the height based on its contents. |
90+
| sx | SystemStyleObject | {} | Style to be applied to the component |
9091

9192
### DialogHeaderProps
9293

src/Dialog/Dialog.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, {useCallback, useEffect, useRef, useState} from 'react'
22
import styled from 'styled-components'
33
import Button, {ButtonPrimary, ButtonDanger, ButtonProps} from '../Button'
44
import Box from '../Box'
5-
import {get, SystemCommonProps, SystemPositionProps, COMMON, POSITION} from '../constants'
5+
import {get} from '../constants'
66
import {useOnEscapePress, useProvidedRefOrCreate} from '../hooks'
77
import {useFocusTrap} from '../hooks/useFocusTrap'
88
import sx, {SxProp} from '../sx'
@@ -185,7 +185,7 @@ interface StyledDialogProps {
185185
height?: DialogHeight
186186
}
187187

188-
const StyledDialog = styled.div<StyledDialogProps & SystemCommonProps & SystemPositionProps & SxProp>`
188+
const StyledDialog = styled.div<StyledDialogProps & SxProp>`
189189
display: flex;
190190
flex-direction: column;
191191
background-color: ${get('colors.canvas.overlay')};
@@ -210,8 +210,6 @@ const StyledDialog = styled.div<StyledDialogProps & SystemCommonProps & SystemPo
210210
}
211211
}
212212
213-
${COMMON};
214-
${POSITION};
215213
${sx};
216214
`
217215

@@ -309,27 +307,27 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP
309307
})
310308
_Dialog.displayName = 'Dialog'
311309

312-
const Header = styled(Box).attrs({as: 'header'})`
310+
const Header = styled.div.attrs({as: 'header'})`
313311
box-shadow: 0 1px 0 ${get('colors.border.default')};
314312
padding: ${get('space.2')};
315313
z-index: 1;
316314
flex-shrink: 0;
317315
`
318-
const Title = styled(Box)`
316+
const Title = styled.div`
319317
font-size: ${get('fontSizes.1')};
320318
font-weight: ${get('fontWeights.bold')};
321319
`
322-
const Subtitle = styled(Box)`
320+
const Subtitle = styled.div`
323321
font-size: ${get('fontSizes.0')};
324322
margin-top: ${get('space.1')};
325323
color: ${get('colors.fg.muted')};
326324
`
327-
const Body = styled(Box)`
325+
const Body = styled.div`
328326
flex-grow: 1;
329327
overflow: auto;
330328
padding: ${get('space.3')};
331329
`
332-
const Footer = styled(Box).attrs({as: 'footer'})`
330+
const Footer = styled.div.attrs({as: 'footer'})`
333331
box-shadow: 0 -1px 0 ${get('colors.border.default')};
334332
padding: ${get('space.3')};
335333
display: flex;

src/__tests__/Dialog2.types.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react'
2+
import {Dialog} from '../Dialog/Dialog'
3+
4+
export function shouldAcceptCallWithNoProps() {
5+
return <Dialog onClose={() => null} />
6+
}
7+
8+
export function shouldNotAcceptSystemProps() {
9+
// @ts-expect-error system props should not be accepted
10+
return <Dialog onClose={() => null} backgroundColor="tomato" />
11+
}

0 commit comments

Comments
 (0)