/** * debug: true */ import React from 'react' import { CheckboxGroup, Checkbox, CheckAll, RadioGroup, Radio } from 'react-icecream' const options = [ { value: 'A' }, { value: 'B', disabled: true }, { value: 'C', disabled: false }, { value: 'D' } ] export default function GroupDemo() { const [checkboxGroupDisabled, checkboxGroupDisabledCtlView] = useBooleanRadioGroup(undefined) const [checkAllDisabled, checkAllDisabledCtlView] = useBooleanRadioGroup(undefined) return (


{options.map(o => {o.value})}
控制 CheckboxGroup 的 disabled:
{checkboxGroupDisabledCtlView}
控制 CheckAll 的 disabled:
{checkAllDisabledCtlView}
) } function useBooleanRadioGroup(initialState: boolean | undefined) { type Value = 'undefined' | 'true' | 'false' const [state, setState] = React.useState(initialState) const value = String(state) as Value function handleChange(newValue: Value) { setState({ undefined, true: true, false: false }[newValue]) } const view = ( radioType="button" value={value} onChange={handleChange}> undefined true false ) return [state, view] as const }