Let's say that I have this enum:
export enum Variant {
Primary = 'pr',
Secondary = 'sec',
}
How would I make a control in storybook that allows me to switch between these two options? I deliberately made the values much less self-explanatory than the keys in this example, as that's one of the main benefits of enums - user-friendly labels for string values.
The problem I noticed with the common approaches is that they use the enum value, rather than key, which I don't think is desirable. But when you use something like this to try to fix this:
argTypes: {
variant: {
options: Object.keys(Variant),
mapping: Variant
}
}
The default value will need to be 'Primary' string instead of Variant.Primary. So it seems like full obfuscation of enum values plus never using strings instead of corresponding enums is not possible. I hope I'm wrong, as this seems like a common scenario and knobs had a very easy way to accomplish this:
variant: select<Variant>('variant', Variant, Variant.Primary)
It would also be cool if the controls docs included an enum example.