UNPKG

@postenbring/hedwig-react

Version:

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

89 lines (87 loc) 3.07 kB
import { focusWithLegendOrLabelInViewport } from "./chunk-CKAL5ZJZ.mjs"; import { Link } from "./chunk-QE2ZES72.mjs"; import { UnorderedList } from "./chunk-3QHKPEXO.mjs"; import { useMergeRefs } from "./chunk-3V4GFS46.mjs"; import { Box } from "./chunk-DEABU7DB.mjs"; import { __objRest, __spreadProps, __spreadValues } from "./chunk-YOSPWY5K.mjs"; // src/form/error-summary/error-summary.tsx import { forwardRef, useEffect, useRef } from "react"; import { clsx } from "@postenbring/hedwig-css/typed-classname"; import { Slot } from "@radix-ui/react-slot"; import { jsx } from "react/jsx-runtime"; var ErrorSummaryHeading = forwardRef((_a, ref) => { var _b = _a, { asChild, children, as: Tag, autoFocus = true } = _b, rest = __objRest(_b, ["asChild", "children", "as", "autoFocus"]); const focusRef = useRef(null); const mergedRef = useMergeRefs([focusRef, ref]); const Component = asChild ? Slot : Tag; useEffect(() => { setTimeout(() => { if (focusRef.current && autoFocus) { focusRef.current.focus(); } }); }, []); return /* @__PURE__ */ jsx(Component, __spreadProps(__spreadValues({ className: clsx(`hds-error-summary__title`), ref: mergedRef, tabIndex: -1 }, rest), { children })); }); ErrorSummaryHeading.displayName = "ErrorSummary.Heading"; var ErrorSummaryList = forwardRef( (_a, ref) => { var _b = _a, { children, size = "small" } = _b, rest = __objRest(_b, ["children", "size"]); return /* @__PURE__ */ jsx(UnorderedList, __spreadProps(__spreadValues({ size, ref }, rest), { children })); } ); ErrorSummaryList.displayName = "ErrorSummary.List"; var ErrorSummaryItem = forwardRef( (_a, ref) => { var _b = _a, { children, href, linkProps } = _b, rest = __objRest(_b, ["children", "href", "linkProps"]); function onClick(e) { var _a2; (_a2 = linkProps == null ? void 0 : linkProps.onClick) == null ? void 0 : _a2.call(linkProps, e); if (focusWithLegendOrLabelInViewport(href.replace("#", ""))) { e.preventDefault(); } } return /* @__PURE__ */ jsx("li", __spreadProps(__spreadValues({ className: clsx(`hds-error-summary__list-item`), ref }, rest), { children: /* @__PURE__ */ jsx(Link, __spreadProps(__spreadValues({ size: "small", href, variant: "solid" }, linkProps), { onClick, children })) })); } ); ErrorSummaryItem.displayName = "ErrorSummary.Item"; var ErrorSummary = forwardRef( (_a, ref) => { var _b = _a, { children, className } = _b, rest = __objRest(_b, ["children", "className"]); return /* @__PURE__ */ jsx( Box, __spreadProps(__spreadValues({ "data-color": "error", ref }, rest), { className: clsx(`hds-error-summary`, className), children }) ); } ); ErrorSummary.displayName = "ErrorSummary"; ErrorSummary.Heading = ErrorSummaryHeading; ErrorSummary.List = ErrorSummaryList; ErrorSummary.Item = ErrorSummaryItem; export { ErrorSummaryHeading, ErrorSummaryList, ErrorSummaryItem, ErrorSummary }; //# sourceMappingURL=chunk-NAXSP4VU.mjs.map