import {
createElement,
Component,
createContext,
Fragment,
} from '@wordpress/element'
import { maybeTransformUnorderedChoices } from '../helpers/parse-choices.js'
import classnames from 'classnames'
import _ from 'underscore'
const Checkboxes = ({
option,
value,
onChange,
option: { view = 'checkboxes' },
}) => {
const orderedChoices = maybeTransformUnorderedChoices(option.choices)
const { inline = false } = option
if (view === 'checkboxes') {
return (
{orderedChoices.map(({ key, value: choiceValue }) => (
))}
)
}
return (
{orderedChoices.map(({ key, value: choiceValue }) => (
-
onChange({
...value,
[key]: value[key]
? Object.values(value).filter((v) => v)
.length === 1 && !option.allow_empty
? true
: false
: true,
})
}>
{choiceValue}
))}
)
}
export default Checkboxes