@storybook/react-native-web-vite 0.0.0-pr-29520-sha-627893bc → 0.0.0-pr-29659-sha-1f47b682
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/README.md +2 -2
- package/dist/index.d.ts +6 -39
- package/dist/preset.d.ts +4 -3
- package/dist/preset.js +1 -1
- package/dist/vite-plugin.d.ts +5 -0
- package/dist/vite-plugin.js +1 -0
- package/dist/vite-plugin.mjs +6 -0
- package/package.json +14 -13
- package/template/cli/js/Button.jsx +109 -0
- package/template/cli/js/Button.stories.jsx +50 -0
- package/template/cli/js/Header.jsx +84 -0
- package/template/cli/js/Header.stories.jsx +29 -0
- package/template/cli/js/Page.jsx +162 -0
- package/template/cli/js/Page.stories.jsx +25 -0
- package/template/cli/ts-3-8/Button.stories.tsx +6 -0
- package/template/cli/ts-3-8/Button.tsx +0 -2
- package/template/cli/ts-3-8/Header.stories.tsx +6 -1
- package/template/cli/ts-3-8/Header.tsx +11 -1
- package/template/cli/ts-3-8/Page.stories.tsx +13 -5
- package/template/cli/ts-3-8/Page.tsx +77 -73
- package/template/cli/ts-4-9/Button.stories.tsx +6 -0
- package/template/cli/ts-4-9/Header.stories.tsx +6 -1
- package/template/cli/ts-4-9/Header.tsx +11 -1
- package/template/cli/ts-4-9/Page.stories.tsx +13 -5
- package/template/cli/ts-4-9/Page.tsx +72 -68
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# Storybook for React & Vite
|
|
1
|
+
# Storybook for React Native Web & Vite
|
|
2
2
|
|
|
3
|
-
See [documentation](https://storybook.js.org/docs/get-started/frameworks/react-vite?renderer=react) for installation instructions, usage examples, APIs, and more.
|
|
3
|
+
See [documentation](https://storybook.js.org/docs/get-started/frameworks/react-native-web-vite?renderer=react-native-web) for installation instructions, usage examples, APIs, and more.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,52 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import docgenTypescript from '@joshwooding/vite-plugin-react-docgen-typescript';
|
|
1
|
+
import { CompatibleString } from 'storybook/internal/types';
|
|
2
|
+
import { FrameworkOptions as FrameworkOptions$1, StorybookConfig as StorybookConfig$1 } from '@storybook/react-vite';
|
|
4
3
|
import { Options, BabelOptions } from '@vitejs/plugin-react';
|
|
5
4
|
|
|
6
|
-
type
|
|
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;
|
|
5
|
+
type FrameworkOptions = FrameworkOptions$1 & {
|
|
21
6
|
pluginReactOptions?: Omit<Options, 'babel'> & {
|
|
22
7
|
babel?: BabelOptions;
|
|
23
8
|
};
|
|
24
9
|
};
|
|
25
|
-
type
|
|
10
|
+
type FrameworkName = CompatibleString<'@storybook/react-native-web-vite'>;
|
|
11
|
+
/** The interface for Storybook configuration in `main.ts` files. */
|
|
12
|
+
type StorybookConfig = Omit<StorybookConfig$1, 'framework'> & {
|
|
26
13
|
framework: FrameworkName | {
|
|
27
14
|
name: FrameworkName;
|
|
28
15
|
options: FrameworkOptions;
|
|
29
16
|
};
|
|
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
17
|
};
|
|
51
18
|
|
|
52
19
|
export { FrameworkOptions, StorybookConfig };
|
package/dist/preset.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
1
2
|
import { StorybookConfig } from './index.js';
|
|
2
3
|
import 'storybook/internal/types';
|
|
3
|
-
import '@storybook/
|
|
4
|
-
import '@joshwooding/vite-plugin-react-docgen-typescript';
|
|
4
|
+
import '@storybook/react-vite';
|
|
5
5
|
import '@vitejs/plugin-react';
|
|
6
6
|
|
|
7
|
+
declare function reactNativeWeb(): PluginOption;
|
|
7
8
|
declare const viteFinal: StorybookConfig['viteFinal'];
|
|
8
9
|
declare const core: {
|
|
9
10
|
builder: string;
|
|
10
11
|
renderer: string;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
|
-
export { core, viteFinal };
|
|
14
|
+
export { core, reactNativeWeb, viteFinal };
|
package/dist/preset.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var preset_exports={};__export(preset_exports,{core:()=>core,viteFinal:()=>viteFinal});module.exports=__toCommonJS(preset_exports);var import_plugin_react=__toESM(require("@vitejs/plugin-react"));function reactNativeWeb(
|
|
1
|
+
"use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var preset_exports={};__export(preset_exports,{core:()=>core,reactNativeWeb:()=>reactNativeWeb,viteFinal:()=>viteFinal});module.exports=__toCommonJS(preset_exports);var import_preset=require("@storybook/react-vite/preset"),import_plugin_react=__toESM(require("@vitejs/plugin-react"));function reactNativeWeb(){return{name:"vite:react-native-web",config(_userConfig,env){return{define:{"global.__x":{},_frameTimestamp:void 0,_WORKLET:!1,__DEV__:`${env.mode==="development"}`,"process.env.NODE_ENV":JSON.stringify(process.env.NODE_ENV||env.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 viteFinal=async(config,options)=>{let{pluginReactOptions={}}=await options.presets.apply("frameworkOptions"),reactConfig=await(0,import_preset.viteFinal)(config,options),{plugins=[]}=reactConfig;return plugins.unshift((0,import_plugin_react.default)({babel:{babelrc:!1,configFile:!1},jsxRuntime:"automatic",...pluginReactOptions})),plugins.push(reactNativeWeb()),reactConfig},core={builder:"@storybook/builder-vite",renderer:"@storybook/react"};0&&(module.exports={core,reactNativeWeb,viteFinal});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var vite_plugin_exports={};__export(vite_plugin_exports,{storybookReactNativeWeb:()=>storybookReactNativeWeb});module.exports=__toCommonJS(vite_plugin_exports);var import_plugin_react2=__toESM(require("@vitejs/plugin-react"));var import_preset=require("@storybook/react-vite/preset"),import_plugin_react=__toESM(require("@vitejs/plugin-react"));function reactNativeWeb(){return{name:"vite:react-native-web",config(_userConfig,env){return{define:{"global.__x":{},_frameTimestamp:void 0,_WORKLET:!1,__DEV__:`${env.mode==="development"}`,"process.env.NODE_ENV":JSON.stringify(process.env.NODE_ENV||env.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 storybookReactNativeWeb=()=>[(0,import_plugin_react2.default)({babel:{babelrc:!1,configFile:!1},jsxRuntime:"automatic"}),reactNativeWeb()];0&&(module.exports={storybookReactNativeWeb});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import react2 from '@vitejs/plugin-react';
|
|
2
|
+
import '@storybook/react-vite/preset';
|
|
3
|
+
|
|
4
|
+
function reactNativeWeb(){return {name:"vite:react-native-web",config(_userConfig,env){return {define:{"global.__x":{},_frameTimestamp:void 0,_WORKLET:!1,__DEV__:`${env.mode==="development"}`,"process.env.NODE_ENV":JSON.stringify(process.env.NODE_ENV||env.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 storybookReactNativeWeb=()=>[react2({babel:{babelrc:!1,configFile:!1},jsxRuntime:"automatic"}),reactNativeWeb()];
|
|
5
|
+
|
|
6
|
+
export { storybookReactNativeWeb };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/react-native-web-vite",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-29659-sha-1f47b682",
|
|
4
4
|
"description": "Develop react-native components an isolated web environment with hot reloading.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook"
|
|
@@ -30,6 +30,11 @@
|
|
|
30
30
|
"types": "./dist/preset.d.ts",
|
|
31
31
|
"require": "./dist/preset.js"
|
|
32
32
|
},
|
|
33
|
+
"./vite-plugin": {
|
|
34
|
+
"types": "./dist/vite-plugin.d.ts",
|
|
35
|
+
"import": "./dist/vite-plugin.mjs",
|
|
36
|
+
"require": "./dist/vite-plugin.js"
|
|
37
|
+
},
|
|
33
38
|
"./package.json": "./package.json"
|
|
34
39
|
},
|
|
35
40
|
"main": "dist/index.js",
|
|
@@ -49,15 +54,10 @@
|
|
|
49
54
|
},
|
|
50
55
|
"dependencies": {
|
|
51
56
|
"@joshwooding/vite-plugin-react-docgen-typescript": "0.3.0",
|
|
52
|
-
"@
|
|
53
|
-
"@storybook/
|
|
54
|
-
"@storybook/react": "0.0.0-pr-
|
|
55
|
-
"@vitejs/plugin-react": "^4.3.2"
|
|
56
|
-
"find-up": "^5.0.0",
|
|
57
|
-
"magic-string": "^0.30.0",
|
|
58
|
-
"react-docgen": "^7.0.0",
|
|
59
|
-
"resolve": "^1.22.8",
|
|
60
|
-
"tsconfig-paths": "^4.2.0"
|
|
57
|
+
"@storybook/builder-vite": "0.0.0-pr-29659-sha-1f47b682",
|
|
58
|
+
"@storybook/react": "0.0.0-pr-29659-sha-1f47b682",
|
|
59
|
+
"@storybook/react-vite": "0.0.0-pr-29659-sha-1f47b682",
|
|
60
|
+
"@vitejs/plugin-react": "^4.3.2"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/node": "^22.0.0",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
|
|
69
69
|
"react-native": ">=0.74.5",
|
|
70
70
|
"react-native-web": "^0.19.12",
|
|
71
|
-
"storybook": "^0.0.0-pr-
|
|
72
|
-
"vite": "^
|
|
71
|
+
"storybook": "^0.0.0-pr-29659-sha-1f47b682",
|
|
72
|
+
"vite": "^5.0.0"
|
|
73
73
|
},
|
|
74
74
|
"engines": {
|
|
75
75
|
"node": ">=18.0.0"
|
|
@@ -80,7 +80,8 @@
|
|
|
80
80
|
"bundler": {
|
|
81
81
|
"entries": [
|
|
82
82
|
"./src/index.ts",
|
|
83
|
-
"./src/preset.ts"
|
|
83
|
+
"./src/preset.ts",
|
|
84
|
+
"./src/vite-plugin.ts"
|
|
84
85
|
],
|
|
85
86
|
"platform": "node"
|
|
86
87
|
},
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/** Primary UI component for user interaction */
|
|
5
|
+
export const Button = ({
|
|
6
|
+
primary = false,
|
|
7
|
+
size = 'medium',
|
|
8
|
+
backgroundColor,
|
|
9
|
+
label,
|
|
10
|
+
style,
|
|
11
|
+
onPress,
|
|
12
|
+
}) => {
|
|
13
|
+
const modeStyle = primary ? styles.primary : styles.secondary;
|
|
14
|
+
const textModeStyle = primary ? styles.primaryText : styles.secondaryText;
|
|
15
|
+
|
|
16
|
+
const sizeStyle = styles[size];
|
|
17
|
+
const textSizeStyle = textSizeStyles[size];
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<TouchableOpacity accessibilityRole="button" activeOpacity={0.6} onPress={onPress}>
|
|
21
|
+
<View
|
|
22
|
+
style={[
|
|
23
|
+
styles.button,
|
|
24
|
+
modeStyle,
|
|
25
|
+
sizeStyle,
|
|
26
|
+
style,
|
|
27
|
+
!!backgroundColor && { backgroundColor },
|
|
28
|
+
{ borderColor: 'black' },
|
|
29
|
+
]}
|
|
30
|
+
>
|
|
31
|
+
<Text style={[textModeStyle, textSizeStyle]}>{label}</Text>
|
|
32
|
+
</View>
|
|
33
|
+
</TouchableOpacity>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const styles = StyleSheet.create({
|
|
38
|
+
button: {
|
|
39
|
+
borderWidth: 0,
|
|
40
|
+
borderRadius: 48,
|
|
41
|
+
},
|
|
42
|
+
buttonText: {
|
|
43
|
+
fontWeight: '700',
|
|
44
|
+
lineHeight: 1,
|
|
45
|
+
},
|
|
46
|
+
primary: {
|
|
47
|
+
backgroundColor: '#1ea7fd',
|
|
48
|
+
},
|
|
49
|
+
primaryText: {
|
|
50
|
+
color: 'white',
|
|
51
|
+
},
|
|
52
|
+
secondary: {
|
|
53
|
+
backgroundColor: 'transparent',
|
|
54
|
+
borderColor: 'rgba(0, 0, 0, 0.15)',
|
|
55
|
+
borderWidth: 1,
|
|
56
|
+
},
|
|
57
|
+
secondaryText: {
|
|
58
|
+
color: '#333',
|
|
59
|
+
},
|
|
60
|
+
small: {
|
|
61
|
+
paddingVertical: 10,
|
|
62
|
+
paddingHorizontal: 16,
|
|
63
|
+
},
|
|
64
|
+
smallText: {
|
|
65
|
+
fontSize: 12,
|
|
66
|
+
},
|
|
67
|
+
medium: {
|
|
68
|
+
paddingVertical: 11,
|
|
69
|
+
paddingHorizontal: 20,
|
|
70
|
+
},
|
|
71
|
+
mediumText: {
|
|
72
|
+
fontSize: 14,
|
|
73
|
+
},
|
|
74
|
+
large: {
|
|
75
|
+
paddingVertical: 12,
|
|
76
|
+
paddingHorizontal: 24,
|
|
77
|
+
},
|
|
78
|
+
largeText: {
|
|
79
|
+
fontSize: 16,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const textSizeStyles = {
|
|
84
|
+
small: styles.smallText,
|
|
85
|
+
medium: styles.mediumText,
|
|
86
|
+
large: styles.largeText,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
Button.propTypes = {
|
|
90
|
+
/** Is this the principal call to action on the page? */
|
|
91
|
+
primary: PropTypes.bool,
|
|
92
|
+
/** What background color to use */
|
|
93
|
+
backgroundColor: PropTypes.string,
|
|
94
|
+
/** How large should the button be? */
|
|
95
|
+
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
96
|
+
/** Button contents */
|
|
97
|
+
label: PropTypes.string.isRequired,
|
|
98
|
+
/** Optional click handler */
|
|
99
|
+
onPress: PropTypes.func,
|
|
100
|
+
/** Optional extra styles */
|
|
101
|
+
style: PropTypes.object,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
Button.defaultProps = {
|
|
105
|
+
backgroundColor: null,
|
|
106
|
+
primary: false,
|
|
107
|
+
size: 'medium',
|
|
108
|
+
onClick: undefined,
|
|
109
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { fn } from '@storybook/test';
|
|
2
|
+
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import { Button } from './Button';
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
title: 'Example/Button',
|
|
9
|
+
component: Button,
|
|
10
|
+
decorators: [
|
|
11
|
+
(Story) => (
|
|
12
|
+
<View style={{ flex: 1, alignItems: 'flex-start' }}>
|
|
13
|
+
<Story />
|
|
14
|
+
</View>
|
|
15
|
+
),
|
|
16
|
+
],
|
|
17
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
18
|
+
tags: ['autodocs'],
|
|
19
|
+
// 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
|
|
20
|
+
args: { onPress: fn() },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default meta;
|
|
24
|
+
|
|
25
|
+
export const Primary = {
|
|
26
|
+
args: {
|
|
27
|
+
primary: true,
|
|
28
|
+
label: 'Button',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const Secondary = {
|
|
33
|
+
args: {
|
|
34
|
+
label: 'Button',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const Large = {
|
|
39
|
+
args: {
|
|
40
|
+
size: 'large',
|
|
41
|
+
label: 'Button',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const Small = {
|
|
46
|
+
args: {
|
|
47
|
+
size: 'small',
|
|
48
|
+
label: 'Button',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { Button } from './Button';
|
|
5
|
+
|
|
6
|
+
export const Header = ({ user, onLogin, onLogout, onCreateAccount }) => (
|
|
7
|
+
<View>
|
|
8
|
+
<View style={styles.wrapper}>
|
|
9
|
+
<View style={styles.logoContainer}>
|
|
10
|
+
<Text style={styles.h1}>Acme</Text>
|
|
11
|
+
</View>
|
|
12
|
+
|
|
13
|
+
<View style={styles.buttonContainer}>
|
|
14
|
+
{user ? (
|
|
15
|
+
<>
|
|
16
|
+
<>
|
|
17
|
+
<Text>Welcome, </Text>
|
|
18
|
+
<Text style={styles.userName}>{user.name}!</Text>
|
|
19
|
+
</>
|
|
20
|
+
<Button style={styles.button} size="small" onPress={onLogout} label="Log out" />
|
|
21
|
+
</>
|
|
22
|
+
) : (
|
|
23
|
+
<>
|
|
24
|
+
<Button style={styles.button} size="small" onPress={onLogin} label="Log in" />
|
|
25
|
+
<Button
|
|
26
|
+
style={styles.button}
|
|
27
|
+
primary
|
|
28
|
+
size="small"
|
|
29
|
+
onPress={onCreateAccount}
|
|
30
|
+
label="Sign up"
|
|
31
|
+
/>
|
|
32
|
+
</>
|
|
33
|
+
)}
|
|
34
|
+
</View>
|
|
35
|
+
</View>
|
|
36
|
+
</View>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const styles = StyleSheet.create({
|
|
40
|
+
wrapper: {
|
|
41
|
+
borderBottomWidth: 1,
|
|
42
|
+
borderBottomColor: 'rgba(0, 0, 0, 0.1)',
|
|
43
|
+
paddingVertical: 15,
|
|
44
|
+
paddingHorizontal: 20,
|
|
45
|
+
flexDirection: 'row',
|
|
46
|
+
justifyContent: 'space-between',
|
|
47
|
+
},
|
|
48
|
+
h1: {
|
|
49
|
+
fontWeight: '900',
|
|
50
|
+
fontSize: 20,
|
|
51
|
+
marginTop: 6,
|
|
52
|
+
marginBottom: 6,
|
|
53
|
+
marginLeft: 10,
|
|
54
|
+
color: 'black',
|
|
55
|
+
alignSelf: 'flex-start',
|
|
56
|
+
},
|
|
57
|
+
logoContainer: {
|
|
58
|
+
flexDirection: 'row',
|
|
59
|
+
alignItems: 'center',
|
|
60
|
+
},
|
|
61
|
+
button: {
|
|
62
|
+
marginLeft: 10,
|
|
63
|
+
},
|
|
64
|
+
buttonContainer: {
|
|
65
|
+
flexDirection: 'row',
|
|
66
|
+
alignItems: 'center',
|
|
67
|
+
},
|
|
68
|
+
userName: {
|
|
69
|
+
fontWeight: '700',
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
Header.propTypes = {
|
|
74
|
+
user: PropTypes.shape({
|
|
75
|
+
name: PropTypes.string.isRequired,
|
|
76
|
+
}),
|
|
77
|
+
onLogin: PropTypes.func.isRequired,
|
|
78
|
+
onLogout: PropTypes.func.isRequired,
|
|
79
|
+
onCreateAccount: PropTypes.func.isRequired,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
Header.defaultProps = {
|
|
83
|
+
user: null,
|
|
84
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Header } from './Header';
|
|
2
|
+
|
|
3
|
+
const meta = {
|
|
4
|
+
title: 'Example/Header',
|
|
5
|
+
component: Header,
|
|
6
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default meta;
|
|
11
|
+
|
|
12
|
+
export const LoggedIn = {
|
|
13
|
+
args: {
|
|
14
|
+
user: {
|
|
15
|
+
name: 'Jane Doe',
|
|
16
|
+
},
|
|
17
|
+
onLogin: () => {},
|
|
18
|
+
onLogout: () => {},
|
|
19
|
+
onCreateAccount: () => {},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const LoggedOut = {
|
|
24
|
+
args: {
|
|
25
|
+
onLogin: () => {},
|
|
26
|
+
onLogout: () => {},
|
|
27
|
+
onCreateAccount: () => {},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
|
|
24
|
+
<Text style={styles.p}>
|
|
25
|
+
We recommend building UIs with a{' '}
|
|
26
|
+
<Text
|
|
27
|
+
style={[styles.a, { fontWeight: 'bold' }]}
|
|
28
|
+
role="link"
|
|
29
|
+
onPress={() => {
|
|
30
|
+
Linking.openURL('https://componentdriven.org');
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
<Text>component-driven</Text>
|
|
34
|
+
</Text>{' '}
|
|
35
|
+
process starting with atomic components and ending with pages.
|
|
36
|
+
</Text>
|
|
37
|
+
|
|
38
|
+
<Text style={styles.p}>
|
|
39
|
+
Render pages with mock data. This makes it easy to build and review page states without
|
|
40
|
+
needing to navigate to them in your app. Here are some handy patterns for managing page
|
|
41
|
+
data in Storybook:
|
|
42
|
+
</Text>
|
|
43
|
+
|
|
44
|
+
<View>
|
|
45
|
+
<View>
|
|
46
|
+
Use a higher-level connected component. Storybook helps you compose such data from the
|
|
47
|
+
"args" of child component stories
|
|
48
|
+
</View>
|
|
49
|
+
|
|
50
|
+
<View>
|
|
51
|
+
Assemble data in the page component from your services. You can mock these services out
|
|
52
|
+
using Storybook.
|
|
53
|
+
</View>
|
|
54
|
+
</View>
|
|
55
|
+
|
|
56
|
+
<Text style={styles.p}>
|
|
57
|
+
Get a guided tutorial on component-driven development at{' '}
|
|
58
|
+
<Text
|
|
59
|
+
style={styles.a}
|
|
60
|
+
role="link"
|
|
61
|
+
onPress={() => {
|
|
62
|
+
Linking.openURL('https://storybook.js.org/tutorials/');
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
Storybook tutorials
|
|
66
|
+
</Text>
|
|
67
|
+
. Read more in the{' '}
|
|
68
|
+
<Text
|
|
69
|
+
style={styles.a}
|
|
70
|
+
role="link"
|
|
71
|
+
onPress={() => {
|
|
72
|
+
Linking.openURL('https://storybook.js.org/docs');
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
docs
|
|
76
|
+
</Text>
|
|
77
|
+
.
|
|
78
|
+
</Text>
|
|
79
|
+
|
|
80
|
+
<View style={styles.tipWrapper}>
|
|
81
|
+
<View style={styles.tip}>
|
|
82
|
+
<Text style={styles.tipText}>Tip </Text>
|
|
83
|
+
</View>
|
|
84
|
+
|
|
85
|
+
<Text>Adjust the width of the canvas with the </Text>
|
|
86
|
+
|
|
87
|
+
<Text>Viewports addon in the toolbar</Text>
|
|
88
|
+
</View>
|
|
89
|
+
</View>
|
|
90
|
+
</View>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const styles = StyleSheet.create({
|
|
95
|
+
section: {
|
|
96
|
+
fontFamily: "'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif",
|
|
97
|
+
fontSize: 14,
|
|
98
|
+
lineHeight: 24,
|
|
99
|
+
paddingVertical: 48,
|
|
100
|
+
paddingHorizontal: 20,
|
|
101
|
+
marginHorizontal: 'auto',
|
|
102
|
+
maxWidth: 600,
|
|
103
|
+
color: '#333',
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
h2: {
|
|
107
|
+
fontWeight: '900',
|
|
108
|
+
fontSize: 32,
|
|
109
|
+
lineHeight: 1,
|
|
110
|
+
marginBottom: 4,
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
p: {
|
|
114
|
+
marginVertical: 16,
|
|
115
|
+
marginHorizontal: 0,
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
a: {
|
|
119
|
+
color: '#1ea7fd',
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
ul: {
|
|
123
|
+
paddingLeft: 30,
|
|
124
|
+
marginVertical: 16,
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
li: {
|
|
128
|
+
marginBottom: 8,
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
tip: {
|
|
132
|
+
alignSelf: 'flex-start',
|
|
133
|
+
borderRadius: 16,
|
|
134
|
+
backgroundColor: '#e7fdd8',
|
|
135
|
+
paddingVertical: 4,
|
|
136
|
+
paddingHorizontal: 12,
|
|
137
|
+
marginRight: 10,
|
|
138
|
+
marginBottom: 4,
|
|
139
|
+
},
|
|
140
|
+
tipText: {
|
|
141
|
+
fontSize: 11,
|
|
142
|
+
lineHeight: 12,
|
|
143
|
+
fontWeight: '700',
|
|
144
|
+
color: '#66bf3c',
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
tipWrapper: {
|
|
148
|
+
fontSize: 13,
|
|
149
|
+
lineHeight: 20,
|
|
150
|
+
marginTop: 40,
|
|
151
|
+
marginBottom: 40,
|
|
152
|
+
flexDirection: 'row',
|
|
153
|
+
flexWrap: 'wrap',
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
tipWrapperSvg: {
|
|
157
|
+
height: 12,
|
|
158
|
+
width: 12,
|
|
159
|
+
marginRight: 4,
|
|
160
|
+
marginTop: 3,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { expect, userEvent, within } from '@storybook/test';
|
|
2
|
+
|
|
3
|
+
import { Page } from './Page';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Example/Page',
|
|
7
|
+
component: Page,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default meta;
|
|
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 = {};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { fn } from '@storybook/test';
|
|
2
3
|
|
|
3
4
|
import { View } from 'react-native';
|
|
4
5
|
|
|
5
6
|
import { Button } from './Button';
|
|
6
7
|
|
|
7
8
|
const meta: Meta<typeof Button> = {
|
|
9
|
+
title: 'Example/Button',
|
|
8
10
|
component: Button,
|
|
9
11
|
decorators: [
|
|
10
12
|
(Story) => (
|
|
@@ -13,6 +15,10 @@ const meta: Meta<typeof Button> = {
|
|
|
13
15
|
</View>
|
|
14
16
|
),
|
|
15
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() },
|
|
16
22
|
};
|
|
17
23
|
|
|
18
24
|
export default meta;
|
|
@@ -12,7 +12,6 @@ export interface ButtonProps {
|
|
|
12
12
|
label: string;
|
|
13
13
|
/** Optional click handler */
|
|
14
14
|
onPress?: () => void;
|
|
15
|
-
style?: StyleProp<ViewStyle>;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
/** Primary UI component for user interaction */
|
|
@@ -21,7 +20,6 @@ export const Button = ({
|
|
|
21
20
|
size = 'medium',
|
|
22
21
|
backgroundColor,
|
|
23
22
|
label,
|
|
24
|
-
style,
|
|
25
23
|
onPress,
|
|
26
24
|
}: ButtonProps) => {
|
|
27
25
|
const modeStyle = primary ? styles.primary : styles.secondary;
|
|
@@ -3,7 +3,10 @@ import type { Meta, StoryObj } from '@storybook/react';
|
|
|
3
3
|
import { Header } from './Header';
|
|
4
4
|
|
|
5
5
|
const meta: Meta<typeof Header> = {
|
|
6
|
+
title: 'Example/Header',
|
|
6
7
|
component: Header,
|
|
8
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
9
|
+
tags: ['autodocs'],
|
|
7
10
|
};
|
|
8
11
|
|
|
9
12
|
export default meta;
|
|
@@ -12,7 +15,9 @@ type Story = StoryObj<typeof meta>;
|
|
|
12
15
|
|
|
13
16
|
export const LoggedIn: Story = {
|
|
14
17
|
args: {
|
|
15
|
-
user: {
|
|
18
|
+
user: {
|
|
19
|
+
name: 'Jane Doe',
|
|
20
|
+
},
|
|
16
21
|
onLogin: () => {},
|
|
17
22
|
onLogout: () => {},
|
|
18
23
|
onCreateAccount: () => {},
|
|
@@ -18,7 +18,13 @@ export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps
|
|
|
18
18
|
|
|
19
19
|
<View style={styles.buttonContainer}>
|
|
20
20
|
{user ? (
|
|
21
|
-
|
|
21
|
+
<>
|
|
22
|
+
<>
|
|
23
|
+
<Text>Welcome, </Text>
|
|
24
|
+
<Text style={styles.userName}>{user.name}!</Text>
|
|
25
|
+
</>
|
|
26
|
+
<Button style={styles.button} size="small" onPress={onLogout} label="Log out" />
|
|
27
|
+
</>
|
|
22
28
|
) : (
|
|
23
29
|
<>
|
|
24
30
|
<Button style={styles.button} size="small" onPress={onLogin} label="Log in" />
|
|
@@ -64,5 +70,9 @@ const styles = StyleSheet.create({
|
|
|
64
70
|
},
|
|
65
71
|
buttonContainer: {
|
|
66
72
|
flexDirection: 'row',
|
|
73
|
+
alignItems: 'center',
|
|
74
|
+
},
|
|
75
|
+
userName: {
|
|
76
|
+
fontWeight: '700',
|
|
67
77
|
},
|
|
68
78
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { expect, userEvent, within } from '@storybook/test';
|
|
2
3
|
|
|
3
|
-
import * as HeaderStories from './Header.stories';
|
|
4
4
|
import { Page } from './Page';
|
|
5
5
|
|
|
6
6
|
const meta: Meta<typeof Page> = {
|
|
7
|
+
title: 'Example/Page',
|
|
7
8
|
component: Page,
|
|
8
9
|
};
|
|
9
10
|
|
|
@@ -12,9 +13,16 @@ export default meta;
|
|
|
12
13
|
type Story = StoryObj<typeof meta>;
|
|
13
14
|
|
|
14
15
|
export const LoggedIn: Story = {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
play: async ({ canvasElement }) => {
|
|
17
|
+
const canvas = within(canvasElement);
|
|
18
|
+
const loginButton = canvas.getByRole('button', { name: /Log in/i });
|
|
19
|
+
await expect(loginButton).toBeInTheDocument();
|
|
20
|
+
await userEvent.click(loginButton);
|
|
21
|
+
// FIXME: await expect(loginButton).not.toBeInTheDocument();
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
|
|
24
|
+
await expect(logoutButton).toBeInTheDocument();
|
|
25
|
+
},
|
|
20
26
|
};
|
|
27
|
+
|
|
28
|
+
export const LoggedOut: Story = {};
|
|
@@ -1,91 +1,95 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
1
3
|
import { Linking, StyleSheet, Text, View } from 'react-native';
|
|
2
4
|
|
|
3
5
|
import { Header } from './Header';
|
|
4
6
|
|
|
5
|
-
export
|
|
6
|
-
user
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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>
|
|
11
23
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
</Text>{' '}
|
|
32
|
-
process starting with atomic components and ending with pages.
|
|
33
|
-
</Text>
|
|
34
|
-
|
|
35
|
-
<Text style={styles.p}>
|
|
36
|
-
Render pages with mock data. This makes it easy to build and review page states without
|
|
37
|
-
needing to navigate to them in your app. Here are some handy patterns for managing page data
|
|
38
|
-
in Storybook:
|
|
39
|
-
</Text>
|
|
40
|
-
|
|
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>
|
|
24
|
+
<Text style={styles.p}>
|
|
25
|
+
We recommend building UIs with a{' '}
|
|
26
|
+
<Text
|
|
27
|
+
style={[styles.a, { fontWeight: 'bold' }]}
|
|
28
|
+
role="link"
|
|
29
|
+
onPress={() => {
|
|
30
|
+
Linking.openURL('https://componentdriven.org');
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
<Text>component-driven</Text>
|
|
34
|
+
</Text>{' '}
|
|
35
|
+
process starting with atomic components and ending with pages.
|
|
36
|
+
</Text>
|
|
37
|
+
|
|
38
|
+
<Text style={styles.p}>
|
|
39
|
+
Render pages with mock data. This makes it easy to build and review page states without
|
|
40
|
+
needing to navigate to them in your app. Here are some handy patterns for managing page
|
|
41
|
+
data in Storybook:
|
|
42
|
+
</Text>
|
|
46
43
|
|
|
47
44
|
<View>
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
<View>
|
|
46
|
+
Use a higher-level connected component. Storybook helps you compose such data from the
|
|
47
|
+
"args" of child component stories
|
|
48
|
+
</View>
|
|
49
|
+
|
|
50
|
+
<View>
|
|
51
|
+
Assemble data in the page component from your services. You can mock these services out
|
|
52
|
+
using Storybook.
|
|
53
|
+
</View>
|
|
50
54
|
</View>
|
|
51
|
-
</View>
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
56
|
+
<Text style={styles.p}>
|
|
57
|
+
Get a guided tutorial on component-driven development at{' '}
|
|
58
|
+
<Text
|
|
59
|
+
style={styles.a}
|
|
60
|
+
role="link"
|
|
61
|
+
onPress={() => {
|
|
62
|
+
Linking.openURL('https://storybook.js.org/tutorials/');
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
Storybook tutorials
|
|
66
|
+
</Text>
|
|
67
|
+
. Read more in the{' '}
|
|
68
|
+
<Text
|
|
69
|
+
style={styles.a}
|
|
70
|
+
role="link"
|
|
71
|
+
onPress={() => {
|
|
72
|
+
Linking.openURL('https://storybook.js.org/docs');
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
docs
|
|
76
|
+
</Text>
|
|
77
|
+
.
|
|
73
78
|
</Text>
|
|
74
|
-
.
|
|
75
|
-
</Text>
|
|
76
79
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
<View style={styles.tipWrapper}>
|
|
81
|
+
<View style={styles.tip}>
|
|
82
|
+
<Text style={styles.tipText}>Tip </Text>
|
|
83
|
+
</View>
|
|
81
84
|
|
|
82
|
-
|
|
85
|
+
<Text>Adjust the width of the canvas with the </Text>
|
|
83
86
|
|
|
84
|
-
|
|
87
|
+
<Text>Viewports addon in the toolbar</Text>
|
|
88
|
+
</View>
|
|
85
89
|
</View>
|
|
86
90
|
</View>
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
);
|
|
92
|
+
};
|
|
89
93
|
|
|
90
94
|
const styles = StyleSheet.create({
|
|
91
95
|
section: {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { fn } from '@storybook/test';
|
|
2
3
|
|
|
3
4
|
import { View } from 'react-native';
|
|
4
5
|
|
|
5
6
|
import { Button } from './Button';
|
|
6
7
|
|
|
7
8
|
const meta = {
|
|
9
|
+
title: 'Example/Button',
|
|
8
10
|
component: Button,
|
|
9
11
|
decorators: [
|
|
10
12
|
(Story) => (
|
|
@@ -13,6 +15,10 @@ const meta = {
|
|
|
13
15
|
</View>
|
|
14
16
|
),
|
|
15
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() },
|
|
16
22
|
} satisfies Meta<typeof Button>;
|
|
17
23
|
|
|
18
24
|
export default meta;
|
|
@@ -3,7 +3,10 @@ import type { Meta, StoryObj } from '@storybook/react';
|
|
|
3
3
|
import { Header } from './Header';
|
|
4
4
|
|
|
5
5
|
const meta = {
|
|
6
|
+
title: 'Example/Header',
|
|
6
7
|
component: Header,
|
|
8
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
9
|
+
tags: ['autodocs'],
|
|
7
10
|
} satisfies Meta<typeof Header>;
|
|
8
11
|
|
|
9
12
|
export default meta;
|
|
@@ -12,7 +15,9 @@ type Story = StoryObj<typeof meta>;
|
|
|
12
15
|
|
|
13
16
|
export const LoggedIn: Story = {
|
|
14
17
|
args: {
|
|
15
|
-
user: {
|
|
18
|
+
user: {
|
|
19
|
+
name: 'Jane Doe',
|
|
20
|
+
},
|
|
16
21
|
onLogin: () => {},
|
|
17
22
|
onLogout: () => {},
|
|
18
23
|
onCreateAccount: () => {},
|
|
@@ -17,7 +17,13 @@ export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps
|
|
|
17
17
|
</View>
|
|
18
18
|
<View style={styles.buttonContainer}>
|
|
19
19
|
{user ? (
|
|
20
|
-
|
|
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
|
+
</>
|
|
21
27
|
) : (
|
|
22
28
|
<>
|
|
23
29
|
<Button style={styles.button} size="small" onPress={onLogin} label="Log in" />
|
|
@@ -62,5 +68,9 @@ const styles = StyleSheet.create({
|
|
|
62
68
|
},
|
|
63
69
|
buttonContainer: {
|
|
64
70
|
flexDirection: 'row',
|
|
71
|
+
alignItems: 'center',
|
|
72
|
+
},
|
|
73
|
+
userName: {
|
|
74
|
+
fontWeight: '700',
|
|
65
75
|
},
|
|
66
76
|
});
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import type { Meta } from '@storybook/react';
|
|
2
|
+
import { expect, userEvent, within } from '@storybook/test';
|
|
2
3
|
|
|
3
|
-
import * as HeaderStories from './Header.stories';
|
|
4
4
|
import { Page } from './Page';
|
|
5
5
|
|
|
6
6
|
export default {
|
|
7
|
+
title: 'Example/Page',
|
|
7
8
|
component: Page,
|
|
8
9
|
} as Meta<typeof Page>;
|
|
9
10
|
|
|
10
11
|
export const LoggedIn = {
|
|
11
|
-
|
|
12
|
-
|
|
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();
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
const logoutButton = canvas.getByRole('button', { name: /Log out/i });
|
|
20
|
+
await expect(logoutButton).toBeInTheDocument();
|
|
21
|
+
},
|
|
16
22
|
};
|
|
23
|
+
|
|
24
|
+
export const LoggedOut = {};
|
|
@@ -1,83 +1,87 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
1
3
|
import { Linking, StyleSheet, Text, View } from 'react-native';
|
|
2
4
|
|
|
3
5
|
import { Header } from './Header';
|
|
4
6
|
|
|
5
|
-
export
|
|
6
|
-
user
|
|
7
|
-
onLogin: () => void;
|
|
8
|
-
onLogout: () => void;
|
|
9
|
-
onCreateAccount: () => void;
|
|
10
|
-
};
|
|
7
|
+
export const Page = () => {
|
|
8
|
+
const [user, setUser] = useState();
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
/>
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
<View>
|
|
39
|
-
<View>
|
|
40
|
-
Use a higher-level connected component. Storybook helps you compose such data from the
|
|
41
|
-
"args" of child component stories
|
|
42
|
-
</View>
|
|
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>
|
|
43
41
|
<View>
|
|
44
|
-
|
|
45
|
-
|
|
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>
|
|
46
50
|
</View>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
+
.
|
|
58
73
|
</Text>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}}
|
|
66
|
-
>
|
|
67
|
-
docs
|
|
68
|
-
</Text>
|
|
69
|
-
.
|
|
70
|
-
</Text>
|
|
71
|
-
<View style={styles.tipWrapper}>
|
|
72
|
-
<View style={styles.tip}>
|
|
73
|
-
<Text style={styles.tipText}>Tip </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>
|
|
74
80
|
</View>
|
|
75
|
-
<Text>Adjust the width of the canvas with the </Text>
|
|
76
|
-
<Text>Viewports addon in the toolbar</Text>
|
|
77
81
|
</View>
|
|
78
82
|
</View>
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
);
|
|
84
|
+
};
|
|
81
85
|
|
|
82
86
|
const styles = StyleSheet.create({
|
|
83
87
|
section: {
|