Skip to content

Commit 7d826f1

Browse files
committed
Dialog2 no longer accepts styled system props
1 parent 25cec73 commit 7d826f1

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
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: 22 additions & 11 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'
@@ -180,12 +180,12 @@ const widthMap = {
180180
export type DialogWidth = keyof typeof widthMap
181181
export type DialogHeight = keyof typeof heightMap
182182

183-
interface StyledDialogProps {
183+
type StyledDialogProps = {
184184
width?: DialogWidth
185185
height?: DialogHeight
186-
}
186+
} & SxProp
187187

188-
const StyledDialog = styled.div<StyledDialogProps & SystemCommonProps & SystemPositionProps & SxProp>`
188+
const StyledDialog = styled.div<StyledDialogProps>`
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,37 @@ 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<SxProp>({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+
317+
const Title = styled.div<SxProp>`
319318
font-size: ${get('fontSizes.1')};
320319
font-weight: ${get('fontWeights.bold')};
320+
321+
${sx};
321322
`
322-
const Subtitle = styled(Box)`
323+
324+
const Subtitle = styled.div<SxProp>`
323325
font-size: ${get('fontSizes.0')};
324326
margin-top: ${get('space.1')};
325327
color: ${get('colors.fg.muted')};
328+
329+
${sx};
326330
`
327-
const Body = styled(Box)`
331+
332+
const Body = styled.div<SxProp>`
328333
flex-grow: 1;
329334
overflow: auto;
330335
padding: ${get('space.3')};
336+
337+
${sx};
331338
`
332-
const Footer = styled(Box).attrs({as: 'footer'})`
339+
340+
const Footer = styled.div.attrs<SxProp>({as: 'footer'})`
333341
box-shadow: 0 -1px 0 ${get('colors.border.default')};
334342
padding: ${get('space.3')};
335343
display: flex;
@@ -344,7 +352,10 @@ const Footer = styled(Box).attrs({as: 'footer'})`
344352
margin-left: 0;
345353
}
346354
}
355+
356+
${sx};
347357
`
358+
348359
const buttonTypes = {
349360
normal: Button,
350361
primary: ButtonPrimary,

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+
}

src/stories/Dialog.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ function CustomHeader({
160160
return null
161161
}
162162
function CustomBody({children}: React.PropsWithChildren<DialogProps>) {
163-
return <Dialog.Body bg="danger.subtle">{children}</Dialog.Body>
163+
return <Dialog.Body sx={{bg: 'danger.subtle'}}>{children}</Dialog.Body>
164164
}
165165
function CustomFooter({footerButtons}: React.PropsWithChildren<DialogProps>) {
166166
return (
167-
<Dialog.Footer bg="attention.subtle">
167+
<Dialog.Footer sx={{bg: 'attention.subtle'}}>
168168
{footerButtons ? <Dialog.Buttons buttons={footerButtons} /> : null}
169169
</Dialog.Footer>
170170
)

0 commit comments

Comments
 (0)