Skip to content

Commit ade58eb

Browse files
committed
[docs] Add TS versionn of WithWidth demo
1 parent a355648 commit ade58eb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
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)