Legacy Switch: updates story from knobs to controls (#32249)

* Legacy Switch: updates story from knobs to controls

* destructure arguments appropriately
This commit is contained in:
Uchechukwu Obasi 2021-03-23 12:33:27 +01:00 committed by GitHub
parent 814f194d07
commit 49a5b9f0cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,9 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Switch } from './Switch'; import { Props, Switch } from './Switch';
import { text } from '@storybook/addon-knobs'; import { Story } from '@storybook/react';
import mdx from './Switch.mdx'; import mdx from './Switch.mdx';
import { NOOP_CONTROL } from '../../../../utils/storybook/noopControl';
const getStory = (title: string, component: any) => ({ const getStory = (title: string, component: any) => ({
title, title,
@ -11,22 +12,26 @@ const getStory = (title: string, component: any) => ({
docs: { docs: {
page: mdx, page: mdx,
}, },
knobs: {
disable: true,
},
},
argTypes: {
className: NOOP_CONTROL,
labelClass: NOOP_CONTROL,
switchClass: NOOP_CONTROL,
}, },
}); });
export default getStory('Forms/Legacy/Switch', Switch); export default getStory('Forms/Legacy/Switch', Switch);
const getKnobs = () => { const SwitchWrapper: Story<Props> = ({ label, ...args }) => {
return {
label: text('Label Text', 'Label'),
tooltip: text('Tooltip', ''),
};
};
const SwitchWrapper = () => {
const { label, tooltip } = getKnobs();
const [checked, setChecked] = useState(false); const [checked, setChecked] = useState(false);
return <Switch label={label} checked={checked} onChange={() => setChecked(!checked)} tooltip={tooltip} />; return <Switch {...args} label={label} checked={checked} onChange={() => setChecked(!checked)} />;
}; };
export const basic = () => <SwitchWrapper />; export const Basic = SwitchWrapper.bind({});
Basic.args = {
label: 'Label',
tooltip: '',
};