/* * Copyright (c) 2018-present, Revolut LTD. * * This source code is licensed under the Apache 2.0 license found in the * LICENSE file in the root directory of this source tree. */ import * as React from 'react' import { action } from '@storybook/addon-actions' import { boolean, text, select, withKnobs } from '@storybook/addon-knobs' import { Checkbox } from './' class Container extends React.Component { constructor({ checked = false, ...props }) { super({ ...props, checked }) this.state = { checked: checked, } } handleChange = (_, checked) => { this.setState({ checked, }) } render() { return this.props.render({ handleChange: this.handleChange, checked: this.state.checked, }) } } const typeOptions = { checkbox: 'checkbox', switcher: 'switcher', wrong: `wrong - have to render fallback 'checkbox'`, } export const NoContainer = () => { const types = select('type', typeOptions, typeOptions.checkbox) return ( ) } export const InContainer = () => ( { const types = select('type', typeOptions, typeOptions.checkbox) return ( ) }} /> ) export const customLabel = () => ( { const types = select('type', typeOptions, typeOptions.checkbox) return ( ( {label} 🧀 )} /> ) }} /> ) export const switcher = () => (
( )} />
) export const switcherInText = () => (
(
Render pizza with cheddar
)} />
) export const usingRenderPropsCustomRender = () => ( ( { const handleClick = e => handleChange(e, !checked) return ( ) }} /> )} /> ) export const usingRenderProps = () => (
( { const handleClick = e => handleChange(e, !checked) const types = { radio: 'radio', checkbox: 'checkbox', } return ( Label sub component{' '} {renderLabelContent({ label: 'LabelComponent prop' })} ) }} /> )} />
) export default { title: 'Checkbox', component: Checkbox, decorators: [withKnobs], }