UNPKG

@trail-ui/react

Version:
42 lines (39 loc) 1.38 kB
import { InternalModalContext } from "./chunk-QCN7MRXM.mjs"; import { _CloseButton } from "./chunk-6APYGYMC.mjs"; // src/modal/modal-close-button.tsx import { callAllHandlers, clsx } from "@trail-ui/shared-utils"; import { forwardRef, useContext, useEffect, useRef } from "react"; import { OverlayTriggerStateContext } from "react-aria-components"; import { mergeRefs } from "@trail-ui/hooks"; import { jsx } from "react/jsx-runtime"; function ModalCloseButton(props, ref) { const { children, className, onPress, ...otherProps } = props; const localRef = useRef(null); const state = useContext(OverlayTriggerStateContext); const { slots, classNames } = useContext(InternalModalContext); useEffect(() => { var _a; if (state == null ? void 0 : state.isOpen) (_a = localRef.current) == null ? void 0 : _a.focus(); }, [state == null ? void 0 : state.isOpen]); return /* @__PURE__ */ jsx( _CloseButton, { ref: mergeRefs(ref, localRef), className: slots.closeButton({ class: clsx(classNames == null ? void 0 : classNames.closeButton, className) }), onPress: callAllHandlers(onPress, () => state == null ? void 0 : state.close()), appearance: "transparent", spacing: "compact", ...otherProps, children } ); } var _ModalCloseButton = forwardRef(ModalCloseButton); export { _ModalCloseButton };