Skip to content

Commit

Permalink
fix: new storybook added
Browse files Browse the repository at this point in the history
Suraj authored and Suraj committed May 9, 2024
1 parent 6efad72 commit c0197c8
Showing 30 changed files with 36,249 additions and 0 deletions.
4 changes: 4 additions & 0 deletions example/storybook-v7/.expo-shared/assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true,
"40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true
}
14 changes: 14 additions & 0 deletions example/storybook-v7/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
node_modules/
.expo/
dist/
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/

# macOS
.DS_Store
11 changes: 11 additions & 0 deletions example/storybook-v7/.ondevice/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import { view } from './storybook.requires';

const StorybookUIRoot = view.getStorybookUI({
storage: {
getItem: AsyncStorage.getItem,
setItem: AsyncStorage.setItem,
},
});

export default StorybookUIRoot;
13 changes: 13 additions & 0 deletions example/storybook-v7/.ondevice/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { StorybookConfig } from '@storybook/react-native';

const main: StorybookConfig = {
stories: ['../components/**/*.stories.?(ts|tsx|js|jsx)'],
addons: [
'@storybook/addon-ondevice-notes',
'@storybook/addon-ondevice-controls',
'@storybook/addon-ondevice-backgrounds',
'@storybook/addon-ondevice-actions',
],
};

export default main;
26 changes: 26 additions & 0 deletions example/storybook-v7/.ondevice/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds';
import type { Preview } from '@storybook/react';

const preview: Preview = {
decorators: [withBackgrounds],

parameters: {
backgrounds: {
default: 'plain',
values: [
{ name: 'plain', value: 'white' },
{ name: 'warm', value: 'hotpink' },
{ name: 'cool', value: 'deepskyblue' },
],
},
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},
};

export default preview;
57 changes: 57 additions & 0 deletions example/storybook-v7/.ondevice/storybook.requires.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* do not change this file, it is auto generated by storybook. */

import {
start,
prepareStories,
getProjectAnnotations,
} from '@storybook/react-native';

import '@storybook/addon-ondevice-notes/register';
import '@storybook/addon-ondevice-controls/register';
import '@storybook/addon-ondevice-backgrounds/register';
import '@storybook/addon-ondevice-actions/register';

const normalizedStories = [
{
titlePrefix: '',
directory: './components',
files: '**/*.stories.?(ts|tsx|js|jsx)',
importPathMatcher:
/^\.(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)(?!\.)(?=.)[^/]*?\.stories\.(?:ts|tsx|js|jsx)?)$/,

req: require.context(
'../components',
true,
/^\.(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)(?!\.)(?=.)[^/]*?\.stories\.(?:ts|tsx|js|jsx)?)$/
),
},
];

const annotations = [
require('./preview'),
require('@storybook/react-native/dist/preview'),
require('@storybook/addon-actions/preview'),
];

global.STORIES = normalizedStories;

module?.hot?.accept?.();

if (!global.view) {
global.view = start({
annotations,
storyEntries: normalizedStories,
});
} else {
const { importMap } = prepareStories({ storyEntries: normalizedStories });

global.view._preview.onStoriesChanged({
importFn: async (importPath) => importMap[importPath],
});

global.view._preview.onGetProjectAnnotationsChanged({
getProjectAnnotations: getProjectAnnotations(global.view, annotations),
});
}

export const view = global.view;
71 changes: 71 additions & 0 deletions example/storybook-v7/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { resolve } from 'path';

/** @type{import("@storybook/react-webpack5").StorybookConfig} */
module.exports = {
stories: [
'../components/**/*.stories.mdx',
'../components/**/*.stories.@(js|jsx|ts|tsx)',
],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-react-native-web',
{
name: '@storybook/addon-styling-webpack',
options: {
rules: [
// Replaces existing CSS rules to support PostCSS
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: { importLoaders: 1 },
},
{
// Gets options from `postcss.config.js` in your project root
loader: 'postcss-loader',
options: { implementation: require.resolve('postcss') },
},
],
},
],
},
},
],
framework: {
name: '@storybook/react-webpack5',
options: {},
},
docs: {
autodocs: true,
},
webpackFinal: async (config: any) => {
config.module.rules.push({
test: /\.(js|jsx|ts|tsx)$/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
},
include: [
resolve(__dirname, './node_modules/react-native-css-interop'),
resolve(__dirname, '../node_modules/react-native-css-interop'),
],
});

config.module.rules.push({
test: /\.(js|jsx|ts|tsx)$/,
loader: 'babel-loader',
options: {
presets: [
['babel-preset-expo', { jsxImportSource: 'nativewind' }],
'nativewind/babel',
],
plugins: ['react-native-reanimated/plugin'],
},
});

return config;
},
};
16 changes: 16 additions & 0 deletions example/storybook-v7/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import './../global.css';
import type { Preview } from '@storybook/react';

const preview: Preview = {
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},
};

export default preview;
37 changes: 37 additions & 0 deletions example/storybook-v7/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { StyleSheet, Text, View } from 'react-native';
// import Constants from "expo-constants";
import './global.css';

function App() {
return (
<View
style={styles.container}
// style={{
// backgroundColor: "red",
// }}
// style={{ $$css: true, container: "bg-red-500" }}
>
<View className="bg-red-500">
<Text>Open up App.tsx to start working on your app! hello</Text>
</View>
</View>
);
}

let AppEntryPoint = App;

// if (Constants.expoConfig?.extra?.storybookEnabled === "true") {
// AppEntryPoint = require("./.ondevice").default;
// }
AppEntryPoint = require('./.ondevice').default;

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});

export default AppEntryPoint;
57 changes: 57 additions & 0 deletions example/storybook-v7/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
![image](https://user-images.githubusercontent.com/3481514/145904252-92e3dc1e-591f-410f-88a1-b4250f4ba6f2.png)

# getting started

```sh
npx create-expo-app --template expo-template-storybook AwesomeStorybook
```

or

```sh
yarn create expo-app --template expo-template-storybook AwesomeStorybook
```

# app

```sh
yarn start
```

# Ondevice

In this template you can now run `yarn storybook` to start ondevice storybook or `yarn start` to start your expo app.
This works via env variables and expo constants.

```sh
# either
yarn storybook

# ios
yarn storybook:ios

# android
yarn storybook:android
```

If you add new stories on the native (ondevice version) you either need to have the watcher running or run the stories loader

To update the stories one time

```sh
yarn storybook-generate
```

# Web

Start react native web storybook:

```
yarn storybook:web
```

build react native web storybook:

```sh
yarn build-storybook
```
32 changes: 32 additions & 0 deletions example/storybook-v7/app.config.js_old
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export default ({ config }) => ({
...config,
name: "HelloWorld",
slug: "expo-template-blank-typescript",
version: "1.0.0",
orientation: "portrait",
icon: "./assets/icon.png",
extra: {
storybookEnabled: process.env.STORYBOOK_ENABLED,
},
splash: {
image: "./assets/splash.png",
resizeMode: "contain",
backgroundColor: "#ffffff",
},
updates: {
fallbackToCacheTimeout: 0,
},
assetBundlePatterns: ["**/*"],
ios: {
supportsTablet: true,
},
android: {
adaptiveIcon: {
foregroundImage: "./assets/adaptive-icon.png",
backgroundColor: "#FFFFFF",
},
},
web: {
favicon: "./assets/favicon.png",
},
});
10 changes: 10 additions & 0 deletions example/storybook-v7/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ExpoConfig, ConfigContext } from 'expo/config';

export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
name: 'App Launch Kit',
slug: 'app-launch-kit',
extra: {
...config?.extra,
},
});
35 changes: 35 additions & 0 deletions example/storybook-v7/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"expo": {
"name": "App Launch Kit",
"slug": "app-launch-kit",
"owner": "applaunchkit-org",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/images/icon.png",
"scheme": "myapp",
"userInterfaceStyle": "automatic",
"splash": {
"image": "./assets/images/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": ["**/*"],
"ios": {
"bundleIdentifier": "com.gluestack.fullstackkit",
"supportsTablet": true
},
"android": {
"package": "com.gluestack.fullstack_kit",
"adaptiveIcon": {
"foregroundImage": "./assets/images/adaptive-icon.png",
"backgroundColor": "#ffffff"
}
},

"experiments": {
"tsconfigPaths": true
},

"runtimeVersion": "1.0.0"
}
}
4 changes: 4 additions & 0 deletions example/storybook-v7/app.json_old
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "storybook-mix",
"slug": "storybook-mix"
}
Binary file added example/storybook-v7/assets/adaptive-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/storybook-v7/assets/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/storybook-v7/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/storybook-v7/assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions example/storybook-v7/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = function (api) {
api.cache(true);
return {
sourceType: 'unambiguous',
presets: [
['babel-preset-expo', { jsxImportSource: 'nativewind' }],
'nativewind/babel',
],
plugins: [
['babel-plugin-react-docgen-typescript', { exclude: 'node_modules' }],
],
};
};
25 changes: 25 additions & 0 deletions example/storybook-v7/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';
import { View } from 'react-native';
import { MyButton } from './Button';

const meta = {
title: 'MyButton',
component: MyButton,
args: {
text: 'Hello world',
},
decorators: [
(Story) => (
<View style={{ padding: 16 }}>
<Story />
</View>
),
],
} satisfies Meta<typeof MyButton>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {};
31 changes: 31 additions & 0 deletions example/storybook-v7/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { TouchableOpacity, Text, StyleSheet, View } from 'react-native';

interface MyButtonProps {
onPress: () => void;
text: string;
}

export const MyButton = ({ onPress, text }: MyButtonProps) => {
return (
<>
<View className="bg-blue-500">
<Text>dfhgfhgfh</Text>
</View>
<TouchableOpacity style={styles.container} onPress={onPress}>
<Text style={styles.text}>{text}</Text>
</TouchableOpacity>
</>
);
};

const styles = StyleSheet.create({
container: {
paddingHorizontal: 32,
paddingVertical: 8,
backgroundColor: 'purple',
alignSelf: 'flex-start',
borderRadius: 8,
},
text: { color: 'white', fontSize: 16, fontWeight: 'bold' },
});
3 changes: 3 additions & 0 deletions example/storybook-v7/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
38 changes: 38 additions & 0 deletions example/storybook-v7/metro.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const path = require('path');
const { getDefaultConfig } = require('expo/metro-config');
const { generate } = require('@storybook/react-native/scripts/generate');
const { withNativeWind } = require('nativewind/metro');

generate({
configPath: path.resolve(__dirname, './.ondevice'),
useJs: true,
});

const defaultConfig = getDefaultConfig(__dirname);

defaultConfig.transformer.unstable_allowRequireContext = true;

// defaultConfig.resolver.resolveRequest = (context, moduleName, platform) => {
// const defaultResolveResult = context.resolveRequest(
// context,
// moduleName,
// platform
// );

// if (
// process.env.STORYBOOK_ENABLED !== "true" &&
// defaultResolveResult?.filePath?.includes?.(".ondevice/")
// ) {
// return {
// type: "empty",
// };
// }

// return defaultResolveResult;
// };

module.exports = defaultConfig;

module.exports = withNativeWind(defaultConfig, {
input: './global.css',
});
600 changes: 600 additions & 0 deletions example/storybook-v7/output.css

Large diffs are not rendered by default.

23,332 changes: 23,332 additions & 0 deletions example/storybook-v7/package-lock.json_old

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions example/storybook-v7/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "storybook-mix",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"license": "MIT",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"storybook:web": "storybook dev -p 6006",
"build-storybook": "storybook build",
"storybook-generate": "sb-rn-get-stories --config-path .ondevice",
"storybook": "cross-env STORYBOOK_ENABLED='true' expo start",
"storybook:ios": "cross-env STORYBOOK_ENABLED='true' expo start --ios",
"storybook:android": "cross-env STORYBOOK_ENABLED='true' expo start --android"
},
"dependencies": {
"@react-native-async-storage/async-storage": "1.21.0",
"@react-native-community/datetimepicker": "7.6.1",
"@react-native-community/slider": "4.4.2",
"autoprefixer": "^10.4.19",
"expo": "~50.0.17",
"expo-constants": "~15.4.6",
"expo-status-bar": "~1.11.1",
"nativewind": "^4.0.36",
"postcss-loader": "^8.1.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.73.6",
"react-native-reanimated": "^3.11.0",
"react-native-safe-area-context": "4.8.2",
"react-native-web": "~0.19.10"
},
"devDependencies": {
"@babel/core": "^7.19.3",
"@expo/metro-runtime": "~3.1.3",
"@storybook/addon-actions": "^7.6.18",
"@storybook/addon-controls": "^7.6.18",
"@storybook/addon-essentials": "^7.6.18",
"@storybook/addon-links": "^7.6.18",
"@storybook/addon-ondevice-actions": "^7.6.18",
"@storybook/addon-ondevice-backgrounds": "^7.6.18",
"@storybook/addon-ondevice-controls": "^7.6.18",
"@storybook/addon-ondevice-notes": "^7.6.18",
"@storybook/addon-react-native-web": "^0.0.23",
"@storybook/addon-styling-webpack": "^1.0.0",
"@storybook/react": "^7.6.18",
"@storybook/react-native": "^7.6.18",
"@storybook/react-webpack5": "^7.6.18",
"@types/react": "~18.2.45",
"babel-loader": "^8.2.3",
"babel-plugin-react-docgen-typescript": "^1.5.1",
"babel-plugin-react-native-web": "^0.19.10",
"cross-env": "^7.0.3",
"storybook": "^7.6.18",
"tailwindcss": "^3.4.3",
"typescript": "^5.3.0"
},
"resolutions": {
"react-docgen-typescript": "2.2.2"
},
"overrides": {
"react-docgen-typescript": "2.2.2"
},
"pnpm": {
"overrides": {
"react-docgen-typescript": "2.2.2"
}
},
"private": true
}
6 changes: 6 additions & 0 deletions example/storybook-v7/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
14 changes: 14 additions & 0 deletions example/storybook-v7/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./components/**/*.{js,ts,jsx,tsx,mdx}',
'./components/*.{js,ts,jsx,tsx,mdx}',
'./App.{js,ts,jsx,tsx,mdx}',
],
presets: [require('nativewind/preset')],
theme: {
extend: {},
},
plugins: [],
// purge: ['./components/**/*.{js,jsx,ts,tsx}'],
};
6 changes: 6 additions & 0 deletions example/storybook-v7/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true
}
}
11,722 changes: 11,722 additions & 0 deletions example/storybook-v7/yarn.lock

Large diffs are not rendered by default.

0 comments on commit c0197c8

Please sign in to comment.