Skip to content

Commit

Permalink
feat: add xsmall and xlarge modal sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
sashuk committed Aug 9, 2023
1 parent 83c013a commit 8be81c2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
31 changes: 17 additions & 14 deletions cypress/component/Modal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,24 @@ describe('Modal', () => {
const { width } = happoTarget

describe(`when screen has ${width}px width`, () => {
Cypress._.each(['small', 'medium', 'large', 'full-screen'], modalSize => {
it(`renders ${modalSize} size modal`, () => {
cy.viewport(width, 1000)

cy.mount(
<TestModalOverflown size={modalSize as ModalProps['size']} />
)

cy.get('body').happoScreenshot({
component,
variant: `modal-${modalSize}-size/${width}-default`,
targets: [happoTarget],
Cypress._.each(
['xsmall', 'small', 'medium', 'large', 'xlarge', 'full-screen'],
modalSize => {
it(`renders ${modalSize} size modal`, () => {
cy.viewport(width, 1000)

cy.mount(
<TestModalOverflown size={modalSize as ModalProps['size']} />
)

cy.get('body').happoScreenshot({
component,
variant: `modal-${modalSize}-size/${width}-default`,
targets: [happoTarget],
})
})
})
})
}
)
})
})
})
4 changes: 3 additions & 1 deletion packages/picasso/src/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export interface Props extends StandardProps, HTMLAttributes<HTMLDivElement> {
/** Whether modal should be displayed */
open: boolean
/** Width of modal */
size?: SizeType<'small' | 'medium' | 'large'> | 'full-screen'
size?:
| SizeType<'xsmall' | 'small' | 'medium' | 'large' | 'xlarge'>
| 'full-screen'
/** Callback executed when backdrop was clicked */
onBackdropClick?: () => void
/** If `true`, clicking the backdrop will not fire `onClose` or `onBackdropClick` */
Expand Down
28 changes: 28 additions & 0 deletions packages/picasso/src/Modal/story/Sizes.example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ const ModalDialog = ({
)

const Example = () => {
const {
showModal: showModalExtraSmall,
hideModal: hideModalExtraSmall,
isOpen: isOpenExtraSmall,
} = useModal()
const {
showModal: showModalSmall,
hideModal: hideModalSmall,
Expand All @@ -74,6 +79,11 @@ const Example = () => {
hideModal: hideModalLarge,
isOpen: isOpenLarge,
} = useModal()
const {
showModal: showModalExtraLarge,
hideModal: hideModalExtraLarge,
isOpen: isOpenExtraLarge,
} = useModal()
const {
showModal: showModalFullscreen,
hideModal: hideModalFullscreen,
Expand All @@ -82,6 +92,15 @@ const Example = () => {

return (
<Container flex>
<Button onClick={showModalExtraSmall} data-testid='trigger-extra-small'>
Open extra-small ("xsmall")
</Button>
<ModalDialog
open={isOpenExtraSmall}
onClose={hideModalExtraSmall}
size='xsmall'
/>

<Button onClick={showModalSmall} data-testid='trigger-small'>
Open small
</Button>
Expand All @@ -101,6 +120,15 @@ const Example = () => {
</Button>
<ModalDialog open={isOpenLarge} onClose={hideModalLarge} size='large' />

<Button onClick={showModalExtraLarge} data-testid='trigger-extra-large'>
Open extra-large ("xlarge")
</Button>
<ModalDialog
open={isOpenExtraLarge}
onClose={hideModalExtraLarge}
size='xlarge'
/>

<Button onClick={showModalFullscreen} data-testid='trigger-full-screen'>
Open full-screen
</Button>
Expand Down
6 changes: 6 additions & 0 deletions packages/picasso/src/Modal/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export default ({ screens, sizes }: Theme) =>
maxWidth,
},
},
xsmall: {
width: '20.5rem',
},
small: {
width: '32.5rem',
},
Expand All @@ -41,6 +44,9 @@ export default ({ screens, sizes }: Theme) =>
large: {
width: '50rem',
},
xlarge: {
width: '75rem',
},
'full-screen': {
height: '100%',
width: '100%',
Expand Down

0 comments on commit 8be81c2

Please sign in to comment.