-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update storybook example * reduce dependency
- Loading branch information
Showing
38 changed files
with
700 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,35 @@ | ||
node_modules | ||
/storybook-static | ||
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files | ||
|
||
# dependencies | ||
node_modules/ | ||
|
||
# Expo | ||
.expo/ | ||
dist/ | ||
web-build/ | ||
|
||
# Native | ||
*.orig.* | ||
*.jks | ||
*.p8 | ||
*.p12 | ||
*.key | ||
*.mobileprovision | ||
|
||
# Metro | ||
.metro-health-check* | ||
|
||
# debug | ||
npm-debug.* | ||
yarn-debug.* | ||
yarn-error.* | ||
|
||
# macOS | ||
.DS_Store | ||
*.pem | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# typescript | ||
*.tsbuildinfo |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { getConfigForPWA } from "expo-pwa"; | ||
import path from "path"; | ||
import { DefinePlugin } from "webpack"; | ||
|
||
/** @type { import('@storybook/react-webpack5').StorybookConfig } */ | ||
const config = { | ||
stories: [ | ||
"../stories/**/*.mdx", | ||
"../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)", | ||
], | ||
addons: [ | ||
"@storybook/addon-links", | ||
"@storybook/addon-essentials", | ||
"@storybook/addon-onboarding", | ||
"@storybook/addon-interactions", | ||
{ | ||
name: "@storybook/addon-react-native-web", | ||
options: { | ||
modulesToTranspile: [], | ||
projectRoot: "../", | ||
babelPlugins: ["@babel/plugin-proposal-export-namespace-from"], | ||
}, | ||
}, | ||
], | ||
framework: { | ||
name: "@storybook/react-webpack5", | ||
options: {}, | ||
}, | ||
docs: { | ||
autodocs: "tag", | ||
}, | ||
webpackFinal: (config) => { | ||
config.plugins.push( | ||
// Used for surfacing information related to constants | ||
new DefinePlugin({ | ||
"process.env.APP_MANIFEST": JSON.stringify( | ||
sanitizeConfig(getConfigForPWA(path.join(__dirname, ".."))) | ||
), | ||
}) | ||
); | ||
|
||
return config; | ||
}, | ||
}; | ||
|
||
function sanitizeConfig(config) { | ||
delete config._internal; | ||
delete config.ios; | ||
delete config.android; | ||
delete config.plugins; | ||
delete config.hooks; | ||
delete config.facebookScheme; | ||
delete config.facebookAppId; | ||
delete config.facebookDisplayName; | ||
delete config.assetBundlePatterns; | ||
return config; | ||
} | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** @type { import('@storybook/react').Preview } */ | ||
const preview = { | ||
parameters: { | ||
actions: { argTypesRegex: "^on[A-Z].*" }, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default preview; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { StatusBar } from 'expo-status-bar'; | ||
import { StyleSheet, Text, View } from 'react-native'; | ||
|
||
export default function App() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text>Open up App.js to start working on your app!</Text> | ||
<StatusBar style="auto" /> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: '#fff', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,26 @@ | ||
# Storybook Example | ||
# Storybook Webpack Example | ||
|
||
<p> | ||
<!-- iOS --> | ||
<img alt="Supports Expo iOS" longdesc="Supports Expo iOS" src="https://img.shields.io/badge/iOS-4630EB.svg?style=flat-square&logo=APPLE&labelColor=999999&logoColor=fff" /> | ||
<!-- Android --> | ||
<img alt="Supports Expo Android" longdesc="Supports Expo Android" src="https://img.shields.io/badge/Android-4630EB.svg?style=flat-square&logo=ANDROID&labelColor=A4C639&logoColor=fff" /> | ||
<!-- Web --> | ||
<img alt="Supports Expo Web" longdesc="Supports Expo Web" src="https://img.shields.io/badge/web-4630EB.svg?style=flat-square&logo=GOOGLE-CHROME&labelColor=4285F4&logoColor=fff" /> | ||
</p> | ||
|
||
<img alt="expo examples" src="https://i.imgur.com/j253BeR.png"> | ||
|
||
You can use Storybook to test and share your component library quickly and easily! This example shows how to use Expo modules with Storybook CLI and Expo CLI. | ||
You can use Storybook to test and share your component library quickly and easily! This example shows how to use Expo libraries with Storybook CLI and Webpack. | ||
|
||
## Running with Storybook CLI | ||
|
||
![expo web with storybook-cli](https://i.imgur.com/0x0Ecmp.png "expo web with storybook-cli") | ||
> web only / Webpack | ||
> web only | ||
This system uses the [community react-native-web addon](https://github.com/storybookjs/addon-react-native-web/) to configure Storybook's Webpack config to support running React Native for web. | ||
|
||
This method runs your Expo components in a Storybook-React environment. This is different to Expo web, but may prove helpful as the Storybook-React community is more robust than the Storybook-React Native community. | ||
This method runs your Expo components in a Storybook-React environment. This is different to Expo CLI's Webpack config. | ||
|
||
- Create Expo project `expo init my-project` | ||
- Create Expo project `npx create expo my-project` | ||
- You can use any template, we'll use the managed blank TypeScript project for this example. | ||
- `cd` into the project and run `npx -p @storybook/cli sb init --type react` to bootstrap a new React project | ||
- Install the expo webpack config so we can add unimodules support `yarn add -D @expo/webpack-config` | ||
- Create a [custom webpack config](./.storybook/webpack.config.js) `touch .storybook/webpack.config.js` | ||
|
||
```js | ||
const { resolve } = require("path"); | ||
const { withUnimodules } = require("@expo/webpack-config/addons"); | ||
|
||
module.exports = ({ config }) => { | ||
return withUnimodules(config, { projectRoot: resolve(__dirname, "../") }); | ||
}; | ||
``` | ||
|
||
- `cd` into the project and run `npx sb init --type react`, and select Webpack 5 to bootstrap a new React project. | ||
- Install the requisite dependencies `npx expo add react-dom react-native-web @storybook/addon-react-native-web expo-pwa` | ||
- The contents of `.storybook/main.js` have been modified to support loading the Expo config for the `expo-constants` libraries. | ||
- Run `yarn build-storybook` to try it out! | ||
- The example should open to `http://localhost:6006/` | ||
- You may also want to add `storybook-static` to your `.gitignore` | ||
|
||
### 📁 File Structure | ||
|
||
``` | ||
Expo with Storybook CLI | ||
├── stories | ||
│ └── Example.stories.js ➡️ A Storybook page to render | ||
├── .storybook | ||
│ ├── config.js ➡️ The entry point / config for a typical Storybook project. | ||
│ └── webpack.config.js ➡️ The custom Webpack config used to add Expo support to Storybook CLI. | ||
├── assets ➡️ All static assets for your project | ||
├── storybook-static ➡️ Generated Storybook files (should be ignored) | ||
└── babel.config.js ➡️ Babel config (should be using `babel-preset-expo`) | ||
``` | ||
|
||
## Running with Expo CLI | ||
|
||
<img alt="storybook with expo-cli" src="https://i.imgur.com/Fpubaor.png"> | ||
|
||
> This method is universal :] | ||
This project can be used for iOS, Android, and web! You may find that it's better to use it for native only, and to use the "Running with Storybook" method for web. Unlike the Expo + Next.js flow, you can use both web methods at the same time! | ||
|
||
- Create Expo project `expo init my-project` | ||
- You can use any template, we'll use the managed blank TypeScript project for this example. | ||
- `cd` into the project and run `npx -p @storybook/cli sb init --type react` to bootstrap a new React project. | ||
- Install the Storybook React Native package: | ||
- `yarn add -D @storybook/react-native` | ||
- In your `App.tsx` or `App.js` | ||
|
||
```ts | ||
import { configure, getStorybookUI } from "@storybook/react-native"; | ||
|
||
configure(() => { | ||
// Since require.context doesn't exist in metro bundler world, we have to | ||
// manually import files ending in *.stories.js | ||
require("./stories"); | ||
}, module); | ||
|
||
export default getStorybookUI(); | ||
``` | ||
|
||
- Create a file for importing all of the stories ([`stories/index.js`](./stories/index.js)): | ||
|
||
- `touch stories/index.js` | ||
- Import all of your stories in this file. Ex: | ||
|
||
```js | ||
// stories/index.js | ||
import "./1-Button.stories"; | ||
``` | ||
|
||
- Register your stories for React Native: | ||
|
||
```diff | ||
// Example.stories.js | ||
+ import { storiesOf } from '@storybook/react-native'; | ||
|
||
export const text = () => ( /_ Example JSX _/ ); | ||
|
||
// Register your story with the `module`, name, and React functional component. | ||
|
||
+ storiesOf('Button', module).add('Text', text); | ||
|
||
``` | ||
|
||
- Now run `yarn start` or `npm run start` to see it in action! | ||
|
||
### 📁 File Structure | ||
|
||
``` | ||
Storybook with Expo CLI | ||
├── stories | ||
│ ├── index.js ➡️ Native story imports | ||
│ └── Example.stories.js ➡️ A Storybook page to render | ||
├── assets ➡️ All static assets for your project | ||
├── App.tsx ➡️ Entry Point for universal Expo apps | ||
├── app.config.js ➡️ Expo config file | ||
└── babel.config.js ➡️ Babel config (should be using `babel-preset-expo`) | ||
``` | ||
|
||
## 📝 Notes | ||
|
||
- [Storybook React](https://storybook.js.org/docs/react/get-started/introduction) | ||
- [Storybook React Native](https://storybook.js.org/docs/guides/guide-react-native/) | ||
To learn more, configure the Storybook plugin according to [the official guide](https://github.com/storybookjs/addon-react-native-web/). |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
{ | ||
"scripts": { | ||
"start": "expo start", | ||
"web": "start-storybook -p 6006", | ||
"build-storybook": "build-storybook" | ||
"storybook": "storybook dev -p 6006", | ||
"build-storybook": "storybook build" | ||
}, | ||
"dependencies": { | ||
"expo": "^49.0.3", | ||
"expo-constants": "~14.4.2", | ||
"expo-font": "~11.4.0", | ||
"expo-linear-gradient": "~12.3.0", | ||
"expo": "~49.0.13", | ||
"expo-linear-gradient": "^12.5.0", | ||
"expo-status-bar": "~1.6.0", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"react-native": "0.72.3", | ||
"react-native": "0.72.5", | ||
"react-native-web": "~0.19.6" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.19.3", | ||
"@expo/webpack-config": "^18.0.1", | ||
"@storybook/addon-actions": "~5.2.1", | ||
"@storybook/addon-links": "~5.2.1", | ||
"@storybook/addons": "~5.2.1", | ||
"@storybook/react": "~5.2.1", | ||
"@storybook/react-native": "~5.3.19", | ||
"@types/react": "~18.2.14", | ||
"@types/react-dom": "~18.0.8", | ||
"@types/react-native": "~0.70.6", | ||
"babel-loader": "^8.0.6", | ||
"typescript": "^5.1.3" | ||
} | ||
"expo-pwa": "^0.0.127", | ||
"@storybook/addon-react-native-web": "^0.0.21", | ||
"@babel/core": "^7.20.0", | ||
"@storybook/addon-essentials": "^7.4.6", | ||
"@storybook/addon-interactions": "^7.4.6", | ||
"@storybook/addon-links": "^7.4.6", | ||
"@storybook/addon-onboarding": "^1.0.8", | ||
"@storybook/blocks": "^7.4.6", | ||
"@storybook/react": "^7.4.6", | ||
"@storybook/react-webpack5": "^7.4.6", | ||
"@storybook/testing-library": "^0.2.2", | ||
"prop-types": "^15.8.1", | ||
"react-dom": "18.2.0", | ||
"storybook": "^7.4.6" | ||
}, | ||
"private": true | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.