Skip to content

Commit 9b99e74

Browse files
committed
Add size option for Modal (#40)
1 parent 5999309 commit 9b99e74

File tree

8 files changed

+55
-11
lines changed

8 files changed

+55
-11
lines changed

src/demo/pages/DemoContainer.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ class DemoContainer extends React.Component {
10001000
/>
10011001
<h3 id="ui-components-modal" className="typography-size-4 mb-6">Modal</h3>
10021002
<Documentation
1003-
name="Modal label"
1003+
name="Modal"
10041004
component={(
10051005
<>
10061006
<Button
@@ -1028,7 +1028,7 @@ class DemoContainer extends React.Component {
10281028
)}
10291029
/>
10301030
<Documentation
1031-
name="Modal label with loading icon"
1031+
name="Small modal with loading icon"
10321032
component={(
10331033
<>
10341034
<Button
@@ -1048,7 +1048,8 @@ class DemoContainer extends React.Component {
10481048
},
10491049
]}
10501050
closeHandler={() => this.setState({ showModal2: false })}
1051-
title="Modal"
1051+
size="small"
1052+
title="Small modal"
10521053
>
10531054
<p>Dialog content</p>
10541055
</Modal>

src/lib/components/ui/Modal/Modal.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ class Modal extends React.Component {
3737
}
3838

3939
render() {
40+
const sizeClass = (size) => {
41+
if (size === 'small') {
42+
return styles.isRootSmall;
43+
}
44+
45+
if (size === 'medium') {
46+
return styles.isRootMedium;
47+
}
48+
49+
return styles.isRootLarge;
50+
};
51+
4052
return (
4153
<div
4254
className={styles.overlay}
@@ -52,6 +64,7 @@ class Modal extends React.Component {
5264
<div
5365
className={`
5466
${styles.root}
67+
${sizeClass(this.props.size)}
5568
${this.state.isContentOverflowing ? styles.isContentOverflowing : ''}
5669
`.trim()}
5770
onClick={(e) => {
@@ -115,6 +128,7 @@ Modal.defaultProps = {
115128
actions: [],
116129
closeHandler: null,
117130
id: undefined,
131+
size: 'medium',
118132
};
119133

120134
Modal.propTypes = {
@@ -132,6 +146,7 @@ Modal.propTypes = {
132146
]).isRequired,
133147
closeHandler: PropTypes.func,
134148
id: PropTypes.string,
149+
size: PropTypes.oneOf(['small', 'medium', 'large']),
135150
title: PropTypes.string.isRequired,
136151
translations: PropTypes.shape({
137152
close: PropTypes.string.isRequired,

src/lib/components/ui/Modal/Modal.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
z-index: $modal-zindex;
1010
display: flex;
1111
flex-direction: column;
12-
width: $modal-width;
1312
max-width: calc(100% - (2 * #{$modal-padding-x}));
1413
max-height: calc(100% - (2 * #{$modal-padding-y}));
1514
overflow-y: auto;
@@ -79,3 +78,15 @@
7978
.isContentOverflowing .footer {
8079
box-shadow: $modal-footer-box-shadow;
8180
}
81+
82+
.isRootSmall {
83+
width: $modal-size-small-width;
84+
}
85+
86+
.isRootMedium {
87+
width: $modal-size-medium-width;
88+
}
89+
90+
.isRootLarge {
91+
width: $modal-size-large-width;
92+
}

src/lib/components/ui/Modal/__tests__/Modal.test.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('rendering', () => {
2828
]}
2929
closeHandler={() => {}}
3030
id="custom-id"
31+
size="large"
3132
title="Modal title"
3233
>
3334
Modal content
@@ -37,7 +38,7 @@ describe('rendering', () => {
3738
expect(shallowToJson(tree)).toMatchSnapshot();
3839
});
3940

40-
it('renders correctly with all with loading icon props except translations', () => {
41+
it('renders correctly with all props except translations and with a loading icon', () => {
4142
const tree = mount((
4243
<Modal
4344
actions={[
@@ -49,6 +50,7 @@ describe('rendering', () => {
4950
]}
5051
closeHandler={() => {}}
5152
id="custom-id"
53+
size="small"
5254
title="Modal title"
5355
>
5456
Modal content

src/lib/components/ui/Modal/__tests__/__snapshots__/Modal.test.jsx.snap

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exports[`rendering renders correctly with all props except translations 1`] = `
1212
}
1313
closeHandler={[Function]}
1414
id="custom-id"
15+
size="large"
1516
title="Modal title"
1617
translations={null}
1718
>
@@ -26,6 +27,7 @@ exports[`rendering renders correctly with all props except translations 1`] = `
2627
}
2728
closeHandler={[Function]}
2829
id="custom-id"
30+
size="large"
2931
title="Modal title"
3032
translations={
3133
Object {
@@ -41,7 +43,8 @@ exports[`rendering renders correctly with all props except translations 1`] = `
4143
role="presentation"
4244
>
4345
<div
44-
className="root"
46+
className="root
47+
isRootLarge"
4548
onClick={[Function]}
4649
role="presentation"
4750
>
@@ -166,7 +169,7 @@ exports[`rendering renders correctly with all props except translations 1`] = `
166169
</WithTranslationContextComponent>
167170
`;
168171

169-
exports[`rendering renders correctly with all with loading icon props except translations 1`] = `
172+
exports[`rendering renders correctly with all props except translations and with a loading icon 1`] = `
170173
<WithTranslationContextComponent
171174
actions={
172175
Array [
@@ -181,6 +184,7 @@ exports[`rendering renders correctly with all with loading icon props except tra
181184
}
182185
closeHandler={[Function]}
183186
id="custom-id"
187+
size="small"
184188
title="Modal title"
185189
translations={null}
186190
>
@@ -198,6 +202,7 @@ exports[`rendering renders correctly with all with loading icon props except tra
198202
}
199203
closeHandler={[Function]}
200204
id="custom-id"
205+
size="small"
201206
title="Modal title"
202207
translations={
203208
Object {
@@ -213,7 +218,8 @@ exports[`rendering renders correctly with all with loading icon props except tra
213218
role="presentation"
214219
>
215220
<div
216-
className="root"
221+
className="root
222+
isRootSmall"
217223
onClick={[Function]}
218224
role="presentation"
219225
>
@@ -362,6 +368,7 @@ exports[`rendering renders correctly with mandatory props only 1`] = `
362368
<Modal
363369
actions={Array []}
364370
closeHandler={null}
371+
size="medium"
365372
title="Modal title"
366373
translations={
367374
Object {
@@ -376,7 +383,8 @@ exports[`rendering renders correctly with mandatory props only 1`] = `
376383
role="presentation"
377384
>
378385
<div
379-
className="root"
386+
className="root
387+
isRootMedium"
380388
onClick={[Function]}
381389
role="presentation"
382390
>
@@ -416,6 +424,7 @@ exports[`rendering renders correctly with translations 1`] = `
416424
<Modal
417425
actions={Array []}
418426
closeHandler={[Function]}
427+
size="medium"
419428
title="Modal title"
420429
translations={
421430
Object {
@@ -430,7 +439,8 @@ exports[`rendering renders correctly with translations 1`] = `
430439
role="presentation"
431440
>
432441
<div
433-
className="root"
442+
className="root
443+
isRootMedium"
434444
onClick={[Function]}
435445
role="presentation"
436446
>

src/lib/components/ui/Modal/_theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ $modal-background: var(--rui-modal-background);
22
$modal-box-shadow: var(--rui-modal-box-shadow);
33
$modal-footer-background: var(--rui-modal-footer-background);
44
$modal-overlay-background: var(--rui-modal-overlay-background);
5+
$modal-size-small-width: var(--rui-modal-size-small-width);
6+
$modal-size-medium-width: var(--rui-modal-size-medium-width);
7+
$modal-size-large-width: var(--rui-modal-size-large-width);

src/lib/components/ui/Modal/_variables.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
// 1. Intentionally using direct color to prevent custom properties from being passed into `rgba` function.
88

9-
$modal-width: 46rem;
109
$modal-padding-x: map-get($offset-values, 5);
1110
$modal-padding-y: map-get($offset-values, 3);
1211
$modal-border-radius: $border-radius;

src/lib/theme.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,9 @@
532532
--rui-modal-box-shadow: none;
533533
--rui-modal-footer-background: var(--rui-color-gray-100);
534534
--rui-modal-overlay-background: rgba(0, 0, 0, 0.5);
535+
--rui-modal-size-small-width: 20rem;
536+
--rui-modal-size-medium-width: 40rem;
537+
--rui-modal-size-large-width: 60rem;
535538

536539
//
537540
// Toolbar

0 commit comments

Comments
 (0)