import { autoUpdate, arrow as flArrow, flip, offset, safePolygon, shift, useDismiss, useFloating, useFocus, useHover, useInteractions, } from "@floating-ui/react"; import React, { Fragment, HTMLAttributes, forwardRef, useRef } from "react"; import { useModalContext } from "../modal/Modal.context"; import { Portal } from "../portal"; import { HStack } from "../primitives/stack"; import { Detail } from "../typography"; import { useId } from "../utils-external"; import { Slot } from "../utils/components/slot/Slot"; import { cl } from "../utils/helpers"; import { useControllableState, useMergeRefs } from "../utils/hooks"; import { useI18n } from "../utils/i18n/i18n.hooks"; export interface TooltipProps extends HTMLAttributes { /** * Element tooltip anchors to. * * Needs to be React.ReactElement, does not support multiple children/react fragment */ children: React.ReactElement & React.RefAttributes; /** * Open state for contolled tooltip */ open?: boolean; /** * Tells tooltip to start in open state. * Use _sparingly_ since hover/focus on other elements will close it. * * `open`-prop overwrites this. */ defaultOpen?: boolean; /** * Change handler for open. */ onOpenChange?: (open: boolean) => void; /** * Orientation for tooltip. * @default "top" */ placement?: "top" | "right" | "bottom" | "left"; /** * Toggles rendering of arrow. * @default true */ arrow?: boolean; /** * Distance from anchor to tooltip. * @default 10px with arrow, 2px without arrow */ offset?: number; /** * Text-content inside tooltip. */ content: string; /** * Sets max character length. * * Ideally you should keep the length of the tooltip to a minimum (80 characters). * Currently this prop only emits a warning in the console, which can be squelched * by setting this to a larger number. However, before doing so you should _try_ * to shorten the content so that it fits into 80 characters. * @default 80 */ maxChar?: number; /** * Adds a delay in milliseconds before opening tooltip. * @default 150 */ delay?: number; /** * List of Keyboard-keys for shortcuts. */ keys?: string[] | [string[], string[]]; /** * When false, Tooltip labels the element, and child-elements content will be ignored by screen-readers. * When true, content is added as additional information to the child element. * @default false */ describesChild?: boolean; } /** * A component that displays a tooltip when the user hovers over its child element. * * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/tooltip) * @see 🏷️ {@link TooltipProps} * * @example * ```jsx Tooltip as only form of labeling * *