Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
es2021: true,
'react-native/react-native': true,
},
extends: ['standard-with-typescript', 'plugin:react/recommended', 'prettier'],
extends: ['standard-with-typescript', 'plugin:react/recommended', 'prettier', 'plugin:storybook/recommended'],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ yarn-error.log
# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

react-native-dropdown-selector-*.tgz
react-native-dropdown-selector-*.tgz
*storybook.log
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
node_modules/
package-lock.json
example/
.storybook/
src/storybook/
65 changes: 65 additions & 0 deletions .storybook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Storybook README

## Installation

Followed the instructions in the official [Storybook documentation for React Native Web](https://storybook.js.org/docs/get-started/frameworks/react-native-web-vite#in-a-project-without-storybook?renderer=react-native-web).

```bash
npm create storybook@latest
```

## Configuration

Since our project is originally a React Native project, we diverged from the official documentation a bit to make it work with Storybook and React Native Web.

### 1. Install the extra necessary dependencies

```bash
npm install --save-dev @storybook/react-native-web-vite react-native-web vite
```

### 2. Make the following changes in `.storybook/main.ts`

```diff
- import type { StorybookConfig } from '@storybook/react-vite';
+ import type { StorybookConfig } from '@storybook/react-native-web-vite';
```

```diff
"stories": [
- "../src/**/*.stories.mdx",
"../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"
]
```

```diff
"framework": {
- "name": "@storybook/react-vite",
+ "name": "@storybook/react-native-web-vite",
"options": {}
}
```

### 3. Remove the demo stories

<!--
Below notation only works in GitHub markdown.
https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts
-->

> [!CAUTION]
> Don't use ``-rf`` in the command below. It will delete the required assets for Storybook.

```bash
rm src/stories/*
```

## Creating Stories

The instructions on how to create stories are the same as the official documentation. You can find them [here](https://storybook.js.org/docs/writing-stories?renderer=react-native-web). Make sure the renderer is selected as `React Native Web` on the Storybook documentation.

## Compatibility Resources
Compatibility between React Native and React Native Web is a bit tricky for some native components. Below are some resources that can help you understand the compatibility between the two.

- [Storybook for React Native vs React Native Web](https://storybook.js.org/docs/get-started/frameworks/react-native-web-vite#react-native-vs-react-native-web)
- [React Native / React Native Web compatibility](https://necolas.github.io/react-native-web/docs/react-native-compatibility/)
18 changes: 18 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { StorybookConfig } from '@storybook/react-native-web-vite';

const config: StorybookConfig = {
"stories": [
"../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"
],
"addons": [
"@storybook/addon-essentials",
"@storybook/addon-onboarding",
"@chromatic-com/storybook",
"@storybook/addon-interactions"
],
"framework": {
"name": "@storybook/react-native-web-vite",
"options": {}
}
};
export default config;
14 changes: 14 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Preview } from '@storybook/react'

const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
};

export default preview;
Loading