Skip to content

Commit

Permalink
extract WithTheme for external use (#9363)
Browse files Browse the repository at this point in the history
Extract WithTheme for external use
  • Loading branch information
rosskevin authored and pelotom committed Dec 1, 2017
1 parent f69c7b5 commit 40d4142
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
36 changes: 36 additions & 0 deletions docs/src/pages/guides/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,41 @@ declare module 'material-ui/styles/createMuiTheme' {
breakpoint: Breakpoint
}
}
// allow configuration using `createMuiTheme`
interface ThemeOptions {
appDrawer?: {
width?: React.CSSProperties['width']
breakpoint?: Breakpoint
}
}
}
```

And a custom theme factory with additional defaulted options:

```js
import {default as createMuiTheme, ThemeOptions} from 'material-ui/styles/createMuiTheme'
import { merge } from 'lodash'

export default function createMyTheme(options: ThemeOptions) {
return createMuiTheme(
merge(
{
appDrawer: {
width: 225,
breakpoint: 'lg',
},
},
options,
),
)
}
```

This could be used like:

```js
import createMyTheme from './styles/createMyTheme'

const theme = createMyTheme({appDrawer: {breakpoint: 'md'}})
```
6 changes: 5 additions & 1 deletion src/styles/withTheme.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Theme } from './createMuiTheme';

export interface WithTheme {
theme: Theme
}

declare const withTheme: <P = {}>() => (
component: React.ComponentType<P & { theme: Theme }>
component: React.ComponentType<P & WithTheme>
) => React.ComponentClass<P>;

export default withTheme

0 comments on commit 40d4142

Please sign in to comment.