{"id":18365369,"url":"https://github.com/le0pard/storybook-addon-root-attribute","last_synced_at":"2025-04-09T17:22:43.004Z","repository":{"id":34588020,"uuid":"180010695","full_name":"le0pard/storybook-addon-root-attribute","owner":"le0pard","description":"Storybook addon, which provide ability to change html, body or some element attribute","archived":false,"fork":false,"pushed_at":"2025-01-24T22:37:14.000Z","size":2243,"stargazers_count":19,"open_issues_count":2,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T10:44:39.603Z","etag":null,"topics":["addon","addons","attribute","html","root","storybook"],"latest_commit_sha":null,"homepage":"https://storybook-addon-root-attribute.leopard.in.ua","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/le0pard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-07T19:06:14.000Z","updated_at":"2025-03-05T20:40:40.000Z","dependencies_parsed_at":"2023-01-15T08:01:23.463Z","dependency_job_id":"32630f01-09f9-4502-b3d1-1b1d528b96ff","html_url":"https://github.com/le0pard/storybook-addon-root-attribute","commit_stats":{"total_commits":94,"total_committers":4,"mean_commits":23.5,"dds":0.276595744680851,"last_synced_commit":"cf0f80901cc9edf57a04b5e6a7d9e65a5ef75da7"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0pard%2Fstorybook-addon-root-attribute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0pard%2Fstorybook-addon-root-attribute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0pard%2Fstorybook-addon-root-attribute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0pard%2Fstorybook-addon-root-attribute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/le0pard","download_url":"https://codeload.github.com/le0pard/storybook-addon-root-attribute/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248075275,"owners_count":21043557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["addon","addons","attribute","html","root","storybook"],"created_at":"2024-11-05T23:13:17.265Z","updated_at":"2025-04-09T17:22:42.983Z","avatar_url":"https://github.com/le0pard.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Storybook Addon Root Attribute [![Build Status](https://travis-ci.com/le0pard/storybook-addon-root-attribute.svg?branch=master)](https://travis-ci.com/le0pard/storybook-addon-root-attribute)\n\nStorybook Addon Root Attribute to switch html, body or some element attribute at runtime for your story [Storybook](https://storybook.js.org)\n\n## [Demo](https://storybook-addon-root-attribute.leopard.in.ua)\n\n## Installation\n\n```sh\nyarn add -D storybook-addon-root-attribute\n```\n\n## Configuration\n\nThen create a file called `addons.js` in your storybook config and add following content to it:\n\n```js\nimport \"storybook-addon-root-attribute/register\";\n```\n\nor create a file called `main.js` and add addon in `addons` section:\n\n```js\nmodule.exports = {\n  ...\n  addons: [\n    ...\n    'storybook-addon-root-attribute/register'\n  ]\n};\n```\n\n## Usage\n\nYou need add the all the attribute values at compile time using the `withRootAttribute` decorator. They can be added globally or per story. You can then choose which ones root attribute activate on addon ui:\n\n```js\n// Import from @storybook/X where X is your framework\nimport {\n  configure,\n  addDecorator,\n  addParameters,\n  storiesOf\n} from \"@storybook/react\";\nimport { withRootAttribute } from \"storybook-addon-root-attribute\";\n\n// global\naddDecorator(withRootAttribute);\naddParameters({\n  rootAttribute: {\n    defaultState: {\n      name: \"Default\",\n      value: null\n    },\n    states: [\n      {\n        name: \"Dark\",\n        value: \"dark\"\n      }\n    ]\n  }\n});\n```\n\nYou can use the `rootAttribute` parameter to override resources on each story individually:\n\n```js\n// per story\nstoriesOf(\"Addons|RootAttribute\", module).add(\n  \"Camera Icon\",\n  () =\u003e \u003ci className=\"fa fa-camera-retro\"\u003e Camera Icon\u003c/i\u003e,\n  {\n    rootAttribute: {\n      defaultState: {\n        name: \"Default\",\n        value: null\n      },\n      states: [\n        {\n          name: \"Dark\",\n          value: \"dark\"\n        }\n      ]\n    }\n  }\n);\n```\n\nIf you want to use a tooltip (panel will not dissapear), you need to set `tooltip` in parameters with `true` value:\n\n```js\naddParameters({\n  rootAttribute: {\n    tooltip: true,\n    defaultState: {\n      name: \"Default\",\n      value: null\n    },\n    states: [\n      {\n        name: \"Dark\",\n        value: \"dark\"\n      }\n    ]\n  }\n});\n```\n\nTooltip and panel will not sync about change attribute.\n\n## Configuration\n\nConfiguration params for `rootAttribute` parameter:\n\n| **Name**     | _Default_ | _Variants_                                                                                          | **Description**                                                                                                         |\n|--------------|-----------|-----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|\n| root         | 'html'    | 'html', 'body', or first element returned by 'document.querySelector(), or if none found -- 'html'' | Root node, which attribute will changed by addon                                                                        |\n| attribute    | 'class'   | any valid attribute name                                                                            | Attribute name                                                                                                          |\n| defaultState | {}        | should contain `name` and `value`                                                                   | Default state for attribute. Value `nil` will remove attribute from root                                                |\n| 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 |\n| tooltip      | false     | boolean value                                                                                       | Add tooltip button for storybook                                                                                        |\n\nConfiguration example:\n\n```js\naddDecorator(withRootAttribute);\naddParameters({\n  rootAttribute: {\n    root: \"html\",\n    attribute: \"class\",\n    defaultState: {\n      name: \"Default\",\n      value: null\n    },\n    states: [\n      {\n        name: \"Dark\",\n        value: \"dark\"\n      },\n      {\n        name: \"A11Y\",\n        value: \"accessibility\"\n      }\n    ]\n  }\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fle0pard%2Fstorybook-addon-root-attribute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fle0pard%2Fstorybook-addon-root-attribute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fle0pard%2Fstorybook-addon-root-attribute/lists"}