@wordpress/components
Version:
UI components for WordPress.
42 lines (41 loc) • 1.36 kB
JavaScript
// packages/components/src/validated-form-controls/components/checkbox-control.tsx
import { useMergeRefs } from "@wordpress/compose";
import { forwardRef, useRef } from "@wordpress/element";
import { ControlWithError } from "../control-with-error";
import CheckboxControl from "../../checkbox-control";
import { jsx as _jsx } from "react/jsx-runtime";
var UnforwardedValidatedCheckboxControl = ({
required,
onValidate,
customValidity,
onChange,
markWhenOptional,
...restProps
}, forwardedRef) => {
const validityTargetRef = useRef(null);
const mergedRefs = useMergeRefs([forwardedRef, validityTargetRef]);
const valueRef = useRef(restProps.checked);
return /* @__PURE__ */ _jsx(ControlWithError, {
required,
markWhenOptional,
ref: mergedRefs,
onValidate: () => {
return onValidate?.(valueRef.current);
},
customValidity,
getValidityTarget: () => validityTargetRef.current?.querySelector('input[type="checkbox"]'),
children: /* @__PURE__ */ _jsx(CheckboxControl, {
__nextHasNoMarginBottom: true,
onChange: (value) => {
valueRef.current = value;
onChange?.(value);
},
...restProps
})
});
};
var ValidatedCheckboxControl = forwardRef(UnforwardedValidatedCheckboxControl);
export {
ValidatedCheckboxControl
};
//# sourceMappingURL=checkbox-control.js.map