-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Snackbar): Modify default behavior of Snackbar and add Alert expl
- Loading branch information
Showing
3 changed files
with
106 additions
and
2 deletions.
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
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 |
---|---|---|
@@ -1 +1,76 @@ | ||
Re-export of @material-ui. See [the official API](https://v4.mui.com/api/snackbar/). | ||
```jsx | ||
import Snackbar from 'cozy-ui/transpiled/react/Snackbar' | ||
import Alert from 'cozy-ui/transpiled/react/Alert' | ||
import Button from 'cozy-ui/transpiled/react/Buttons' | ||
import CrossIcon from 'cozy-ui/transpiled/react/Icons/Cross' | ||
import IconButton from 'cozy-ui/transpiled/react/IconButton' | ||
import Typography from 'cozy-ui/transpiled/react/Typography' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
import InfoIcon from 'cozy-ui/transpiled/react/Icons/Info' | ||
|
||
initialState = { open: isTesting() } | ||
|
||
const handleToggle = () => {setState(state => ({ open: !state.open }))} | ||
|
||
; | ||
|
||
<> | ||
<Button | ||
variant="ghost" | ||
size="small" | ||
label="Open snackbar" | ||
onClick={handleToggle} | ||
/> | ||
<Snackbar | ||
open={state.open} | ||
message="This is a simple snackbar." | ||
action={ | ||
<> | ||
<Button variant="text" color="error" size="small" label="UNDO" onClick={handleToggle} /> | ||
<IconButton aria-label="close" color="inherit" onClick={handleToggle}> | ||
<Icon icon={CrossIcon} size={14} /> | ||
</IconButton> | ||
</> | ||
} | ||
onClose={handleToggle} | ||
/> | ||
</> | ||
``` | ||
|
||
### With `Alert` inside the `Snackbar` | ||
|
||
```jsx | ||
import Snackbar from 'cozy-ui/transpiled/react/Snackbar' | ||
import Alert from 'cozy-ui/transpiled/react/Alert' | ||
import Button from 'cozy-ui/transpiled/react/Buttons' | ||
import Variants from 'cozy-ui/docs/components/Variants' | ||
|
||
initialState = { open: isTesting() } | ||
|
||
const handleToggle = () => {setState(state => ({ open: !state.open }))} | ||
|
||
const colors = ['primary', 'secondary', 'success', 'error', 'warning', 'info'] | ||
const initialVariants = [{ primary: true, secondary: true, success: false, error: false, warning: false, info: false }] | ||
|
||
; | ||
|
||
<> | ||
<Variants initialVariants={initialVariants} radio screenshotAllVariants> | ||
{variant => ( | ||
<> | ||
<Snackbar open={state.open} onClose={handleToggle}> | ||
<Alert onClose={handleToggle} severity={Object.keys(variant).find(key => variant[key])}> | ||
This is a {Object.keys(variant).find(key => variant[key])} message! | ||
</Alert> | ||
</Snackbar> | ||
</> | ||
)} | ||
</Variants> | ||
<Button | ||
variant="ghost" | ||
size="small" | ||
label="Open snackbar" | ||
onClick={handleToggle} | ||
/> | ||
</> | ||
``` |
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 |
---|---|---|
@@ -1,3 +1,19 @@ | ||
import React, { forwardRef } from 'react' | ||
import MuiSnackbar from '@material-ui/core/Snackbar' | ||
|
||
export default MuiSnackbar | ||
const Snackbar = forwardRef(({ children, ...props }, ref) => { | ||
return ( | ||
<MuiSnackbar ref={ref} {...props}> | ||
{children} | ||
</MuiSnackbar> | ||
) | ||
}) | ||
|
||
Snackbar.defaultProps = { | ||
anchorOrigin: { | ||
vertical: 'top', | ||
horizontal: 'center' | ||
} | ||
} | ||
|
||
export default Snackbar |