@hiroyoshi-mori/storybook-css-framework-switcher
TypeScript icon, indicating that this package has built-in type declarations

0.0.9 • Public • Published

Storybook Addon CSS Framework Switcher

Easy switcher it switches CSS Framework used in preview and add environment variable CSS_FRAMEWORK which can be used to identify which css framework is used now Github

Installation

First, install the package.

npm install --save-dev @hiroyoshi-mori/storybook-css-framework-switcher

Then, register it as an addon in .storybook/main.js.

// .storybook/main.ts

// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';

const config: StorybookConfig = {
  // ...rest of config
  addons: [
    '@storybook/addon-essentials',
    '@hiroyoshi-mori/storybook-css-framework-switcher', // 👈 register the addon here
  ],
  staticDirs: [
    { from: '../node_modules/cirrus-ui/dist/', to: '/assets/cirrus-ui'}, // 👈 Copy files from css framework dist directories to /assets
    { from: '../node_modules/bulma/css/', to: '/assets/bulma'},
  ],
};

export default config;

Usage

The primary way to use this addon is to define the exampleParameter parameter. You can do this the component level, as below, to affect all stories in the file, or you can do it for a single story.

const preview: Preview = {
  parameters: {
    cssFrameworkSwitcher: {
      frameworks: [
        { id: 'Cirrus', srcPath: '/assets/cirrus-ui/cirrus-all.css' },  // 👈 Set ID and css path to load
        { id: 'Bulma', srcPath: '/assets/bulma/bulma.css' },
      ],
    },
  },
};

Copyright and license Github

Copyright 2024 Hiroyoshi Mori / Script Laboratory.

Package Sidebar

Install

npm i @hiroyoshi-mori/storybook-css-framework-switcher

Weekly Downloads

1

Version

0.0.9

License

MIT

Unpacked Size

1.02 MB

Total Files

15

Last publish

Collaborators

  • hiroyoshi-mori