UNPKG

@carbon/react

Version:

React components for the Carbon Design System

82 lines (80 loc) 3.1 kB
/** * Copyright IBM Corp. 2016, 2026 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ const require_runtime = require("../../_virtual/_rolldown/runtime.js"); const require_usePrefix = require("../../internal/usePrefix.js"); const require_deprecate = require("../../prop-types/deprecate.js"); const require_useMergedRefs = require("../../internal/useMergedRefs.js"); let react = require("react"); react = require_runtime.__toESM(react); let prop_types = require("prop-types"); prop_types = require_runtime.__toESM(prop_types); let react_jsx_runtime = require("react/jsx-runtime"); //#region src/components/InlineCheckbox/InlineCheckbox.tsx /** * Copyright IBM Corp. 2016, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ const InlineCheckbox = react.default.forwardRef((props, forwardRef) => { const { ["aria-label"]: ariaLabel, ariaLabel: deprecatedAriaLabel, checked = false, disabled, id, indeterminate, name, onChange = () => {}, onClick, onKeyDown, title } = props; const prefix = require_usePrefix.usePrefix(); const inputRef = (0, react.useRef)(null); const ref = require_useMergedRefs.useMergedRefs([inputRef, forwardRef]); const inputProps = { checked, className: `${prefix}--checkbox`, disabled, id, name, onClick: onClick ? onClickCheckBoxInput : onClick, onChange: (evt) => { onChange(evt.target.checked, id, evt); }, onKeyDown, ref, type: "checkbox" }; if (indeterminate) inputProps.checked = false; (0, react.useEffect)(() => { if (inputRef?.current) inputRef.current.indeterminate = indeterminate || false; }, [indeterminate]); function onClickCheckBoxInput(evt) { if (indeterminate) evt.target.checked = false; onClick?.(evt); } return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { className: `${prefix}--checkbox--inline`, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", { ...inputProps }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", { htmlFor: id, className: `${prefix}--checkbox-label`, title, onClick: (evt) => { evt.stopPropagation(); }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: `${prefix}--visually-hidden`, children: deprecatedAriaLabel || ariaLabel }) })] }); }); InlineCheckbox.propTypes = { ["aria-label"]: prop_types.default.string.isRequired, ariaLabel: require_deprecate.deprecate(prop_types.default.string.isRequired, "The `ariaLabel` prop has been deprecated in favor of `aria-label`. This prop will be removed in the next major release."), checked: prop_types.default.bool, disabled: prop_types.default.bool, id: prop_types.default.string.isRequired, indeterminate: prop_types.default.bool, name: prop_types.default.string.isRequired, onChange: prop_types.default.func, onClick: prop_types.default.func, onKeyDown: prop_types.default.func, title: prop_types.default.string }; //#endregion exports.default = InlineCheckbox;