import React from 'react' import Checkbox from './checkbox' import CheckboxGroup from './checkbox_group' import { observable } from 'mobx' import { Col, Row } from '../grid' import _ from 'lodash' const store = observable({ value: [1, 4], data: [ { value: 1, text: '广州', }, { value: 2, text: '深圳', disabled: true, }, { value: 3, text: '成都', }, { value: 4, text: '东莞', disabled: true, }, { value: 5, text: '珠海', }, { value: 6, text: '惠州', }, ], setValue(value: any) { console.log(value) this.value = value }, checked: false, setChecked() { this.checked = !this.checked }, }) export const ComCheckbox = () => (
默认
{ store.setChecked() }} > 选中 checked true { store.setChecked() }} > checked false { store.setChecked() }} > checked indeterminate
disabled
checked true checked false checked indeterminate
) export const ComCheckboxGroup = () => ( { store.setValue(value) }} > {store.data.map((v) => ( {v.text} ))} ) export const ComCheckboxGroupForGrid = () => { const two = _.groupBy(store.data, (v) => Math.floor((v.value - 1) / 2)) console.log(two) return (
垂直布局
{ store.setValue(value) }} > {_.map(store.data, (v) => (
{v.text}
))}
两列
{ store.setValue(value) }} > {_.map(two, (one) => ( {_.map(one, (v) => ( {v.text} ))} ))}
) } export default { title: '表单/Checkbox', }