How do I get dropdown in controls addon for Storybook?

Viewed 18998

I want to get this: enter image description here

My stories.tsx code looks like this:

export default {
  title: "Components/Switch",
  argTypes: {
    color: { control: "select", options: ["primary", "secondary"] },
  },
};

However, the page just fails to render when I do that.

To reproduce:

Clone this repository: https://github.com/jauggy/storybook-args-error

npm i

npm run storybook

Select the Switch component on the left menu.

2 Answers

You could also provide there an enum:

const SwitchTypeEnum {
    PRIMARY = "primary",
    SECONDARY = "secondary",
}

export default {
  title: "Components/Switch",
  argTypes: {
    table: {
        summary: "SwitchTypeEnum",
        defaultValue: { summary: "SwitchTypeEnum.PRIMARY" },
    },
    color: { control: { type: "select", options: SwitchTypeEnum },
  },
};
Related