🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@storybook-extras/variants

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storybook-extras/variants

Storybook addon for displaying component variants all together in one story.

latest
Source
npmnpm
Version
0.0.68
Version published
Maintainers
1
Created
Source
logo

Story Variants

Storybook addon for displaying component variants all together in one story.

Table of Contents

Getting started

  • Install the addon:
yarn add @storybook-extras/variants -D
  • Add the addon
// .storybook/main.ts
import { StorybookConfig } from '@storybook/angular';
import { ExtrasConfig } from '@storybook-extras/preset';

const config: StorybookConfig & ExtrasConfig = {
    ...
    "addons": [
        "@storybook-extras/variants",
        // it will be included automatically if you are using
        // "@storybook-extras/preset",
        ...
    ],
    ...
}

export default config;

How to use

  • Simply enable the variants through the toolbar or using the parameters like so:
// .storybook/preview.ts 
// button.stories.ts
parameters: {
    variants: {
        enable: true
    },
};

Parameters

NameTypeDefaultDescription
enablebooleanfalseEnable the variants addon
includestring[][]Include variants from the list
excludestring[][]Exclude variants from the list
groupBystring[][]Group the variants by these keys
autoCalculatebooleanfalseAutomatically calculate the variants

NOTES

  • If you set autoCalculate to false, you can use the include parameters to include the variants.
  • If you set autoCalculate to true, you can use the exclude parameters to filter the variants.
  • Toolbar button will not show if autoCalculate is set to true or include is not empty.

Compatibility

This addon was initially developed for Angular 15 & Storybook v7 in mind. However, you can still use it in older versions, but you will need to use the decorator directly in preview.js instead of adding the addon in your main.js.

// .storybook/preview.ts
import { withVariants } from '@storybook-extras/variants';

export const decorators = [withVariants()];

This approach will also work for React, Vue, and other frameworks. Please open an issue if you find any compatibility issues, pull requests are always welcome.

Keywords

storybook

FAQs

Package last updated on 01 Mar 2023

Did you know?

Socket

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.

Install

Related posts