@storybook/react-native-web-vite 0.0.4-0 → 8.5.0-alpha.7

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 CHANGED
@@ -1,23 +1,3 @@
1
- # @storybook/react-native-web-vite
1
+ # Storybook for React Native Web & Vite
2
2
 
3
- ```ts
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 { StorybookConfig as StorybookConfig$1, TypescriptOptions as TypescriptOptions$1, CompatibleString } from 'storybook/internal/types';
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 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"> & {
5
+ type FrameworkOptions = FrameworkOptions$1 & {
6
+ pluginReactOptions?: Omit<Options, 'babel'> & {
22
7
  babel?: BabelOptions;
23
8
  };
24
9
  };
25
- type StorybookConfigFramework = {
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 type { FrameworkOptions, StorybookConfig };
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
+
@@ -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,5 @@
1
+ import * as vite from 'vite';
2
+
3
+ declare const storybookReactNativeWeb: () => vite.PluginOption[];
4
+
5
+ export { storybookReactNativeWeb };
@@ -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,95 +1,89 @@
1
1
  {
2
2
  "name": "@storybook/react-native-web-vite",
3
- "version": "0.0.4-0",
4
- "description": "Sets up react native web with vite",
3
+ "version": "8.5.0-alpha.7",
4
+ "description": "Develop react-native components an isolated web environment with hot reloading.",
5
5
  "keywords": [
6
- "react-native-web",
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/react-native-web-vite"
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
- "import": "./dist/index.js",
20
- "require": "./dist/index.cjs"
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
  },
25
- "types": "dist/index.d.ts",
26
40
  "main": "dist/index.js",
27
41
  "module": "dist/index.mjs",
42
+ "types": "dist/index.d.ts",
28
43
  "files": [
29
44
  "dist/**/*",
45
+ "template/cli/**/*",
30
46
  "README.md",
31
47
  "*.js",
32
- "*.d.ts"
48
+ "*.d.ts",
49
+ "!src/**/*"
33
50
  ],
34
51
  "scripts": {
35
- "build": "tsup",
36
- "build:watch": "npm run build -- --watch",
37
- "test": "echo \"Error: no test specified\" && exit 1",
38
- "start": "run-p build:watch \"storybook --quiet\"",
39
- "prerelease": "zx scripts/prepublish-checks.js",
40
- "release": "npm run build && auto shipit",
41
- "eject-ts": "zx scripts/eject-typescript.js",
42
- "storybook": "storybook dev -p 6006",
43
- "build-storybook": "storybook build"
52
+ "check": "jiti ../../../scripts/prepare/check.ts",
53
+ "prep": "jiti ../../../scripts/prepare/bundle.ts"
44
54
  },
45
55
  "dependencies": {
46
- "@storybook/builder-vite": "^8.3.6",
47
- "@storybook/react": "^8.3.6",
48
- "@vitejs/plugin-react": "^4.3.2",
49
- "vite-plugin-babel": "^1.2.0",
50
- "@joshwooding/vite-plugin-react-docgen-typescript": "^0.4.1"
56
+ "@joshwooding/vite-plugin-react-docgen-typescript": "0.3.0",
57
+ "@storybook/builder-vite": "8.5.0-alpha.7",
58
+ "@storybook/react": "8.5.0-alpha.7",
59
+ "@storybook/react-vite": "8.5.0-alpha.7",
60
+ "@vitejs/plugin-react": "^4.3.2"
51
61
  },
52
62
  "devDependencies": {
53
- "@storybook/addon-essentials": "^8.3.6",
54
- "@storybook/addon-interactions": "^8.3.6",
55
- "@storybook/addon-links": "^8.3.6",
56
- "@storybook/blocks": "^8.3.6",
57
- "@storybook/react-vite": "^8.3.6",
58
- "@storybook/test": "^8.3.6",
59
- "@types/node": "^20.10.0",
60
- "@types/react": "^18.2.65",
61
- "@types/react-dom": "^18.2.21",
62
- "@vitejs/plugin-react": "^4.3.2",
63
- "auto": "^11.1.1",
64
- "boxen": "^7.1.1",
65
- "dedent": "^1.5.1",
66
- "prettier": "^3.3.3",
67
- "prompts": "^2.4.2",
68
- "react": "^18.2.0",
69
- "react-dom": "^18.2.0",
70
- "react-native": "^0.75.4",
71
- "react-native-web": "^0.19.12",
72
- "storybook": "^8.3.6",
73
- "tsup": "^8.2.4",
74
- "typescript": "^5.5.4",
75
- "vite": "^5.3.5",
76
- "zx": "^7.2.3"
63
+ "@types/node": "^22.0.0",
64
+ "typescript": "^5.3.2"
77
65
  },
78
66
  "peerDependencies": {
79
- "react-native": "^0.75.4",
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",
80
70
  "react-native-web": "^0.19.12",
81
- "storybook": "^8",
82
- "vite": "^4.0.0 || ^5.0.0"
71
+ "storybook": "^8.5.0-alpha.7",
72
+ "vite": "^5.0.0"
73
+ },
74
+ "engines": {
75
+ "node": ">=18.0.0"
83
76
  },
84
77
  "publishConfig": {
85
78
  "access": "public"
86
79
  },
87
80
  "bundler": {
88
- "exportEntries": [
89
- "src/index.ts"
81
+ "entries": [
82
+ "./src/index.ts",
83
+ "./src/preset.ts",
84
+ "./src/vite-plugin.ts"
90
85
  ],
91
- "nodeEntries": [
92
- "src/preset.ts"
93
- ]
94
- }
95
- }
86
+ "platform": "node"
87
+ },
88
+ "gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae16"
89
+ }
package/preset.js CHANGED
@@ -1,4 +1 @@
1
- // this file is slightly misleading. It needs to be CJS, and thus in this "type": "module" package it should be named preset.cjs
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,7 @@
1
+ {
2
+ "rules": {
3
+ "import/extensions": "off",
4
+ "react/no-unknown-property": "off",
5
+ "react/react-in-jsx-scope": "off"
6
+ }
7
+ }
@@ -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
+ };