11import React from 'react'
2- import { StoryFn , Meta } from '@storybook/react'
2+ import type { Meta , StoryObj } from '@storybook/react'
33
44import Reset from '../components/decorator-reset'
55
66import { useControls } from '../../src'
77
8- export default {
8+ const meta = {
99 title : 'Inputs/Select' ,
1010 decorators : [ Reset ] ,
11- } as Meta
11+ } satisfies Meta
1212
13- const Template : StoryFn = ( args ) => {
13+ export default meta
14+ type Story = StoryObj < typeof meta >
15+
16+ const Render = ( args : any ) => {
1417 const values = useControls ( {
1518 foo : args ,
1619 } )
@@ -25,50 +28,60 @@ const Template: StoryFn = (args) => {
2528/**
2629 * Passes a list of values. The value will be used as both value AND label.
2730 */
28- export const Simple = Template . bind ( { } )
29- Simple . args = {
30- value : 'x' ,
31- options : [ 'x' , 'y' ] ,
32- }
31+ export const Simple : Story = {
32+ args : {
33+ value : 'x' ,
34+ options : [ 'x' , 'y' ] ,
35+ } ,
36+ render : Render ,
37+ } as Story
3338
3439/**
3540 * No value is passed, so the first option will be selected as the default.
3641 */
37- export const NoValue = Template . bind ( { } )
38- NoValue . args = {
39- options : [ 'x' , 'y' ] ,
40- }
42+ export const NoValue : Story = {
43+ args : {
44+ options : [ 'x' , 'y' ] ,
45+ } ,
46+ render : Render ,
47+ } as Story
4148
4249/**
4350 * Passes an object of values. The key will be used as label and the value will be used as value.
4451 */
45- export const CustomLabels = Template . bind ( { } )
46- CustomLabels . args = {
47- value : 'helloWorld' ,
48- options : {
49- 'Hello World' : 'helloWorld' ,
50- 'Leva is awesome!' : 'leva' ,
52+ export const CustomLabels : Story = {
53+ args : {
54+ value : 'helloWorld' ,
55+ options : {
56+ 'Hello World' : 'helloWorld' ,
57+ 'Leva is awesome!' : 'leva' ,
58+ } ,
5159 } ,
52- }
60+ render : Render ,
61+ } as Story
5362
54- export const InferredValueAsOption = Template . bind ( { } )
55- InferredValueAsOption . args = {
56- value : true ,
57- options : [ false ] ,
58- }
63+ export const InferredValueAsOption : Story = {
64+ args : {
65+ value : true ,
66+ options : [ false ] ,
67+ } ,
68+ render : Render ,
69+ } as Story
5970
6071const ComponentA = ( ) => < span > Component A</ span >
6172const ComponentB = ( ) => < span > Component B</ span >
6273
6374/**
6475 * Shows passing functions as the option values.
6576 */
66- export const FunctionAsOptions = ( ) => {
77+ const FunctionAsOptionsRender = ( ) => {
6778 const values = useControls ( {
6879 foo : { options : { none : '' , ComponentA, ComponentB } } ,
6980 } )
7081
71- if ( ! values . foo ) return null
82+ if ( ! values . foo ) {
83+ return < div > No component selected</ div >
84+ }
7285
7386 // render value.foo as a react component
7487 const Component = values . foo as React . ComponentType
@@ -80,15 +93,21 @@ export const FunctionAsOptions = () => {
8093 )
8194}
8295
96+ export const FunctionAsOptions : Story = {
97+ render : FunctionAsOptionsRender ,
98+ } as Story
99+
83100/**
84101 * Shows passing a value/label records array.
85102 */
86- export const ValueLabelObjects = Template . bind ( { } )
87- ValueLabelObjects . args = {
88- value : '#f00' ,
89- options : [
90- { value : '#f00' , label : 'red' } ,
91- { value : '#0f0' , label : 'green' } ,
92- { value : '#00f' , label : 'blue' } ,
93- ] ,
94- }
103+ export const ValueLabelObjects : Story = {
104+ args : {
105+ value : '#f00' ,
106+ options : [
107+ { value : '#f00' , label : 'red' } ,
108+ { value : '#0f0' , label : 'green' } ,
109+ { value : '#00f' , label : 'blue' } ,
110+ ] ,
111+ } ,
112+ render : Render ,
113+ } as Story
0 commit comments