-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Typescript migration of snackbar stories (#808)
* 🚚 Rename to tsx * ♻️ Use typescript in Snackbar story * 📝 Add SnackbarAction as a subcomponent * ♻️ Refactor to named function * ♻️ Code with typescript error in story. Use FC for some alignment with components without refs * ♻️ Export only the type of the Snackbar itself for the Story
- Loading branch information
Showing
6 changed files
with
81 additions
and
116 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,64 @@ | ||
import React, { useState } from 'react' | ||
import { Snackbar, SnackbarProps, Button } from '@equinor/eds-core-react' | ||
import { Story, Meta } from '@storybook/react' | ||
|
||
const { SnackbarAction } = Snackbar | ||
|
||
export default { | ||
title: 'Components/Snackbar', | ||
component: Snackbar, | ||
subcomponents: { SnackbarAction }, | ||
} as Meta | ||
|
||
export const Default: Story<SnackbarProps> = (args) => { | ||
const { open } = args | ||
const [visible, setVisible] = useState(open) | ||
return ( | ||
<> | ||
<Button type="button" onClick={() => setVisible(true)}> | ||
Show a simple snackbar with default options | ||
</Button> | ||
<Snackbar {...args} open={visible} onClose={() => setVisible(false)}> | ||
Play with me | ||
</Snackbar> | ||
</> | ||
) | ||
} | ||
export const Simple: Story<SnackbarProps> = () => { | ||
const [open, setOpen] = useState(false) | ||
|
||
return ( | ||
<> | ||
<Button type="button" onClick={() => setOpen(true)}> | ||
Show a simple snackbar for 5 seconds | ||
</Button> | ||
<Snackbar | ||
open={open} | ||
onClose={() => setOpen(false)} | ||
autoHideDuration={5000} | ||
leftAlignFrom="1500px" | ||
> | ||
Message goes here | ||
</Snackbar> | ||
</> | ||
) | ||
} | ||
|
||
export const WithAction: Story<SnackbarProps> = () => { | ||
const [withActionOpen, setWithActionOpen] = useState(false) | ||
return ( | ||
<> | ||
<Button type="button" onClick={() => setWithActionOpen(true)}> | ||
Show a snackbar with action for the default 7 seconds | ||
</Button> | ||
<Snackbar open={withActionOpen} onClose={() => setWithActionOpen(false)}> | ||
Your changes was saved | ||
<SnackbarAction> | ||
<Button variant="ghost">Undo</Button> | ||
</SnackbarAction> | ||
</Snackbar> | ||
</> | ||
) | ||
} | ||
|
||
WithAction.storyName = 'With action' |
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
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
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
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