-
Notifications
You must be signed in to change notification settings - Fork 11
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(Drawer): new component #1306
Open
pladaria
wants to merge
17
commits into
master
Choose a base branch
from
pladaria/WEB-2113_drawer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3757136
WEB-2113 create file
46da8a7
WEB-2113 initial draft
89fee12
WEB-2113 drawer layout
e3bba8b
WEB-2113 close with esc + modal state effect
5cc29b3
WEB-2113 layout with scrollable area
fda0071
WEB-2113 fix portal, show dividers while scrolling content
1fadd9c
WEB-2113 add screenshot tests
3d89e89
WEB-2113 export + snippet
8c12f8c
WEB-2113 update screenshots
7a0f8b3
WEB-2113 cleanup
c09f8d8
WEB-2113 add unit tests
3e366b8
WEB-2113 move styles to sprinkles
83e5c9c
WEB-2113 add width arg
f5382d3
Merge branch 'master' into pladaria/WEB-2113_drawer
pladaria bf43423
WEB-2113 use bleedY in linkbutton
d0ea098
WEB-2113 use bleedY in linkbutton
07dafe9
WEB-2113 fix paddings
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+22.3 KB
...t-tsx-drawer-desktop-actions-false-dismissible-true-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+27.5 KB
...st-tsx-drawer-desktop-actions-true-dismissible-true-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+31.7 KB
...sx-drawer-mobile-ios-actions-false-dismissible-true-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+40.5 KB
...sx-drawer-mobile-ios-actions-true-dismissible-false-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+40.8 KB
...tsx-drawer-mobile-ios-actions-true-dismissible-true-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+46.6 KB
...tsx-drawer-mobile-ios-actions-true-dismissible-true-content-length-5-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.9 KB
...st-tsx-drawer-tablet-actions-false-dismissible-true-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.2 KB
...est-tsx-drawer-tablet-actions-true-dismissible-true-content-length-1-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {openStoryPage, screen} from '../test-utils'; | ||
|
||
import type {Device} from '../test-utils'; | ||
|
||
test.each` | ||
device | withActions | dismissible | contentLength | ||
${'MOBILE_IOS'} | ${true} | ${true} | ${1} | ||
${'MOBILE_IOS'} | ${true} | ${true} | ${5} | ||
${'MOBILE_IOS'} | ${true} | ${false} | ${1} | ||
${'DESKTOP'} | ${true} | ${true} | ${1} | ||
${'TABLET'} | ${true} | ${true} | ${1} | ||
${'MOBILE_IOS'} | ${false} | ${true} | ${1} | ||
${'DESKTOP'} | ${false} | ${true} | ${1} | ||
${'TABLET'} | ${false} | ${true} | ${1} | ||
`( | ||
'Drawer $device actions:$withActions dismissible:$dismissible contentLength:$contentLength', | ||
async ({device, withActions, dismissible, contentLength}) => { | ||
const page = await openStoryPage({ | ||
id: 'components-modals-drawer--default', | ||
device: device as Device, | ||
args: { | ||
showButton: withActions, | ||
showSecondaryButton: withActions, | ||
showButtonLink: withActions, | ||
onDismissHandler: dismissible, | ||
contentLength, | ||
}, | ||
}); | ||
|
||
const button = await screen.findByRole('button', {name: 'Open Drawer'}); | ||
await button.click(); | ||
|
||
const image = await page.screenshot(); | ||
expect(image).toMatchImageSnapshot(); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import * as React from 'react'; | ||
import Drawer from '../drawer'; | ||
import {Placeholder} from '../placeholder'; | ||
import Stack from '../stack'; | ||
import {ButtonPrimary} from '../button'; | ||
import {Text3} from '../text'; | ||
|
||
export default { | ||
title: 'Components/Modals/Drawer', | ||
component: Drawer, | ||
argTypes: { | ||
width: { | ||
control: {type: 'range', min: 0, max: 1000, step: 1}, | ||
}, | ||
}, | ||
}; | ||
|
||
type Args = { | ||
title: string; | ||
subtitle: string; | ||
description: string; | ||
contentLength: number; | ||
onDismissHandler: boolean; | ||
showButton: boolean; | ||
showSecondaryButton: boolean; | ||
showButtonLink: boolean; | ||
width: number; | ||
}; | ||
|
||
export const Default = ({ | ||
title, | ||
subtitle, | ||
description, | ||
contentLength, | ||
onDismissHandler, | ||
showButton, | ||
showSecondaryButton, | ||
showButtonLink, | ||
width, | ||
}: Args): JSX.Element => { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
const [result, setResult] = React.useState(''); | ||
const content = ( | ||
<Stack space={16}> | ||
{Array.from({length: contentLength}).map((_, index) => ( | ||
<Placeholder key={index} height={200} /> | ||
))} | ||
</Stack> | ||
); | ||
|
||
return ( | ||
<> | ||
<Stack space={16}> | ||
<ButtonPrimary onPress={() => setIsOpen(true)}>Open Drawer</ButtonPrimary> | ||
<Text3 regular> | ||
Result: <span data-testid="result">{result}</span> | ||
</Text3> | ||
</Stack> | ||
{isOpen && ( | ||
<Drawer | ||
width={width} | ||
title={title} | ||
subtitle={subtitle} | ||
description={description} | ||
onClose={() => setIsOpen(false)} | ||
onDismiss={onDismissHandler ? () => setResult('dismiss') : undefined} | ||
button={showButton ? {text: 'Primary', onPress: () => setResult('primary')} : undefined} | ||
secondaryButton={ | ||
showSecondaryButton | ||
? {text: 'Secondary', onPress: () => setResult('secondary')} | ||
: undefined | ||
} | ||
buttonLink={showButtonLink ? {text: 'Link', onPress: () => setResult('link')} : undefined} | ||
> | ||
{content} | ||
</Drawer> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
Default.storyName = 'Drawer'; | ||
|
||
Default.args = { | ||
title: 'Title', | ||
subtitle: 'Subtitle', | ||
description: 'Description', | ||
contentLength: 2, | ||
onDismissHandler: true, | ||
showButton: true, | ||
showSecondaryButton: true, | ||
showButtonLink: true, | ||
width: 0, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import * as React from 'react'; | ||
import {makeTheme} from './test-utils'; | ||
import {render, screen, waitFor} from '@testing-library/react'; | ||
import ThemeContextProvider from '../theme-context-provider'; | ||
import Drawer from '../drawer'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
const DrawerTest = ({ | ||
onDismiss, | ||
onButtonPrimaryPress, | ||
onButtonSecondaryPress, | ||
onButtonLinkPress, | ||
}: { | ||
onDismiss?: () => void; | ||
onButtonPrimaryPress?: () => void; | ||
onButtonSecondaryPress?: () => void; | ||
onButtonLinkPress?: () => void; | ||
}) => { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
return ( | ||
<ThemeContextProvider theme={makeTheme()}> | ||
<button onClick={() => setIsOpen(true)}>open</button> | ||
{isOpen && ( | ||
<Drawer | ||
dismissLabel="CustomDismissLabel" | ||
onDismiss={onDismiss} | ||
onClose={() => setIsOpen(false)} | ||
button={{text: 'Primary', onPress: onButtonPrimaryPress}} | ||
secondaryButton={{text: 'Secondary', onPress: onButtonSecondaryPress}} | ||
buttonLink={{text: 'Link', onPress: onButtonLinkPress}} | ||
/> | ||
)} | ||
</ThemeContextProvider> | ||
); | ||
}; | ||
|
||
test.each(['esc', 'overlay', 'x'])('Drawer dismiss: %s', async (dismissMethod: string) => { | ||
const onDismissSpy = jest.fn(); | ||
render(<DrawerTest onDismiss={onDismissSpy} />); | ||
|
||
const openButton = screen.getByRole('button', {name: 'open'}); | ||
await userEvent.click(openButton); | ||
|
||
const drawer = await screen.findByRole('dialog'); | ||
|
||
switch (dismissMethod) { | ||
case 'esc': | ||
await userEvent.keyboard('{Escape}'); | ||
break; | ||
case 'overlay': | ||
await userEvent.click(screen.getByTestId('drawerOverlay')); | ||
break; | ||
case 'x': | ||
await userEvent.click(screen.getByRole('button', {name: 'CustomDismissLabel'})); | ||
break; | ||
default: | ||
throw new Error('unexpected dismiss method'); | ||
} | ||
|
||
await waitFor(() => { | ||
expect(onDismissSpy).toHaveBeenCalledTimes(1); | ||
expect(drawer).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test.each(['primary', 'secondary', 'link'])('Drawer close: %s', async (closeMethod: string) => { | ||
const onButtonPrimaryPress = jest.fn(); | ||
const onButtonSecondaryPress = jest.fn(); | ||
const onButtonLinkPress = jest.fn(); | ||
|
||
render( | ||
<DrawerTest | ||
onButtonPrimaryPress={onButtonPrimaryPress} | ||
onButtonSecondaryPress={onButtonSecondaryPress} | ||
onButtonLinkPress={onButtonLinkPress} | ||
/> | ||
); | ||
|
||
const openButton = screen.getByRole('button', {name: 'open'}); | ||
await userEvent.click(openButton); | ||
|
||
const drawer = await screen.findByRole('dialog'); | ||
|
||
switch (closeMethod) { | ||
case 'primary': | ||
await userEvent.click(screen.getByRole('button', {name: 'Primary'})); | ||
break; | ||
case 'secondary': | ||
await userEvent.click(screen.getByRole('button', {name: 'Secondary'})); | ||
break; | ||
case 'link': | ||
await userEvent.click(screen.getByRole('button', {name: 'Link'})); | ||
break; | ||
default: | ||
throw new Error('unexpected dismiss method'); | ||
} | ||
|
||
await waitFor(() => { | ||
expect(drawer).not.toBeInTheDocument(); | ||
}); | ||
|
||
switch (closeMethod) { | ||
case 'primary': | ||
expect(onButtonPrimaryPress).toHaveBeenCalledTimes(1); | ||
break; | ||
case 'secondary': | ||
expect(onButtonSecondaryPress).toHaveBeenCalledTimes(1); | ||
break; | ||
case 'link': | ||
expect(onButtonLinkPress).toHaveBeenCalledTimes(1); | ||
break; | ||
default: | ||
throw new Error('unexpected dismiss method'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these defined in the spec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in spec, but I was assuming the same testids for these elements that we were using in cards, etc