/** * @file Radios * @description * @author fex * * @param 参数说明: * options: [ * { * label: '显示的名字', * value: '值', * disabled: false * } * ] */ import React from 'react'; import {uncontrollable} from 'uncontrollable'; import Checkbox from './Checkbox'; import {value2array, OptionProps, Option} from './Select'; import chunk from 'lodash/chunk'; import {ClassNamesFn, themeable} from '../theme'; interface RadioProps extends OptionProps { id?: string; type: string; value?: string; className?: string; style?: React.CSSProperties; inline?: boolean; disabled?: boolean; onChange?: Function; columnsCount: number; itemClassName?: string; labelField?: string; labelClassName?: string; classPrefix: string; classnames: ClassNamesFn; } export class Radios extends React.Component { static defaultProps = { type: 'radio', resetValue: '', inline: true, joinValues: true, clearable: false, columnsCount: 1 // 一行显示一个 }; toggleOption(option: Option) { const { value, onChange, valueField, clearable, delimiter, options } = this.props; let valueArray = value2array(value, { multiple: false, delimiter, valueField, options }); const idx = valueArray.indexOf(option); if (~idx) { clearable && valueArray.splice(idx, 1); } else { valueArray = [option]; } let newValue = valueArray[0]; onChange && onChange(newValue); } renderGroup(option: Option, index: number, valueArray: Array