npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

storybook-addon-themepack

v0.0.3

Published

Storybook addon for theme packs

Downloads

5

Readme

🎨 storybook-themepack

Better themepacks for Storybook

npm version

Storybook addon for custom themes.

Ideal for themes based on CSS custom properties (CSS variables).

Demo

Online demo link here.

Demo source code.

Example

Feel free to test this addon in your local environment: npm run demo.

Usage

Install:

npm install --save-dev storybook-themepack

// Install peer deps
npm install --save-dev @storybook/components @storybook/api @storybook/addons

Then register addon:

// main.js
module.exports = {
    "addons": [
        'storybook-addon-themepack'
    ]
}

And add some configuration:

const gaps = {
    // Some pretty plain CSS in this values
    gapSmall: '--gap: 12px;',
    gapMedium: '--gap: 16px;'
};

export default {
    title: 'Components/MyComponent',
    parameters: {
        themepack: {
            pack: {
                gap: [ 'Gap', pack(gaps) ]
            }
        }
    }
}

Voilà! Now you can use all the power of themes based on CSS custom properties.

TypeScript

You can find an example repo here: examples/storybook-themepack-example

Configuration and options

Example configuration

// config.js
import {pack} from 'storybook-themepack';

addParameters({
    themepack: {
        // This items will be preloaded
        preloadedState: {
            brand: 'My'
        },

        // All the styles
        pack: {
            brand: ['Brand', pack({'My': defaultMyTheme, 'Project': defaultProjectTheme})],
            color: [
                'Color',
                pack(
                    {colorMyDefault, colorMyBrand, colorMyInverse, colorMySuccess},
                    ({brand}) => brand ? brand === 'My' : false
                ),
                pack(
                    {colorProjectBrand, colorProjectDefault, colorProjectInverse, colorProjectSuccess},
                    ({brand}) => brand ? brand === 'Project' : false
                ),
            ],
            gap: ['Gap', pack({gapSmall, gapMedium})]
        },

        // Themepack icon
        icon: 'mirror',

        // Use preview sign for themepack contents
        usePreview: true,

        // Caption for clear item
        labelForClear: '-',

        // If there is `sortFunction` themepack uses it to sort main panel menu items
        sortFunction: (a, b) => {
            if (a === 'brand') {
                return 1;
            }
            return a === b ? 0 : a > b ? 1 : -1;
        },

        // Custom styles for preview items and for the storybook preview iframe
        styles: {
            preview: `
                border-color: var(--color-bg-border);
                color: var(--color-typo-brand);
                background-color: var(--color-bg-default);
            `,
            iframe: `
                background-color: var(--color-bg-default);
            `
        }
    },
});

pack

Main themepack configuration. Every field of this object is an array.

Every option (for example, brand) contain sources for tooltips that can switch theme and preview your themed component. Packs' content for any option is merged in tooltip options.

Syntax:

[ <theme name>, <pack(...)>, <pack(...)>, ... ]

Packs' syntax:

pack(
    // Object contains options for tooltip
    {'theme option item name': 'css content'},
    // Optional function for conditional drawing. Uses selected values for every option
    ({yourThemeOption1, yourThemeOption2}) => true
);

pack(
    // Array of options for tooltip
    [{ label: 'theme option item name', css: 'css content' }]
);

icon

Icon for the first item.

Variants are in @storybook/components.

Default value is mirror.

usePreview

Adds preview for every option of the tooltips.

You can set up preview styles in configuration property styles.preview.

Default value is true.

labelForClear

Text for the element that clears tooltip.

Default value is -.

sortFunction

Function that sorts keys of your themepack.

Default value is not set.

styles

Object {preview: 'string', iframe 'string'} with CSS styles.

It contains styles for a themepack item preview inside every tooltip and global style for your component preview inside Storybook.

Default value is not set.

TODO

[ ] Update Readme and examples to Storybook v6