Skip to content

Commit 694dd95

Browse files
CopilotfrancineluccaCopilot
authored
Add className, width and height props to ConfirmationDialog (#6107)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: francinelucca <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Marie Lucca <[email protected]>
1 parent e963f2f commit 694dd95

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

.changeset/big-actors-smoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
feat(ConfirmationDialog): add className, width and height

packages/react/src/ConfirmationDialog/ConfirmationDialog.test.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,36 @@ const ShorthandHookFromActionMenu = () => {
7070
)
7171
}
7272

73+
const CustomProps = ({
74+
className,
75+
width,
76+
height,
77+
}: Pick<React.ComponentProps<typeof ConfirmationDialog>, 'className' | 'width' | 'height'>) => {
78+
const [isOpen, setIsOpen] = useState(false)
79+
const buttonRef = useRef<HTMLButtonElement>(null)
80+
const onDialogClose = useCallback(() => setIsOpen(false), [])
81+
return (
82+
<ThemeProvider theme={theme}>
83+
<BaseStyles>
84+
<Button ref={buttonRef} onClick={() => setIsOpen(!isOpen)}>
85+
Show dialog
86+
</Button>
87+
{isOpen && (
88+
<ConfirmationDialog
89+
title="Confirm"
90+
onClose={onDialogClose}
91+
className={className}
92+
width={width}
93+
height={height}
94+
>
95+
Lorem ipsum dolor sit Pippin good dog.
96+
</ConfirmationDialog>
97+
)}
98+
</BaseStyles>
99+
</ThemeProvider>
100+
)
101+
}
102+
73103
describe('ConfirmationDialog', () => {
74104
behavesAsComponent({
75105
Component: ConfirmationDialog,
@@ -121,4 +151,32 @@ describe('ConfirmationDialog', () => {
121151
expect(getByRole('button', {name: 'Primary'})).toEqual(document.activeElement)
122152
expect(getByRole('button', {name: 'Secondary'})).not.toEqual(document.activeElement)
123153
})
154+
155+
it('accepts a className prop', async () => {
156+
const testClassName = 'test-class-name'
157+
const {getByText, getByRole} = HTMLRender(<CustomProps className={testClassName} />)
158+
159+
fireEvent.click(getByText('Show dialog'))
160+
161+
const dialog = getByRole('alertdialog')
162+
expect(dialog.classList.contains(testClassName)).toBe(true)
163+
})
164+
165+
it('accepts a width prop', async () => {
166+
const {getByText, getByRole} = HTMLRender(<CustomProps width="large" />)
167+
168+
fireEvent.click(getByText('Show dialog'))
169+
170+
const dialog = getByRole('alertdialog')
171+
expect(dialog.getAttribute('data-width')).toBe('large')
172+
})
173+
174+
it('accepts a height prop', async () => {
175+
const {getByText, getByRole} = HTMLRender(<CustomProps height="small" />)
176+
177+
fireEvent.click(getByText('Show dialog'))
178+
179+
const dialog = getByRole('alertdialog')
180+
expect(dialog.getAttribute('data-height')).toBe('small')
181+
})
124182
})

packages/react/src/ConfirmationDialog/ConfirmationDialog.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {createRoot} from 'react-dom/client'
44
import type {ThemeProviderProps} from '../ThemeProvider'
55
import {ThemeProvider, useTheme} from '../ThemeProvider'
66
import {FocusKeys} from '@primer/behaviors'
7-
import type {DialogProps, DialogHeaderProps, DialogButtonProps} from '../Dialog/Dialog'
7+
import type {DialogProps, DialogHeaderProps, DialogButtonProps, DialogWidth, DialogHeight} from '../Dialog/Dialog'
88
import {Dialog} from '../Dialog/Dialog'
99
import {useFocusZone} from '../hooks/useFocusZone'
1010
import BaseStyles from '../BaseStyles'
@@ -40,6 +40,29 @@ export interface ConfirmationDialogProps {
4040
* The type of button to use for the confirm button. Default: Button.
4141
*/
4242
confirmButtonType?: 'normal' | 'primary' | 'danger'
43+
44+
/**
45+
* Additional class names to apply to the dialog
46+
*/
47+
className?: string
48+
49+
/**
50+
* The width of the dialog.
51+
* small: 296px
52+
* medium: 320px
53+
* large: 480px
54+
* xlarge: 640px
55+
* @default 'medium'
56+
*/
57+
width?: DialogWidth
58+
59+
/**
60+
* The height of the dialog.
61+
* small: 480px
62+
* large: 640px
63+
* auto: variable based on contents
64+
*/
65+
height?: DialogHeight
4366
}
4467

4568
const ConfirmationHeader: React.FC<React.PropsWithChildren<DialogHeaderProps>> = ({title, onClose, dialogLabelId}) => {
@@ -87,6 +110,9 @@ export const ConfirmationDialog: React.FC<React.PropsWithChildren<ConfirmationDi
87110
confirmButtonContent = 'OK',
88111
confirmButtonType = 'normal',
89112
children,
113+
className,
114+
width = 'medium',
115+
height,
90116
} = props
91117

92118
const onCancelButtonClick = useCallback(() => {
@@ -114,7 +140,9 @@ export const ConfirmationDialog: React.FC<React.PropsWithChildren<ConfirmationDi
114140
title={title}
115141
footerButtons={footerButtons}
116142
role="alertdialog"
117-
width="medium"
143+
width={width}
144+
height={height}
145+
className={className}
118146
renderHeader={ConfirmationHeader}
119147
renderBody={ConfirmationBody}
120148
renderFooter={ConfirmationFooter}

0 commit comments

Comments
 (0)