Skip to content

Commit 57b518f

Browse files
committed
added storybook
1 parent 45278af commit 57b518f

File tree

7 files changed

+83
-78
lines changed

7 files changed

+83
-78
lines changed

.storybook/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["env", "react"]
3+
}

.storybook/addons.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// To get our default addons (actions and links)
2-
import '@storybook/react/addons';
3-
// To add the knobs addon
1+
import '@storybook/addon-actions/register';
2+
import '@storybook/addon-links/register';
43
import '@storybook/addon-knobs/register'
5-
import '@storybook/addon-options/register';

.storybook/config.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
import { configure, addDecorator, setAddon } from '@storybook/react';
2-
import { setOptions } from '@storybook/addon-options'
3-
import infoAddon from '@storybook/react-addon-info';
1+
import { configure } from '@storybook/react';
42

5-
setAddon(infoAddon);;
3+
// automatically import all files ending in *.stories.js
4+
const req = require.context('../stories', true, /.stories.js$/);
5+
function loadStories() {
6+
req.keys().forEach((filename) => req(filename));
7+
}
68

7-
setOptions({
8-
name: 'react currency formatter',
9-
url: 'https://github.com/kadirahq/storybook-addon-options',
10-
goFullScreen: false,
11-
showLeftPanel: true,
12-
showDownPanel: true,
13-
showSearchBox: false,
14-
downPanelInRight: true,
15-
sortStoriesByKind: false
16-
});
17-
18-
configure(() => require('./stories'), module);
9+
configure(loadStories, module);

.storybook/stories/index.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,29 @@
1414
],
1515
"main": "dist/react-currency-formatter.cjs.js",
1616
"module": "dist/react-currency-formatter.esm.js",
17-
"browser": "dist/react-currency-formatter.umd.js",
1817
"repository": {
1918
"type": "git",
2019
"url": "https://github.com/xDae/react-currency-formatter.git"
2120
},
2221
"scripts": {
2322
"build": "rimraf dist && rollup -c",
23+
"build-storybook": "build-storybook",
2424
"dev": "rollup -c -w",
25+
"storybook": "start-storybook -p 6006",
2526
"pretest": "npm run build",
2627
"test": "jest",
2728
"test:watch": "jest --watch"
2829
},
30+
"browser": "dist/react-currency-formatter.umd.js",
2931
"dependencies": {
3032
"prop-types": "^15.6.0"
3133
},
3234
"devDependencies": {
35+
"@storybook/addon-actions": "^3.3.3",
36+
"@storybook/addon-info": "^3.3.3",
37+
"@storybook/addon-knobs": "^3.3.3",
38+
"@storybook/addon-links": "^3.3.3",
39+
"@storybook/react": "^3.3.3",
3340
"babel-core": "^6.26.0",
3441
"babel-jest": "^22.0.4",
3542
"babel-preset-env": "^1.6.1",
@@ -38,6 +45,7 @@
3845
"enzyme": "^3.3.0",
3946
"enzyme-adapter-react-16": "^1.1.1",
4047
"jest": "^22.0.4",
48+
"lodash.values": "^4.3.0",
4149
"react": "^16.2.0",
4250
"react-dom": "^16.2.0",
4351
"regenerator-runtime": "^0.11.1",

src/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// import React from 'react';
1+
import React from 'react';
22
import PropTypes from 'prop-types';
33

44
import locales from './locales';
@@ -187,7 +187,7 @@ const ReactCurrencyFormatter = props => {
187187
pattern
188188
} = props;
189189

190-
return (format(quantity, {
190+
return (format(props.quantity, {
191191
currency,
192192
symbol,
193193
locale,

stories/index.stories.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React from 'react';
2+
import { storiesOf } from '@storybook/react';
3+
import { withInfo } from '@storybook/addon-info';
4+
import { withKnobs, text, boolean, number, select } from '@storybook/addon-knobs/react';
5+
6+
import values from 'lodash.values';
7+
8+
import symbolsArray from '../src/symbols'
9+
import defaultLocales from '../src/default-locales';
10+
11+
import Currency from '../src/main';
12+
13+
const stories = storiesOf('Currency Formatter', module);
14+
stories.addDecorator((story, context) => withInfo('common info')(story)(context));
15+
stories.addDecorator(withKnobs);
16+
17+
const currencyList = {};
18+
Object.keys(symbolsArray).map(currency => currencyList[currency] = currency);
19+
20+
const locales = {};
21+
values(defaultLocales).map(locale => locales[locale] = locale);
22+
23+
stories.add('Default', () => (
24+
<Currency
25+
quantity={89}
26+
currency={select('Currency', currencyList, 'USD')}
27+
symbol={text('Symbol', '$')}
28+
decimal={text('Decimal', undefined)}
29+
group={text('Group', undefined)}
30+
locale={select('Locale', locales, 'en')}
31+
/>
32+
));
33+
34+
stories.add('EUR Currency', () => (
35+
<Currency
36+
quantity={89}
37+
currency={select('Currency', currencyList, 'EUR')}
38+
/>
39+
));
40+
41+
stories.add('GBP Currency', () => (
42+
<Currency
43+
quantity={89}
44+
currency={select('Currency', currencyList, 'GBP')}
45+
/>
46+
));
47+
48+
stories.add('Customized symbol', () => (
49+
<Currency
50+
quantity={89}
51+
symbol={text('Currency', '💵')}
52+
/>
53+
));
54+
55+
stories.add('Changing pattern', () => (
56+
<Currency
57+
quantity={89}
58+
pattern="##,### !"
59+
/>
60+
));

0 commit comments

Comments
 (0)