Skip to content

Commit 000f6d0

Browse files
committed
Adds theme
1 parent d34ddb3 commit 000f6d0

File tree

7 files changed

+129
-8
lines changed

7 files changed

+129
-8
lines changed

Diff for: .storybook/main.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
module.exports = {
22
stories: ['../client/**/*.stories.(jsx|mdx)'],
3-
addons: ['@storybook/addon-actions', '@storybook/addon-docs', '@storybook/addon-knobs', '@storybook/addon-links'],
3+
addons: [
4+
'@storybook/addon-actions',
5+
'@storybook/addon-docs',
6+
'@storybook/addon-knobs',
7+
'@storybook/addon-links',
8+
'storybook-addon-theme-playground/dist/register'
9+
],
410
webpackFinal: async config => {
511
// do mutation to the config
612

Diff for: .storybook/preview.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import { addDecorator, addParameters } from '@storybook/react';
3+
import { withKnobs } from "@storybook/addon-knobs";
4+
import { withThemePlayground } from 'storybook-addon-theme-playground';
5+
import { ThemeProvider } from "styled-components";
6+
7+
import theme, { Theme } from '../client/theme';
8+
9+
addDecorator(withKnobs);
10+
11+
const themeConfigs = Object.values(Theme).map(
12+
name => {
13+
return { name, theme: theme[name] };
14+
}
15+
);
16+
17+
addDecorator(withThemePlayground({
18+
theme: themeConfigs,
19+
provider: ThemeProvider
20+
}));
21+
22+
// addDecorator(storyFn => <ThemeProvider theme={theme}>{storyFn()}</ThemeProvider>);

Diff for: client/components/Button/index.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33
import styled from 'styled-components';
4+
import { remSize, prop } from '../../theme';
45

56
const StyledButton = styled.button`
7+
background-color: ${prop('buttonColorBackground')};
8+
color: ${prop('buttonColor')};
9+
cursor: pointer;
10+
border: 2px solid ${prop('buttonBorderColor')};
11+
border-radius: 2px;
12+
padding: ${remSize(8)} ${remSize(25)};
13+
line-height: 1;
614
margin: 0;
7-
padding: 0;
8-
border: none;
9-
background: none;
15+
16+
&:hover:not(:disabled) {
17+
color: ${prop('buttonHoverColor')};
18+
background-color: ${prop('buttonHoverColorBackground')};
19+
}
20+
21+
&:disabled {
22+
color: ${prop('buttonDisabledColor')};
23+
background-color: ${prop('buttonDisabledColorBackground')};
24+
cursor: not-allowed;
25+
}
1026
`;
1127

1228
/**
@@ -24,7 +40,7 @@ Button.propTypes = {
2440
/**
2541
If the button can be clicked or not
2642
*/
27-
disabled: PropTypes.boolean,
43+
disabled: PropTypes.bool,
2844
/*
2945
* An ARIA Label used for accessibility
3046
*/

Diff for: client/index.jsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import { render } from 'react-dom';
33
import { hot } from 'react-hot-loader/root';
44
import { Provider } from 'react-redux';
55
import { Router, browserHistory } from 'react-router';
6+
import { ThemeProvider } from 'styled-components';
7+
68
import configureStore from './store';
79
import routes from './routes';
10+
import theme, { Theme } from './theme';
811

912
require('./styles/main.scss');
1013

@@ -16,10 +19,14 @@ const initialState = window.__INITIAL_STATE__;
1619

1720
const store = configureStore(initialState);
1821

22+
const currentTheme = Theme.light;
23+
1924
const App = () => (
20-
<Provider store={store}>
21-
<Router history={history} routes={routes(store)} />
22-
</Provider>
25+
<ThemeProvider theme={{ ...theme, current: theme[currentTheme] }}>
26+
<Provider store={store}>
27+
<Router history={history} routes={routes(store)} />
28+
</Provider>
29+
</ThemeProvider>
2330
);
2431

2532
const HotApp = hot(App);

Diff for: client/theme.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
export const Theme = {
2+
contrast: 'contrast',
3+
dark: 'dark',
4+
light: 'light',
5+
};
6+
7+
export const colors = {
8+
p5pink: '#ed225d',
9+
yellow: '#f5dc23',
10+
};
11+
12+
export const common = {
13+
baseFontSize: 12
14+
};
15+
16+
export const remSize = size => `${size / common.baseFontSize}rem`;
17+
18+
export const prop = key => props => props.theme[key];
19+
20+
export default {
21+
[Theme.light]: {
22+
colors,
23+
...common,
24+
primaryTextColor: '#333',
25+
26+
buttonColor: '#f10046',
27+
buttonColorBackground: '#fff',
28+
buttonBorderColor: '#b5b5b5',
29+
buttonHoverColor: '#fff',
30+
buttonHoverColorBackground: colors.p5pink,
31+
},
32+
[Theme.dark]: {
33+
colors,
34+
...common,
35+
primaryTextColor: '#FFF',
36+
37+
buttonColor: '#f10046',
38+
buttonColorBackground: '#fff',
39+
buttonBorderColor: '#b5b5b5',
40+
buttonHoverColor: '#fff',
41+
buttonHoverColorBackground: colors.p5pink,
42+
},
43+
[Theme.contrast]: {
44+
colors,
45+
...common,
46+
primaryTextColor: '#F5DC23',
47+
48+
buttonColor: '#333',
49+
buttonColorBackground: colors.yellow,
50+
buttonBorderColor: '#b5b5b5',
51+
buttonHoverColor: '#333',
52+
buttonHoverColorBackground: '#fff',
53+
},
54+
};

Diff for: package-lock.json

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"react-test-renderer": "^16.6.0",
9494
"rimraf": "^2.6.3",
9595
"sass-loader": "^6.0.7",
96+
"storybook-addon-theme-playground": "^1.2.0",
9697
"style-loader": "^1.0.0",
9798
"terser-webpack-plugin": "^1.4.1",
9899
"webpack-cli": "^3.3.7",
@@ -185,6 +186,7 @@
185186
"slugify": "^1.3.4",
186187
"srcdoc-polyfill": "^0.2.0",
187188
"styled-components": "^5.0.0",
189+
"styled-theming": "^2.2.0",
188190
"url": "^0.11.0",
189191
"webpack": "^4.39.2",
190192
"webpack-dev-middleware": "^2.0.6",

0 commit comments

Comments
 (0)