Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jul 31, 2020
1 parent 24e3bbf commit f8f49c2
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 61 deletions.
2 changes: 1 addition & 1 deletion docs/pages/api-docs/snackbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The `MuiSnackbar` name can be used for providing [default props](/customization/
| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">action</span> | <span class="prop-type">node</span> | | The action to display. It renders after the message, at the end of the snackbar. |
| <span class="prop-name">anchorOrigin</span> | <span class="prop-type">{ horizontal: 'center'<br>&#124;&nbsp;'default'<br>&#124;&nbsp;'left'<br>&#124;&nbsp;'right', vertical: 'bottom'<br>&#124;&nbsp;'top' }</span> | <span class="prop-default">{ vertical: 'bottom', horizontal: 'default' }</span> | The anchor of the `Snackbar`. The `Snackbar` is placed by default bottom center on Mobile and bottom left on Desktop |
| <span class="prop-name">anchorOrigin</span> | <span class="prop-type">{ horizontal: 'center'<br>&#124;&nbsp;'left'<br>&#124;&nbsp;'right', vertical: 'bottom'<br>&#124;&nbsp;'top' }</span> | <span class="prop-default">{ vertical: 'bottom', horizontal: 'left' }</span> | The anchor of the `Snackbar`. |
| <span class="prop-name">autoHideDuration</span> | <span class="prop-type">number</span> | <span class="prop-default">null</span> | The number of milliseconds to wait before automatically calling the `onClose` function. `onClose` should then set the state of the `open` prop to hide the Snackbar. This behavior is disabled by default with the `null` value. |
| <span class="prop-name">children</span> | <span class="prop-type">element</span> | | Replace the `SnackbarContent` component. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
Expand Down
4 changes: 0 additions & 4 deletions docs/src/pages/components/snackbars/ConsecutiveSnackbars.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ export default function ConsecutiveSnackbars() {
<Button onClick={handleClick('Message B')}>Show message B</Button>
<Snackbar
key={messageInfo ? messageInfo.key : undefined}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
open={open}
autoHideDuration={6000}
onClose={handleClose}
Expand Down
4 changes: 0 additions & 4 deletions docs/src/pages/components/snackbars/ConsecutiveSnackbars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ export default function ConsecutiveSnackbars() {
<Button onClick={handleClick('Message B')}>Show message B</Button>
<Snackbar
key={messageInfo ? messageInfo.key : undefined}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
open={open}
autoHideDuration={6000}
onClose={handleClose}
Expand Down
36 changes: 17 additions & 19 deletions docs/src/pages/components/snackbars/SimpleSnackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,31 @@ export default function SimpleSnackbar() {
setOpen(false);
};

const action = (
<React.Fragment>
<Button color="secondary" size="small" onClick={handleClose}>
UNDO
</Button>
<IconButton
size="small"
aria-label="close"
color="inherit"
onClick={handleClose}
>
<CloseIcon fontSize="small" />
</IconButton>
</React.Fragment>
);

return (
<div>
<Button onClick={handleClick}>Open simple snackbar</Button>
<Snackbar
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
open={open}
autoHideDuration={6000}
onClose={handleClose}
message="Note archived"
action={
<React.Fragment>
<Button color="secondary" size="small" onClick={handleClose}>
UNDO
</Button>
<IconButton
size="small"
aria-label="close"
color="inherit"
onClick={handleClose}
>
<CloseIcon fontSize="small" />
</IconButton>
</React.Fragment>
}
action={action}
/>
</div>
);
Expand Down
36 changes: 17 additions & 19 deletions docs/src/pages/components/snackbars/SimpleSnackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,31 @@ export default function SimpleSnackbar() {
setOpen(false);
};

const action = (
<React.Fragment>
<Button color="secondary" size="small" onClick={handleClose}>
UNDO
</Button>
<IconButton
size="small"
aria-label="close"
color="inherit"
onClick={handleClose}
>
<CloseIcon fontSize="small" />
</IconButton>
</React.Fragment>
);

return (
<div>
<Button onClick={handleClick}>Open simple snackbar</Button>
<Snackbar
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
open={open}
autoHideDuration={6000}
onClose={handleClose}
message="Note archived"
action={
<React.Fragment>
<Button color="secondary" size="small" onClick={handleClose}>
UNDO
</Button>
<IconButton
size="small"
aria-label="close"
color="inherit"
onClick={handleClose}
>
<CloseIcon fontSize="small" />
</IconButton>
</React.Fragment>
}
action={action}
/>
</div>
);
Expand Down
8 changes: 5 additions & 3 deletions docs/src/pages/guides/migration-v4/migration-v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ This change affects almost all components where you're using the `component` pro

### Snackbar

- The default value of `anchorOrigin` on Desktop is changed from `bottom center` to `bottom left`
- The notification now displays at the bottom left on large screens.
It better matches the behavior of Gmail, Google Keep, material.io, etc.
You can restore the previous behavior with:
```diff
-<Snackbar anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }} />
+<Snackbar anchorOrigin={{ vertical: 'bottom', horizontal: desktop ? 'left' : 'center' }} />
-<Snackbar />
+<Snackbar anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }} />
```

### TablePagination
Expand Down
3 changes: 1 addition & 2 deletions packages/material-ui/src/Snackbar/Snackbar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ClickAwayListenerProps } from '../ClickAwayListener';

export interface SnackbarOrigin {
vertical: 'top' | 'bottom';
horizontal: 'left' | 'center' | 'right' | 'default';
horizontal: 'left' | 'center' | 'right';
}

export type SnackbarCloseReason = 'timeout' | 'clickaway';
Expand All @@ -22,7 +22,6 @@ export interface SnackbarProps
action?: SnackbarContentProps['action'];
/**
* The anchor of the `Snackbar`.
* The `Snackbar` is placed by default bottom center on Mobile and bottom left on Desktop
*/
anchorOrigin?: SnackbarOrigin;
/**
Expand Down
11 changes: 2 additions & 9 deletions packages/material-ui/src/Snackbar/Snackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ export const styles = (theme) => {
right: 8,
justifyContent: 'center',
alignItems: 'center',
/* default ancohrOrigin */
...bottom1,
[theme.breakpoints.up('sm')]: {
...bottom3,
...left3,
},
},
/* Styles applied to the root element if `anchorOrigin={{ 'top', 'center' }}`. */
anchorOriginTopCenter: {
Expand Down Expand Up @@ -104,7 +98,7 @@ export const styles = (theme) => {
const Snackbar = React.forwardRef(function Snackbar(props, ref) {
const {
action,
anchorOrigin: { vertical, horizontal } = { vertical: 'bottom', horizontal: 'default' },
anchorOrigin: { vertical, horizontal } = { vertical: 'bottom', horizontal: 'left' },
autoHideDuration = null,
children,
classes,
Expand Down Expand Up @@ -271,10 +265,9 @@ Snackbar.propTypes = {
action: PropTypes.node,
/**
* The anchor of the `Snackbar`.
* The `Snackbar` is placed by default bottom center on Mobile and bottom left on Desktop
*/
anchorOrigin: PropTypes.shape({
horizontal: PropTypes.oneOf(['center', 'default', 'left', 'right']).isRequired,
horizontal: PropTypes.oneOf(['center', 'left', 'right']).isRequired,
vertical: PropTypes.oneOf(['bottom', 'top']).isRequired,
}),
/**
Expand Down

0 comments on commit f8f49c2

Please sign in to comment.