Skip to content

Commit 38c7360

Browse files
rogerclotetoliviertassinari
authored andcommitted
[docs] Migrate WithTheme demo to Typescript (#16941)
1 parent 9d30d62 commit 38c7360

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

docs/src/pages/styles/advanced/WithTheme.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ function DeepChildRaw(props) {
77
}
88

99
DeepChildRaw.propTypes = {
10-
theme: PropTypes.object.isRequired,
10+
theme: PropTypes.shape({
11+
spacing: PropTypes.string.isRequired,
12+
}).isRequired,
1113
};
1214

1315
const DeepChild = withTheme(DeepChildRaw);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import { ThemeProvider, WithTheme as WithThemeProps, withTheme } from '@material-ui/styles';
3+
4+
interface Theme {
5+
spacing: string;
6+
}
7+
8+
interface Props extends WithThemeProps<Theme> {}
9+
10+
function DeepChildRaw(props: Props) {
11+
return <span>{`spacing ${props.theme.spacing}`}</span>;
12+
}
13+
14+
const DeepChild = withTheme<Theme, typeof DeepChildRaw>(DeepChildRaw);
15+
16+
function WithTheme() {
17+
return (
18+
<ThemeProvider
19+
theme={{
20+
spacing: '8px',
21+
}}
22+
>
23+
<DeepChild />
24+
</ThemeProvider>
25+
);
26+
}
27+
28+
export default WithTheme;

0 commit comments

Comments
 (0)