Skip to content

Commit

Permalink
Merge pull request #574 from Panenco/feat/modal-scroll-type-prop
Browse files Browse the repository at this point in the history
feat: modal scroll type prop
  • Loading branch information
vozbrann authored Feb 8, 2023
2 parents 1994a34 + 51fa50b commit 302b625
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/components/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cx from 'classnames';

import { StyledModal, StyledModalBackdrop, StyledModalContainer, StyledFocusLock } from './style';
import { ModalContext } from './modalContext';
import { ModalSizesType } from './types';
import { ModalScrollType, ModalSizesType } from './types';

export interface ModalProps extends React.HTMLAttributes<HTMLDivElement> {
/**
Expand Down Expand Up @@ -34,6 +34,11 @@ export interface ModalProps extends React.HTMLAttributes<HTMLDivElement> {
* Callback fired when the modal requests to be closed
* */
onHide?: () => void;
/**
* The scroll behavior of the modal
* @default body
* */
scroll?: ModalScrollType;
/**
* If `true`, the modal is visible
* @default true
Expand All @@ -56,6 +61,7 @@ export const Modal = React.forwardRef<HTMLDivElement, ModalProps>(
size = 'md',
dialogClassName,
autoFocus = true,
scroll = 'body',
...props
}: ModalProps,
ref,
Expand Down Expand Up @@ -106,6 +112,7 @@ export const Modal = React.forwardRef<HTMLDivElement, ModalProps>(
role='dialog'
aria-modal='true'
ref={ref}
scroll={scroll}
>
<StyledModal
size={size}
Expand Down
25 changes: 22 additions & 3 deletions src/components/modal/style.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from 'styled-components';
import styled, { css } from 'styled-components';
import { breakpoints } from 'styles/breakpoints';
import FocusLock from 'react-focus-lock';
import { ModalSizesType } from './types';
import { ModalScrollType, ModalSizesType } from './types';

const sizeOptions = {
sm: '320px',
Expand Down Expand Up @@ -67,12 +67,31 @@ export const StyledModal = styled.div<{
}
`;

export const StyledModalContainer = styled.div`
export const StyledModalContainer = styled.div<{
scroll: ModalScrollType;
}>`
display: flex;
align-items: flex-start;
justify-content: center;
padding: 0;
min-height: 100%;
${({ scroll }) =>
scroll === 'paper' &&
css`
height: 100%;
${StyledModal} {
max-height: 100%;
overflow-y: auto;
overflow-x: hidden;
}
${StyledModalBody} {
overflow-y: auto;
overflow-x: hidden;
}
`}
@media (min-width: ${breakpoints.sm}) {
padding: 100px 10px;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/modal/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export type ModalSizesType = 'sm' | 'md' | 'lg';
export type ModalScrollType = 'paper' | 'body';
16 changes: 15 additions & 1 deletion stories/modal/Modal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ const Template: ComponentStory<typeof Modal> = (args) => {
<Modal.Header>
<Modal.Title id='exampleModal'>Modal title</Modal.Title>
</Modal.Header>
<Modal.Body>Modal body</Modal.Body>
<Modal.Body>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Facere quasi praesentium sed dolorem, voluptas
maiores sapiente reiciendis tempora repudiandae error! Adipisci voluptates debitis reiciendis rem officia
eaque, commodi nesciunt, quos sequi, eius quibusdam magnam. Omnis quod quia nulla! Fuga, quibusdam. Cumque
dicta numquam cupiditate dolore repellendus expedita est, voluptatum aspernatur dignissimos hic et ratione,
facilis quam aliquam, ullam eum error soluta deserunt pariatur mollitia alias sed repellat. Dolor laborum
omnis cupiditate deserunt ratione inventore porro, sapiente magnam eum molestias quaerat molestiae incidunt
culpa adipisci ducimus. Odit cum doloremque accusamus nemo animi asperiores quisquam molestiae. Aperiam sint
nostrum vitae doloribus perferendis!
</Modal.Body>
<Modal.Footer>Modal footer</Modal.Footer>
</Modal>
</>
Expand All @@ -72,3 +81,8 @@ export const Large = Template.bind({});
Large.args = {
size: 'lg',
};

export const ScrollPaper = Template.bind({});
ScrollPaper.args = {
scroll: 'paper',
};

0 comments on commit 302b625

Please sign in to comment.