Skip to content

Commit c688f3a

Browse files
burtyisheps1lon
authored andcommitted
[docs] Add TS demo for WithWidth (#17930)
1 parent 702cde3 commit c688f3a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

docs/src/pages/customization/breakpoints/WithWidth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function WithWidth(props) {
2121
}
2222

2323
WithWidth.propTypes = {
24-
width: PropTypes.string.isRequired,
24+
width: PropTypes.oneOf(['lg', 'md', 'sm', 'xl', 'xs']).isRequired,
2525
};
2626

2727
export default withWidth()(WithWidth);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import withWidth from '@material-ui/core/withWidth';
3+
import Typography from '@material-ui/core/Typography';
4+
import { Breakpoint } from '@material-ui/core/styles/createBreakpoints';
5+
6+
type TagName = 'em' | 'u' | 'del';
7+
8+
const components: Partial<Record<Breakpoint, TagName>> = {
9+
sm: 'em',
10+
md: 'u',
11+
lg: 'del',
12+
};
13+
14+
function WithWidth(props: { width: Breakpoint }) {
15+
const { width } = props;
16+
const Component = components[width] || 'span';
17+
18+
return (
19+
<Typography variant="subtitle1">
20+
<Component>{`Current width: ${width}`}</Component>
21+
</Typography>
22+
);
23+
}
24+
25+
export default withWidth()(WithWidth);

0 commit comments

Comments
 (0)