Installations
npm install @react-theming/storybook-addon
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
16.14.2
NPM Version
8.5.0
Score
56.6
Supply Chain
65.7
Quality
71.3
Maintenance
100
Vulnerability
97.3
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (95.47%)
HTML (4.46%)
Shell (0.07%)
Developer
Download Statistics
Total Downloads
4,520,680
Last Day
668
Last Week
13,843
Last Month
93,843
Last Year
1,250,439
GitHub Statistics
206 Stars
399 Commits
36 Forks
4 Watching
7 Branches
31 Contributors
Bundle Size
146.53 kB
Minified
45.52 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.1.10
Package Id
@react-theming/storybook-addon@1.1.10
Unpacked Size
916.89 kB
Size
311.93 kB
File Count
52
NPM Version
8.5.0
Node Version
16.14.2
Total Downloads
Cumulative downloads
Total Downloads
4,520,680
Last day
-84.7%
668
Compared to previous day
Last week
-40.6%
13,843
Compared to previous week
Last month
-7.2%
93,843
Compared to previous month
Last year
-12.8%
1,250,439
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
9
Peer Dependencies
3
Dev Dependencies
31
Storybook Addon @ React Theming
Storybook addon for Styled Components, Emotion, Material-UI and any other theming solution. Allows to develop themed components in isolation.
1npm i --save-dev @react-theming/storybook-addon
Features :dizzy:
- Universal - can be used with any styling library
- Switching between themes from addon panel.
- Change a color and see how it affects to your components
- Easily copy-paste paths of nesting theme props into your code
- Auto changes background
- Supports dark Storybook theme
- Keep selected theme on stories updates
Usage
specify addon in .storybook/main.js
1// .storybook/main.js 2 3module.exports = { 4 stories: ['../src/**/*.stories.js'], 5 addons: ['@react-theming/storybook-addon'], 6};
or in .storybook/addons.js
for older versions of Storybook
1import '@react-theming/storybook-addon/register'; 2
Then you'll need to add a decorator with a ThemeProvider of your library. This project is not related to any particular styling solutions, instead, you can use any of theme providers you're using in your project.
1import ThemeProvider from 'library-of-your-choice'; 2import { withThemes } from '@react-theming/storybook-addon'; 3import { theme } from '../src/theme'; 4 5// create decorator 6const themingDecorator = withThemes(ThemeProvider, [theme]);
ThemeProvider should accept a theme via theme
props. This is usually the case for the most common styling libraries like Styled Components, Emotion, Material-UI.
In case of non standard ThemeProvider you can pass providerFn
function in options:
1const providerFn = ({ theme, children }) => { 2 return <ThemeProvider theme={muTheme}>{children}</ThemeProvider>; 3}; 4 5const themingDecorator = withThemes(null, [theme], { providerFn });
Use your output of the selected value
1// .storybook/preview.js 2 3import { ThemeProvider } from 'styled-components'; 4import { addDecorator } from '@storybook/react'; 5import { withThemes } from '@react-theming/storybook-addon'; 6 7import { theme } from '../src/theme'; 8
Example getCustomFieldSnippet
1const selectedValue = { 2 name: "accent5", 3 namespace: ["palette", "colors"], 4 type: "color", 5 value: "#ac924d" 6} 7 8 9const getCustomFieldSnippet = selectedValue => { 10 const { namespace, name } = selectedValue; 11 const path = namespace.join('.'); 12 const fullPath = `${path}.${name}`; 13 const themeProp = `\${({ theme }) => theme.${fullPath}}`; 14 return themeProp; 15}; 16 17// The snippet Func function takes the SelectedValue parameter and returns a string 18addDecorator(withThemes(ThemeProvider, [theme], { getCustomFieldSnippet })); 19
Example getCustomValueSnippet
By default, the addon outputs colors in HEX format, if you need some kind of add-in, then pass the colorSnippet parameter.
1const getCustomValueSnippet = ({value, name, type}) => {
2 // Here is your code
3 return value
4};
5
6// The colorSnipept function accepts an object consisting of { value : HEX, name: string, type: color}
7addDecorator(withThemes(ThemeProvider, [theme], { getCustomValueSnippet }));
8
BACKGROUND COLOR
This addon has ability to auto change background color when it detect a dark theme. By default it checks if the theme name contains 'dark'.
You can customize this behavior by passing onThemeSwitch
function:
1export const onThemeSwitch = context => { 2 const { theme } = context; 3 const background = theme.name === 'Dark theme' ? '#2c2f33' : 'white'; 4 const parameters = { 5 backgrounds: { 6 default: background, 7 }, 8 // Pass backgrounds: null to disable background switching at all 9 }; 10 return { 11 parameters, 12 }; 13}; 14 15const themingDecorator = withThemes(null, [theme], { onThemeSwitch });
This way you can have own checks of what the theme is selected and pass what ever color you need.
!important: The addon change background color on each theme selecting. In some scenarios you might want to disable this behavior e.g. if you already using addon-backgrounds. You can disable background switching by passing backgrounds: null
in parameters.
Below the use cases for most popular styling libraries:
Using with Emotion
1// .storybook/preview.js 2 3import { ThemeProvider } from '@emotion/react'; 4import { addDecorator } from '@storybook/react'; 5import { withThemes } from '@react-theming/storybook-addon'; 6 7import { theme } from '../src/theme'; 8 9// pass ThemeProvider and array of your themes to decorator 10addDecorator(withThemes(ThemeProvider, [theme]));
💅 Using with Styled Components
1// .storybook/preview.js 2 3import { ThemeProvider } from 'styled-components'; 4import { addDecorator } from '@storybook/react'; 5import { withThemes } from '@react-theming/storybook-addon'; 6 7import { theme } from '../src/theme'; 8 9// pass ThemeProvider and array of your themes to decorator 10addDecorator(withThemes(ThemeProvider, [theme]));
Using with Material-UI
1// theme.js 2import { red } from '@material-ui/core/colors'; 3 4// A custom theme for this app 5const theme = { 6 palette: { 7 primary: { 8 main: '#556cd6', 9 }, 10 secondary: { 11 main: '#19857b', 12 }, 13 error: { 14 main: red.A400, 15 }, 16 background: { 17 default: '#fff', 18 }, 19 }, 20}; 21 22export default theme;
1// .storybook/preview.js 2 3import { ThemeProvider } from '@material-ui/core'; 4import { createMuiTheme } from '@material-ui/core/styles'; 5import { addDecorator } from '@storybook/react'; 6import { withThemes } from '@react-theming/storybook-addon'; 7 8import theme from '../src/theme'; 9 10const providerFn = ({ theme, children }) => { 11 const muTheme = createMuiTheme(theme); 12 return <ThemeProvider theme={muTheme}>{children}</ThemeProvider>; 13}; 14 15// pass ThemeProvider and array of your themes to decorator 16addDecorator(withThemes(null, [theme], { providerFn }));
1// index.js 2 3import React from 'react'; 4import ReactDOM from 'react-dom'; 5import { ThemeProvider } from '@material-ui/core/styles'; 6import { createMuiTheme } from '@material-ui/core/styles'; 7import App from './App'; 8import theme from './theme'; 9 10ReactDOM.render( 11 <ThemeProvider theme={createMuiTheme(theme)}> 12 <App /> 13 </ThemeProvider>, 14 document.querySelector('#root'), 15); 16
There is an example app with CRA, Material-UI and Storybook Addon Demo Source
Credits
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
SAST tool detected but not run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Warn: 0 commits out of 22 are checked with a SAST tool
Reason
Found 2/10 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci-tests.yml:1
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-tests.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/react-theming/storybook-addon/ci-tests.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-tests.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/react-theming/storybook-addon/ci-tests.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci-tests.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/react-theming/storybook-addon/ci-tests.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/react-theming/storybook-addon/codeql-analysis.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/react-theming/storybook-addon/codeql-analysis.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:53: update your workflow using https://app.stepsecurity.io/secureworkflow/react-theming/storybook-addon/codeql-analysis.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:67: update your workflow using https://app.stepsecurity.io/secureworkflow/react-theming/storybook-addon/codeql-analysis.yml/master?enable=pin
- Info: 0 out of 7 GitHub-owned GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
Project has not signed or included provenance with any releases.
Details
- Warn: release artifact 0.2.0 not signed: https://api.github.com/repos/react-theming/storybook-addon/releases/4991195
- Warn: release artifact 0.2.0 does not have provenance: https://api.github.com/repos/react-theming/storybook-addon/releases/4991195
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
79 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-whgm-jr23-g3j9
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-3wcq-x3mq-6r9p
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-pfq8-rq6v-vf5m
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-c7qv-q95q-8v27
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-7r28-3m3f-r2pr
- Warn: Project is vulnerable to: GHSA-r8j5-h5cx-65gg
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-5rrq-pxf6-6jx5
- Warn: Project is vulnerable to: GHSA-8fr3-hfg3-gpgp
- Warn: Project is vulnerable to: GHSA-gf8q-jrpm-jvxq
- Warn: Project is vulnerable to: GHSA-2r2c-g63r-vccr
- Warn: Project is vulnerable to: GHSA-cfm4-qjh2-4765
- Warn: Project is vulnerable to: GHSA-x4jg-mjrx-434g
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-px4h-xg32-q955
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
- Warn: Project is vulnerable to: GHSA-3j8f-xvm3-ffx4
- Warn: Project is vulnerable to: GHSA-4p35-cfcx-8653
- Warn: Project is vulnerable to: GHSA-7f3x-x4pr-wqhj
- Warn: Project is vulnerable to: GHSA-jpp7-7chh-cf67
- Warn: Project is vulnerable to: GHSA-q6wq-5p59-983w
- Warn: Project is vulnerable to: GHSA-j9fq-vwqv-2fm2
- Warn: Project is vulnerable to: GHSA-pqw5-jmp5-px4v
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-5q6m-3h65-w53x
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-h9rv-jmmf-4pgx
- Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-c9g6-9335-x697
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-w5p7-h5w8-2hfq
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-hc6q-2mpp-qw7j
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986
- Warn: Project is vulnerable to: GHSA-wr3j-pwj9-hqq6
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2.9
/10
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