le0pard / storybook-addon-root-attribute

Storybook addon, which provide ability to change html, body or some element attribute
https://storybook-addon-root-attribute.leopard.in.ua
MIT License
18 stars 6 forks source link

Overwrite default state on stories #7

Closed esbenjuul closed 3 years ago

esbenjuul commented 4 years ago

Hi First of all thanks for the addon. I tried to overwrite the default state on my story but unless I select a whole new state i get the error 'ERROR: Found non unique name values'. Would be cool if it was possible to select one of the already defined states on my stories. I can try to do a PR if you like.

Best Esben

le0pard commented 4 years ago

Hi @ esbenjuul

Can you provide example (js code), so it issue will be more clear for me?

certainlyakey commented 3 years ago

Maybe what's meant here is the same issue that i have. I want to use this addon to allow users of a Storybook to switch LTR/RTL direction (dir attribute). It is also necessary to have the dir attribute to be set to ltr by default.

So it makes sense to configure the addon like this:

rootAttribute: {
  defaultState: {
      name: 'LTR',
      value: 'ltr'
  },
  attribute: 'dir',
  states: [
      {
          name: 'LTR',
          value: 'ltr'
      },
      {
          name: 'RTL',
          value: 'rtl'
      }
  ]
}

with one of the selectable states being the default one, therefore having the same name and value. But in this case we indeed get a message in the panel ERROR: Found non unique name values.

Is this something that could be resolved?

le0pard commented 3 years ago

@certainlyakey Just remove duplication from state, because defaultState also part of state:

rootAttribute: {
  defaultState: {
      name: 'LTR',
      value: 'ltr'
  },
  attribute: 'dir',
  states: [
      {
          name: 'RTL',
          value: 'rtl'
      }
  ]
}
certainlyakey commented 3 years ago

Thanks, it worked! 😊