Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Modal): add isFullWidth prop #12462

Merged
merged 2 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions e2e/components/ComposedModal/ComposedModal-test.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ test.describe('ComposedModal', () => {
theme,
});
});
test('full width modal @vrt', async ({ page }) => {
await snapshotStory(page, {
component: 'ComposedModal',
id: 'components-composedmodal--full-width',
theme,
});
});
});
});

Expand Down
8 changes: 8 additions & 0 deletions e2e/components/Modal/Modal-test.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ test.describe('Modal', () => {
theme,
});
});

test('full width modal @vrt', async ({ page }) => {
await snapshotStory(page, {
component: 'Modal',
id: 'components-modal--full-width',
theme,
});
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,9 @@ Map {
"danger": Object {
"type": "bool",
},
"isFullWidth": Object {
"type": "bool",
},
"onClose": Object {
"type": "func",
},
Expand Down Expand Up @@ -4060,6 +4063,9 @@ Map {
"id": Object {
"type": "string",
},
"isFullWidth": Object {
"type": "bool",
},
"modalAriaLabel": Object {
"type": "string",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const ComposedModal = React.forwardRef(function ComposedModal(
className: customClassName,
containerClassName,
danger,
isFullWidth,
onClose,
onKeyDown,
open,
Expand Down Expand Up @@ -169,6 +170,7 @@ const ComposedModal = React.forwardRef(function ComposedModal(
const containerClass = cx({
[`${prefix}--modal-container`]: true,
[`${prefix}--modal-container--${size}`]: size,
[`${prefix}--modal-container--full-width`]: isFullWidth,
[containerClassName]: containerClassName,
});

Expand Down Expand Up @@ -301,6 +303,11 @@ ComposedModal.propTypes = {
*/
danger: PropTypes.bool,

/**
* Specify whether or not the Modal content should have any inner padding.
*/
isFullWidth: PropTypes.bool,

/**
* Specify an optional handler for closing modal.
* Returning `false` here prevents closing modal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import Select from '../Select';
import SelectItem from '../SelectItem';
import TextInput from '../TextInput';
import Button from '../Button';
import {
StructuredListWrapper,
StructuredListHead,
StructuredListBody,
StructuredListRow,
StructuredListCell,
} from '../StructuredList';
import mdx from './ComposedModal.mdx';

export default {
Expand Down Expand Up @@ -58,6 +65,67 @@ export const Default = () => {
);
};

export const FullWidth = () => {
return (
<ComposedModal open isFullWidth>
<ModalHeader
label="An example of a modal with no padding"
title="Full Width Modal"
/>
<ModalBody>
<StructuredListWrapper>
<StructuredListHead>
<StructuredListRow head>
<StructuredListCell head noWrap>
Column A
</StructuredListCell>
<StructuredListCell head noWrap>
Column B
</StructuredListCell>
<StructuredListCell head noWrap>
Column C
</StructuredListCell>
</StructuredListRow>
</StructuredListHead>
<StructuredListBody>
<StructuredListRow>
<StructuredListCell noWrap>Row 1</StructuredListCell>
<StructuredListCell>Row 1</StructuredListCell>
<StructuredListCell>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc
dui magna, finibus id tortor sed, aliquet bibendum augue. Aenean
posuere sem vel euismod dignissim. Nulla ut cursus dolor.
Pellentesque vulputate nisl a porttitor interdum.
</StructuredListCell>
</StructuredListRow>
<StructuredListRow>
<StructuredListCell noWrap>Row 2</StructuredListCell>
<StructuredListCell>Row 2</StructuredListCell>
<StructuredListCell>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc
dui magna, finibus id tortor sed, aliquet bibendum augue. Aenean
posuere sem vel euismod dignissim. Nulla ut cursus dolor.
Pellentesque vulputate nisl a porttitor interdum.
</StructuredListCell>
</StructuredListRow>
<StructuredListRow>
<StructuredListCell noWrap>Row 3</StructuredListCell>
<StructuredListCell>Row 3</StructuredListCell>
<StructuredListCell>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc
dui magna, finibus id tortor sed, aliquet bibendum augue. Aenean
posuere sem vel euismod dignissim. Nulla ut cursus dolor.
Pellentesque vulputate nisl a porttitor interdum.
</StructuredListCell>
</StructuredListRow>
</StructuredListBody>
</StructuredListWrapper>
</ModalBody>
<ModalFooter primaryButtonText="Add" secondaryButtonText="Cancel" />
</ComposedModal>
);
};

export const PassiveModal = () => {
return (
<ComposedModal open>
Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/components/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const Modal = React.forwardRef(function Modal(
hasScrollingContent,
closeButtonLabel,
preventCloseOnClickOutside, // eslint-disable-line
isFullWidth,
...rest
},
ref
Expand Down Expand Up @@ -127,6 +128,7 @@ const Modal = React.forwardRef(function Modal(

const containerClasses = classNames(`${prefix}--modal-container`, {
[`${prefix}--modal-container--${size}`]: size,
[`${prefix}--modal-container--full-width`]: isFullWidth,
});

const contentClasses = classNames(`${prefix}--modal-content`, {
Expand Down Expand Up @@ -354,6 +356,11 @@ Modal.propTypes = {
*/
id: PropTypes.string,

/**
* Specify whether or not the Modal content should have any inner padding.
*/
isFullWidth: PropTypes.bool,

/**
* Specify a label to be read by screen readers on the modal root node
*/
Expand Down
67 changes: 67 additions & 0 deletions packages/react/src/components/Modal/Modal.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import Dropdown from '../Dropdown';
import SelectItem from '../SelectItem';
import TextInput from '../TextInput';
import mdx from './Modal.mdx';
import {
StructuredListWrapper,
StructuredListHead,
StructuredListBody,
StructuredListRow,
StructuredListCell,
} from '../StructuredList';

export default {
title: 'Components/Modal',
Expand Down Expand Up @@ -79,6 +86,66 @@ export const Default = () => {
);
};

export const FullWidth = () => {
return (
<Modal
open
isFullWidth
modalHeading="Full Width Modal"
modalLabel="An example of a modal with no padding"
primaryButtonText="Add"
secondaryButtonText="Cancel">
<StructuredListWrapper>
<StructuredListHead>
<StructuredListRow head>
<StructuredListCell head noWrap>
Column A
</StructuredListCell>
<StructuredListCell head noWrap>
Column B
</StructuredListCell>
<StructuredListCell head noWrap>
Column C
</StructuredListCell>
</StructuredListRow>
</StructuredListHead>
<StructuredListBody>
<StructuredListRow>
<StructuredListCell noWrap>Row 1</StructuredListCell>
<StructuredListCell>Row 1</StructuredListCell>
<StructuredListCell>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dui
magna, finibus id tortor sed, aliquet bibendum augue. Aenean
posuere sem vel euismod dignissim. Nulla ut cursus dolor.
Pellentesque vulputate nisl a porttitor interdum.
</StructuredListCell>
</StructuredListRow>
<StructuredListRow>
<StructuredListCell noWrap>Row 2</StructuredListCell>
<StructuredListCell>Row 2</StructuredListCell>
<StructuredListCell>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dui
magna, finibus id tortor sed, aliquet bibendum augue. Aenean
posuere sem vel euismod dignissim. Nulla ut cursus dolor.
Pellentesque vulputate nisl a porttitor interdum.
</StructuredListCell>
</StructuredListRow>
<StructuredListRow>
<StructuredListCell noWrap>Row 3</StructuredListCell>
<StructuredListCell>Row 3</StructuredListCell>
<StructuredListCell>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc dui
magna, finibus id tortor sed, aliquet bibendum augue. Aenean
posuere sem vel euismod dignissim. Nulla ut cursus dolor.
Pellentesque vulputate nisl a porttitor interdum.
</StructuredListCell>
</StructuredListRow>
</StructuredListBody>
</StructuredListWrapper>
</Modal>
);
};

export const DangerModal = () => {
return (
<Modal
Expand Down
6 changes: 6 additions & 0 deletions packages/styles/scss/components/modal/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@
z-index: z('modal');
}

// Fluid Modal (No padding)
.#{$prefix}--modal-container--full-width .#{$prefix}--modal-content {
padding: 0;
margin: 0;
}

// Windows HCM fix
/* stylelint-disable */
.#{$prefix}--modal-close__icon {
Expand Down