Skip to content
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

[Badge] Improve demos #18981

Merged
merged 3 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions docs/src/pages/components/badges/BadgeMax.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ const useStyles = makeStyles(theme => ({
},
}));

const defaultProps = {
color: 'secondary',
children: <MailIcon />,
};

export default function BadgeMax() {
const classes = useStyles();

return (
<div className={classes.root}>
<Badge badgeContent={99} color="primary">
<MailIcon />
</Badge>
<Badge badgeContent={100} color="primary">
<MailIcon />
</Badge>
<Badge badgeContent={1000} max={999} color="primary">
<MailIcon />
</Badge>
<Badge badgeContent={99} {...defaultProps} />
<Badge badgeContent={100} {...defaultProps} />
<Badge badgeContent={1000} max={999} {...defaultProps} />
</div>
);
}
17 changes: 8 additions & 9 deletions docs/src/pages/components/badges/BadgeMax.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ const useStyles = makeStyles((theme: Theme) =>
}),
);

const defaultProps = {
color: 'secondary' as 'secondary',
children: <MailIcon />,
};

export default function BadgeMax() {
const classes = useStyles();

return (
<div className={classes.root}>
<Badge badgeContent={99} color="primary">
<MailIcon />
</Badge>
<Badge badgeContent={100} color="primary">
<MailIcon />
</Badge>
<Badge badgeContent={1000} max={999} color="primary">
<MailIcon />
</Badge>
<Badge badgeContent={99} {...defaultProps} />
<Badge badgeContent={100} {...defaultProps} />
<Badge badgeContent={1000} max={999} {...defaultProps} />
</div>
);
}
62 changes: 34 additions & 28 deletions docs/src/pages/components/badges/BadgeVisibility.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Badge from '@material-ui/core/Badge';
import ButtonGroup from '@material-ui/core/ButtonGroup';
import Button from '@material-ui/core/Button';
import AddIcon from '@material-ui/icons/Add';
import RemoveIcon from '@material-ui/icons/Remove';
import MailIcon from '@material-ui/icons/Mail';
import Switch from '@material-ui/core/Switch';
import FormGroup from '@material-ui/core/FormGroup';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Divider from '@material-ui/core/Divider';

const useStyles = makeStyles(theme => ({
root: {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
width: '100%',
},
margin: {
margin: theme.spacing(1),
},
divider: {
margin: theme.spacing(2, 0),
width: '100%',
},
row: {
marginTop: theme.spacing(2),
'& > *': {
marginBottom: theme.spacing(2),
},
'& .MuiBadge-root': {
marginRight: theme.spacing(4),
},
},
}));

export default function BadgeVisibility() {
const classes = useStyles();
const [count, setCount] = React.useState(1);
const [invisible, setInvisible] = React.useState(false);

const handleBadgeVisibility = () => {
Expand All @@ -36,28 +33,37 @@ export default function BadgeVisibility() {

return (
<div className={classes.root}>
<div className={classes.row}>
<Badge color="secondary" badgeContent={4} invisible={invisible} className={classes.margin}>
<div>
<Badge color="secondary" badgeContent={count}>
<MailIcon />
</Badge>
<Badge color="secondary" variant="dot" invisible={invisible} className={classes.margin}>
<ButtonGroup>
<Button
aria-label="reduce"
onClick={() => {
setCount(Math.max(count - 1, 0));
}}
>
<RemoveIcon fontSize="small" />
</Button>
<Button
aria-label="increase"
onClick={() => {
setCount(count + 1);
}}
>
<AddIcon fontSize="small" />
</Button>
</ButtonGroup>
</div>
<div>
<Badge color="secondary" variant="dot" invisible={invisible}>
<MailIcon />
</Badge>
</div>
<FormGroup row>
<FormControlLabel
control={<Switch color="primary" checked={!invisible} onChange={handleBadgeVisibility} />}
label="Show Badge"
/>
</FormGroup>
<Divider className={classes.divider} />
<div className={classes.row}>
<Badge color="secondary" badgeContent={0} className={classes.margin}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={0} showZero className={classes.margin}>
<MailIcon />
</Badge>
</div>
</div>
);
Expand Down
62 changes: 34 additions & 28 deletions docs/src/pages/components/badges/BadgeVisibility.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
import React from 'react';
import { Theme, createStyles, makeStyles } from '@material-ui/core/styles';
import Badge from '@material-ui/core/Badge';
import ButtonGroup from '@material-ui/core/ButtonGroup';
import Button from '@material-ui/core/Button';
import AddIcon from '@material-ui/icons/Add';
import RemoveIcon from '@material-ui/icons/Remove';
import MailIcon from '@material-ui/icons/Mail';
import Switch from '@material-ui/core/Switch';
import FormGroup from '@material-ui/core/FormGroup';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Divider from '@material-ui/core/Divider';

const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
width: '100%',
},
margin: {
margin: theme.spacing(1),
},
divider: {
margin: theme.spacing(2, 0),
width: '100%',
},
row: {
marginTop: theme.spacing(2),
'& > *': {
marginBottom: theme.spacing(2),
},
'& .MuiBadge-root': {
marginRight: theme.spacing(4),
},
},
}),
);

export default function BadgeVisibility() {
const classes = useStyles();
const [count, setCount] = React.useState(1);
const [invisible, setInvisible] = React.useState(false);

const handleBadgeVisibility = () => {
Expand All @@ -38,28 +35,37 @@ export default function BadgeVisibility() {

return (
<div className={classes.root}>
<div className={classes.row}>
<Badge color="secondary" badgeContent={4} invisible={invisible} className={classes.margin}>
<div>
<Badge color="secondary" badgeContent={count}>
<MailIcon />
</Badge>
<Badge color="secondary" variant="dot" invisible={invisible} className={classes.margin}>
<ButtonGroup>
<Button
aria-label="reduce"
onClick={() => {
setCount(Math.max(count - 1, 0));
}}
>
<RemoveIcon fontSize="small" />
</Button>
<Button
aria-label="increase"
onClick={() => {
setCount(count + 1);
}}
>
<AddIcon fontSize="small" />
</Button>
</ButtonGroup>
</div>
<div>
<Badge color="secondary" variant="dot" invisible={invisible}>
<MailIcon />
</Badge>
</div>
<FormGroup row>
<FormControlLabel
control={<Switch color="primary" checked={!invisible} onChange={handleBadgeVisibility} />}
label="Show Badge"
/>
</FormGroup>
<Divider className={classes.divider} />
<div className={classes.row}>
<Badge color="secondary" badgeContent={0} className={classes.margin}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={0} showZero className={classes.margin}>
<MailIcon />
</Badge>
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/badges/CustomizedBadges.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const StyledBadge = withStyles(theme => ({
export default function CustomizedBadges() {
return (
<IconButton aria-label="cart">
<StyledBadge badgeContent={4} color="primary">
<StyledBadge badgeContent={4} color="secondary">
<ShoppingCartIcon />
</StyledBadge>
</IconButton>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/badges/CustomizedBadges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const StyledBadge = withStyles((theme: Theme) =>
export default function CustomizedBadges() {
return (
<IconButton aria-label="cart">
<StyledBadge badgeContent={4} color="primary">
<StyledBadge badgeContent={4} color="secondary">
<ShoppingCartIcon />
</StyledBadge>
</IconButton>
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/badges/DotBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ export default function DotBadge() {

return (
<div className={classes.root}>
<Badge color="primary" variant="dot">
<MailIcon />
</Badge>
<Badge color="secondary" variant="dot">
<MailIcon />
</Badge>
<Badge color="error" variant="dot">
<Badge color="secondary" variant="dot">
<Typography>Typography</Typography>
</Badge>
</div>
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/badges/DotBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ export default function DotBadge() {

return (
<div className={classes.root}>
<Badge color="primary" variant="dot">
<MailIcon />
</Badge>
<Badge color="secondary" variant="dot">
<MailIcon />
</Badge>
<Badge color="error" variant="dot">
<Badge color="secondary" variant="dot">
<Typography>Typography</Typography>
</Badge>
</div>
Expand Down
27 changes: 27 additions & 0 deletions docs/src/pages/components/badges/ShowZeroBadge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Badge from '@material-ui/core/Badge';
import MailIcon from '@material-ui/icons/Mail';

const useStyles = makeStyles(theme => ({
root: {
'& > *': {
margin: theme.spacing(1),
},
},
}));

export default function ShowZeroBadge() {
const classes = useStyles();

return (
<div className={classes.root}>
<Badge color="secondary" badgeContent={0}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={0} showZero>
<MailIcon />
</Badge>
</div>
);
}
29 changes: 29 additions & 0 deletions docs/src/pages/components/badges/ShowZeroBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { Theme, createStyles, makeStyles } from '@material-ui/core/styles';
import Badge from '@material-ui/core/Badge';
import MailIcon from '@material-ui/icons/Mail';

const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
'& > *': {
margin: theme.spacing(1),
},
},
}),
);

export default function ShowZeroBadge() {
const classes = useStyles();

return (
<div className={classes.root}>
<Badge color="secondary" badgeContent={0}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={0} showZero>
<MailIcon />
</Badge>
</div>
);
}
11 changes: 4 additions & 7 deletions docs/src/pages/components/badges/SimpleBadge.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Badge from '@material-ui/core/Badge';
import IconButton from '@material-ui/core/IconButton';
import MailIcon from '@material-ui/icons/Mail';

const useStyles = makeStyles(theme => ({
Expand All @@ -20,14 +19,12 @@ export default function SimpleBadge() {
<Badge badgeContent={4} color="primary">
<MailIcon />
</Badge>
<Badge badgeContent={10} color="secondary">
<Badge badgeContent={4} color="secondary">
<MailIcon />
</Badge>
<Badge badgeContent={4} color="error">
<MailIcon />
</Badge>
<IconButton aria-label="4 pending messages">
<Badge badgeContent={4} color="primary">
<MailIcon />
</Badge>
</IconButton>
</div>
);
}
Loading