Gathering detailed insights and metrics for @storybook/react-native-theming
Gathering detailed insights and metrics for @storybook/react-native-theming
Gathering detailed insights and metrics for @storybook/react-native-theming
Gathering detailed insights and metrics for @storybook/react-native-theming
npm install @storybook/react-native-theming
Typescript
Module System
Node Version
NPM Version
59.2
Supply Chain
41.5
Quality
81.2
Maintenance
50
Vulnerability
93.2
License
TypeScript (99.51%)
JavaScript (0.49%)
Total Downloads
6,254,099
Last Day
10,246
Last Week
69,415
Last Month
593,439
Last Year
5,462,606
1,091 Stars
24,971 Commits
157 Forks
24 Watching
17 Branches
951 Contributors
Latest Version
8.4.3
Package Id
@storybook/react-native-theming@8.4.3
Unpacked Size
125.84 kB
Size
28.84 kB
File Count
5
NPM Version
lerna/8.1.8/node@v22.6.0+arm64 (darwin)
Node Version
22.6.0
Publised On
06 Dec 2024
Cumulative downloads
Total Downloads
Last day
-63.4%
10,246
Compared to previous day
Last week
-54.2%
69,415
Compared to previous week
Last month
-3.4%
593,439
Compared to previous month
Last year
590.2%
5,462,606
Compared to previous year
1
2
3
[!IMPORTANT]
This readme is for v8, for v7 docs see the v7.6 docs.
With Storybook for React Native you can design and develop individual React Native components without running your app.
If you are migrating from 7.6 to 8.3 you can find the migration guide here
For more information about storybook visit: storybook.js.org
[!NOTE]
@storybook/react-native
requires atleast 8.3.1, if you install other storybook core packages they should be^8.3.1
or newer.
There is some project boilerplate with @storybook/react-native
and @storybook/addon-react-native-web
both already configured with a simple example.
For expo you can use this template with the following command
1# With NPM 2npx create-expo-app --template expo-template-storybook AwesomeStorybook
For react native cli you can use this template
1npx react-native init MyApp --template react-native-template-storybook
Run init to setup your project with all the dependencies and configuration files:
1npx storybook@latest init
The only thing left to do is return Storybook's UI in your app entry point (such as App.tsx
) like this:
1export { default } from './.storybook';
Then wrap your metro config with the withStorybook function as seen below
If you want to be able to swap easily between storybook and your app, have a look at this blog post
If you want to add everything yourself check out the the manual guide here.
We require the unstable_allowRequireContext transformer option to enable dynamic story imports based on the stories glob in main.ts
. We can also call the storybook generate function from the metro config to automatically generate the storybook.requires.ts
file when metro runs.
Expo
First create metro config file if you don't have it yet.
1npx expo customize metro.config.js
Then wrap your config in the withStorybook function as seen below.
1// metro.config.js
2const path = require('path');
3const { getDefaultConfig } = require('expo/metro-config');
4const withStorybook = require('@storybook/react-native/metro/withStorybook');
5
6/** @type {import('expo/metro-config').MetroConfig} */
7const config = getDefaultConfig(__dirname);
8
9module.exports = withStorybook(config, {
10 // Set to false to remove storybook specific options
11 // you can also use a env variable to set this
12 enabled: true,
13 // Path to your storybook config
14 configPath: path.resolve(__dirname, './.storybook'),
15
16 // Optional websockets configuration
17 // Starts a websocket server on the specified port and host on metro start
18 // websockets: {
19 // port: 7007,
20 // host: 'localhost',
21 // },
22});
React native
1const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
2const path = require('path');
3const withStorybook = require('@storybook/react-native/metro/withStorybook');
4const defaultConfig = getDefaultConfig(__dirname);
5
6/**
7 * Metro configuration
8 * https://reactnative.dev/docs/metro
9 *
10 * @type {import('metro-config').MetroConfig}
11 */
12const config = {};
13// set your own config here 👆
14
15const finalConfig = mergeConfig(defaultConfig, config);
16
17module.exports = withStorybook(finalConfig, {
18 // Set to false to remove storybook specific options
19 // you can also use a env variable to set this
20 enabled: true,
21 // Path to your storybook config
22 configPath: path.resolve(__dirname, './.storybook'),
23
24 // Optional websockets configuration
25 // Starts a websocket server on the specified port and host on metro start
26 // websockets: {
27 // port: 7007,
28 // host: 'localhost',
29 // },
30});
Make sure you have react-native-reanimated
in your project and the plugin setup in your babel config.
1// babel.config.js 2plugins: ['react-native-reanimated/plugin'];
In storybook we use a syntax called CSF that looks like this:
1import type { Meta, StoryObj } from '@storybook/react'; 2import { MyButton } from './Button'; 3 4const meta = { 5 component: MyButton, 6} satisfies Meta<typeof MyButton>; 7 8export default meta; 9 10type Story = StoryObj<typeof meta>; 11 12export const Basic: Story = { 13 args: { 14 text: 'Hello World', 15 color: 'purple', 16 }, 17};
You should configure the path to your story files in the main.ts
config file from the .storybook
folder.
1// .storybook/main.ts 2import { StorybookConfig } from '@storybook/react-native'; 3 4const main: StorybookConfig = { 5 stories: ['../components/**/*.stories.?(ts|tsx|js|jsx)'], 6 addons: [], 7}; 8 9export default main;
For stories you can add decorators and parameters on the default export or on a specifc story.
1import type { Meta } from '@storybook/react'; 2import { Button } from './Button'; 3 4const meta = { 5 title: 'Button', 6 component: Button, 7 decorators: [ 8 (Story) => ( 9 <View style={{ alignItems: 'center', justifyContent: 'center', flex: 1 }}> 10 <Story /> 11 </View> 12 ), 13 ], 14 parameters: { 15 backgrounds: { 16 values: [ 17 { name: 'red', value: '#f00' }, 18 { name: 'green', value: '#0f0' }, 19 { name: 'blue', value: '#00f' }, 20 ], 21 }, 22 }, 23} satisfies Meta<typeof Button>; 24 25export default meta;
For global decorators and parameters, you can add them to preview.tsx
inside your .storybook
folder.
1// .storybook/preview.tsx 2import type { Preview } from '@storybook/react'; 3import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds'; 4 5const preview: Preview = { 6 decorators: [ 7 withBackgrounds, 8 (Story) => ( 9 <View style={{ flex: 1, color: 'blue' }}> 10 <Story /> 11 </View> 12 ), 13 ], 14 parameters: { 15 backgrounds: { 16 default: 'plain', 17 values: [ 18 { name: 'plain', value: 'white' }, 19 { name: 'warm', value: 'hotpink' }, 20 { name: 'cool', value: 'deepskyblue' }, 21 ], 22 }, 23 }, 24}; 25 26export default preview;
The cli will install some basic addons for you such as controls and actions. Ondevice addons are addons that can render with the device ui that you see on the phone.
Currently the addons available are:
@storybook/addon-ondevice-controls
: adjust your components props in realtime@storybook/addon-ondevice-actions
: mock onPress calls with actions that will log information in the actions tab@storybook/addon-ondevice-notes
: Add some markdown to your stories to help document their usage@storybook/addon-ondevice-backgrounds
: change the background of storybook to compare the look of your component against different backgroundsInstall each one you want to use and add them to the main.ts
addons list as follows:
1// .storybook/main.ts 2import { StorybookConfig } from '@storybook/react-native'; 3 4const main: StorybookConfig = { 5 // ... rest of config 6 addons: [ 7 '@storybook/addon-ondevice-notes', 8 '@storybook/addon-ondevice-controls', 9 '@storybook/addon-ondevice-backgrounds', 10 '@storybook/addon-ondevice-actions', 11 ], 12}; 13 14export default main;
For details of each ondevice addon you can see the readme:
Storybook on react native is a normal React Native component that can be used or hidden anywhere in your RN application based on your own logic.
You can also create a separate app just for storybook that also works as a package for your visual components. Some have opted to toggle the storybook component by using a custom option in the react native developer menu.
withStorybook
is a wrapper function to extend your Metro config for Storybook. It accepts your existing Metro config and an object of options for how Storybook should be started and configured.
1// metro.config.js
2const { getDefaultConfig } = require('expo/metro-config');
3const withStorybook = require('@storybook/react-native/metro/withStorybook');
4
5const defaultConfig = getDefaultConfig(__dirname);
6
7module.exports = withStorybook(defaultConfig, {
8 enabled: true,
9 // See API section below for available options
10});
Type: boolean
, default: true
Determines whether the options specified are applied to the Metro config. This can be useful for project setups that use Metro both with and without Storybook and need to conditionally apply the options. In this example, it is made conditional using an environment variable:
1// metro.config.js
2const { getDefaultConfig } = require('expo/metro-config');
3const withStorybook = require('@storybook/react-native/metro/withStorybook');
4
5const defaultConfig = getDefaultConfig(__dirname);
6
7module.exports = withStorybook(defaultConfig, {
8 enabled: process.env.WITH_STORYBOOK,
9 // ... other options
10});
Type: boolean
, default: false
If onDisabledRemoveStorybook true
and enabled
is false
, the storybook package will be removed from the build.
This is useful if you want to remove storybook from your production build.
Type: boolean
, default: false
Generates the .storybook/storybook.requires
file in JavaScript instead of TypeScript.
Type: string
, default: path.resolve(process.cwd(), './.storybook')
The location of your Storybook configuration directory, which includes main.ts
and other project-related files.
Type: { host: string?, port: number? }
, default: undefined
If specified, create a WebSocket server on startup. This allows you to sync up multiple devices to show the same story and arg values connected to the story in the UI.
Type: string
, default: 'localhost'
The host on which to run the WebSocket, if specified.
Type: number
, default: 7007
The port on which to run the WebSocket, if specified.
You can pass these parameters to getStorybookUI call in your storybook entry point:
{
initialSelection?: string | Object (undefined)
-- initialize storybook with a specific story. eg: `mybutton--largebutton` or `{ kind: 'MyButton', name: 'LargeButton' }`
storage?: Object (undefined)
-- {getItem: (key: string) => Promise<string | null>;setItem: (key: string, value: string) => Promise<void>;}
-- Custom storage to be used instead of AsyncStorage
onDeviceUI?: boolean;
-- show the ondevice ui
enableWebsockets?: boolean;
-- enable websockets for the storybook ui
query?: string;
-- query params for the websocket connection
host?: string;
-- host for the websocket connection
port?: number;
-- port for the websocket connection
secured?: boolean;
-- use secured websockets
shouldPersistSelection?: boolean;
-- store the last selected story in the device's storage
theme: Partial<Theme>;
-- theme for the storybook ui
}
Storybook provides testing utilities that allow you to reuse your stories in external test environments, such as Jest. This way you can write unit tests easier and reuse the setup which is already done in Storybook, but in your unit tests. You can find more information about it in the portable stories section.
We welcome contributions to Storybook!
Looking for a first issue to tackle?
Here are some example projects to help you get started
No vulnerabilities found.
Reason
30 commit(s) and 26 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
3 existing vulnerabilities detected
Details
Reason
Found 10/29 approved changesets -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More