Skip to content

Commit d420518

Browse files
authored
feat: v7 (storybookjs#502)
* make storage configurable * fix: wrong ids created for multiple configs with titlePrefix (v7) (storybookjs#542) * fix: race condition see storybookjs#543 including contributions from @stevoland and @patlux
1 parent d7a84be commit d420518

File tree

166 files changed

+9972
-12315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+9972
-12315
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ aliases:
44
- &defaults
55
working_directory: /tmp/storybook
66
docker:
7-
- image: cimg/node:16.20.0
7+
- image: cimg/node:20.9.0
88

99
jobs:
1010
build:

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ module.exports = {
44
rules: {
55
'react-native/no-inline-styles': 'off',
66
'react/react-in-jsx-scope': 'off',
7+
curly: ['error', 'multi-line'],
78
},
89
};

.github/ISSUE_TEMPLATE.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
If you are reporting a bug or requesting support, start here:
2+
23
### Bug or support request summary
34

4-
_Please provide issue details here - What did you expect to happen? What happened instead?_
5+
_Please provide issue details here - What did you expect to happen? What happened instead?_
56

67
### Steps to reproduce
78

@@ -14,24 +15,25 @@ _(A screencast can be useful for visual bugs, but it is not a substitute for a t
1415
- @storybook/react x.x.x
1516
- @storybook/addon-something x.x.x
1617

17-
### Affected platforms
18+
### Affected platforms
1819

1920
- _If UI related, please indicate browser, OS, and version_
2021
- _If dependency related, please include relevant version numbers_
2122
- _If developer tooling related, please include the platform information_
2223

2324
### Screenshots / Screencast / Code Snippets (Optional)
2425

25-
```js
26+
```ts
2627
// code here
2728
```
28-
End bug report support request - delete the rest below
2929

30+
End bug report support request - delete the rest below
3031

3132
If you are creating a issue to track work to be completed, start here:
33+
3234
### Work summary
3335

34-
_Please provide a description of the work to be completed here - Include some context as to why something needs to be done and link any related tickets._
36+
_Please provide a description of the work to be completed here - Include some context as to why something needs to be done and link any related tickets._
3537

3638
### Where to start
3739

.vscode/settings.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"typescript.tsdk": "node_modules/typescript/lib",
3-
"editor.codeActionsOnSave": {
4-
"source.organizeImports": true
5-
}
2+
"typescript.tsdk": "node_modules/typescript/lib"
63
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
diff --git a/esm/vanilla.mjs b/esm/vanilla.mjs
2+
index 59d78cf8e0490d98e104e4ba2ba58afb3bf97560..5f60e0f80f67546966f76333346790802b294e29 100644
3+
--- a/esm/vanilla.mjs
4+
+++ b/esm/vanilla.mjs
5+
@@ -578,11 +578,6 @@ if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") {
6+
}
7+
const getDefaultStore = () => {
8+
if (!defaultStore) {
9+
- if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production" && globalThis.__NUMBER_OF_JOTAI_INSTANCES__ !== 1) {
10+
- console.warn(
11+
- "Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044"
12+
- );
13+
- }
14+
defaultStore = createStore();
15+
}
16+
return defaultStore;
17+
diff --git a/system/vanilla.development.js b/system/vanilla.development.js
18+
index 5045cde2971e1372ab48b82bbd161886d13eeccd..f7f3741f9cfdd9b200d0ea304a61f0d11847d013 100644
19+
--- a/system/vanilla.development.js
20+
+++ b/system/vanilla.development.js
21+
@@ -580,11 +580,6 @@ System.register([], (function (exports) {
22+
}
23+
const getDefaultStore = exports("getDefaultStore", () => {
24+
if (!defaultStore) {
25+
- if (globalThis.__NUMBER_OF_JOTAI_INSTANCES__ !== 1) {
26+
- console.warn(
27+
- "Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044"
28+
- );
29+
- }
30+
defaultStore = createStore();
31+
}
32+
return defaultStore;
33+
diff --git a/umd/vanilla.development.js b/umd/vanilla.development.js
34+
index d9587e70701c3a4717c6be4951a65e40d60b90b1..f9fcbefe4d53a5910edb320643f8bfb7139081b5 100644
35+
--- a/umd/vanilla.development.js
36+
+++ b/umd/vanilla.development.js
37+
@@ -671,9 +671,6 @@
38+
}
39+
var getDefaultStore = function getDefaultStore() {
40+
if (!defaultStore) {
41+
- if (globalThis.__NUMBER_OF_JOTAI_INSTANCES__ !== 1) {
42+
- console.warn('Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044');
43+
- }
44+
defaultStore = createStore();
45+
}
46+
return defaultStore;
47+
diff --git a/vanilla.js b/vanilla.js
48+
index 946fa9155cc4120bffd0022c9e50f77011dfab02..234c958df45eaa5bf5240be5d707f6d48261ab85 100644
49+
--- a/vanilla.js
50+
+++ b/vanilla.js
51+
@@ -672,9 +672,6 @@ if (process.env.NODE_ENV !== 'production') {
52+
}
53+
var getDefaultStore = function getDefaultStore() {
54+
if (!defaultStore) {
55+
- if (process.env.NODE_ENV !== 'production' && globalThis.__NUMBER_OF_JOTAI_INSTANCES__ !== 1) {
56+
- console.warn('Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044');
57+
- }
58+
defaultStore = createStore();
59+
}
60+
return defaultStore;

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ The current manual release sequence is as follows:
241241

242242
**NOTE:** The very first time you publish a scoped package (`@storybook/x`) you need to make sure that it's package.json contains the following
243243

244-
```js
244+
```json
245245
"publishConfig": {
246246
"access": "public"
247247
}

MANUAL_SETUP.md

Lines changed: 85 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Setup for v6 React Native Storybook
1+
# Setup for v7 React Native Storybook
22

33
Before getting into the guide consider using a template for a simpler setup process.
44

@@ -16,11 +16,6 @@ For react native cli you can use this [template](https://github.com/dannyhw/reac
1616
npx react-native init MyApp --template react-native-template-storybook
1717
```
1818

19-
You can also choose to use a bash script if you prefer, however it is more involved.
20-
21-
- [expo setup script](https://gist.github.com/dannyhw/92b3ff0d6ccaead9df2820a507154b87)
22-
- [rn-cli setup script](https://gist.github.com/dannyhw/9b84973dcc6ff4fa2e86e32d571d294e)
23-
2419
# Manual setup
2520

2621
You may wish to setup everything yourself, you can use the following guide to do so.
@@ -30,18 +25,18 @@ You may wish to setup everything yourself, you can use the following guide to do
3025
**Expo**
3126

3227
```sh
33-
expo install @storybook/react-native @storybook/[email protected] @react-native-async-storage/async-storage react-dom react-native-safe-area-context
28+
expo install @storybook/react-native @react-native-async-storage/async-storage react-dom react-native-safe-area-context
3429
```
3530

3631
**React native CLI**
3732

3833
```sh
39-
yarn add -D @storybook/react-native @storybook/[email protected] @react-native-async-storage/async-storage react-native-safe-area-context react-dom
34+
yarn add -D @storybook/react-native @react-native-async-storage/async-storage react-native-safe-area-context react-dom
4035
```
4136

4237
**IOS**
4338

44-
If running on an IOS device make sure to run pod install first
39+
If running on an IOS device with rn cli make sure to run pod install first
4540

4641
```sh
4742
cd ios; pod install; cd ..;
@@ -51,138 +46,157 @@ cd ios; pod install; cd ..;
5146

5247
## .storybook
5348

54-
Create a folder called `.storybook` with files: `main.js`, `preview.js`, `Storybook.tsx`
49+
Create a folder called `.storybook` with files: `main.ts`, `preview.tsx`, `index.tsx`
5550

5651
You can use this one-liner to quickly create those files:
52+
5753
```console
58-
mkdir .storybook && cd .storybook && touch main.js preview.js Storybook.tsx
54+
mkdir .storybook && touch .storybook/main.ts .storybook/preview.tsx .storybook/index.tsx
5955
```
6056

61-
### main.js
57+
### .storybook/main.ts
6258

63-
```js
64-
module.exports = {
65-
stories: [
66-
'../components/**/*.stories.?(ts|tsx|js|jsx)'
67-
],
59+
```ts
60+
import { StorybookConfig } from '@storybook/react-native';
61+
62+
const main: StorybookConfig = {
63+
stories: ['../components/**/*.stories.?(ts|tsx|js|jsx)'],
6864
addons: [],
6965
};
66+
67+
export default main;
7068
```
7169

72-
### preview.js
70+
### .storybook/preview.tsx
7371

74-
```js
75-
export const decorators = [];
76-
export const parameters = {};
72+
```ts
73+
import type { Preview } from '@storybook/react';
74+
75+
const preview: Preview = {
76+
parameters: {},
77+
decorators: [],
78+
};
79+
80+
export default preview;
81+
```
82+
83+
## package.json
84+
85+
Add the following to the scripts in your package.json.
86+
87+
```json
88+
{
89+
"scripts": {
90+
"storybook-generate": "sb-rn-get-stories"
91+
}
92+
}
7793
```
7894

79-
### Storybook.tsx
95+
### generate storybook.requires.ts
96+
97+
run `yarn storybook-generate`
8098

81-
```jsx
82-
import { getStorybookUI } from '@storybook/react-native';
99+
### .storybook/index.tsx
83100

84-
import './storybook.requires';
101+
```tsx
102+
import { view } from './storybook.requires';
103+
import AsyncStorage from '@react-native-async-storage/async-storage';
85104

86-
const StorybookUIRoot = getStorybookUI({});
105+
const StorybookUIRoot = view.getStorybookUI({
106+
storage: {
107+
getItem: AsyncStorage.getItem,
108+
setItem: AsyncStorage.setItem,
109+
},
110+
});
87111

88112
export default StorybookUIRoot;
89113
```
90114

91115
## metro.config.js
92116

93-
Update your metro config to include sbmodern in the resolverMainFields.
117+
Update your metro config to enable `transformer.unstable_allowRequireContext`
94118

95119
**Expo**
96120

97-
First create metro config file if you don't have it yet.
121+
First create metro config file if you don't have it yet.
122+
98123
```sh
99124
npx expo customize metro.config.js
100125
```
101126

102-
Then add sbmodern to the start of the `resolver.resolverMainFields` list.
127+
Then set `transformer.unstable_allowRequireContext` to true
103128

104129
```js
105130
const { getDefaultConfig } = require('expo/metro-config');
106131

132+
const { generate } = require('@storybook/react-native/scripts/generate');
133+
134+
generate({
135+
configPath: path.resolve(__dirname, './.storybook'),
136+
});
137+
107138
const defaultConfig = getDefaultConfig(__dirname);
108139

109-
defaultConfig.resolver.resolverMainFields.unshift('sbmodern');
140+
defaultConfig.transformer.unstable_allowRequireContext = true;
110141

111142
module.exports = defaultConfig;
112143
```
113144

114145
**React native**
115146

116147
```js
148+
const { generate } = require('@storybook/react-native/scripts/generate');
149+
150+
generate({
151+
configPath: path.resolve(__dirname, './.storybook'),
152+
});
153+
117154
module.exports = {
118155
/* existing config */
119-
resolver: {
120-
resolverMainFields: ['sbmodern', 'react-native', 'browser', 'main'],
156+
transformer: {
157+
unstable_allowRequireContext: true,
121158
},
122159
};
123160
```
124161

125-
## package.json
126-
127-
Add the following to the scripts in your package.json, we use the name `prestart` to cause the script to run before every `yarn start`.
128-
129-
```json
130-
{
131-
"scripts": {
132-
"prestart": "sb-rn-get-stories",
133-
"storybook-watcher": "sb-rn-watcher",
134-
}
135-
}
136-
```
137-
138-
139-
# Adding stories
140-
141-
To render storybook update your App.tsx file to export the UI component.
142-
143-
```js
144-
import StorybookUIRoot from './.storybook/Storybook';
145-
export { StorybookUIRoot as default };
146-
```
147-
148162
**Add a stories file**
149163

150-
In the main.js we created the path was set as `../components/**/*.stories.?(ts|tsx|js|jsx)` which matches any .stories file inside the components folder.
164+
In the `main.ts` we created the path was set as `../components/\*_/_.stories.?(ts|tsx|js|jsx)` which matches any .stories file inside the components folder.
151165

152166
Create a file called `Button.stories.tsx` in the components folder.
153167

154-
```jsx
155-
import {Button} from 'react-native';
168+
```tsx
169+
import type { Meta, StoryObj } from '@storybook/react';
170+
import { Button } from 'react-native';
156171

157-
export default {
172+
const meta = {
158173
title: 'React Native Button',
159174
component: Button,
175+
} satisfies Meta<typeof Button>;
176+
177+
export default meta;
178+
179+
type Story = StoryObj<typeof meta>;
180+
181+
export const Basic: Story = {
160182
args: {
161183
title: 'Hello world',
162184
},
163185
};
164-
165-
export const Basic = args => <Button {...args} />;
166186
```
167187

168188
This is a simple example you can do more by adding addons and exploring more features of storybook.
169189

170190
## Render Storybook
171191

172-
The only thing left to do is return Storybook's UI in your app entry point (such as `App.js`) like this:
192+
The only thing left to do is return Storybook's UI in your app entry point (such as `App.tsx`) like this:
173193

174-
```jsx
175-
export {default} from './.storybook'
194+
```tsx
195+
export { default } from './.storybook';
176196
```
177197

178198
If you want to be able to swap easily between storybook and your app, have a look at this [blog post](https://dev.to/dannyhw/how-to-swap-between-react-native-storybook-and-your-app-p3o)
179199

180200
# Run storybook
181201

182-
To run storybook first generate the stories list:
183-
184-
```sh
185-
yarn sb-rn-get-stories
186-
```
187-
188-
Then you can run `yarn ios` or `yarn android` to run the app.
202+
Then you can run `yarn ios` or `yarn android` to run the app like normal.

0 commit comments

Comments
 (0)