UNPKG

@postenbring/hedwig-react

Version:

React components for [Hedwig Design System](https://github.com/bring/hedwig-design-system).

103 lines (101 loc) 3.07 kB
import { useFieldsetContext } from "./chunk-4K54KSRB.mjs"; import { ValidationMessage } from "./chunk-7REW23LO.mjs"; import { getValidationMessageValue } from "./chunk-3V4GFS46.mjs"; import { __objRest, __spreadProps, __spreadValues } from "./chunk-YOSPWY5K.mjs"; // src/form/checkbox/checkbox.tsx import { forwardRef, useId } from "react"; import { clsx } from "@postenbring/hedwig-css/typed-classname"; import { jsx, jsxs } from "react/jsx-runtime"; var Checkbox = forwardRef( (_a, ref) => { var _b = _a, { variant = "plain", hasError: hasErrorProp, validationMessage, validationMessageProps, errorMessage, errorMessageProps, title, children, className, size = "" } = _b, rest = __objRest(_b, [ "variant", "hasError", "validationMessage", "validationMessageProps", "errorMessage", "errorMessageProps", "title", "children", "className", "size" ]); const validationMessageId = useId(); const { hasError: hasFieldsetError, size: fieldsetSize } = useFieldsetContext(); const hasError = !!errorMessage || hasFieldsetError || hasErrorProp; const effectiveSize = size || fieldsetSize; const validationMessageValue = getValidationMessageValue(validationMessage, errorMessage); return /* @__PURE__ */ jsxs( "div", { className: clsx("hds-checkbox-wrapper", { "hds-checkbox-wrapper--small": effectiveSize === "small" }), children: [ /* @__PURE__ */ jsxs( "div", { className: clsx( "hds-checkbox", { [`hds-checkbox--${variant}`]: variant === "bounding-box" }, className ), children: [ /* @__PURE__ */ jsxs("label", { children: [ /* @__PURE__ */ jsx( "input", __spreadValues({ "aria-invalid": hasError ? true : void 0, "aria-describedby": validationMessageValue ? validationMessageId : void 0, ref, type: "checkbox" }, rest) ), /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "hds-checkbox__checkmark" }), title ? /* @__PURE__ */ jsx("p", { className: "hds-checkbox__title", children: title }) : children ] }), title ? children : null ] } ), /* @__PURE__ */ jsx( ValidationMessage, __spreadProps(__spreadValues({ id: validationMessageId }, validationMessageProps != null ? validationMessageProps : errorMessageProps), { children: validationMessageValue }) ) ] } ); } ); Checkbox.displayName = "Checkbox"; export { Checkbox }; //# sourceMappingURL=chunk-BUFV457A.mjs.map