@storybook/react-native 9.0.0-alpha.0 → 9.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/react-native",
3
- "version": "9.0.0-alpha.0",
3
+ "version": "9.0.0-alpha.1",
4
4
  "description": "A better way to develop React Native Components for your app",
5
5
  "keywords": [
6
6
  "react",
@@ -48,8 +48,8 @@
48
48
  "@storybook/csf": "^0.1.13",
49
49
  "@storybook/global": "^5.0.0",
50
50
  "@storybook/react": "9.0.0-alpha.3",
51
- "@storybook/react-native-theming": "^9.0.0-alpha.0",
52
- "@storybook/react-native-ui": "^9.0.0-alpha.0",
51
+ "@storybook/react-native-theming": "^9.0.0-alpha.1",
52
+ "@storybook/react-native-ui": "^9.0.0-alpha.1",
53
53
  "commander": "^8.2.0",
54
54
  "dedent": "^1.5.1",
55
55
  "deepmerge": "^4.3.0",
@@ -87,5 +87,5 @@
87
87
  "publishConfig": {
88
88
  "access": "public"
89
89
  },
90
- "gitHead": "6ca21ab6b467c73887d17a383fdd464da37865d6"
90
+ "gitHead": "ec42eef3ebdf389ebf9cf669d425712db99f9e37"
91
91
  }
@@ -0,0 +1,53 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-native-web-vite';
2
+
3
+ import { View } from 'react-native';
4
+ import { fn } from 'storybook/test';
5
+
6
+ import { Button } from './Button';
7
+
8
+ const meta = {
9
+ title: 'Example/Button',
10
+ component: Button,
11
+ decorators: [
12
+ (Story) => (
13
+ <View style={{ flex: 1, alignItems: 'flex-start' }}>
14
+ <Story />
15
+ </View>
16
+ ),
17
+ ],
18
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
19
+ tags: ['autodocs'],
20
+ // Use `fn` to spy on the onPress arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
21
+ args: { onPress: fn() },
22
+ } satisfies Meta<typeof Button>;
23
+
24
+ export default meta;
25
+
26
+ type Story = StoryObj<typeof meta>;
27
+
28
+ export const Primary: Story = {
29
+ args: {
30
+ primary: true,
31
+ label: 'Button',
32
+ },
33
+ };
34
+
35
+ export const Secondary: Story = {
36
+ args: {
37
+ label: 'Button',
38
+ },
39
+ };
40
+
41
+ export const Large: Story = {
42
+ args: {
43
+ size: 'large',
44
+ label: 'Button',
45
+ },
46
+ };
47
+
48
+ export const Small: Story = {
49
+ args: {
50
+ size: 'small',
51
+ label: 'Button',
52
+ },
53
+ };
@@ -0,0 +1,101 @@
1
+ import type { StyleProp, ViewStyle } from 'react-native';
2
+ import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
3
+
4
+ export interface ButtonProps {
5
+ /** Is this the principal call to action on the page? */
6
+ primary?: boolean;
7
+ /** What background color to use */
8
+ backgroundColor?: string;
9
+ /** How large should the button be? */
10
+ size?: 'small' | 'medium' | 'large';
11
+ /** Button contents */
12
+ label: string;
13
+ /** Optional click handler */
14
+ onPress?: () => void;
15
+ style?: StyleProp<ViewStyle>;
16
+ }
17
+
18
+ /** Primary UI component for user interaction */
19
+ export const Button = ({
20
+ primary = false,
21
+ size = 'medium',
22
+ backgroundColor,
23
+ label,
24
+ style,
25
+ onPress,
26
+ }: ButtonProps) => {
27
+ const modeStyle = primary ? styles.primary : styles.secondary;
28
+ const textModeStyle = primary ? styles.primaryText : styles.secondaryText;
29
+
30
+ const sizeStyle = styles[size];
31
+ const textSizeStyle = textSizeStyles[size];
32
+
33
+ return (
34
+ <TouchableOpacity accessibilityRole="button" activeOpacity={0.6} onPress={onPress}>
35
+ <View
36
+ style={[
37
+ styles.button,
38
+ modeStyle,
39
+ sizeStyle,
40
+ style,
41
+ !!backgroundColor && { backgroundColor },
42
+ { borderColor: 'black' },
43
+ ]}
44
+ >
45
+ <Text style={[textModeStyle, textSizeStyle]}>{label}</Text>
46
+ </View>
47
+ </TouchableOpacity>
48
+ );
49
+ };
50
+
51
+ const styles = StyleSheet.create({
52
+ button: {
53
+ borderWidth: 0,
54
+ borderRadius: 48,
55
+ },
56
+ buttonText: {
57
+ fontWeight: '700',
58
+ lineHeight: 1,
59
+ },
60
+ primary: {
61
+ backgroundColor: '#1ea7fd',
62
+ },
63
+ primaryText: {
64
+ color: 'white',
65
+ },
66
+ secondary: {
67
+ backgroundColor: 'transparent',
68
+ borderColor: 'rgba(0, 0, 0, 0.15)',
69
+ borderWidth: 1,
70
+ },
71
+ secondaryText: {
72
+ color: '#333',
73
+ },
74
+ small: {
75
+ paddingVertical: 10,
76
+ paddingHorizontal: 16,
77
+ },
78
+ smallText: {
79
+ fontSize: 12,
80
+ },
81
+ medium: {
82
+ paddingVertical: 11,
83
+ paddingHorizontal: 20,
84
+ },
85
+ mediumText: {
86
+ fontSize: 14,
87
+ },
88
+ large: {
89
+ paddingVertical: 12,
90
+ paddingHorizontal: 24,
91
+ },
92
+ largeText: {
93
+ fontSize: 16,
94
+ },
95
+ });
96
+
97
+ const textSizeStyles = {
98
+ small: styles.smallText,
99
+ medium: styles.mediumText,
100
+ large: styles.largeText,
101
+ };
@@ -0,0 +1,33 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-native-web-vite';
2
+
3
+ import { Header } from './Header';
4
+
5
+ const meta = {
6
+ title: 'Example/Header',
7
+ component: Header,
8
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
9
+ tags: ['autodocs'],
10
+ } satisfies Meta<typeof Header>;
11
+
12
+ export default meta;
13
+
14
+ type Story = StoryObj<typeof meta>;
15
+
16
+ export const LoggedIn: Story = {
17
+ args: {
18
+ user: {
19
+ name: 'Jane Doe',
20
+ },
21
+ onLogin: () => {},
22
+ onLogout: () => {},
23
+ onCreateAccount: () => {},
24
+ },
25
+ };
26
+
27
+ export const LoggedOut: Story = {
28
+ args: {
29
+ onLogin: () => {},
30
+ onLogout: () => {},
31
+ onCreateAccount: () => {},
32
+ },
33
+ };
@@ -0,0 +1,76 @@
1
+ import { StyleSheet, Text, View } from 'react-native';
2
+
3
+ import { Button } from './Button';
4
+
5
+ export type HeaderProps = {
6
+ user?: {};
7
+ onLogin: () => void;
8
+ onLogout: () => void;
9
+ onCreateAccount: () => void;
10
+ };
11
+
12
+ export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => (
13
+ <View>
14
+ <View style={styles.wrapper}>
15
+ <View style={styles.logoContainer}>
16
+ <Text style={styles.h1}>Acme</Text>
17
+ </View>
18
+ <View style={styles.buttonContainer}>
19
+ {user ? (
20
+ <>
21
+ <>
22
+ <Text>Welcome, </Text>
23
+ <Text style={styles.userName}>{user.name}!</Text>
24
+ </>
25
+ <Button style={styles.button} size="small" onPress={onLogout} label="Log out" />
26
+ </>
27
+ ) : (
28
+ <>
29
+ <Button style={styles.button} size="small" onPress={onLogin} label="Log in" />
30
+ <Button
31
+ style={styles.button}
32
+ primary
33
+ size="small"
34
+ onPress={onCreateAccount}
35
+ label="Sign up"
36
+ />
37
+ </>
38
+ )}
39
+ </View>
40
+ </View>
41
+ </View>
42
+ );
43
+
44
+ const styles = StyleSheet.create({
45
+ wrapper: {
46
+ borderBottomWidth: 1,
47
+ borderBottomColor: 'rgba(0, 0, 0, 0.1)',
48
+ paddingVertical: 15,
49
+ paddingHorizontal: 20,
50
+ flexDirection: 'row',
51
+ justifyContent: 'space-between',
52
+ },
53
+ h1: {
54
+ fontWeight: '900',
55
+ fontSize: 20,
56
+ marginTop: 6,
57
+ marginBottom: 6,
58
+ marginLeft: 10,
59
+ color: 'black',
60
+ alignSelf: 'flex-start',
61
+ },
62
+ logoContainer: {
63
+ flexDirection: 'row',
64
+ alignItems: 'center',
65
+ },
66
+ button: {
67
+ marginLeft: 10,
68
+ },
69
+ buttonContainer: {
70
+ flexDirection: 'row',
71
+ alignItems: 'center',
72
+ },
73
+ userName: {
74
+ fontWeight: '700',
75
+ },
76
+ });
@@ -0,0 +1,25 @@
1
+ import type { Meta } from '@storybook/react-native-web-vite';
2
+
3
+ import { expect, userEvent, within } from 'storybook/test';
4
+
5
+ import { Page } from './Page';
6
+
7
+ export default {
8
+ title: 'Example/Page',
9
+ component: Page,
10
+ } as Meta<typeof Page>;
11
+
12
+ export const LoggedIn = {
13
+ play: async ({ canvasElement }) => {
14
+ const canvas = within(canvasElement);
15
+ const loginButton = canvas.getByRole('button', { name: /Log in/i });
16
+ await expect(loginButton).toBeInTheDocument();
17
+ await userEvent.click(loginButton);
18
+ // FIXME: await expect(loginButton).not.toBeInTheDocument();
19
+
20
+ const logoutButton = canvas.getByRole('button', { name: /Log out/i });
21
+ await expect(logoutButton).toBeInTheDocument();
22
+ },
23
+ };
24
+
25
+ export const LoggedOut = {};
@@ -0,0 +1,154 @@
1
+ import { useState } from 'react';
2
+
3
+ import { Linking, StyleSheet, Text, View } from 'react-native';
4
+
5
+ import { Header } from './Header';
6
+
7
+ export const Page = () => {
8
+ const [user, setUser] = useState();
9
+
10
+ return (
11
+ <View>
12
+ <Header
13
+ user={user}
14
+ onLogin={() => setUser({ name: 'Jane Doe' })}
15
+ onLogout={() => setUser(undefined)}
16
+ onCreateAccount={() => setUser({ name: 'Jane Doe' })}
17
+ />
18
+
19
+ <View style={styles.section}>
20
+ <Text role="heading" style={styles.h2}>
21
+ Pages in Storybook
22
+ </Text>
23
+ <Text style={styles.p}>
24
+ We recommend building UIs with a{' '}
25
+ <Text
26
+ style={[styles.a, { fontWeight: 'bold' }]}
27
+ role="link"
28
+ onPress={() => {
29
+ Linking.openURL('https://componentdriven.org');
30
+ }}
31
+ >
32
+ <Text>component-driven</Text>
33
+ </Text>{' '}
34
+ process starting with atomic components and ending with pages.
35
+ </Text>
36
+ <Text style={styles.p}>
37
+ Render pages with mock data. This makes it easy to build and review page states without
38
+ needing to navigate to them in your app. Here are some handy patterns for managing page
39
+ data in Storybook:
40
+ </Text>
41
+ <View>
42
+ <View>
43
+ Use a higher-level connected component. Storybook helps you compose such data from the
44
+ "args" of child component stories
45
+ </View>
46
+ <View>
47
+ Assemble data in the page component from your services. You can mock these services out
48
+ using Storybook.
49
+ </View>
50
+ </View>
51
+ <Text style={styles.p}>
52
+ Get a guided tutorial on component-driven development at{' '}
53
+ <Text
54
+ style={styles.a}
55
+ role="link"
56
+ onPress={() => {
57
+ Linking.openURL('https://storybook.js.org/tutorials/');
58
+ }}
59
+ >
60
+ Storybook tutorials
61
+ </Text>
62
+ . Read more in the{' '}
63
+ <Text
64
+ style={styles.a}
65
+ role="link"
66
+ onPress={() => {
67
+ Linking.openURL('https://storybook.js.org/docs');
68
+ }}
69
+ >
70
+ docs
71
+ </Text>
72
+ .
73
+ </Text>
74
+ <View style={styles.tipWrapper}>
75
+ <View style={styles.tip}>
76
+ <Text style={styles.tipText}>Tip </Text>
77
+ </View>
78
+ <Text>Adjust the width of the canvas with the </Text>
79
+ <Text>Viewports addon in the toolbar</Text>
80
+ </View>
81
+ </View>
82
+ </View>
83
+ );
84
+ };
85
+
86
+ const styles = StyleSheet.create({
87
+ section: {
88
+ fontFamily: "'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif",
89
+ fontSize: 14,
90
+ lineHeight: 24,
91
+ paddingVertical: 48,
92
+ paddingHorizontal: 20,
93
+ marginHorizontal: 'auto',
94
+ maxWidth: 600,
95
+ color: '#333',
96
+ },
97
+
98
+ h2: {
99
+ fontWeight: '900',
100
+ fontSize: 32,
101
+ lineHeight: 1,
102
+ marginBottom: 4,
103
+ },
104
+
105
+ p: {
106
+ marginVertical: 16,
107
+ marginHorizontal: 0,
108
+ },
109
+
110
+ a: {
111
+ color: '#1ea7fd',
112
+ },
113
+
114
+ ul: {
115
+ paddingLeft: 30,
116
+ marginVertical: 16,
117
+ },
118
+
119
+ li: {
120
+ marginBottom: 8,
121
+ },
122
+
123
+ tip: {
124
+ alignSelf: 'flex-start',
125
+ borderRadius: 16,
126
+ backgroundColor: '#e7fdd8',
127
+ paddingVertical: 4,
128
+ paddingHorizontal: 12,
129
+ marginRight: 10,
130
+ marginBottom: 4,
131
+ },
132
+ tipText: {
133
+ fontSize: 11,
134
+ lineHeight: 12,
135
+ fontWeight: '700',
136
+ color: '#66bf3c',
137
+ },
138
+
139
+ tipWrapper: {
140
+ fontSize: 13,
141
+ lineHeight: 20,
142
+ marginTop: 40,
143
+ marginBottom: 40,
144
+ flexDirection: 'row',
145
+ flexWrap: 'wrap',
146
+ },
147
+
148
+ tipWrapperSvg: {
149
+ height: 12,
150
+ width: 12,
151
+ marginRight: 4,
152
+ marginTop: 3,
153
+ },
154
+ });
@@ -1,33 +0,0 @@
1
- import { View } from 'react-native';
2
- import type { Meta, StoryObj } from '@storybook/react';
3
- import { MyButton } from './Button';
4
-
5
- const meta = {
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={{ padding: 16, alignItems: 'flex-start' }}>
17
- <Story />
18
- </View>
19
- ),
20
- ],
21
- } satisfies Meta<typeof MyButton>;
22
-
23
- export default meta;
24
-
25
- type Story = StoryObj<typeof meta>;
26
-
27
- export const Basic: Story = {};
28
-
29
- export const AnotherExample: Story = {
30
- args: {
31
- text: 'Another example',
32
- },
33
- };
@@ -1,24 +0,0 @@
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
- });