Skip to content

Commit

Permalink
[docs] Migrate WithTheme demo to Typescript (#16941)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerclotet authored and oliviertassinari committed Aug 9, 2019
1 parent 9d30d62 commit 38c7360
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/src/pages/styles/advanced/WithTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ function DeepChildRaw(props) {
}

DeepChildRaw.propTypes = {
theme: PropTypes.object.isRequired,
theme: PropTypes.shape({
spacing: PropTypes.string.isRequired,
}).isRequired,
};

const DeepChild = withTheme(DeepChildRaw);
Expand Down
28 changes: 28 additions & 0 deletions docs/src/pages/styles/advanced/WithTheme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { ThemeProvider, WithTheme as WithThemeProps, withTheme } from '@material-ui/styles';

interface Theme {
spacing: string;
}

interface Props extends WithThemeProps<Theme> {}

function DeepChildRaw(props: Props) {
return <span>{`spacing ${props.theme.spacing}`}</span>;
}

const DeepChild = withTheme<Theme, typeof DeepChildRaw>(DeepChildRaw);

function WithTheme() {
return (
<ThemeProvider
theme={{
spacing: '8px',
}}
>
<DeepChild />
</ThemeProvider>
);
}

export default WithTheme;

0 comments on commit 38c7360

Please sign in to comment.