|
| 1 | +/* External dependencies */ |
| 2 | +import React, { useState } from 'react' |
| 3 | +import { withKnobs, text } from '@storybook/addon-knobs' |
| 4 | + |
| 5 | +/* Internal dependencies */ |
| 6 | +import { Text } from '../Text' |
| 7 | +import Typography from '../../styling/Typography' |
| 8 | +import { ThemeProvider, LightTheme } from '../../styling/Theme' |
| 9 | +import Radio from './Radio' |
| 10 | + |
| 11 | +export default { |
| 12 | + title: 'Radio', |
| 13 | + decorators: [withKnobs], |
| 14 | +} |
| 15 | + |
| 16 | +export const Primary = () => { |
| 17 | + const value = 1 |
| 18 | + |
| 19 | + return ( |
| 20 | + <ThemeProvider theme={LightTheme}> |
| 21 | + <div style={{ margin: 10 }}> |
| 22 | + <Radio |
| 23 | + watchingValue={value} |
| 24 | + value={value} |
| 25 | + > |
| 26 | + <Text> |
| 27 | + { text('label', 'hello!') } |
| 28 | + </Text> |
| 29 | + </Radio> |
| 30 | + </div> |
| 31 | + </ThemeProvider> |
| 32 | + ) |
| 33 | +} |
| 34 | + |
| 35 | +export const Disabled = () => ( |
| 36 | + <ThemeProvider theme={LightTheme}> |
| 37 | + <Radio disabled> |
| 38 | + <Text> |
| 39 | + { text('label', 'hello, world!') } |
| 40 | + </Text> |
| 41 | + </Radio> |
| 42 | + </ThemeProvider> |
| 43 | +) |
| 44 | + |
| 45 | +export const CheckedDisabled = () => { |
| 46 | + const value = 1 |
| 47 | + |
| 48 | + return ( |
| 49 | + <ThemeProvider theme={LightTheme}> |
| 50 | + <Radio |
| 51 | + value={value} |
| 52 | + watchingValue={value} |
| 53 | + disabled |
| 54 | + > |
| 55 | + <Text> |
| 56 | + { text('label', 'hello, world!') } |
| 57 | + </Text> |
| 58 | + </Radio> |
| 59 | + </ThemeProvider> |
| 60 | + ) |
| 61 | +} |
| 62 | + |
| 63 | +export const MultiRadio = () => { |
| 64 | + const [selected, setSelected] = useState(1) |
| 65 | + |
| 66 | + const options = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
| 67 | + |
| 68 | + return ( |
| 69 | + <ThemeProvider theme={LightTheme}> |
| 70 | + <Text typo={Typography.Size24}> |
| 71 | + selected Option: { selected } |
| 72 | + </Text> |
| 73 | + |
| 74 | + { |
| 75 | + options.map(value => ( |
| 76 | + <Radio |
| 77 | + key={value} |
| 78 | + value={value} |
| 79 | + watchingValue={selected} |
| 80 | + onClick={v => setSelected(v)} |
| 81 | + disabled={value >= 8} |
| 82 | + > |
| 83 | + <Text> |
| 84 | + { value }st option |
| 85 | + </Text> |
| 86 | + </Radio> |
| 87 | + )) |
| 88 | + } |
| 89 | + </ThemeProvider> |
| 90 | + ) |
| 91 | +} |
0 commit comments