
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
storybook-addon-themes
Advanced tools
A storybook addon to switch between different themes for your preview
Greatly inspired by @storybook/addon-backgrounds.
This Storybook Theme Decorator can be used to add a custom HTML class or classes to the the preview in Storybook.
This version is compatible with storybook version 5.x.x
.
npm i -D storybook-addon-themes
Then, configure it as an addon by adding it to your addons.js
file (located in the Storybook config directory):
import 'storybook-addon-themes/register';
Use the decorator in your stories:
import React from 'react';
import { storiesOf } from '@storybook/react'; // <- or your storybook framework
import { withThemes } from 'storybook-addon-themes';
storiesOf('Button', module)
.addDecorator(withThemes)
.add('with text', () => <button>Click me</button>);
Or setup the decorator globally in the config.js
file (located in the Storybook config directory):
import { addDecorator } from '@storybook/react'; // <- or your storybook framework
import { withThemes } from 'storybook-addon-themes';
addDecorator(withThemes);
Configure the themes in your stories like this:
import React from 'react';
import { storiesOf } from '@storybook/react'; // <- or your storybook framework
storiesOf('Button', module)
.addParameters({
themes: [
{ name: 'twitter', class: 'theme-twt', color: '#00aced', default: true },
{ name: 'facebook', class: 'theme-fb', color: '#3b5998' },
],
})
.add('with text', () => <button>Click me</button>);
Or globally in the config.js
file:
import { addParameters } from '@storybook/react'; // <- or your storybook framework
addParameters({
themes: [
{ name: 'twitter', class: 'theme-twt', color: '#00aced', default: true },
{ name: 'facebook', class: 'theme-fb', color: '#3b5998' },
],
});
And if you want to override themes for a single story or group of stories, pass the themes
parameter:
import React from 'react';
import { storiesOf } from '@storybook/react';
storiesOf('Button', module)
.add('with text', () => <button>Click me</button>, {
themes: [{
name: 'red', class: 'theme-red', color: 'rgba(255, 0, 0)',
}]
});
If you don't want to use themes for a story, you can set the themes
parameter to []
, or use { disable: true }
to skip the addon:
import React from 'react';
import { storiesOf } from '@storybook/react';
storiesOf('Button', module)
.add('example 1', () => <button>Click me</button>, {
themes: [],
});
storiesOf('Button', module)
.add('example 2', () => <button>Click me</button>, {
themes: { disable: true },
});
Also you can add multiple classes by passing an array in class
parameter:
import React from 'react';
import { storiesOf } from '@storybook/react';
storiesOf('Button', module)
.addParameters({
themes: [
{ name: 'twitter', class: ['theme-twt', 'light-mode'], color: '#00aced', default: true },
{ name: 'facebook', class: ['theme-fb', 'dark-mode'], color: '#3b5998' },
],
})
.add('with text', () => <button>Click me</button>);
You can setup this addon without using the decorator.
In this case the classes will be added to the body
element.
But in this case your theme will not be visible by other addons (like @storybook/addon-backgrounds).
Also this usage is considered as deprecated and may be removed in the next versions.
FAQs
A storybook addon to switch between different themes for your preview
The npm package storybook-addon-themes receives a total of 26,609 weekly downloads. As such, storybook-addon-themes popularity was classified as popular.
We found that storybook-addon-themes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.