Storybook Addon Root Attributes to switch html, body or some element attributes (multiple) at runtime for you story

Overview

Storybook Addon Root Attributes

demo

What is this

This project was inspired by le0pard/storybook-addon-root-attribute

The existing library received only one attribute. So, this library can change multiple attributes by receiving the attribute as array.

Storybook Addon Root Attributes to switch html, body or some element attribute at runtime for your story Storybook

Demo

Installation

yarn add -D storybook-addon-root-attributes

Configuration

create a file called main.js and add addon in addons section:

module.exports = {
  ...
  addons: [
    ...
    'storybook-addon-root-attributes'
  ]
};

Usage

create a file called preview.js and add parameter in addParameters

import { addParameters } from '@storybook/react';

// global
addParameters({
  rootAttribute: [
    {
      defaultState: {
        name: 'Default',
        value: null,
      },
      states: [
        {
          name: 'Dark',
          value: 'dark',
        },
      ],
    },
    {
      defaultState: {
        name: 'Default',
        value: null,
      },
      states: [
        {
          name: 'IOS',
          value: 'ios',
        },
      ],
    },
  ],
});

You can use the rootAttributes parameter to override resources on each story individually:

// per story: Button.stories.js
export default {
  title: 'Example/Button',
  component: Button,
  parameters: {
    rootAttributes: [
      {
        root: 'html',
        attribute: 'data-color-scheme',
        defaultState: {
          name: 'Yellow',
          value: 'yellow',
        },
        states: [
          {
            name: 'Blue',
            value: 'blue',
          },
          {
            name: 'Red',
            value: 'red',
          },
          {
            name: 'Green',
            value: 'green',
          },
        ],
      },
    ],
  },
};

If you want to use a tooltip (panel will not dissapear), you need to set rootAttributesTooltip in parameters with true value:

addParameters({
  rootAttributesTooltip: true, // you need to set this property
  rootAttributes: [
    {
      root: 'html',
      attribute: 'data-scale-color',
      defaultState: {
        name: 'Light',
        value: 'light',
      },
      states: [
        {
          name: 'Dark',
          value: 'dark',
        },
        {
          name: 'Gray',
          value: 'gray',
        },
      ],
    },
    {
      root: 'html',
      attribute: 'data-letter-spacing',
      defaultState: {
        name: 'IOS',
        value: 'ios',
      },
      states: [
        {
          name: 'Android',
          value: 'android',
        },
      ],
    },
  ],
});

Configuration

Configuration params for rootAttributes parameter:

Name Default Variants Description
rootAttributes rootAttribute[] array with objects, which contain rootAttribute Check more detail info in below
rootAttributesTooltip false boolean value Add tooltip button for storybook

Configuration params for rootAttribute parameter:

Name Default Variants Description
root 'html' 'html', 'body', or first element returned by 'document.querySelector(), or if none found -- 'html'' Root node, which attribute will changed by addon
attribute 'class' any valid attribute name Attribute name
defaultState {} should contain name and value Default state for attribute. Value nil will remove attribute from root
states [] array with objects, which contain unique name and value for attribute All needed states for attribute values. Each object should contain unique name (for button) and value for attribute

Configuration example:

addParameters({
  rootAttributesTooltip: true,
  rootAttributes: [
    {
      root: 'html',
      attribute: 'data-scale-color',
      defaultState: {
        name: 'Light',
        value: 'light',
      },
      states: [
        {
          name: 'Dark',
          value: 'dark',
        },
        {
          name: 'Gray',
          value: 'gray',
        },
      ],
    },
    {
      root: 'html',
      attribute: 'data-letter-spacing',
      defaultState: {
        name: 'IOS',
        value: 'ios',
      },
      states: [
        {
          name: 'Android',
          value: 'android',
        },
      ],
    },
  ],
});
You might also like...

A jQuery plugin to make your form controls look how you want them to. Now with HTML-5 attributes!

(jQuery) Uniform A jQuery plugin to make your form controls look how you want them to. Now with HTML-5 attributes! Works well with jQuery 1.6+, but we

Jan 2, 2023

A planetary body simulator with a HTML5/CSS3/JS frontend and simulated using Rust WebAssembly.

A planetary body simulator with a HTML5/CSS3/JS frontend and simulated using Rust WebAssembly.

Solar Sim πŸͺ A planetary body simulator with a HTML5/CSS3/JS frontend and simulated using Rust WebAssembly. Try the latest version here! Built with πŸ¦€

Jun 15, 2022

This package enables you to mount your Remix app at a different path than root

This package enables you to mount your Remix app at a different path than root

Remix Mount Routes This package enables you to mount your Remix app at a different path than root. πŸ›  Installation npm install -D remix-mount-routes

Dec 17, 2022

With this script you can bypass both root detection and ssl pinning for your android app.

frida_rootansslbypas β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—

Dec 24, 2022

JavaScript micro-library: pass in an element and a callback and this will trigger when you click anywhere other than the element

Add a click listener to fire a callback for everywhere on the window except your chosen element. Installation run npm install @lukeboyle/when-clicked-

May 13, 2021

Serialize an HTML Form to a JavaScript Object, supporting nested attributes and arrays.

jquery.serializeJSON Adds the method .serializeJSON() to jQuery to serializes a form into a JavaScript Object. Supports the same format for nested par

Dec 12, 2022

Group together Tailwind CSS modifiers like focus, peer-checked, dark:hover and more with HTML attributes πŸ‘©β€πŸš€

Tailwind CSS Group Classes Group together Tailwind CSS modifiers like focus, peer-checked, dark:hover and more with HTML attributes πŸ‘©β€πŸš€ Using with a

Sep 15, 2022
Releases(v1.0.11)
Grupprojekt fΓΆr kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet fΓΆr kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide FΓΆr information om hur utv

Svante Jonsson IT-HΓΆgskolan 3 May 18, 2022
Hemsida fΓΆr personer i Sverige som kan och vill erbjuda boende till mΓ€nniskor pΓ₯ flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo fΓΆr kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Have you always wanted to check if someone has checked out your story or not?

InstaStoryChecker - Search in your story viewers Have you always wanted to check if a certain person has checked out your story or not and you had to

Mohammad Saleh 4 Jul 7, 2022
Some ideas for grid to slideshow switch animations using GSAP's Flip plugin.

Grid to Slideshow Switch Animations Some ideas for grid to slideshow switch animations using GSAP's Flip plugin. Article on Codrops Demo Installation

Codrops 31 Jun 22, 2023
Nutrition tracking software that uses machine learning to help you reach your body composition goals.

LogSmarter - Machine Learning Nutrition Tracker Description LogSmarter LogSmarterβ„’ is not just another calorie counter. It is an AI nutrition coach th

Ryan Lefebvre 24 Sep 4, 2022
This is a dependency-free easy-to-use vanilla JavaScript addon allowing you to create HTML currency inputs with various different currencies and formattings.

intl-currency-input This is a dependency-free easy-to-use vanilla JavaScript addon allowing you to create HTML currency inputs with various different

null 6 Jan 4, 2023
Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator Types generator is a utility tool that will help User to create TS Interfaces from JSON. All you have to do is paste your single objec

Vineeth.TR 16 Dec 6, 2022
An interactive story framework.

Tale-js Tale-js is an interactive story maker, that allows you to write a story using JavaScript logic controls. There are a few requirements: // For

Jesse 4 May 23, 2022
Story Show Gallery - JS & React - minimalist, vertical photo gallery, mobile friendly

Vertical photo gallery optimized for smartphones (notch area included). SSG will support your brand and marketing. Optimally placed captions, full screen lightbox, no ugly arrows

Roman FlΓΆssler 21 Oct 4, 2022