import { Popover as PopoverPrimitive, usePopoverContext } from "@seed-design/react-popover"; import { Primitive, type PrimitiveProps } from "@seed-design/react-primitive"; import { helpBubble, type HelpBubbleVariantProps } from "@seed-design/css/recipes/help-bubble"; import { forwardRef } from "react"; import { createSlotRecipeContext } from "../../utils/createSlotRecipeContext"; import { createWithStateProps } from "../../utils/createWithStateProps"; import { withStyleProps, type StyleProps } from "../../utils/styled"; import { getHelpBubbleArrowTipPath } from "../../utils/getHelpBubbleArrowTipPath"; import { composeRefs } from "@radix-ui/react-compose-refs"; import clsx from "clsx"; const { withRootProvider, withContext, useClassNames } = createSlotRecipeContext(helpBubble); const withStateProps = createWithStateProps([usePopoverContext]); //////////////////////////////////////////////////////////////////////////////////// export interface HelpBubbleRootProps extends HelpBubbleVariantProps, PopoverPrimitive.RootProps { /** * @default "top" */ placement?: PopoverPrimitive.RootProps["placement"]; /** * @default 4 */ gutter?: PopoverPrimitive.RootProps["gutter"]; /** * @default 16 */ overflowPadding?: PopoverPrimitive.RootProps["overflowPadding"]; /** * @default 14 */ arrowPadding?: PopoverPrimitive.RootProps["arrowPadding"]; } export const HelpBubbleRoot = withRootProvider(PopoverPrimitive.Root, { defaultProps: { placement: "top", gutter: 4, // TODO: get value from rootage spec overflowPadding: 16, arrowPadding: 14, }, }); //////////////////////////////////////////////////////////////////////////////////// export interface HelpBubbleAnchorProps extends PopoverPrimitive.AnchorProps {} export const HelpBubbleAnchor = PopoverPrimitive.Anchor; //////////////////////////////////////////////////////////////////////////////////// export interface HelpBubbleTriggerProps extends PopoverPrimitive.TriggerProps {} export const HelpBubbleTrigger = PopoverPrimitive.Trigger; //////////////////////////////////////////////////////////////////////////////////// export interface HelpBubblePositionerProps extends PopoverPrimitive.PositionerProps {} export const HelpBubblePositioner = withContext( PopoverPrimitive.Positioner, "positioner", ); export interface HelpBubblePositionerPortalProps extends PopoverPrimitive.PositionerPortalProps {} export const HelpBubblePositionerPortal = withContext< HTMLDivElement, HelpBubblePositionerPortalProps >(PopoverPrimitive.PositionerPortal, "positioner"); //////////////////////////////////////////////////////////////////////////////////// export interface HelpBubbleContentProps extends PrimitiveProps, Pick, React.HTMLAttributes {} export const HelpBubbleContent = withContext( withStyleProps(withStateProps(Primitive.div)), "content", ); //////////////////////////////////////////////////////////////////////////////////// export interface HelpBubbleArrowProps extends PopoverPrimitive.ArrowProps {} export const HelpBubbleArrow = withContext( PopoverPrimitive.Arrow, "arrow", ); //////////////////////////////////////////////////////////////////////////////////// export interface HelpBubbleArrowTipProps extends React.SVGProps { /** * radius of the arrow tip * @default 2 */ tipRadius?: number; } export const HelpBubbleArrowTip = forwardRef( (props, ref) => { const { tipRadius = 2, // TODO: get value from rootage spec className, ...otherProps } = props; const api = usePopoverContext(); const classNames = useClassNames(); const width = api.rects.arrowTip?.width || 0; const height = api.rects.arrowTip?.height || 0; const pathData = getHelpBubbleArrowTipPath(width, height, tipRadius); // TODO: mergeProps with api.stateProps return ( ); }, ); HelpBubbleArrowTip.displayName = "HelpBubbleArrowTip"; //////////////////////////////////////////////////////////////////////////////////// export interface HelpBubbleCloseButtonProps extends PopoverPrimitive.CloseButtonProps {} export const HelpBubbleCloseButton = withContext( PopoverPrimitive.CloseButton, "closeButton", ); //////////////////////////////////////////////////////////////////////////////////// export interface HelpBubbleBodyProps extends PrimitiveProps, React.HTMLAttributes {} export const HelpBubbleBody = withContext( withStateProps(Primitive.div), "body", ); export interface HelpBubbleTitleProps extends PrimitiveProps, React.HTMLAttributes {} export const HelpBubbleTitle = withContext( withStateProps(Primitive.span), "title", ); export interface HelpBubbleDescriptionProps extends PrimitiveProps, React.HTMLAttributes {} export const HelpBubbleDescription = withContext( withStateProps(Primitive.div), "description", );