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: open modal for the whole page #2009

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 additions & 0 deletions src/components/Modal/Modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ $modal-default-border-radius: 5px;
animation-name: #{variables.$ns}modal;
animation-duration: 200ms;
}

&_full-page {
#{$block} {
&__content-aligner,
&__content-wrapper,
&__content {
width: 100%;
height: 100%;
}

&__content-wrapper {
margin: 0;
}

&__content-wrapper,
&__content {
border-radius: unset;
}
}
}
}

@keyframes #{variables.$ns}modal {
Expand Down
9 changes: 8 additions & 1 deletion src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface ModalProps extends DOMProps, LayerExtendableProps, QAProps {
onTransitionExit?: VoidFunction;
onTransitionExited?: VoidFunction;
contentOverflow?: 'visible' | 'auto';
fullPage?: boolean;
}

export type ModalCloseReason = LayerCloseReason;
Expand Down Expand Up @@ -79,6 +80,7 @@ export function Modal({
'aria-label': ariaLabel,
container,
qa,
fullPage,
}: ModalProps) {
const containerRef = React.useRef<HTMLDivElement>(null);
const contentRef = React.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -130,7 +132,12 @@ export function Modal({
}}
>
<Portal container={container}>
<div ref={containerRef} style={style} className={b({open}, className)} data-qa={qa}>
<div
ref={containerRef}
style={style}
className={b({open, 'full-page': fullPage}, className)}
data-qa={qa}
>
<div className={b('content-aligner')}>
<div className={b('content-wrapper')}>
<FocusTrap
Expand Down
1 change: 1 addition & 0 deletions src/components/Modal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const [open, setOpen] = React.useState(false);
| aria-label | `aria-label` HTML attribute to describe `Modal` | `string` | |
| aria-labelledby | ID of the visible `Modal` caption element | `string` | |
| contentOverflow | Determines whether the `Modal` has a scroll indicator inside or gets larger with the content | `visible` `auto` | `visible` |
| fullPage | Open modal window for the whole page | `boolean` | `false` |

## CSS API

Expand Down
35 changes: 26 additions & 9 deletions src/components/Modal/__stories__/Modal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export default {
component: Modal,
} as Meta;

const showButtonStyle = {
width: '100%',
height: 200,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
};

export const Default: StoryFn<ModalProps> = (props) => {
const [open, setOpen] = React.useState(false);

Expand All @@ -19,17 +27,26 @@ export const Default: StoryFn<ModalProps> = (props) => {
<Modal {...props} open={open} onClose={() => setOpen(false)}>
<div style={{padding: 10}}>Modal content</div>
</Modal>
<div
style={{
width: '100%',
height: 200,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<div style={showButtonStyle}>
<Button onClick={() => setOpen(true)}>Show</Button>
</div>
</React.Fragment>
);
};

export const FullPage: StoryFn<ModalProps> = (props) => {
const [open, setOpen] = React.useState(false);

return (
<React.Fragment>
<Modal {...props} open={open} onClose={() => setOpen(false)} fullPage>
<div style={{padding: 10}}>
<Button onClick={() => setOpen(false)}>Close</Button>
</div>
</Modal>
<div style={showButtonStyle}>
<Button onClick={() => setOpen(true)}>Show full page modal</Button>
</div>
</React.Fragment>
);
};
Loading