Git Product home page Git Product logo

storybook-addon-cssprops's Introduction

Storybook CSS Custom Properties Addon

Installation

npm i -D @ljcl/storybook-addon-cssprops

Enable the addon in .storybook/main.js:

module.exports = {
  addons: ["@ljcl/storybook-addon-cssprops"],
};

To use it inside MDX, or when customising the docs page:

import { CssPropsBlock } from "@ljcl/storybook-addon-cssprops";

Usage

Include your CSS Custom Properties without the initial -- prefix, the addon will apply and document this automatically.

export default {
  title: "Simple Component",
  parameters: {
    cssprops: {
      "css-custom-property-1": {
        value: "hsl(120deg 100% 25% / 49%)",
        description: "Optional description",
      },
    }
  },
} as Meta;

Configuration

The addon can be configured wherever other parameters can be configured (at the Global, Story, or individual story level). It will also attempt to detect between colour and text, this can be overriden by specifying the control property.

parameters: {
  cssprops: {
    // Disable the addon by setting disable to true:
    disable: false,
    // Override the detected default control type:
    "override-property-detection-type": {
      value: "green",
      control: "text",
      description: "Maybe you want 'green' for reasons differing to colour"
    },
    // Override the detected default control type:
    "optional-category-or-subcategory": {
      value: "red",
      category: "Optional",
      subcategory: "Very Optional",
      description: "This property will be grouped under a category called 'Optional', and then a further subcategory of 'Very Optional'",
    },
    // Customise preset colours for the colourpicker
    presetColors: ['#FFF']
  }
}

Adding to DocsPage and MDX

DocsPage

Modify the docs page based by following the storybook docs. Including <CssPropsBlock /> where you prefer.

Development

This monorepo uses npm@7 workspaces, run npm i at the root.

TODO

  • Look for the args of a defined component when in MDX
  • Better specificity when injecting styles (with & without iframes)
  • Reset the default values without requiring a page refresh (ArgsTable)

storybook-addon-cssprops's People

Contributors

ljcl avatar github-actions[bot] avatar kwickramasekara avatar lukethacoder avatar bcldvd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.