bramw_baserow/web-frontend/stories/SwitchInput.stories.mdx

100 lines
2.5 KiB
Plaintext

import { Meta, Story, Props, Canvas } from '@storybook/addon-docs/blocks'
import { config, withDesign } from 'storybook-addon-designs'
import { action } from '@storybook/addon-actions'
import { useArgs } from '@storybook/client-api'
import SwitchInput from '@baserow/modules/core/components/SwitchInput'
<Meta
title="Baserow/Form/Switch"
component={SwitchInput}
parameters={{
backgrounds: {
default: 'white',
values: [
{ name: 'white', value: '#ffffff' },
{ name: 'light', value: '#eeeeee' },
{ name: 'dark', value: '#222222' },
],
},
}}
decorators={[
withDesign,
(story, context) => {
const [_, updateArgs] = useArgs()
return story({ ...context, updateArgs })
},
]}
argTypes={{
default: {
defaultValue: 'Label',
},
value: {
control: {
type: 'radio',
options: [2, true, false],
},
defaultValue: false,
},
disabled: {
control: {
type: 'boolean',
options: [true, false],
},
defaultValue: false,
},
small: {
control: {
type: 'boolean',
options: [true, false],
},
defaultValue: false,
},
}}
/>
# Switch Input
The switch input is a simple checkbox that can be used to toggle a value. It has also an intermediate state that can be used to indicate that the value is not yet known.
export const Template = (args, { argTypes, updateArgs }) => ({
methods: {
action,
handleInput(checkboxValue) {
const value = checkboxValue
updateArgs({ ...args, value })
action('handleInput')(checkboxValue)
},
},
components: { SwitchInput },
props: Object.keys(argTypes),
template: `
<SwitchInput v-bind="$props" @input="handleInput">${args.default}</SwitchInput>`,
})
export const designConfig = {
type: 'figma',
url: 'https://www.figma.com/file/W7R2rQW7ohsZMeHRfEcPFW/Design-Library?node-id=1%3A89&mode=dev',
}
<Canvas>
<Story
name="Switch"
parameters={{
design: config(designConfig),
}}
>
{Template.bind({})}
</Story>
</Canvas>
## Example
```javascript
<SwitchInput></SwitchInput>
```
## Props
<Props of={SwitchInput} />