Skip to content

Commit bd58fa8

Browse files
committed
add size prop
1 parent b4439b3 commit bd58fa8

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

packages/react/src/Dialog/Dialog.module.css

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,13 @@
101101

102102
.Dialog {
103103
display: flex;
104-
/* stylelint-disable-next-line primer/responsive-widths */
105-
width: 640px;
106-
min-width: 296px;
104+
width: min(var(--overlay-width), 100vw - 2rem);
105+
min-width: var(--overlay-width-xsmall);
107106
max-width: calc(100dvw - 64px);
108-
height: auto;
109-
max-height: calc(100dvh - 64px);
107+
max-height: min(calc(100dvh - 2rem), var(--overlay-height));
110108
flex-direction: column;
111109
background-color: var(--overlay-bgColor);
112110
border-radius: var(--borderRadius-large);
113-
border-radius: var(--borderRadius-large, var(--borderRadius-large));
114111
box-shadow: var(--shadow-floating-small);
115112
opacity: 1;
116113

@@ -135,6 +132,30 @@
135132
height: 640px;
136133
}
137134

135+
&:where([data-height='auto']) {
136+
height: auto;
137+
}
138+
139+
&:where([data-size='small']) {
140+
--overlay-height: var(--overlay-height-small);
141+
--overlay-width: var(--overlay-width-small);
142+
}
143+
144+
&:where([data-size='medium']) {
145+
--overlay-height: var(--overlay-height-medium);
146+
--overlay-width: var(--overlay-width-medium);
147+
}
148+
149+
&:where([data-size='large']) {
150+
--overlay-height: var(--overlay-height-large);
151+
--overlay-width: var(--overlay-width-large);
152+
}
153+
154+
&:where([data-size='xlarge']) {
155+
--overlay-height: var(--overlay-height-xlarge);
156+
--overlay-width: var(--overlay-width-xlarge);
157+
}
158+
138159
@media screen and (prefers-reduced-motion: no-preference) {
139160
animation: Overlay--motion-scaleFade 0.2s cubic-bezier(0.33, 1, 0.68, 1) 1ms 1 normal none running;
140161
}

packages/react/src/Dialog/Dialog.stories.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,19 @@ export const Playground = (
135135
)
136136
}
137137
Playground.args = {
138-
width: 'xlarge',
138+
size: 'large',
139139
height: 'auto',
140140
subtitle: 'Subtitle',
141141
title: 'Dialog heading',
142142
position: 'center',
143143
}
144144
Playground.argTypes = {
145+
size: {
146+
control: {
147+
type: 'radio',
148+
},
149+
options: ['small', 'medium', 'large', 'xlarge'],
150+
},
145151
width: {
146152
control: {
147153
type: 'radio',

packages/react/src/Dialog/Dialog.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ export interface DialogProps {
126126
*/
127127
height?: DialogHeight
128128

129+
size?: 'small' | 'medium' | 'large' | 'xlarge'
130+
129131
/**
130132
* The position of the dialog
131133
*/
@@ -236,8 +238,9 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP
236238
renderFooter,
237239
onClose,
238240
role = 'dialog',
239-
width = 'xlarge',
241+
width,
240242
height = 'auto',
243+
size = 'large',
241244
footerButtons = defaultFooterButtons,
242245
position = defaultPosition,
243246
returnFocusRef,
@@ -325,6 +328,7 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP
325328
{...positionDataAttributes}
326329
data-width={width}
327330
data-height={height}
331+
data-size={size}
328332
className={clsx(className, classes.Dialog)}
329333
>
330334
{header}

0 commit comments

Comments
 (0)