Gathering detailed insights and metrics for @react-theming/storybook-addon
Gathering detailed insights and metrics for @react-theming/storybook-addon
Gathering detailed insights and metrics for @react-theming/storybook-addon
Gathering detailed insights and metrics for @react-theming/storybook-addon
npm install @react-theming/storybook-addon
Typescript
Module System
Node Version
NPM Version
56.6
Supply Chain
65.7
Quality
71.3
Maintenance
100
Vulnerability
97.3
License
JavaScript (95.47%)
HTML (4.46%)
Shell (0.07%)
Total Downloads
4,520,680
Last Day
668
Last Week
13,843
Last Month
93,843
Last Year
1,250,439
206 Stars
399 Commits
36 Forks
4 Watching
7 Branches
31 Contributors
Minified
Minified + Gzipped
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
Cumulative downloads
Total Downloads
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
9
3
31
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
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 });
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
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
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:
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]));
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]));
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
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
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
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
79 existing vulnerabilities detected
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