Skip to content

Commit 8a207fe

Browse files
committed
feat: 🎸 add storybook
1 parent 6e5e947 commit 8a207fe

File tree

9 files changed

+146
-3
lines changed

9 files changed

+146
-3
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import AsyncStorage from '@react-native-async-storage/async-storage';
2+
import { view } from './storybook.requires';
3+
4+
const StorybookUIRoot = view.getStorybookUI({
5+
storage: {
6+
getItem: AsyncStorage.getItem,
7+
setItem: AsyncStorage.setItem,
8+
},
9+
});
10+
11+
export default StorybookUIRoot;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { StorybookConfig } from '@storybook/react-native';
2+
3+
const main: StorybookConfig = {
4+
stories: ['./stories/**/*.stories.?(ts|tsx|js|jsx)'],
5+
addons: ['@storybook/addon-ondevice-controls', '@storybook/addon-ondevice-actions'],
6+
};
7+
8+
export default main;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Preview } from '@storybook/react';
2+
3+
const preview: Preview = {
4+
parameters: {
5+
controls: {
6+
matchers: {
7+
color: /(background|color)$/i,
8+
date: /Date$/,
9+
},
10+
},
11+
},
12+
};
13+
14+
export default preview;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { View } from 'react-native';
2+
import type { Meta, StoryObj } from '@storybook/react';
3+
import { MyButton } from './Button';
4+
5+
const MyButtonMeta: Meta<typeof MyButton> = {
6+
title: 'MyButton',
7+
component: MyButton,
8+
argTypes: {
9+
onPress: { action: 'pressed the button' },
10+
},
11+
args: {
12+
text: 'Hello world',
13+
},
14+
decorators: [
15+
(Story) => (
16+
<View style={{ alignItems: 'center', justifyContent: 'center', flex: 1 }}>
17+
<Story />
18+
</View>
19+
),
20+
],
21+
};
22+
23+
export default MyButtonMeta;
24+
25+
export const Basic: StoryObj<typeof MyButton> = {};
26+
27+
export const AnotherExample: StoryObj<typeof MyButton> = {
28+
args: {
29+
text: 'Another example',
30+
},
31+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { TouchableOpacity, Text, StyleSheet } from 'react-native';
2+
3+
export type MyButtonProps = {
4+
onPress: () => void;
5+
text: string;
6+
};
7+
8+
export const MyButton = ({ onPress, text }: MyButtonProps) => {
9+
return (
10+
<TouchableOpacity style={styles.container} onPress={onPress} activeOpacity={0.8}>
11+
<Text style={styles.text}>{text}</Text>
12+
</TouchableOpacity>
13+
);
14+
};
15+
16+
const styles = StyleSheet.create({
17+
container: {
18+
paddingHorizontal: 16,
19+
paddingVertical: 8,
20+
backgroundColor: 'purple',
21+
borderRadius: 8,
22+
},
23+
text: { color: 'white' },
24+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* do not change this file, it is auto generated by storybook. */
2+
3+
import { start } from '@storybook/react-native';
4+
5+
import '@storybook/addon-ondevice-controls/register';
6+
import '@storybook/addon-ondevice-actions/register';
7+
8+
const normalizedStories = [
9+
{
10+
titlePrefix: '',
11+
directory: './.storybook/stories',
12+
files: '**/*.stories.?(ts|tsx|js|jsx)',
13+
importPathMatcher:
14+
/^\.(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)(?!\.)(?=.)[^/]*?\.stories\.(?:ts|tsx|js|jsx)?)$/,
15+
// @ts-ignore
16+
req: require.context(
17+
'./stories',
18+
true,
19+
/^\.(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)(?!\.)(?=.)[^/]*?\.stories\.(?:ts|tsx|js|jsx)?)$/
20+
),
21+
},
22+
];
23+
24+
// @ts-ignore
25+
global.STORIES = normalizedStories;
26+
27+
export const view = start({
28+
annotations: [
29+
require('./preview'),
30+
require('@storybook/react-native/dist/preview'),
31+
require('@storybook/addon-actions/preview'),
32+
],
33+
storyEntries: normalizedStories,
34+
});

hackathon/offline-with-legend-state/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ const styles = StyleSheet.create({
4141
},
4242
});
4343

44-
export default App;
44+
// export default App;
45+
export { default } from "./.storybook";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Learn more https://docs.expo.io/guides/customizing-metro
2+
const { getDefaultConfig } = require('expo/metro-config');
3+
4+
/** @type {import('expo/metro-config').MetroConfig} */
5+
const config = getDefaultConfig(__dirname);
6+
7+
config.transformer.unstable_allowRequireContext = true;
8+
9+
module.exports = config;

hackathon/offline-with-legend-state/package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"start": "expo start",
77
"android": "expo start --android",
88
"ios": "expo start --ios",
9-
"web": "expo start --web"
9+
"web": "expo start --web",
10+
"storybook-generate": "sb-rn-get-stories",
11+
"storybook": "sb-rn-get-stories && expo start"
1012
},
1113
"dependencies": {
1214
"@legendapp/state": "^2.1.8",
@@ -17,8 +19,17 @@
1719
},
1820
"devDependencies": {
1921
"@babel/core": "^7.20.0",
22+
"@react-native-async-storage/async-storage": "^1.22.3",
23+
"@react-native-community/datetimepicker": "^7.6.2",
24+
"@react-native-community/slider": "^4.5.0",
25+
"@storybook/addon-ondevice-actions": "^7.6.15",
26+
"@storybook/addon-ondevice-controls": "^7.6.15",
27+
"@storybook/react-native": "^7.6.15",
2028
"@types/react": "~18.2.45",
29+
"babel-loader": "^8.3.0",
30+
"react-dom": "18.2.0",
31+
"react-native-safe-area-context": "^4.9.0",
2132
"typescript": "^5.1.3"
2233
},
2334
"private": true
24-
}
35+
}

0 commit comments

Comments
 (0)