UNPKG

@wordpress/components

Version:
65 lines (59 loc) 1.71 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { createElement } from "@wordpress/element"; /** * External dependencies */ import classnames from 'classnames'; /** * WordPress dependencies */ import { useInstanceId } from '@wordpress/compose'; import deprecated from '@wordpress/deprecated'; import { Icon, check } from '@wordpress/icons'; /** * Internal dependencies */ import BaseControl from '../base-control'; export default function CheckboxControl({ label, className, heading, checked, help, onChange, ...props }) { if (heading) { deprecated('`heading` prop in `CheckboxControl`', { alternative: 'a separate element to implement a heading', plugin: 'Gutenberg' }); } const instanceId = useInstanceId(CheckboxControl); const id = `inspector-checkbox-control-${instanceId}`; const onChangeValue = event => onChange(event.target.checked); return createElement(BaseControl, { label: heading, id: id, help: help, className: classnames('components-checkbox-control', className) }, createElement("span", { className: "components-checkbox-control__input-container" }, createElement("input", _extends({ id: id, className: "components-checkbox-control__input", type: "checkbox", value: "1", onChange: onChangeValue, checked: checked, "aria-describedby": !!help ? id + '__help' : undefined }, props)), checked ? createElement(Icon, { icon: check, className: "components-checkbox-control__checked", role: "presentation" }) : null), createElement("label", { className: "components-checkbox-control__label", htmlFor: id }, label)); } //# sourceMappingURL=index.js.map