import React, { useState } from 'react'; import { Meta, Story } from '@storybook/react'; import SwitchLabeled, { ISwitchLabeledProps } from './SwitchLabeled'; export default { title: 'Controls/SwitchLabeled', component: SwitchLabeled, subcomponents: { 'SwitchLabeled.Label': SwitchLabeled.Label }, parameters: { docs: { description: { component: (SwitchLabeled as any).peek.description, }, }, }, args: SwitchLabeled.defaultProps, } as Meta; export const Basic: Story = (args) => { const [isSelected, setIsSelected] = useState(false); const handleSelected = () => { setIsSelected(!isSelected); }; return ( ); }; /* Interactive */ export const Interactive: Story = (args) => { const style = { marginBottom: '3px', }; const [state, setState] = useState({ airplaneMode: false, bluetooth: false, cellularData: false, }); const handleSelectedAirplaneMode = (isSelected: any) => { setState({ ...state, airplaneMode: isSelected, }); }; const handleSelectedBluetooth = (isSelected: any) => { setState({ ...state, bluetooth: isSelected, }); }; const handleSelectedCellularData = (isSelected: any) => { setState({ ...state, cellularData: isSelected, }); }; return (

(Use the styles on the parent container of SwitchLabeled{' '} components to ensure only the switches and their labels are clickable)

Airplane Mode Bluetooth Cellular Data
); }; /* Interactive With Changing Labels */ export const InteractiveWithChangingLabels: Story = ( args ) => { const style = { marginBottom: '3px', }; const [state, setState] = useState({ airplaneMode: false, bluetooth: false, cellularData: false, spam: false, }); const handleSelectedAirplaneMode = (isSelected: any) => { setState({ ...state, airplaneMode: isSelected, }); }; const handleSelectedBluetooth = (isSelected: any) => { setState({ ...state, bluetooth: isSelected, }); }; const handleSelectedCellularData = (isSelected: any) => { setState({ ...state, cellularData: isSelected, }); }; const handleSelectedSpam = (isSelected: any) => { setState({ ...state, spam: isSelected, }); }; const spamSwitchLabel = state.spam ? 'Yes! I would like to receive updates, special offers, and other information from Xandr and its subsidiaries.' : 'No! Please keep your messages to yourself!'; return (

{spamSwitchLabel}
); }; /* Label As Prop */ export const LabelAsProp: Story = (args) => { const style = { marginRight: '5px', }; return (
HTML element} style={style} /> HTML element in an array, Again only the first value in the array is used , The rest should not be rendered, ]} style={style} />
); }; /* States */ export const States: Story = (args) => { const style = { marginBottom: '3px', marginRight: '13px', }; return (
(default props)
Selected Disabled Disabled & selected
); };