Skip to content

Commit c2c8612

Browse files
authored
Merge pull request #1 from timelessco/integrating-storybook
Added Storybook and React Native Jest
2 parents 5a9ef3e + cd9b4a8 commit c2c8612

File tree

11 files changed

+5986
-187
lines changed

11 files changed

+5986
-187
lines changed

example/App/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from '../storybook';

example/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AppRegistry } from 'react-native';
2-
import App from './src/App';
2+
import App from './App';
33
import { name as appName } from './app.json';
44

55
AppRegistry.registerComponent(appName, () => App);

example/ios/Podfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ PODS:
245245
- React-Core (= 0.63.4)
246246
- React-cxxreact (= 0.63.4)
247247
- React-jsi (= 0.63.4)
248+
- RNCAsyncStorage (1.15.7):
249+
- React-Core
248250
- Yoga (1.14.0)
249251

250252
DEPENDENCIES:
@@ -275,6 +277,7 @@ DEPENDENCIES:
275277
- React-RCTText (from `../node_modules/react-native/Libraries/Text`)
276278
- React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`)
277279
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
280+
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
278281
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
279282

280283
SPEC REPOS:
@@ -332,6 +335,8 @@ EXTERNAL SOURCES:
332335
:path: "../node_modules/react-native/Libraries/Vibration"
333336
ReactCommon:
334337
:path: "../node_modules/react-native/ReactCommon"
338+
RNCAsyncStorage:
339+
:path: "../node_modules/@react-native-async-storage/async-storage"
335340
Yoga:
336341
:path: "../node_modules/react-native/ReactCommon/yoga"
337342

@@ -362,6 +367,7 @@ SPEC CHECKSUMS:
362367
React-RCTText: 5c51df3f08cb9dedc6e790161195d12bac06101c
363368
React-RCTVibration: ae4f914cfe8de7d4de95ae1ea6cc8f6315d73d9d
364369
ReactCommon: 73d79c7039f473b76db6ff7c6b159c478acbbb3b
370+
RNCAsyncStorage: 7102fe8985f889579a3ae148d957bbb3f308122b
365371
Yoga: 4bd86afe9883422a7c4028c00e34790f560923d6
366372

367373
PODFILE CHECKSUM: 13a162c689671245dafa37cc996e23cde5f466da

example/jest.config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"preset": "react-native",
3+
"setupFilesAfterEnv": ["@testing-library/jest-native/extend-expect"]
4+
}

example/package.json

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,43 @@
66
"scripts": {
77
"android": "react-native run-android",
88
"ios": "react-native run-ios",
9-
"start": "react-native start"
9+
"start": "react-native start --reset-cache",
10+
"storybook": "start-storybook -p 7007",
11+
"build-storybook": "build-storybook",
12+
"prestorybook": "rnstl"
13+
},
14+
"config": {
15+
"react-native-storybook-loader": {
16+
"searchDir": [
17+
"./App",
18+
"./App/stories"
19+
],
20+
"pattern": "**/*.stories.tsx",
21+
"outputFile": "./storybook/storyLoader.ts"
22+
}
1023
},
1124
"dependencies": {
25+
"@react-native-async-storage/async-storage": "^1.15.7",
1226
"react": "16.13.1",
13-
"react-native": "0.63.4"
27+
"react-native": "0.63.4",
28+
"typescript": "4.4.2"
1429
},
1530
"devDependencies": {
1631
"@babel/core": "^7.12.10",
1732
"@babel/runtime": "^7.12.5",
33+
"@storybook/addon-actions": "^5.3",
34+
"@storybook/addon-knobs": "^5.3",
35+
"@storybook/addon-links": "^5.3",
36+
"@storybook/addon-ondevice-actions": "^5.3.23",
37+
"@storybook/addon-ondevice-knobs": "^5.3.25",
38+
"@storybook/react-native": "^5.3.25",
39+
"@storybook/react-native-server": "^5.3.23",
40+
"@testing-library/jest-native": "^4.0.2",
41+
"@testing-library/react-native": "^7.2.0",
42+
"babel-loader": "^8.2.2",
1843
"babel-plugin-module-resolver": "^4.0.0",
19-
"metro-react-native-babel-preset": "^0.64.0"
44+
"metro-react-native-babel-preset": "^0.64.0",
45+
"react-dom": "16.13.1",
46+
"react-native-storybook-loader": "^2.0.4"
2047
}
2148
}

example/src/App.tsx

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

example/storybook/addons.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import '@storybook/addon-actions/register';
2+
import '@storybook/addon-links/register';
3+
import '@storybook/addon-knobs/register';

example/storybook/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// if you use expo remove this line
2+
import { AppRegistry } from 'react-native';
3+
4+
import {
5+
getStorybookUI,
6+
configure,
7+
addDecorator,
8+
} from '@storybook/react-native';
9+
import { withKnobs } from '@storybook/addon-knobs';
10+
11+
import './rn-addons';
12+
import { loadStories } from './storyLoader';
13+
14+
// enables knobs for all stories
15+
addDecorator(withKnobs);
16+
17+
// import stories
18+
configure(() => {
19+
loadStories();
20+
}, module);
21+
22+
// Refer to https://github.com/storybookjs/storybook/tree/master/app/react-native#start-command-parameters
23+
// To find allowed options for getStorybookUI
24+
const StorybookUIRoot = getStorybookUI({ asyncStorage: null });
25+
26+
// If you are using React Native vanilla and after installation you don't see your app name here, write it manually.
27+
// If you use Expo you should remove this line.
28+
AppRegistry.registerComponent('%APP_NAME%', () => StorybookUIRoot);
29+
30+
export default StorybookUIRoot;

example/storybook/rn-addons.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import '@storybook/addon-ondevice-actions/register';
2+
import '@storybook/addon-ondevice-knobs/register';

example/storybook/storyLoader.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Auto-generated file created by react-native-storybook-loader
2+
// Do not edit.
3+
//
4+
// https://github.com/elderfo/react-native-storybook-loader.git
5+
6+
export function loadStories() {
7+
require('../App/stories/Button.stories');
8+
}
9+
10+
export const stories = ['../App/stories/Button.stories'];

0 commit comments

Comments
 (0)