UNPKG

@postenbring/hedwig-react

Version:

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

69 lines (67 loc) 2.04 kB
import { ErrorMessage } from "./chunk-LHIG6RW7.mjs"; import { __objRest, __spreadProps, __spreadValues } from "./chunk-YOSPWY5K.mjs"; // src/form/fieldset/fieldset.tsx import { useId, forwardRef, createContext, useContext } from "react"; import { clsx } from "@postenbring/hedwig-css/typed-classname"; import { jsx, jsxs } from "react/jsx-runtime"; var FieldsetContext = createContext({ hasError: false }); var useFieldsetContext = () => useContext(FieldsetContext); var Fieldset = forwardRef(function Fieldset2(_a, ref) { var _b = _a, { className, style, errorMessage, errorMessageProps, legendProps: _c = {} } = _b, _d = _c, { size: legendSize = "default", className: legendClassName } = _d, legendProps = __objRest(_d, ["size", "className"]), _e = _b, { legend, children } = _e, rest = __objRest(_e, [ "className", "style", "errorMessage", "errorMessageProps", "legendProps", "legend", "children" ]); const errorMessageId = useId(); return /* @__PURE__ */ jsxs( "fieldset", __spreadProps(__spreadValues({ "aria-describedby": errorMessage ? errorMessageId : void 0, "aria-invalid": errorMessage ? true : void 0, className: clsx("hds-fieldset", className), ref, style }, rest), { children: [ /* @__PURE__ */ jsx( "legend", __spreadProps(__spreadValues({ className: clsx( "hds-fieldset__legend", { [`hds-fieldset__legend--${legendSize}`]: legendSize }, legendClassName ) }, legendProps), { children: legend }) ), /* @__PURE__ */ jsx(FieldsetContext.Provider, { value: { hasError: Boolean(errorMessage) }, children }), /* @__PURE__ */ jsx(ErrorMessage, __spreadProps(__spreadValues({ id: errorMessageId }, errorMessageProps), { children: errorMessage })) ] }) ); }); export { useFieldsetContext, Fieldset }; //# sourceMappingURL=chunk-Z2ZPTZ6F.mjs.map