Last active
January 10, 2022 18:29
-
-
Save kelwys/51601c177f838cd6d15c3ac3194edbd2 to your computer and use it in GitHub Desktop.
Ant Checkbox.Group from an array with grid and complex layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import 'antd/dist/antd.css'; | |
import './index.css'; | |
import { Checkbox, Row, Col } from 'antd'; | |
function onChange(checkedValues) { | |
console.log('checked = ', checkedValues); | |
} | |
const options = [ | |
{ label: 'Apple', value: 'Apple' }, | |
{ label: 'Pear', value: 'Pear' }, | |
{ label: 'Cherry', value: 'Cherry' }, | |
{ label: 'Melon', value: 'Melon' }, | |
{ label: 'Grape', value: 'Grape' }, | |
{ label: 'Orange', value: 'Orange' }, | |
]; | |
ReactDOM.render( | |
<> | |
<Checkbox.Group style={{ width: '100%' }} onChange={onChange}> | |
<Row> | |
{options.map((item, idx) => { | |
return ( | |
<Col key={idx} span={6}> | |
<Checkbox value={item.value}>{item.label}</Checkbox> | |
</Col> | |
); | |
})} | |
</Row> | |
</Checkbox.Group> | |
</>, | |
document.getElementById('container') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment