UNPKG

@postenbring/hedwig-react

Version:

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

86 lines (84 loc) 2.18 kB
import { __objRest, __spreadProps, __spreadValues } from "./chunk-YOSPWY5K.mjs"; // src/box/box.tsx import { forwardRef, useCallback, useState } from "react"; import { clsx } from "@postenbring/hedwig-css/typed-classname"; import { Slot, Slottable } from "@radix-ui/react-slot"; import { jsx, jsxs } from "react/jsx-runtime"; var BoxCloseButton = forwardRef( (_a, ref) => { var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]); return /* @__PURE__ */ jsx( "button", __spreadValues({ className: clsx("hds-box__close-button", className), ref, type: "button" }, rest) ); } ); BoxCloseButton.displayName = "Box.CloseButton"; var Box = forwardRef( (_a, ref) => { var _b = _a, { asChild, variant, closeable = false, onClose: onCloseProp, closed: closedProp, closeButtonProps, children, className } = _b, rest = __objRest(_b, [ "asChild", "variant", "closeable", "onClose", "closed", "closeButtonProps", "children", "className" ]); const [closedState, setClosedState] = useState(false); const onClose = useCallback(() => { if (onCloseProp) { const result = onCloseProp(); if (result === true) { setClosedState(true); } } else { setClosedState(true); } }, []); const closed = closedProp != null ? closedProp : closedState; const Component = asChild ? Slot : "div"; return /* @__PURE__ */ jsxs( Component, __spreadProps(__spreadValues({ className: clsx( "hds-box", variant && `hds-box--${variant}`, { "hds-box--closed": closed }, className ), ref }, rest), { children: [ closeable ? /* @__PURE__ */ jsx(BoxCloseButton, __spreadValues({ onClick: onClose }, closeButtonProps)) : null, /* @__PURE__ */ jsx(Slottable, { children }) ] }) ); } ); Box.displayName = "Box"; Box.CloseButton = BoxCloseButton; export { BoxCloseButton, Box }; //# sourceMappingURL=chunk-3OGHJOJF.mjs.map