@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.
- package/README.md +2 -22
- package/dist/index.d.ts +8 -41
- package/dist/index.js +1 -3
- package/dist/index.mjs +1 -0
- package/dist/preset.d.ts +14 -0
- package/dist/preset.js +1 -0
- 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 +56 -59
- package/preset.js +1 -4
- package/template/cli/.eslintrc.json +7 -0
- 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 +53 -0
- package/template/cli/ts-3-8/Button.tsx +99 -0
- package/template/cli/ts-3-8/Header.stories.tsx +33 -0
- package/template/cli/ts-3-8/Header.tsx +78 -0
- package/template/cli/ts-3-8/Page.stories.tsx +28 -0
- package/template/cli/ts-3-8/Page.tsx +162 -0
- package/template/cli/ts-4-9/Button.stories.tsx +53 -0
- package/template/cli/ts-4-9/Button.tsx +101 -0
- package/template/cli/ts-4-9/Header.stories.tsx +33 -0
- package/template/cli/ts-4-9/Header.tsx +76 -0
- package/template/cli/ts-4-9/Page.stories.tsx +24 -0
- package/template/cli/ts-4-9/Page.tsx +154 -0
- package/dist/index.cjs +0 -4
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -52
- package/dist/index.js.map +0 -1
- package/dist/preset.cjs +0 -15
- package/dist/preset.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Storybook for React Native Web & Vite
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
import { StorybookConfig } from "@storybook/react-native-web-vite";
|
|
5
|
-
const path = require("path");
|
|
6
|
-
|
|
7
|
-
const main: StorybookConfig = {
|
|
8
|
-
stories: ["../src/components/**/*.stories.?(ts|tsx|js|jsx)"],
|
|
9
|
-
|
|
10
|
-
addons: ["@storybook/addon-essentials"],
|
|
11
|
-
|
|
12
|
-
framework: {
|
|
13
|
-
name: "@storybook/react-native-web-vite", // <--- This is the important part.
|
|
14
|
-
options: {},
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
typescript: {
|
|
18
|
-
reactDocgen: "react-docgen-typescript",
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export default main;
|
|
23
|
-
```
|
|
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 {
|
|
1
|
+
import { CompatibleString } from 'storybook/internal/types';
|
|
2
|
+
import { FrameworkOptions as FrameworkOptions$1, StorybookConfig as StorybookConfig$1 } from '@storybook/react-vite';
|
|
2
3
|
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
4
|
|
|
6
|
-
type
|
|
7
|
-
|
|
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"> & {
|
|
5
|
+
type FrameworkOptions = FrameworkOptions$1 & {
|
|
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
|
-
export
|
|
19
|
+
export { FrameworkOptions, StorybookConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
3
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __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 __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var src_exports={};module.exports=__toCommonJS(src_exports);
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/preset.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
|
+
import { StorybookConfig } from './index.js';
|
|
3
|
+
import 'storybook/internal/types';
|
|
4
|
+
import '@storybook/react-vite';
|
|
5
|
+
import '@vitejs/plugin-react';
|
|
6
|
+
|
|
7
|
+
declare function reactNativeWeb(): PluginOption;
|
|
8
|
+
declare const viteFinal: StorybookConfig['viteFinal'];
|
|
9
|
+
declare const core: {
|
|
10
|
+
builder: string;
|
|
11
|
+
renderer: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { core, reactNativeWeb, viteFinal };
|
package/dist/preset.js
ADDED
|
@@ -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 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,92 +1,89 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/react-native-web-vite",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "8.5.0-alpha.10",
|
|
4
|
+
"description": "Develop react-native components an isolated web environment with hot reloading.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"storybook-frameworks"
|
|
6
|
+
"storybook"
|
|
8
7
|
],
|
|
8
|
+
"homepage": "https://github.com/storybookjs/storybook/tree/next/code/frameworks/react-native-web-vite",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/storybookjs/storybook/issues"
|
|
11
|
+
},
|
|
9
12
|
"repository": {
|
|
10
13
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/storybookjs/
|
|
14
|
+
"url": "https://github.com/storybookjs/storybook.git",
|
|
15
|
+
"directory": "code/frameworks/react-native-web-vite"
|
|
16
|
+
},
|
|
17
|
+
"funding": {
|
|
18
|
+
"type": "opencollective",
|
|
19
|
+
"url": "https://opencollective.com/storybook"
|
|
12
20
|
},
|
|
13
|
-
"type": "module",
|
|
14
21
|
"license": "MIT",
|
|
15
|
-
"author": "Daniel Williams <dannyhyunsoowilliams@gmail.com>",
|
|
16
22
|
"exports": {
|
|
17
23
|
".": {
|
|
18
24
|
"types": "./dist/index.d.ts",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
25
|
+
"node": "./dist/index.js",
|
|
26
|
+
"import": "./dist/index.mjs",
|
|
27
|
+
"require": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./preset": {
|
|
30
|
+
"types": "./dist/preset.d.ts",
|
|
31
|
+
"require": "./dist/preset.js"
|
|
32
|
+
},
|
|
33
|
+
"./vite-plugin": {
|
|
34
|
+
"types": "./dist/vite-plugin.d.ts",
|
|
35
|
+
"import": "./dist/vite-plugin.mjs",
|
|
36
|
+
"require": "./dist/vite-plugin.js"
|
|
21
37
|
},
|
|
22
|
-
"./preset": "./dist/preset.cjs",
|
|
23
38
|
"./package.json": "./package.json"
|
|
24
39
|
},
|
|
40
|
+
"main": "dist/index.js",
|
|
41
|
+
"module": "dist/index.mjs",
|
|
42
|
+
"types": "dist/index.d.ts",
|
|
25
43
|
"files": [
|
|
26
44
|
"dist/**/*",
|
|
45
|
+
"template/cli/**/*",
|
|
27
46
|
"README.md",
|
|
28
47
|
"*.js",
|
|
29
|
-
"*.d.ts"
|
|
48
|
+
"*.d.ts",
|
|
49
|
+
"!src/**/*"
|
|
30
50
|
],
|
|
31
51
|
"scripts": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
35
|
-
"start": "run-p build:watch \"storybook --quiet\"",
|
|
36
|
-
"prerelease": "zx scripts/prepublish-checks.js",
|
|
37
|
-
"release": "npm run build && auto shipit",
|
|
38
|
-
"eject-ts": "zx scripts/eject-typescript.js",
|
|
39
|
-
"storybook": "storybook dev -p 6006",
|
|
40
|
-
"build-storybook": "storybook build"
|
|
52
|
+
"check": "jiti ../../../scripts/prepare/check.ts",
|
|
53
|
+
"prep": "jiti ../../../scripts/prepare/bundle.ts"
|
|
41
54
|
},
|
|
42
55
|
"dependencies": {
|
|
43
|
-
"@
|
|
44
|
-
"@storybook/
|
|
45
|
-
"@
|
|
46
|
-
"vite
|
|
47
|
-
"@
|
|
56
|
+
"@joshwooding/vite-plugin-react-docgen-typescript": "0.3.0",
|
|
57
|
+
"@storybook/builder-vite": "8.5.0-alpha.10",
|
|
58
|
+
"@storybook/react": "8.5.0-alpha.10",
|
|
59
|
+
"@storybook/react-vite": "8.5.0-alpha.10",
|
|
60
|
+
"@vitejs/plugin-react": "^4.3.2"
|
|
48
61
|
},
|
|
49
62
|
"devDependencies": {
|
|
50
|
-
"@
|
|
51
|
-
"
|
|
52
|
-
"@storybook/addon-links": "^8.3.6",
|
|
53
|
-
"@storybook/blocks": "^8.3.6",
|
|
54
|
-
"@storybook/react-vite": "^8.3.6",
|
|
55
|
-
"@storybook/test": "^8.3.6",
|
|
56
|
-
"@types/node": "^20.10.0",
|
|
57
|
-
"@types/react": "^18.2.65",
|
|
58
|
-
"@types/react-dom": "^18.2.21",
|
|
59
|
-
"@vitejs/plugin-react": "^4.3.2",
|
|
60
|
-
"auto": "^11.1.1",
|
|
61
|
-
"boxen": "^7.1.1",
|
|
62
|
-
"dedent": "^1.5.1",
|
|
63
|
-
"prettier": "^3.3.3",
|
|
64
|
-
"prompts": "^2.4.2",
|
|
65
|
-
"react": "^18.2.0",
|
|
66
|
-
"react-dom": "^18.2.0",
|
|
67
|
-
"react-native": "^0.75.4",
|
|
68
|
-
"react-native-web": "^0.19.12",
|
|
69
|
-
"storybook": "^8.3.6",
|
|
70
|
-
"tsup": "^8.2.4",
|
|
71
|
-
"typescript": "^5.5.4",
|
|
72
|
-
"vite": "^5.3.5",
|
|
73
|
-
"zx": "^7.2.3"
|
|
63
|
+
"@types/node": "^22.0.0",
|
|
64
|
+
"typescript": "^5.3.2"
|
|
74
65
|
},
|
|
75
66
|
"peerDependencies": {
|
|
76
|
-
"react
|
|
67
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
|
|
68
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
|
|
69
|
+
"react-native": ">=0.74.5",
|
|
77
70
|
"react-native-web": "^0.19.12",
|
|
78
|
-
"storybook": "^8",
|
|
79
|
-
"vite": "^
|
|
71
|
+
"storybook": "^8.5.0-alpha.10",
|
|
72
|
+
"vite": "^5.0.0"
|
|
73
|
+
},
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=18.0.0"
|
|
80
76
|
},
|
|
81
77
|
"publishConfig": {
|
|
82
78
|
"access": "public"
|
|
83
79
|
},
|
|
84
80
|
"bundler": {
|
|
85
|
-
"
|
|
86
|
-
"src/index.ts"
|
|
81
|
+
"entries": [
|
|
82
|
+
"./src/index.ts",
|
|
83
|
+
"./src/preset.ts",
|
|
84
|
+
"./src/vite-plugin.ts"
|
|
87
85
|
],
|
|
88
|
-
"
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
86
|
+
"platform": "node"
|
|
87
|
+
},
|
|
88
|
+
"gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae16"
|
|
89
|
+
}
|
package/preset.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// but Storybook won't pick that filename up so we have to name it preset.js instead
|
|
3
|
-
|
|
4
|
-
module.exports = require('./dist/preset.cjs');
|
|
1
|
+
module.exports = require('./dist/preset');
|
|
@@ -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
|
+
};
|