mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-02-06 05:40:09 +00:00
106 lines
2.7 KiB
Text
106 lines
2.7 KiB
Text
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 Elements/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: ['intermediate state', true, false],
|
|
},
|
|
defaultValue: false,
|
|
},
|
|
disabled: {
|
|
control: {
|
|
type: 'boolean',
|
|
options: [true, false],
|
|
},
|
|
defaultValue: false,
|
|
},
|
|
small: {
|
|
control: {
|
|
type: 'boolean',
|
|
options: [true, false],
|
|
},
|
|
defaultValue: false,
|
|
},
|
|
color: {
|
|
control: {
|
|
type: 'select',
|
|
options: ['green', 'neutral'],
|
|
},
|
|
defaultValue: 'green',
|
|
},
|
|
}}
|
|
/>
|
|
|
|
# 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} />
|