@uiw/react-native
Version:
UIW for React Native
34 lines • 896 B
JavaScript
import React from 'react';
import { View } from 'react-native';
import CheckBox from '../../CheckBox';
import Flex from '../../Flex';
const FormCheckBox = ({
value = [],
onChange,
options = [],
...others
}) => {
return <Flex justify="start" wrap="wrap" style={{
paddingTop: 15
}}>
{options.map((item, idx) => <View key={idx} style={{
marginRight: 15,
marginBottom: 15,
height: 24
}}>
<CheckBox key={idx} checked={value.includes(item.value)} onChange={() => {
let data = value || [];
if (!data.includes(item.value)) {
data.push(item.value);
} else {
const idx = data.findIndex(v => v === item.value);
data.splice(idx, 1);
}
onChange?.(data);
}} {...others}>
{item.label}
</CheckBox>
</View>)}
</Flex>;
};
export default FormCheckBox;