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

[docs] Add accessibility section to Badges #26009

Merged
merged 5 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
30 changes: 30 additions & 0 deletions docs/src/pages/components/badges/AccessibleBadges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import IconButton from '@material-ui/core/IconButton';
import Badge from '@material-ui/core/Badge';
import MailIcon from '@material-ui/icons/Mail';

function notificationsLabel(count) {
if (count === 0) {
return 'no notifications';
}
if (count > 99) {
return 'more than 99 notifications';
}
return `${count} notifications`;
}

const preventDefault = (event) => event.preventDefault();

export default function AccessibleBadges() {
return (
<IconButton
aria-label={notificationsLabel(100)}
href="/inbox"
onClick={preventDefault}
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
>
<Badge badgeContent={100} color="secondary">
<MailIcon />
</Badge>
</IconButton>
);
}
30 changes: 30 additions & 0 deletions docs/src/pages/components/badges/AccessibleBadges.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import IconButton from '@material-ui/core/IconButton';
import Badge from '@material-ui/core/Badge';
import MailIcon from '@material-ui/icons/Mail';

function notificationsLabel(count: number) {
if (count === 0) {
return 'no notifications';
}
if (count > 99) {
return 'more than 99 notifications';
}
return `${count} notifications`;
}

const preventDefault = (event: React.SyntheticEvent) => event.preventDefault();

export default function AccessibleBadges() {
return (
<IconButton
aria-label={notificationsLabel(100)}
href="/inbox"
onClick={preventDefault}
>
<Badge badgeContent={100} color="secondary">
<MailIcon />
</Badge>
</IconButton>
);
}
1 change: 1 addition & 0 deletions docs/src/pages/components/badges/BadgeAlignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default function BadgeAlignment() {
sx={{
display: 'flex',
justifyContent: 'center',
color: 'action.active',
'& > *': {
margin: 2,
},
Expand Down
29 changes: 12 additions & 17 deletions docs/src/pages/components/badges/BadgeMax.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';
import Stack from '@material-ui/core/Stack';
import Badge from '@material-ui/core/Badge';
import MailIcon from '@material-ui/icons/Mail';

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

export default function BadgeMax() {
return (
<Box
sx={{
'& > *': {
margin: 2,
},
}}
>
<Badge badgeContent={99} {...defaultProps} />
<Badge badgeContent={100} {...defaultProps} />
<Badge badgeContent={1000} max={999} {...defaultProps} />
</Box>
<Stack spacing={4} direction="row" sx={{ color: 'action.active' }}>
<Badge color="secondary" badgeContent={99}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={100}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={1000} max={999}>
<MailIcon />
</Badge>
</Stack>
);
}
29 changes: 12 additions & 17 deletions docs/src/pages/components/badges/BadgeMax.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';
import Stack from '@material-ui/core/Stack';
import Badge from '@material-ui/core/Badge';
import MailIcon from '@material-ui/icons/Mail';

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

export default function BadgeMax() {
return (
<Box
sx={{
'& > *': {
margin: 2,
},
}}
>
<Badge badgeContent={99} {...defaultProps} />
<Badge badgeContent={100} {...defaultProps} />
<Badge badgeContent={1000} max={999} {...defaultProps} />
</Box>
<Stack spacing={4} direction="row" sx={{ color: 'action.active' }}>
<Badge color="secondary" badgeContent={99}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={100}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={1000} max={999}>
<MailIcon />
</Badge>
</Stack>
);
}
18 changes: 7 additions & 11 deletions docs/src/pages/components/badges/BadgeOverlap.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';
import Stack from '@material-ui/core/Stack';
import Badge from '@material-ui/core/Badge';

const shapeStyles = { bgcolor: 'primary.main', width: 40, height: 40 };
const shapeCircleStyles = { borderRadius: '50%' };
const rectangle = <Box component="span" sx={shapeStyles} />;
const circle = (
<Box component="span" sx={{ ...shapeStyles, ...shapeCircleStyles }} />
);

export default function BadgeOverlap() {
const rectangle = <Box sx={shapeStyles} />;
const circle = <Box sx={{ ...shapeStyles, ...shapeCircleStyles }} />;

return (
<Box
sx={{
'& > *': {
margin: 1,
},
}}
>
<Stack spacing={3} direction="row">
<Badge color="secondary" badgeContent=" ">
{rectangle}
</Badge>
Expand All @@ -29,6 +25,6 @@ export default function BadgeOverlap() {
<Badge color="secondary" overlap="circular" badgeContent=" " variant="dot">
{circle}
</Badge>
</Box>
</Stack>
);
}
18 changes: 7 additions & 11 deletions docs/src/pages/components/badges/BadgeOverlap.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';
import Stack from '@material-ui/core/Stack';
import Badge from '@material-ui/core/Badge';

const shapeStyles = { bgcolor: 'primary.main', width: 40, height: 40 };
const shapeCircleStyles = { borderRadius: '50%' };
const rectangle = <Box component="span" sx={shapeStyles} />;
const circle = (
<Box component="span" sx={{ ...shapeStyles, ...shapeCircleStyles }} />
);

export default function BadgeOverlap() {
const rectangle = <Box sx={shapeStyles} />;
const circle = <Box sx={{ ...shapeStyles, ...shapeCircleStyles }} />;

return (
<Box
sx={{
'& > *': {
margin: 1,
},
}}
>
<Stack spacing={3} direction="row">
<Badge color="secondary" badgeContent=" ">
{rectangle}
</Badge>
Expand All @@ -29,6 +25,6 @@ export default function BadgeOverlap() {
<Badge color="secondary" overlap="circular" badgeContent=" " variant="dot">
{circle}
</Badge>
</Box>
</Stack>
);
}
2 changes: 2 additions & 0 deletions docs/src/pages/components/badges/BadgeVisibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function BadgeVisibility() {
return (
<Box
sx={{
color: 'action.active',
display: 'flex',
flexDirection: 'column',
'& > *': {
Expand Down Expand Up @@ -58,6 +59,7 @@ export default function BadgeVisibility() {
<MailIcon />
</Badge>
<FormControlLabel
sx={{ color: 'text.primary' }}
control={<Switch checked={!invisible} onChange={handleBadgeVisibility} />}
label="Show Badge"
/>
Expand Down
2 changes: 2 additions & 0 deletions docs/src/pages/components/badges/BadgeVisibility.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function BadgeVisibility() {
return (
<Box
sx={{
color: 'action.active',
display: 'flex',
flexDirection: 'column',
'& > *': {
Expand Down Expand Up @@ -58,6 +59,7 @@ export default function BadgeVisibility() {
<MailIcon />
</Badge>
<FormControlLabel
sx={{ color: 'text.primary' }}
control={<Switch checked={!invisible} onChange={handleBadgeVisibility} />}
label="Show Badge"
/>
Expand Down
12 changes: 1 addition & 11 deletions docs/src/pages/components/badges/DotBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@ import * as React from 'react';
import Box from '@material-ui/core/Box';
import Badge from '@material-ui/core/Badge';
import MailIcon from '@material-ui/icons/Mail';
import Typography from '@material-ui/core/Typography';

export default function DotBadge() {
return (
<Box
sx={{
'& > *': {
m: 1,
},
}}
>
<Box sx={{ color: 'action.active' }}>
<Badge color="secondary" variant="dot">
<MailIcon />
</Badge>
<Badge color="secondary" variant="dot">
<Typography>Typography</Typography>
</Badge>
</Box>
);
}
12 changes: 1 addition & 11 deletions docs/src/pages/components/badges/DotBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@ import * as React from 'react';
import Box from '@material-ui/core/Box';
import Badge from '@material-ui/core/Badge';
import MailIcon from '@material-ui/icons/Mail';
import Typography from '@material-ui/core/Typography';

export default function DotBadge() {
return (
<Box
sx={{
'& > *': {
m: 1,
},
}}
>
<Box sx={{ color: 'action.active' }}>
<Badge color="secondary" variant="dot">
<MailIcon />
</Badge>
<Badge color="secondary" variant="dot">
<Typography>Typography</Typography>
</Badge>
</Box>
);
}
12 changes: 3 additions & 9 deletions docs/src/pages/components/badges/ShowZeroBadge.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';
import Stack from '@material-ui/core/Stack';
import Badge from '@material-ui/core/Badge';
import MailIcon from '@material-ui/icons/Mail';

export default function ShowZeroBadge() {
return (
<Box
sx={{
'& > *': {
m: 1,
},
}}
>
<Stack spacing={4} direction="row" sx={{ color: 'action.active' }}>
<Badge color="secondary" badgeContent={0}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={0} showZero>
<MailIcon />
</Badge>
</Box>
</Stack>
);
}
12 changes: 3 additions & 9 deletions docs/src/pages/components/badges/ShowZeroBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';
import Stack from '@material-ui/core/Stack';
import Badge from '@material-ui/core/Badge';
import MailIcon from '@material-ui/icons/Mail';

export default function ShowZeroBadge() {
return (
<Box
sx={{
'& > *': {
m: 1,
},
}}
>
<Stack spacing={4} direction="row" sx={{ color: 'action.active' }}>
<Badge color="secondary" badgeContent={0}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={0} showZero>
<MailIcon />
</Badge>
</Box>
</Stack>
);
}
15 changes: 3 additions & 12 deletions docs/src/pages/components/badges/SimpleBadge.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
import * as React from 'react';
import Box from '@material-ui/core/Box';
import Stack from '@material-ui/core/Stack';
import Badge from '@material-ui/core/Badge';
import MailIcon from '@material-ui/icons/Mail';

export default function SimpleBadge() {
return (
<Box
sx={{
'& > *': {
m: 1,
},
}}
>
<Badge badgeContent={4} color="primary">
<MailIcon />
</Badge>
<Stack spacing={4} direction="row" sx={{ color: 'action.active' }}>
<Badge badgeContent={4} color="secondary">
<MailIcon />
</Badge>
<Badge badgeContent={4} color="error">
<MailIcon />
</Badge>
</Box>
</Stack>
);
}
Loading