// // Copyright 2026 DXOS.org // // @import-as-namespace import { Portal } from '@ark-ui/react/portal'; import { Tour as TourPrimitive, type TourStepDetails, type UseTourProps, type UseTourReturn, useTourContext, useTour as useTourPrimitive, } from '@ark-ui/react/tour'; import React, { type ComponentPropsWithoutRef, type ReactNode, type RefObject, forwardRef } from 'react'; import { useTranslation } from 'react-i18next'; import { mx } from '@dxos/ui-theme'; import { type ThemedClassName } from '@dxos/ui-types'; import { translationKey } from '#translations'; import { recipes } from '../../recipes.ts'; import { type Size } from '../../sizes.ts'; import { Button, type ButtonProps } from '../Button/Button.tsx'; /** * Creates the machine, which owns the steps, waits for each target, scrolls it into view, places the card beside it * (or centres it, for a `dialog` step), cuts it out of the backdrop and traps focus. The spotlight sits on the target's * own rect (zag pads it by 10px), so its inset ring paints over the target's border. */ const useTour = (props?: UseTourProps): UseTourReturn => useTourPrimitive({ spotlightOffset: { x: 0, y: 0 }, ...props }); type TourStepPlacement = NonNullable; type TourStepAction = NonNullable[number]; // // Root // type TourRootProps = TourPrimitive.RootProps; /** Provides the machine from `useTour` to the parts; renders no element. The card mounts only while the tour runs. */ const TourRoot = ({ lazyMount = true, unmountOnExit = true, ...props }: TourRootProps) => ( ); TourRoot.displayName = 'Tour.Root'; // // Content // type TourContentProps = ThemedClassName & { /** The card's size; it has no sized trigger to inherit one from. */ size?: Size; /** Portals into this element instead of the body. */ container?: RefObject; }; /** * The card, an `alertdialog` at `level='popup'` named by its Title and described by its Description. It brings the * backdrop (shown for a step with `backdrop`), the spotlight over the target and the arrow (for a step with `arrow`), * all portalled, since the machine places them against the document. */ const TourContent = forwardRef( ({ classNames, size = 'md', container, children, ...props }, forwardedRef) => ( {children} ), ); TourContent.displayName = 'Tour.Content'; // // Header // type TourHeaderProps = ThemedClassName>; /** A block row holding the Title and an optional trailing CloseTrigger. */ const TourHeader = forwardRef(({ classNames, ...props }, forwardedRef) => (
)); TourHeader.displayName = 'Tour.Header'; // // Title // type TourTitleProps = ThemedClassName; /** The step's `title` by default. */ const TourTitle = forwardRef(({ classNames, ...props }, forwardedRef) => ( )); TourTitle.displayName = 'Tour.Title'; // // Description // type TourDescriptionProps = ThemedClassName; /** The step's `description` by default. */ const TourDescription = forwardRef( ({ classNames, ...props }, forwardedRef) => ( ), ); TourDescription.displayName = 'Tour.Description'; // // ProgressText // type TourProgressTextProps = ThemedClassName; /** "1 of 4" by default, from the machine's translations; children replace it. */ const TourProgressText = forwardRef(({ classNames, ...props }, forwardedRef) => ( )); TourProgressText.displayName = 'Tour.ProgressText'; // // Control // type TourControlProps = ThemedClassName; /** The block row the progress and actions sit in, pushed apart. */ const TourControl = forwardRef(({ classNames, ...props }, forwardedRef) => ( )); TourControl.displayName = 'Tour.Control'; // // Actions // type TourActionsProps = TourPrimitive.ActionsProps; /** Render prop over the current step's `actions`. */ const TourActions = TourPrimitive.Actions; // // ActionTrigger // type TourActionTriggerProps = Omit & { action: TourStepAction; /** Defaults to the action's `label`. */ label?: string; }; /** * A Button wired to one step action (`next`, `prev`, `dismiss`, `skip` or a function), named by its visible label * rather than zag's role label ("next step"), so what is read matches what is shown. */ const TourActionTrigger = forwardRef( ({ action, label, ...props }, forwardedRef) => ( // Button drops zag's `aria-label` unless it is icon-only, so its visible label names it.