You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a developer,
I want to use non-serializable objects in controls,
so that I can choose between different {images, react components, etc.}
Currently, all keys and values must be JSON serializable (telejson-serializable, actually), which is a serious restriction when components can take arbitrary blob values / complex functions as their inputs.
Workaround
There is a workaround, which is to define an enum and then manually map it in the story function. For an example, see the last example in fully custom args docs:
exportdefault{component: YourComponent,title: 'A complex case with a function',// creates specific argTypes with optionsargTypes: {propertyA: {control: {type: 'select',options: ['One','Two','Three'],},},}};constMAP={One: <Foo/>,Two: <Bar/>Three: </Baz>}constTemplate=({ propertyA, ...rest})=>{constsomeFunctionResult=MAP[propertyA];return<YourComponentsomeProperty={someFunctionResult}{...rest}/>;};
Proposal
We can make this much more ergonomic by providing a new ArgType and control for "blob" types.
exportdefault{component: YourComponent,title: 'A complex case with a function',// creates specific argTypes with optionsargTypes: {propertyA: {control: {type: 'blob',values: {One: <Foo/>,Two: <Bar/>Three: </Baz>},},},},};constTemplate=(args)=>{constsomeFunctionResult=MAP[propertyA];return<YourComponent{...args}/>;};
The blob ArgType is special because is implemented as a select control, but the Arg serialization serializes and displays the key, which must be be a serializable string. There needs to be some code in the preview rendering that maps that key to the blob value before the arg is received by the story function.
Related
This feature also makes the security restrictions introduced in URL handling more bearable: #13803
As a developer,
I want to use non-serializable objects in controls,
so that I can choose between different {images, react components, etc.}
Currently, all keys and values must be JSON serializable (telejson-serializable, actually), which is a serious restriction when components can take arbitrary blob values / complex functions as their inputs.
Workaround
There is a workaround, which is to define an enum and then manually map it in the story function. For an example, see the last example in fully custom args docs:
Proposal
We can make this much more ergonomic by providing a new ArgType and control for "blob" types.
The blob ArgType is special because is implemented as a
select
control, but the Arg serialization serializes and displays the key, which must be be a serializable string. There needs to be some code in the preview rendering that maps that key to the blob value before the arg is received by the story function.Related
This feature also makes the security restrictions introduced in URL handling more bearable: #13803
It can also be a workaround for #11429
The text was updated successfully, but these errors were encountered: