diff options
author | 2019-01-09 11:05:32 +0100 | |
---|---|---|
committer | 2019-01-09 11:05:32 +0100 | |
commit | 2c514e58eabd71af280b727514dccb7c8db4e6cf (patch) | |
tree | b9677f450fe300c6ff16d1ea1e2af7ea35a7bc02 /uidev/src/withTheme/index.tsx | |
parent | Make packages work in electron, node and web (diff) | |
download | ferdium-app-2c514e58eabd71af280b727514dccb7c8db4e6cf.tar.gz ferdium-app-2c514e58eabd71af280b727514dccb7c8db4e6cf.tar.zst ferdium-app-2c514e58eabd71af280b727514dccb7c8db4e6cf.zip |
Finalize packages & replace storybook with homegrown `uidev`
Diffstat (limited to 'uidev/src/withTheme/index.tsx')
-rw-r--r-- | uidev/src/withTheme/index.tsx | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/uidev/src/withTheme/index.tsx b/uidev/src/withTheme/index.tsx new file mode 100644 index 000000000..17a1074d3 --- /dev/null +++ b/uidev/src/withTheme/index.tsx | |||
@@ -0,0 +1,50 @@ | |||
1 | import { theme, Theme, ThemeType } from '@meetfranz/theme'; | ||
2 | import { Classes } from 'jss'; | ||
3 | import React from 'react'; | ||
4 | import injectSheet, { ThemeProvider } from 'react-jss'; | ||
5 | |||
6 | const defaultTheme = { | ||
7 | name: 'Default', | ||
8 | variables: theme(ThemeType.default), | ||
9 | }; | ||
10 | |||
11 | const darkTheme = { | ||
12 | name: 'Dark Mode', | ||
13 | variables: theme(ThemeType.dark), | ||
14 | }; | ||
15 | |||
16 | const themes = [defaultTheme, darkTheme]; | ||
17 | |||
18 | const styles = (theme: Theme) => ({ | ||
19 | title: { | ||
20 | fontSize: 14, | ||
21 | }, | ||
22 | container: { | ||
23 | border: theme.inputBorder, | ||
24 | borderRadius: theme.borderRadiusSmall, | ||
25 | marginBottom: 20, | ||
26 | padding: 20, | ||
27 | background: theme.colorContentBackground, | ||
28 | }, | ||
29 | }); | ||
30 | |||
31 | const Container = injectSheet(styles)(({ name, classes, story }: { name: string, classes: Classes, story: React.ReactNode }) => ( | ||
32 | <article> | ||
33 | <h1 className={classes.title}>{name}</h1> | ||
34 | <div className={classes.container}> | ||
35 | {story} | ||
36 | </div> | ||
37 | </article> | ||
38 | )); | ||
39 | |||
40 | export const WithTheme = ({ children }: {children: React.ReactChild}) => { | ||
41 | return ( | ||
42 | <> | ||
43 | {themes.map((theme, key) => ( | ||
44 | <ThemeProvider key={key} theme={theme.variables}> | ||
45 | <Container story={children} name={theme.name} /> | ||
46 | </ThemeProvider> | ||
47 | ))} | ||
48 | </> | ||
49 | ); | ||
50 | }; | ||