UNPKG

@1771technologies/lytenyte-pro

Version:

796 lines (795 loc) 27.8 kB
import { jsxs, jsx } from "react/jsx-runtime"; import * as React from "react"; import { useMemo, forwardRef } from "react"; import { clsx } from "@1771technologies/js-utils"; import { u as useAnchor } from "./anchor-context-Cqr_oiJt.js"; import { m as mergeProps, P as PropTypes, H as HTMLElementType, r as refType, n as useOpenChangeComplete, D as FloatingFocusManager, d as useEnhancedEffect, j as useEventCallback } from "./proptypes-BjYr2nFr.js"; import { u as usePopoverRootContext, a as usePopoverPortalContext } from "./PopoverPortalContext-BdsDjihw.js"; import { u as useForkRef, a as useComponentRenderer, p as popupStateMapping, I as InternalBackdrop, t as transitionStatusMapping, b as useBaseUiId } from "./InternalBackdrop-C4RACVzs.js"; import { u as useAnchorPositioning } from "./useAnchorPositioning-52zK7jlD.js"; function usePopoverPositioner(params) { const { open, mounted } = usePopoverRootContext(); const positioning = useAnchorPositioning(params); const getPositionerProps = React.useCallback((externalProps = {}) => { const hiddenStyles = {}; if (!open) { hiddenStyles.pointerEvents = "none"; } return mergeProps({ role: "presentation", hidden: !mounted, style: { ...positioning.positionerStyles, ...hiddenStyles } }, externalProps); }, [open, mounted, positioning.positionerStyles]); return React.useMemo(() => ({ getPositionerProps, ...positioning }), [getPositionerProps, positioning]); } const PopoverPositionerContext = /* @__PURE__ */ React.createContext(void 0); if (process.env.NODE_ENV !== "production") { PopoverPositionerContext.displayName = "PopoverPositionerContext"; } function usePopoverPositionerContext() { const context = React.useContext(PopoverPositionerContext); if (context === void 0) { throw new Error("Base UI: PopoverPositionerContext is missing. PopoverPositioner parts must be placed within <Popover.Positioner>."); } return context; } const PopoverPositioner$1 = /* @__PURE__ */ React.forwardRef(function PopoverPositioner(props, forwardedRef) { const { render, className, anchor, positionMethod = "absolute", side = "bottom", align = "center", sideOffset = 0, alignOffset = 0, collisionBoundary = "clipping-ancestors", collisionPadding = 5, arrowPadding = 5, sticky = false, trackAnchor = true, ...otherProps } = props; const { floatingRootContext, open, mounted, setPositionerElement, modal, openReason, openMethod } = usePopoverRootContext(); const keepMounted = usePopoverPortalContext(); const positioner = usePopoverPositioner({ anchor, floatingRootContext, positionMethod, mounted, open, side, sideOffset, align, alignOffset, arrowPadding, collisionBoundary, collisionPadding, sticky, trackAnchor, keepMounted }); const state2 = React.useMemo(() => ({ open, side: positioner.side, align: positioner.align, anchorHidden: positioner.anchorHidden }), [open, positioner.side, positioner.align, positioner.anchorHidden]); const mergedRef = useForkRef(forwardedRef, setPositionerElement); const { renderElement } = useComponentRenderer({ propGetter: positioner.getPositionerProps, render: render ?? "div", className, state: state2, ref: mergedRef, extraProps: otherProps, customStyleHookMapping: popupStateMapping }); return /* @__PURE__ */ jsxs(PopoverPositionerContext.Provider, { value: positioner, children: [mounted && modal && openReason !== "hover" && openMethod !== "touch" && /* @__PURE__ */ jsx(InternalBackdrop, { inert: !open }), renderElement()] }); }); process.env.NODE_ENV !== "production" ? PopoverPositioner$1.propTypes = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * How to align the popup relative to the specified side. * @default 'center' */ align: PropTypes.oneOf(["center", "end", "start"]), /** * Additional offset along the alignment axis in pixels. * Also accepts a function that returns the offset to read the dimensions of the anchor * and positioner elements, along with its side and alignment. * * - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. * - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. * - `data.side`: which side of the anchor element the positioner is aligned against. * - `data.align`: how the positioner is aligned relative to the specified side. * @default 0 */ alignOffset: PropTypes.oneOfType([PropTypes.func, PropTypes.number]), /** * An element to position the popup against. * By default, the popup will be positioned against the trigger. */ anchor: PropTypes.oneOfType([HTMLElementType, refType, PropTypes.object, PropTypes.func]), /** * Minimum distance to maintain between the arrow and the edges of the popup. * * Use it to prevent the arrow element from hanging out of the rounded corners of a popup. * @default 5 */ arrowPadding: PropTypes.number, /** * @ignore */ children: PropTypes.node, /** * CSS class applied to the element, or a function that * returns a class based on the component’s state. */ className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), /** * An element or a rectangle that delimits the area that the popup is confined to. * @default 'clipping-ancestors' */ collisionBoundary: PropTypes.oneOfType([HTMLElementType, PropTypes.arrayOf(HTMLElementType), PropTypes.string, PropTypes.shape({ height: PropTypes.number, width: PropTypes.number, x: PropTypes.number, y: PropTypes.number })]), /** * Additional space to maintain from the edge of the collision boundary. * @default 5 */ collisionPadding: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({ bottom: PropTypes.number, left: PropTypes.number, right: PropTypes.number, top: PropTypes.number })]), /** * Determines which CSS `position` property to use. * @default 'absolute' */ positionMethod: PropTypes.oneOf(["absolute", "fixed"]), /** * Allows you to replace the component’s HTML element * with a different tag, or compose it with another component. * * Accepts a `ReactElement` or a function that returns the element to render. */ render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]), /** * Which side of the anchor element to align the popup against. * May automatically change to avoid collisions. * @default 'bottom' */ side: PropTypes.oneOf(["bottom", "inline-end", "inline-start", "left", "right", "top"]), /** * Distance between the anchor and the popup in pixels. * Also accepts a function that returns the distance to read the dimensions of the anchor * and positioner elements, along with its side and alignment. * * - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. * - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. * - `data.side`: which side of the anchor element the positioner is aligned against. * - `data.align`: how the positioner is aligned relative to the specified side. * @default 0 */ sideOffset: PropTypes.oneOfType([PropTypes.func, PropTypes.number]), /** * Whether to maintain the popup in the viewport after * the anchor element was scrolled out of view. * @default false */ sticky: PropTypes.bool, /** * Whether the popup tracks any layout shift of its positioning anchor. * @default true */ trackAnchor: PropTypes.bool } : void 0; function usePopoverPopup(params) { const { getProps, titleId, descriptionId, initialFocus } = params; const { popupRef, openMethod } = usePopoverRootContext(); const getPopupProps = React.useCallback((externalProps = {}) => { return mergeProps({ "aria-labelledby": titleId, "aria-describedby": descriptionId }, getProps(externalProps)); }, [getProps, titleId, descriptionId]); const defaultInitialFocus = React.useCallback((interactionType) => { if (interactionType === "touch") { return popupRef; } return 0; }, [popupRef]); const resolvedInitialFocus = React.useMemo(() => { if (initialFocus == null) { return defaultInitialFocus(openMethod ?? ""); } if (typeof initialFocus === "function") { return initialFocus(openMethod ?? ""); } return initialFocus; }, [defaultInitialFocus, initialFocus, openMethod]); return React.useMemo(() => ({ getPopupProps, resolvedInitialFocus }), [getPopupProps, resolvedInitialFocus]); } const customStyleHookMapping$1 = { ...popupStateMapping, ...transitionStatusMapping }; const PopoverPopup$1 = /* @__PURE__ */ React.forwardRef(function PopoverPopup(props, forwardedRef) { const { className, render, initialFocus, finalFocus, ...otherProps } = props; const { open, instantType, transitionStatus, getRootPopupProps, titleId, descriptionId, popupRef, mounted, openReason, onOpenChangeComplete } = usePopoverRootContext(); const positioner = usePopoverPositionerContext(); useOpenChangeComplete({ open, ref: popupRef, onComplete() { if (open) { onOpenChangeComplete?.(true); } } }); const { getPopupProps, resolvedInitialFocus } = usePopoverPopup({ getProps: getRootPopupProps, titleId, descriptionId, initialFocus }); const state2 = React.useMemo(() => ({ open, side: positioner.side, align: positioner.align, instant: instantType, transitionStatus }), [open, positioner.side, positioner.align, instantType, transitionStatus]); const mergedRef = useForkRef(popupRef, forwardedRef); const { renderElement } = useComponentRenderer({ propGetter: getPopupProps, ref: mergedRef, render: render ?? "div", className, state: state2, extraProps: transitionStatus === "starting" ? mergeProps({ style: { transition: "none" } }, otherProps) : otherProps, customStyleHookMapping: customStyleHookMapping$1 }); return /* @__PURE__ */ jsx(FloatingFocusManager, { context: positioner.context, modal: false, disabled: !mounted || openReason === "hover", initialFocus: resolvedInitialFocus, returnFocus: finalFocus, children: renderElement() }); }); process.env.NODE_ENV !== "production" ? PopoverPopup$1.propTypes = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * @ignore */ children: PropTypes.node, /** * CSS class applied to the element, or a function that * returns a class based on the component’s state. */ className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), /** * Determines the element to focus when the popover is closed. * By default, focus returns to the trigger. */ finalFocus: refType, /** * Determines the element to focus when the popover is opened. * By default, the first focusable element is focused. */ initialFocus: PropTypes.oneOfType([PropTypes.func, refType]), /** * Allows you to replace the component’s HTML element * with a different tag, or compose it with another component. * * Accepts a `ReactElement` or a function that returns the element to render. */ render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]) } : void 0; const PopoverArrow$1 = /* @__PURE__ */ React.forwardRef(function PopoverArrow(props, forwardedRef) { const { className, render, ...otherProps } = props; const { open } = usePopoverRootContext(); const { arrowRef, side, align, arrowUncentered, arrowStyles } = usePopoverPositionerContext(); const getArrowProps = React.useCallback((externalProps = {}) => { return mergeProps({ style: arrowStyles, "aria-hidden": true }, externalProps); }, [arrowStyles]); const state2 = React.useMemo(() => ({ open, side, align, uncentered: arrowUncentered }), [open, side, align, arrowUncentered]); const mergedRef = useForkRef(arrowRef, forwardedRef); const { renderElement } = useComponentRenderer({ propGetter: getArrowProps, render: render ?? "div", className, state: state2, ref: mergedRef, extraProps: otherProps, customStyleHookMapping: popupStateMapping }); return renderElement(); }); process.env.NODE_ENV !== "production" ? PopoverArrow$1.propTypes = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * @ignore */ children: PropTypes.node, /** * CSS class applied to the element, or a function that * returns a class based on the component’s state. */ className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), /** * Allows you to replace the component’s HTML element * with a different tag, or compose it with another component. * * Accepts a `ReactElement` or a function that returns the element to render. */ render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]) } : void 0; const customStyleHookMapping = { ...popupStateMapping, ...transitionStatusMapping }; const PopoverBackdrop$1 = /* @__PURE__ */ React.forwardRef(function PopoverBackdrop(props, forwardedRef) { const { className, render, ...other } = props; const { open, mounted, transitionStatus, openReason } = usePopoverRootContext(); const state2 = React.useMemo(() => ({ open, transitionStatus }), [open, transitionStatus]); const { renderElement } = useComponentRenderer({ render: render ?? "div", className, state: state2, ref: forwardedRef, extraProps: mergeProps({ role: "presentation", hidden: !mounted, style: openReason === "hover" ? { pointerEvents: "none" } : {} }, other), customStyleHookMapping }); return renderElement(); }); process.env.NODE_ENV !== "production" ? PopoverBackdrop$1.propTypes = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * @ignore */ children: PropTypes.node, /** * CSS class applied to the element, or a function that * returns a class based on the component’s state. */ className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), /** * Allows you to replace the component’s HTML element * with a different tag, or compose it with another component. * * Accepts a `ReactElement` or a function that returns the element to render. */ render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]) } : void 0; function usePopoverTitle(params) { const { titleId, setTitleId } = params; const id = useBaseUiId(titleId); const getTitleProps = React.useCallback((externalProps = {}) => { return mergeProps({ id }, externalProps); }, [id]); useEnhancedEffect(() => { setTitleId(id); return () => { setTitleId(void 0); }; }, [setTitleId, id]); return React.useMemo(() => ({ getTitleProps }), [getTitleProps]); } const state$2 = {}; const PopoverTitle$1 = /* @__PURE__ */ React.forwardRef(function PopoverTitle(props, forwardedRef) { const { render, className, ...otherProps } = props; const { setTitleId } = usePopoverRootContext(); const { getTitleProps } = usePopoverTitle({ titleId: otherProps.id, setTitleId }); const { renderElement } = useComponentRenderer({ propGetter: getTitleProps, render: render ?? "h2", className, state: state$2, ref: forwardedRef, extraProps: otherProps }); return renderElement(); }); process.env.NODE_ENV !== "production" ? PopoverTitle$1.propTypes = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * @ignore */ children: PropTypes.node, /** * CSS class applied to the element, or a function that * returns a class based on the component’s state. */ className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), /** * @ignore */ id: PropTypes.string, /** * Allows you to replace the component’s HTML element * with a different tag, or compose it with another component. * * Accepts a `ReactElement` or a function that returns the element to render. */ render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]) } : void 0; function usePopoverDescription(params) { const { descriptionId, setDescriptionId } = params; const id = useBaseUiId(descriptionId); const getDescriptionProps = React.useCallback((externalProps = {}) => { return mergeProps({ id }, externalProps); }, [id]); useEnhancedEffect(() => { setDescriptionId(id); return () => { setDescriptionId(void 0); }; }, [setDescriptionId, id]); return React.useMemo(() => ({ getDescriptionProps }), [getDescriptionProps]); } const state$1 = {}; const PopoverDescription$1 = /* @__PURE__ */ React.forwardRef(function PopoverDescription(props, forwardedRef) { const { render, className, ...otherProps } = props; const { setDescriptionId } = usePopoverRootContext(); const { getDescriptionProps } = usePopoverDescription({ descriptionId: otherProps.id, setDescriptionId }); const { renderElement } = useComponentRenderer({ propGetter: getDescriptionProps, render: render ?? "p", className, state: state$1, ref: forwardedRef, extraProps: otherProps }); return renderElement(); }); process.env.NODE_ENV !== "production" ? PopoverDescription$1.propTypes = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * @ignore */ children: PropTypes.node, /** * CSS class applied to the element, or a function that * returns a class based on the component’s state. */ className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), /** * @ignore */ id: PropTypes.string, /** * Allows you to replace the component’s HTML element * with a different tag, or compose it with another component. * * Accepts a `ReactElement` or a function that returns the element to render. */ render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]) } : void 0; function usePopoverClose(params) { const { onClose: onCloseProp } = params; const onClose = useEventCallback(onCloseProp); const getCloseProps = React.useCallback((externalProps = {}) => { return mergeProps({ onClick: onClose }, externalProps); }, [onClose]); return React.useMemo(() => ({ getCloseProps }), [getCloseProps]); } const state = {}; const PopoverClose$1 = /* @__PURE__ */ React.forwardRef(function PopoverClose(props, forwardedRef) { const { render, className, ...otherProps } = props; const { setOpen } = usePopoverRootContext(); const { getCloseProps } = usePopoverClose({ onClose() { setOpen(false); } }); const { renderElement } = useComponentRenderer({ propGetter: getCloseProps, render: render ?? "button", className, state, extraProps: otherProps, ref: forwardedRef }); return renderElement(); }); process.env.NODE_ENV !== "production" ? PopoverClose$1.propTypes = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * @ignore */ children: PropTypes.node, /** * CSS class applied to the element, or a function that * returns a class based on the component’s state. */ className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), /** * Allows you to replace the component’s HTML element * with a different tag, or compose it with another component. * * Accepts a `ReactElement` or a function that returns the element to render. */ render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]) } : void 0; function usePopoverClass(name, className) { return useMemo(() => { if (typeof className !== "function") return clsx(name, className); return (p) => clsx(name, className(p)); }, [className, name]); } function ArrowSvg(props) { return /* @__PURE__ */ jsxs("svg", { width: "20", height: "10", viewBox: "0 0 20 10", fill: "currentcolor", ...props, children: [ /* @__PURE__ */ jsx( "path", { fill: "var(--lng1771-gray-05)", d: "M9.66437 2.60207L4.80758 6.97318C4.07308 7.63423 3.11989 8 2.13172 8H0V10H20V8H18.5349C17.5468 8 16.5936 7.63423 15.8591 6.97318L11.0023 2.60207C10.622 2.2598 10.0447 2.25979 9.66437 2.60207Z" } ), /* @__PURE__ */ jsx( "path", { fill: "var(--lng1771-gray-05)", d: "M8.99542 1.85876C9.75604 1.17425 10.9106 1.17422 11.6713 1.85878L16.5281 6.22989C17.0789 6.72568 17.7938 7.00001 18.5349 7.00001L15.89 7L11.0023 2.60207C10.622 2.2598 10.0447 2.2598 9.66436 2.60207L4.77734 7L2.13171 7.00001C2.87284 7.00001 3.58774 6.72568 4.13861 6.22989L8.99542 1.85876Z" } ), /* @__PURE__ */ jsx( "path", { fill: "var(--lng1771-gray-30)", d: "M10.3333 3.34539L5.47654 7.71648C4.55842 8.54279 3.36693 9 2.13172 9H0V8H2.13172C3.11989 8 4.07308 7.63423 4.80758 6.97318L9.66437 2.60207C10.0447 2.25979 10.622 2.2598 11.0023 2.60207L15.8591 6.97318C16.5936 7.63423 17.5468 8 18.5349 8H20V9H18.5349C17.2998 9 16.1083 8.54278 15.1901 7.71648L10.3333 3.34539Z" } ) ] }); } const PopoverBackdrop2 = forwardRef(function PopoverBackdrop22({ className, ...props }, ref) { const cl = usePopoverClass("lng1771-popover__backdrop", className); return /* @__PURE__ */ jsx(PopoverBackdrop$1, { ...props, ref, className: cl }); }); const PopoverPopup2 = forwardRef(function PopoverPopup22({ className, ...props }, ref) { const cl = usePopoverClass("lng1771-popover", className); return /* @__PURE__ */ jsx(PopoverPopup$1, { ...props, ref, className: cl }); }); const PopoverTitle2 = forwardRef(function PopoverTitle22({ className, ...props }, ref) { const cl = usePopoverClass("lng1771-popover__title", className); return /* @__PURE__ */ jsx(PopoverTitle$1, { ...props, ref, className: cl }); }); const PopoverDescription2 = forwardRef(function PopoverDescription22({ className, ...props }, ref) { const cl = usePopoverClass("lng1771-popover__description", className); return /* @__PURE__ */ jsx(PopoverDescription$1, { ...props, ref, className: cl }); }); const PopoverClose2 = forwardRef(function PopoverClose22({ className, ...props }, ref) { const cl = usePopoverClass("lng1771-popover__close", className); return /* @__PURE__ */ jsx(PopoverClose$1, { ...props, ref, className: cl }); }); const PopoverPositioner2 = forwardRef(function PopoverPositioner22({ className, ...props }, ref) { const target = useAnchor(); const cl = usePopoverClass("lng1771-popover__positioner", className); return /* @__PURE__ */ jsx( PopoverPositioner$1, { anchor: target ? "getBoundingClientRect" in target ? target : { getBoundingClientRect: () => ({ x: target.x, y: target.y, width: target.width, height: target.height, top: target.y, left: target.x, bottom: target.y, right: target.x, toJSON: () => "" }) } : void 0, sideOffset: 8, ...props, ref, className: cl } ); }); const PopoverArrow2 = forwardRef(function PopoverArrow22({ className, ...props }, ref) { const cl = usePopoverClass("lng1771-popover__arrow", className); return /* @__PURE__ */ jsx(PopoverArrow$1, { ...props, ref, className: cl, children: props.children ?? /* @__PURE__ */ jsx(ArrowSvg, {}) }); }); const Popover = { Arrow: PopoverArrow2, Backdrop: PopoverBackdrop2, Close: PopoverClose2, Description: PopoverDescription2, Container: PopoverPopup2, Positioner: PopoverPositioner2, Title: PopoverTitle2 }; export { Popover };