import React, { useState } from 'react'; import Button from '../../button'; import Space from '../../space'; import { Radio, RadioGroup, Form, Tooltip } from '../../index'; import { Row, Col } from '../../grid'; import './radio.scss'; export default { title: 'Radio' } export const _Radio = () => { let cssStyle = { width: '200px', }; return (
Experts say the abandonment of book reading may have some unappealing consequences for cognition. “People are clearly reading fewer books now than they used to, and that has to have a cost because we know book reading is very good cognitive exercise,” says Ken Pugh, director of research at the Yale-affiliated Haskins Laboratories, which examines the importance of spoken and written language.
); }; _Radio.story = { name: 'radio', }; export const RadioWithExtra = () => { return ( <> 示例文本 示例文本 ); }; RadioWithExtra.story = { name: 'radio with extra', }; export const RadioChecked = () => { return (
{'受控的checked = true'} 111
{'受控的checked = false'} 111
{'不受控的defaultChecked = true'} 111
{'不受控的defaultChecked = false'} 111
); }; RadioChecked.story = { name: 'radio checked', }; export const RadioDisabled = () => { return (
111 111
); }; RadioDisabled.story = { name: 'radio disabled', }; class RadioControl extends React.Component { state = { checked: true, disabled: false, }; toggleChecked = () => { this.setState({ checked: !this.state.checked }); }; toggleDisable = () => { this.setState({ disabled: !this.state.disabled }); }; onChange = e => { console.log('checked = ', e.target.checked); this.setState({ checked: e.target.checked, }); }; render() { const label = `${this.state.checked ? 'Checked' : 'Unchecked'}-${ this.state.disabled ? 'Disabled' : 'Enabled' }`; return (

{label}

); } } export const RadioControlledDisabledChecked = () => ; RadioControlledDisabledChecked.story = { name: 'Radio controlled disabled & checked', }; const RadioGroup1 = () => { const [state, setChecked] = useState('1'); console.log(state); return (
{ setChecked(evt.target.value); }} > 1 2 点击触发state变化,state变化触发展示变化 { setChecked(evt.target.value); }} > 2 1
); }; class RadioWithControlled extends React.Component { constructor(props) { super(props); this.state = { value: false, }; } onChange(value) { this.setState({ value: value.target.value, }); } render() { return ( 111 222 ); } } export const _RadioGroup = () => { let onChange = data => { console.log('change', data); }; return (
value=1 111 222
defaultValue=1 111 222
value+onchange
联动
); }; _RadioGroup.story = { name: 'radio group', }; export const RadioWithVertical = () => { return ( 无限长的一串字The Storybook webapp UI can be customised with this addon. It can be used to change the header, show/hide various UI elements and to enable full-screen mode by default. C D E ); }; RadioWithVertical.story = { name: 'radio with vertical', }; export const RadioGroupWithOptions = () => { const plainOptions = ['Apple', 'Pear', 'Orange']; const options = [ { label: 'Apple', value: 'Apple' }, { label: 'Pear', value: 'Pear' }, { label: 'Orange', value: 'Orange', disabled: true }, ]; const optionsWithDisabled = [ { label: 'Apple', value: 'Apple' }, { label: 'Pear', value: 'Pear' }, { label: 'Orange', value: 'Orange', disabled: false }, ]; function onChange(event) { console.log(event); } return (
); }; RadioGroupWithOptions.story = { name: 'radio group with options', }; const RadioWithAdvancedMode = () => { const [state, setChecked] = useState([true]); return (
{ console.log(e); setChecked(e.target.checked); e.stopPropagation(); e.preventDefault(); }} > 111
); }; export const _RadioWithAdvancedMode = () => ; _RadioWithAdvancedMode.story = { name: 'radio with advanced mode', }; export const RadioGroupWithAdvancedMode = () => { function onChange(evt) { console.log(evt); } return ( <> 111 222 333

111
222
333
); }; RadioGroupWithAdvancedMode.story = { name: 'radio group with advanced mode', }; export const RadioGrid = () => { return ( 无限长的一串字The Storybook webapp UI can be customised with this addon. It can be used to change the header, show/hide various UI elements and to enable full-screen mode by default. B C D E ); }; RadioGrid.story = { name: 'radio + grid', }; export const DynamicRadioGroup = () => { const Demo = () => { const [value, setValue] = useState(1); const onChange = e => { console.log('radio checked', e.target.value); setValue(e.target.value); }; return ( {value !== 4 ? A : null} B C D ); }; return ; }; DynamicRadioGroup.style = { name: 'dynamic radioGroup' }; export const RadioGroupButtonStyle = () => { const Demo = () => { const [value1, setValue1] = useState(1); const [value2, setValue2] = useState(2); const [value3, setValue3] = useState(3); const onChange1 = e => { setValue1(e.target.value); }; const onChange2 = e => { setValue2(e.target.value); }; const onChange3 = e => { setValue3(e.target.value); }; return ( semi pipixia hotsoon toutiao semi pipixia hotsoon toutiao semi pipixia hotsoon toutiao ); }; return ; }; RadioGroupButtonStyle.story = { name: 'radioGroup button style' }; export const RadioGroupCardStyle = () => ( <>
常见情况
多选框标题 多选框标题 多选框标题

radio disabled
多选框标题 多选框标题 多选框标题

radioGroup disabled
多选框标题 多选框标题 多选框标题

文字很长,并且没有设置宽度,因此换行显示
多选框标题 多选框标题 多选框标题

设置了width=180
多选框标题 多选框标题 多选框标题

没有extra,width=180
多选框标题 多选框标题 多选框标题

没有标题,width=380



下面是垂直的情况:
常见情况
多选框标题 多选框标题 多选框标题

没有设置宽度
多选框标题 多选框标题 多选框标题

设置了width=380
多选框标题 多选框标题 多选框标题 ); RadioGroupCardStyle.story = { name: 'radioGroup card style' } export const RadioGroupPureCardStyle = () => ( <>
常见情况
多选框标题 多选框标题 多选框标题

radio disabled
多选框标题 多选框标题 多选框标题

radioGroup disabled
多选框标题 多选框标题 多选框标题

文字很长,并且没有设置宽度,因此换行显示
多选框标题 多选框标题 多选框标题

设置了width=180
多选框标题 多选框标题 多选框标题

没有extra,width=180
多选框标题 多选框标题 多选框标题

没有标题,width=380



下面是垂直的情况:
常见情况
多选框标题 多选框标题 多选框标题

没有设置宽度
多选框标题 多选框标题 多选框标题

设置了width=380
多选框标题 多选框标题 多选框标题 ); RadioGroupPureCardStyle.story = { name: 'radioGroup pureCard style' } export const FixWithFieldLossRef = () => { return (
Semi
); } FixWithFieldLossRef.storyName = '修复 Form Field 丢失 ref 问题 #384'; export const SwitchValueToNaN = () => { const [val, setVal] = useState(1); return ( <> A B C D ); } SwitchValueToNaN.storyName = 'SwitchValueToNaN';