import { StoryObj } from '@storybook/react-webpack5'; import React from 'react'; import { createSandboxStory, globalScope, } from '../../../.storybook/components/sandbox/SandboxEditor'; import Button from '../../Button'; import SegmentedControl from '..'; export default { component: SegmentedControl, title: 'Forms/SegmentedControl', }; type Story = StoryObj; export const Sandbox = createSandboxStory({ code: `const App = () => { const [value, setValue] = React.useState('cupcakes'); const segments = [ { id: 'CUPCAKE', label: 'Cupcakes', value: 'cupcakes' }, { id: 'SPONGECAKE', label: 'Sponge cake', value: 'spongecake' }, { id: 'CARROT_CAKE', label: 'Carrot cake', value: 'carrotcake' }, ]; return ( setValue(newValue)} /> ); };`, scope: globalScope, }); const Template: Story = { render: (args) => { const [segments, setSegments] = React.useState([ { id: 'CUPCAKE', label: 'Cupcakes', value: 'cupcakes' }, { id: 'SPONGECAKE', label: 'Sponge cake', value: 'spongecake' }, { id: 'CARROT_CAKE', label: 'Carrot cake', value: 'carrotcake' }, ]); const [segmentsWithControls, setSegmentsWithControls] = React.useState([ { id: 'CUPCAKE', label: 'Cupcakes', value: 'cupcakes', controls: 'aControlId' }, { id: 'SPONGECAKE', label: 'Sponge cake', value: 'spongecake', controls: 'aControlId' }, { id: 'CARROT_CAKE', label: 'Carrot cake', value: 'carrotcake', controls: 'aControlId' }, ]); const [value, setValue] = React.useState(segments[0].value); console.log('render: segments.length', segments.length); return (

Selected value: {value}

Force the selectedValue to be one of the following:

); }, }; export const SegmentedControlDefault: Story = { ...Template, args: { mode: 'input', }, }; export const SegmentedControlView: Story = { ...Template, args: { mode: 'view', }, };