Skip to content

Commit 1e5d697

Browse files
committed
style card and button with new theme package
1 parent 1493036 commit 1e5d697

30 files changed

+325
-29
lines changed

.storybook/addons.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import '@storybook/addon-knobs/register'
44
import '@storybook/addon-viewport/register'
55
import 'storybook-addon-jsx/register'
66
import '@storybook/addon-storysource/register'
7-
import '@storybook/addon-backgrounds/register'
7+
// import '@storybook/addon-backgrounds/register'
88
import '@storybook/addon-options/register'

.storybook/config.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ configureViewport({
3636
},
3737
})
3838

39-
addDecorator(
40-
withBackgrounds([
41-
{ name: 'gray', value: '#efefef' },
42-
{ name: 'white', value: '#fff', default: true },
43-
]),
44-
)
39+
// NOTE: does not work when using <GlobalStyles /> in a story
40+
// addDecorator(
41+
// withBackgrounds([
42+
// { name: 'gray', value: '#efefef' },
43+
// { name: 'white', value: '#fff', default: true },
44+
// ]),
45+
// )
4546

4647
setAddon(JSXAddon)
4748

.storybook/preview-head.html

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- register fonts or other assets here -->
2+
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

packages/button/package.json packages/base/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "@natterstefan/ns-button-js",
2+
"name": "@natterstefan/ns-base-js",
33
"version": "0.1.0",
4-
"description": "Example button component",
4+
"description": "Example base components",
55
"main": "lib/index.js",
66
"module": "src/index.js",
77
"files": ["dist", "es", "esm", "lib"],
@@ -29,6 +29,7 @@
2929
"author": "Stefan Natter",
3030
"license": "MIT",
3131
"dependencies": {
32+
"lodash": "^4.17.11",
3233
"react": "^16.8.1",
3334
"styled-components": "^4.1.3"
3435
}

packages/button/src/index.js packages/base/src/components/button/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import React from 'react'
2+
import { get } from 'lodash'
23
import styled from 'styled-components'
34

45
export const StyledButton = styled.button`
5-
border: 1px solid #000;
6+
border: 2px solid ${props => get(props, 'theme.colors.accent') || '#000'};
7+
border-radius: 5px;
68
padding: 10px;
9+
margin-top: 10px;
710
811
:hover {
9-
border: 2px solid blue;
1012
cursor: pointer;
13+
border-color: ${props => get(props, 'theme.colors.secondary') || '#000'};
1114
font-weight: 700;
1215
}
1316

packages/button/src/index.stories.js packages/base/src/components/button/index.stories.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { storiesOf } from '@storybook/react'
33
import { action } from '@storybook/addon-actions'
44
import { withKnobs, text } from '@storybook/addon-knobs'
55
import { withReadme } from 'storybook-readme'
6+
import { ThemeProvider } from 'styled-components'
67

7-
import ButtonReadme from '../README.md'
8+
import { GlobalStyle, theme } from '../../../../theme/src'
9+
import ButtonReadme from '../../../README.md'
810

911
import Button from '.'
1012

@@ -23,10 +25,13 @@ const StoryComponent = () => {
2325
}
2426

2527
return (
26-
<div>
27-
<p>You clicked {count} times</p>
28-
<Button onClick={onClick}>{buttonText}</Button>
29-
</div>
28+
<ThemeProvider theme={theme}>
29+
<div style={{ margin: '0 auto', width: '300px' }}>
30+
<GlobalStyle />
31+
<p>You clicked {count} times</p>
32+
<Button onClick={onClick}>{buttonText}</Button>
33+
</div>
34+
</ThemeProvider>
3035
)
3136
}
3237

@@ -35,6 +40,13 @@ storiesOf('Button', module)
3540
.addDecorator(withReadme(ButtonReadme))
3641
.addWithJSX('default', () => {
3742
const buttonText = text('text', 'Click me')
38-
return <Button onClick={onClickHandler}>{buttonText}</Button>
43+
return (
44+
<ThemeProvider theme={theme}>
45+
<div style={{ margin: '0 auto', width: '300px' }}>
46+
<GlobalStyle />
47+
<Button onClick={onClickHandler}>{buttonText}</Button>
48+
</div>
49+
</ThemeProvider>
50+
)
3951
})
4052
.addWithJSX('with click counter (hooks)', () => <StoryComponent />)

packages/base/src/components/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './button'

packages/base/src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './components'
File renamed without changes.

packages/card/package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
"description": "Example card component",
55
"main": "lib/index.js",
66
"module": "src/index.js",
7-
"files": ["dist", "es", "esm", "lib"],
7+
"files": [
8+
"dist",
9+
"es",
10+
"esm",
11+
"lib"
12+
],
813
"directories": {
914
"lib": "src"
1015
},
@@ -29,7 +34,8 @@
2934
"author": "Stefan Natter",
3035
"license": "MIT",
3136
"dependencies": {
32-
"@natterstefan/ns-button-js": "^0.1.0",
37+
"@natterstefan/ns-base-js": "^0.1.0",
38+
"lodash": "^4.17.11",
3339
"react": "^16.8.1",
3440
"styled-components": "^4.1.3"
3541
}

packages/card/src/index.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
import React from 'react'
2+
import { get } from 'lodash'
23
import styled from 'styled-components'
3-
import Button from '@natterstefan/ns-button-js'
4+
import { Button } from '@natterstefan/ns-base-js'
45

56
export const StyledCard = styled.div`
6-
border: 1px solid black;
7-
padding: 0 10px 15px;
7+
border: 5px solid ${props => get(props, 'theme.Card.borderColor') || '#000'};
8+
border-radius: 10px;
9+
padding: 20px;
810
text-align: center;
11+
12+
h1 {
13+
color: ${props => get(props, 'theme.colors.primary') || 'inherit'};
14+
margin-bottom: 25px;
15+
}
16+
17+
button {
18+
margin-top: 20px;
19+
}
920
`
1021

11-
export const Card = ({ onClick, buttonText, title }) => (
22+
export const Card = ({ children, onClick, buttonText, title }) => (
1223
<StyledCard>
1324
<h1>{title}</h1>
25+
<p>{children}</p>
1426
<Button onClick={onClick}>{buttonText}</Button>
1527
</StyledCard>
1628
)

packages/card/src/index.stories.js

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React from 'react'
22
import { storiesOf } from '@storybook/react'
33
import { action } from '@storybook/addon-actions'
4-
import { withKnobs, text } from '@storybook/addon-knobs'
4+
import { withKnobs, color, text } from '@storybook/addon-knobs'
55
import { withReadme } from 'storybook-readme'
6+
import { ThemeProvider } from 'styled-components'
67

8+
import { GlobalStyle, createTheme } from '../../theme/src'
79
import CardReadme from '../README.md'
810

911
import Card from '.'
@@ -18,7 +20,27 @@ storiesOf('Card', module)
1820
.addDecorator(withKnobs)
1921
.addDecorator(withReadme(CardReadme))
2022
.addWithJSX('default', () => {
21-
const cardTitle = text('cardTitle', 'Card')
22-
const buttonText = text('buttonText', 'Click me')
23-
return <Card buttonText={buttonText} onClick={onClick} title={cardTitle} />
23+
// data
24+
const cardTitle = text('Card Title', 'Card', 'Data')
25+
const cardText = text(
26+
'Card Text',
27+
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.',
28+
)
29+
const buttonText = text('Button Text', 'Click me', 'Data')
30+
31+
// styling and theme
32+
const accent = color('Accent Color', '#9FB1BC', 'Colors')
33+
const bodyColor = color('Body Color', '#465775', 'Colors')
34+
const theme = createTheme({ colors: { bodyColor, accent } })
35+
36+
return (
37+
<ThemeProvider theme={theme}>
38+
<div style={{ margin: '0 auto', width: '300px' }}>
39+
<GlobalStyle />
40+
<Card buttonText={buttonText} onClick={onClick} title={cardTitle}>
41+
{cardText}
42+
</Card>
43+
</div>
44+
</ThemeProvider>
45+
)
2446
})

packages/card/src/index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import { mount, shallow } from 'enzyme'
3-
import Button from '@natterstefan/ns-button-js'
3+
import { Button } from '@natterstefan/ns-base-js'
44

55
import Card from '.'
66

packages/theme/.eslintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const rules = require('../../.eslintrc.js')
2+
3+
module.exports = rules

packages/theme/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
dist
3+
node_modules
4+
*.log
5+
tmp

packages/theme/.stylelintrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": [
3+
"../../.stylelintrc"
4+
]
5+
}

packages/theme/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Example App Theme
2+
3+
## Usage
4+
5+
```js
6+
import React from 'react';
7+
import { ThemeProvider } from 'styled-components
8+
import { GlobalStyles } from '@natterstefan/ns-theme-js'
9+
10+
import { theme } from './theme'
11+
12+
export const App = () => {
13+
return (
14+
<ThemeProvider theme={theme}>
15+
<GlobalStyles>
16+
<div>Hello World</div>
17+
</ThemeProvider>
18+
);
19+
};
20+
21+
```

packages/theme/jest.config.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const baseConfig = require('../../jest.config.js')
2+
3+
const pack = require('./package')
4+
5+
module.exports = {
6+
...baseConfig,
7+
displayName: pack.name,
8+
modulePaths: ['<rootDir>'],
9+
name: pack.name,
10+
rootDir: '../..',
11+
setupFilesAfterEnv: ['./jest.setup.js'],
12+
testMatch: ['/**/*.test.js'],
13+
}

packages/theme/package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "@natterstefan/ns-theme-js",
3+
"version": "0.1.0",
4+
"description": "Example theme component",
5+
"main": "lib/index.js",
6+
"module": "src/index.js",
7+
"files": [
8+
"dist",
9+
"es",
10+
"esm",
11+
"lib"
12+
],
13+
"directories": {
14+
"lib": "src"
15+
},
16+
"private": true,
17+
"scripts": {
18+
"prebuild": "rimraf dist && rimraf es && rimraf esm && rimraf lib",
19+
"build": "yarn build-csj && yarn build-es && yarn build-esm && yarn build-umd",
20+
"build-csj": "BABEL_ENV=cjs babel --root-mode upward src --ignore */*.test.js,**/*.test.js,*/*.stories.js,**/stories.js --out-dir lib",
21+
"build-esm": "BABEL_ENV=esm babel --root-mode upward src --ignore */*.test.js,**/*.test.js,*/*.stories.js,**/stories.js --out-dir esm",
22+
"build-es": "BABEL_ENV=es babel --root-mode upward src --ignore */*.test.js,**/*.test.js,*/*.stories.js,**/stories.js --out-dir es",
23+
"build-umd": "webpack --mode=production",
24+
"lint": "yarn lint-js && yarn lint-css",
25+
"lint-js": "eslint src",
26+
"lint-css": "stylelint 'src/**/*.js'",
27+
"pretest": "yarn build",
28+
"test": "jest"
29+
},
30+
"publishConfig": {
31+
"access": "public",
32+
"registry": "http://localhost:4873/"
33+
},
34+
"author": "Stefan Natter",
35+
"license": "MIT",
36+
"dependencies": {
37+
"lodash": "^4.17.11",
38+
"react": "^16.8.1",
39+
"styled-components": "^4.1.3"
40+
}
41+
}

packages/theme/src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './styles'
2+
export * from './theme'

0 commit comments

Comments
 (0)