@storybook/react-native-web-vite 0.0.3-0 → 8.5.0-alpha.10

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.
@@ -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';
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,24 @@
1
+ import type { Meta } from '@storybook/react';
2
+ import { expect, userEvent, within } from '@storybook/test';
3
+
4
+ import { Page } from './Page';
5
+
6
+ export default {
7
+ title: 'Example/Page',
8
+ component: Page,
9
+ } as Meta<typeof Page>;
10
+
11
+ export const LoggedIn = {
12
+ play: async ({ canvasElement }) => {
13
+ const canvas = within(canvasElement);
14
+ const loginButton = canvas.getByRole('button', { name: /Log in/i });
15
+ await expect(loginButton).toBeInTheDocument();
16
+ await userEvent.click(loginButton);
17
+ // FIXME: await expect(loginButton).not.toBeInTheDocument();
18
+
19
+ const logoutButton = canvas.getByRole('button', { name: /Log out/i });
20
+ await expect(logoutButton).toBeInTheDocument();
21
+ },
22
+ };
23
+
24
+ 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
+ });
package/dist/index.cjs DELETED
@@ -1,4 +0,0 @@
1
- 'use strict';
2
-
3
- //# sourceMappingURL=index.cjs.map
4
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
package/dist/index.d.cts DELETED
@@ -1,52 +0,0 @@
1
- import { StorybookConfig as StorybookConfig$1, TypescriptOptions as TypescriptOptions$1, CompatibleString } from 'storybook/internal/types';
2
- import { Options, BabelOptions } from '@vitejs/plugin-react';
3
- import { BuilderOptions, StorybookConfigVite } from '@storybook/builder-vite';
4
- import docgenTypescript from '@joshwooding/vite-plugin-react-docgen-typescript';
5
-
6
- type FrameworkName = CompatibleString<"@storybook/react-native-web-vite">;
7
- type BuilderName = CompatibleString<"@storybook/builder-vite">;
8
- type FrameworkOptions = {
9
- builder?: BuilderOptions;
10
- strictMode?: boolean;
11
- /**
12
- * Use React's legacy root API to mount components
13
- *
14
- * React has introduced a new root API with React 18.x to enable a whole set of new features (e.g.
15
- * concurrent features) If this flag is true, the legacy Root API is used to mount components to
16
- * make it easier to migrate step by step to React 18.
17
- *
18
- * @default false
19
- */
20
- legacyRootApi?: boolean;
21
- pluginReactOptions?: Omit<Options, "babel"> & {
22
- babel?: BabelOptions;
23
- };
24
- };
25
- type StorybookConfigFramework = {
26
- framework: FrameworkName | {
27
- name: FrameworkName;
28
- options: FrameworkOptions;
29
- };
30
- core?: StorybookConfig$1["core"] & {
31
- builder?: BuilderName | {
32
- name: BuilderName;
33
- options: BuilderOptions;
34
- };
35
- };
36
- };
37
- type TypescriptOptions = TypescriptOptions$1 & {
38
- /**
39
- * Sets the type of Docgen when working with React and TypeScript
40
- *
41
- * @default `'react-docgen'`
42
- */
43
- reactDocgen: "react-docgen-typescript" | "react-docgen" | false;
44
- /** Configures `@joshwooding/vite-plugin-react-docgen-typescript` */
45
- reactDocgenTypescriptOptions: Parameters<typeof docgenTypescript>[0];
46
- };
47
- /** The interface for Storybook configuration in `main.ts` files. */
48
- type StorybookConfig = Omit<StorybookConfig$1, keyof StorybookConfigVite | keyof StorybookConfigFramework | "typescript"> & StorybookConfigVite & StorybookConfigFramework & {
49
- typescript?: Partial<TypescriptOptions>;
50
- };
51
-
52
- export type { FrameworkOptions, StorybookConfig };
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/dist/preset.cjs DELETED
@@ -1,15 +0,0 @@
1
- 'use strict';
2
-
3
- var builderVite = require('@storybook/builder-vite');
4
- var n = require('@vitejs/plugin-react');
5
-
6
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
-
8
- var n__default = /*#__PURE__*/_interopDefault(n);
9
-
10
- function r(t){return {name:"vite:react-native-web",enforce:"pre",config(o,e){return {plugins:[n__default.default({jsxRuntime:"automatic",...t})],define:{"global.__x":{},_frameTimestamp:void 0,_WORKLET:!1,__DEV__:`${e.mode==="development"}`,"process.env.NODE_ENV":JSON.stringify(process.env.NODE_ENV||e.mode)},optimizeDeps:{include:[],esbuildOptions:{jsx:"transform",resolveExtensions:[".web.js",".web.ts",".web.tsx",".js",".jsx",".json",".ts",".tsx",".mjs"],loader:{".js":"jsx"}}},resolve:{extensions:[".web.js",".web.ts",".web.tsx",".js",".jsx",".json",".ts",".tsx",".mjs"],alias:{"react-native":"react-native-web"}}}}}}var b=async(t,s)=>{let{pluginReactOptions:o={}}=await s.presets.apply("frameworkOptions"),{plugins:e=[]}=t;return await builderVite.hasVitePlugins(e,["vite:react-native-web"])||e.push(r(o)),t},c={builder:"@storybook/builder-vite",renderer:"@storybook/react"};
11
-
12
- exports.core = c;
13
- exports.viteFinal = b;
14
- //# sourceMappingURL=preset.cjs.map
15
- //# sourceMappingURL=preset.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/preset.ts"],"names":["reactNativeWeb","reactOptions","_userConfig","env","react","viteFinal","config","options","pluginReactOptions","plugins","hasVitePlugins","core"],"mappings":";;;;;;;;;AAQA,SAASA,CAAAA,CACPC,CACQ,CAAA,CA8DR,OA7DuB,CACrB,IAAA,CAAM,uBACN,CAAA,OAAA,CAAS,MACT,MAAOC,CAAAA,CAAAA,CAAaC,CAAK,CAAA,CACvB,OAAO,CACL,OAAA,CAAS,CACPC,kBAAAA,CAAM,CACJ,UAAY,CAAA,WAAA,CACZ,GAAGH,CACL,CAAC,CACH,CAAA,CACA,MAAQ,CAAA,CAEN,aAAc,EAAC,CACf,eAAiB,CAAA,KAAA,CAAA,CACjB,SAAU,CACV,CAAA,CAAA,OAAA,CAAS,CAAGE,EAAAA,CAAAA,CAAI,OAAS,aAAa,CAAA,CAAA,CACtC,sBAAwB,CAAA,IAAA,CAAK,UAC3B,OAAQ,CAAA,GAAA,CAAI,QAAYA,EAAAA,CAAAA,CAAI,IAC9B,CACF,CAAA,CACA,YAAc,CAAA,CACZ,QAAS,EAAC,CACV,cAAgB,CAAA,CACd,IAAK,WACL,CAAA,iBAAA,CAAmB,CACjB,SAAA,CACA,UACA,UACA,CAAA,KAAA,CACA,MACA,CAAA,OAAA,CACA,MACA,MACA,CAAA,MACF,CACA,CAAA,MAAA,CAAQ,CACN,KAAO,CAAA,KACT,CACF,CACF,EACA,OAAS,CAAA,CACP,UAAY,CAAA,CACV,UACA,SACA,CAAA,UAAA,CACA,KACA,CAAA,MAAA,CACA,QACA,KACA,CAAA,MAAA,CACA,MACF,CAAA,CACA,MAAO,CACL,cAAA,CAAgB,kBAClB,CACF,CACF,CACF,CACF,CAGF,KAEaE,CAA0C,CAAA,MACrDC,CACAC,CAAAA,CAAAA,GACG,CACH,GAAM,CAAE,kBAAAC,CAAAA,CAAAA,CAAqB,EAAG,CAAA,CAC9B,MAAMD,CAAAA,CAAQ,QAAQ,KAAwB,CAAA,kBAAkB,CAE5D,CAAA,CAAE,QAAAE,CAAU,CAAA,EAAG,CAAA,CAAIH,EAEzB,OAAM,MAAMI,0BAAeD,CAAAA,CAAAA,CAAS,CAAC,uBAAuB,CAAC,CAC3DA,EAAAA,CAAAA,CAAQ,KAAKT,CAAeQ,CAAAA,CAAkB,CAAC,CAAA,CAG1CF,CACT,CAEaK,CAAAA,CAAAA,CAAO,CAClB,OAAS,CAAA,yBAAA,CACT,SAAU,kBACZ","file":"preset.cjs","sourcesContent":["import { hasVitePlugins } from \"@storybook/builder-vite\";\nimport react, {\n BabelOptions,\n Options as ReactOptions,\n} from \"@vitejs/plugin-react\";\nimport { Plugin } from \"vite\";\nimport { FrameworkOptions, StorybookConfig } from \"./types\";\n\nfunction reactNativeWeb(\n reactOptions: Omit<ReactOptions, \"babel\"> & { babel?: BabelOptions },\n): Plugin {\n const plugin: Plugin = {\n name: \"vite:react-native-web\",\n enforce: \"pre\",\n config(_userConfig, env) {\n return {\n plugins: [\n react({\n jsxRuntime: \"automatic\",\n ...reactOptions,\n }),\n ],\n define: {\n // reanimated support\n \"global.__x\": {},\n _frameTimestamp: undefined,\n _WORKLET: false,\n __DEV__: `${env.mode === \"development\"}`,\n \"process.env.NODE_ENV\": JSON.stringify(\n process.env.NODE_ENV || env.mode,\n ),\n },\n optimizeDeps: {\n include: [],\n esbuildOptions: {\n jsx: \"transform\",\n resolveExtensions: [\n \".web.js\",\n \".web.ts\",\n \".web.tsx\",\n \".js\",\n \".jsx\",\n \".json\",\n \".ts\",\n \".tsx\",\n \".mjs\",\n ],\n loader: {\n \".js\": \"jsx\",\n },\n },\n },\n resolve: {\n extensions: [\n \".web.js\",\n \".web.ts\",\n \".web.tsx\",\n \".js\",\n \".jsx\",\n \".json\",\n \".ts\",\n \".tsx\",\n \".mjs\",\n ],\n alias: {\n \"react-native\": \"react-native-web\",\n },\n },\n };\n },\n };\n\n return plugin;\n}\n\nexport const viteFinal: StorybookConfig[\"viteFinal\"] = async (\n config,\n options,\n) => {\n const { pluginReactOptions = {} } =\n await options.presets.apply<FrameworkOptions>(\"frameworkOptions\");\n\n const { plugins = [] } = config;\n\n if (!(await hasVitePlugins(plugins, [\"vite:react-native-web\"]))) {\n plugins.push(reactNativeWeb(pluginReactOptions));\n }\n\n return config;\n};\n\nexport const core = {\n builder: \"@storybook/builder-vite\",\n renderer: \"@storybook/react\",\n};\n"]}