Skip to content
awesome-tour

Type to search every page.

    DHotspotContents

    Hotspot

    A pulsing beacon pinned to an element that opens a hint popover.

    Hotspots
    Loopworknight-drive.lwp
    001.1.1

    Beat A

    16 steps · drums
    Kick
    Snare
    Hat
    Clap

    Mixer

    4 channels
    Drums
    80%
    Bass
    35%
    Keys
    60%
    Vox
    50%
    Non-blocking: keep playing, tweak a knob, then open a beacon.
    HotspotDemo.tsx
    import { LoopworkApp, part } from '@loopwork';
    import { HotspotHint } from '@/components/awesome-tour/hotspot';
    import { DemoFrame } from './ui';
    export function HotspotDemo() {
    return (
    <DemoFrame
    title="Hotspots"
    footer="Non-blocking: keep playing, tweak a knob, then open a beacon."
    >
    <LoopworkApp scope="hints" layout="compact">
    <HotspotHint
    target={part('hints', 'fx-slot')}
    title="New: tape saturation"
    beaconLabel="What’s new in drum effects"
    side="left"
    >
    Warm up the drum bus. Open the effects and switch on Tape.
    </HotspotHint>
    <HotspotHint
    target={part('hints', 'bpm')}
    title="Tip"
    label="Tip about the tempo"
    beaconLabel="Tip about the tempo"
    side="bottom"
    >
    Click the BPM and use ↑ ↓ to nudge the tempo by one.
    </HotspotHint>
    </LoopworkApp>
    </DemoFrame>
    );
    }

    Installation

    Terminal window
    pnpm dlx shadcn@latest add @awesome-tour/hotspot
    Terminal window
    npx shadcn@latest add @awesome-tour/hotspot

    Usage

    import { HotspotHint } from '@/components/awesome-tour/hotspot';
    <HotspotHint target="#export" title="New: PDF export" side="bottom">
    Export any report as a PDF, ready to share.
    </HotspotHint>

    The beacon’s pulse is disabled for users who prefer reduced motion. Parts: HotspotBeacon, HotspotCard, HotspotTitle, HotspotDescription.

    Source

    components/awesome-tour/hotspot.tsx
    'use client';
    import {
    Hotspot,
    type HotspotBeaconProps,
    type HotspotContentProps,
    type HotspotRootProps,
    useTourMessages,
    } from '@awesome-tour/react';
    import { X } from 'lucide-react';
    import type * as React from 'react';
    import { Button } from '@/components/ui/button';
    import { cn } from '@/lib/utils';
    /** A pulsing dot pinned to the target's corner. */
    function HotspotBeacon({
    className,
    label,
    ...props
    }: HotspotBeaconProps & {
    /** Accessible name of the beacon button. Default: the `showHint` message. */
    label?: string;
    }) {
    const { showHint } = useTourMessages();
    return (
    <Hotspot.Beacon
    data-slot="hotspot-beacon"
    aria-label={label ?? showHint}
    className={cn(
    'group/beacon z-40 flex size-4 cursor-pointer items-center justify-center rounded-full outline-none',
    'focus-visible:ring-[3px] focus-visible:ring-ring/50',
    className,
    )}
    {...props}
    >
    <span className="absolute inline-flex size-full animate-ping rounded-full bg-primary opacity-60 group-data-[state=open]/beacon:hidden motion-reduce:hidden" />
    <span className="relative inline-flex size-3 rounded-full border-2 border-background bg-primary shadow-sm" />
    </Hotspot.Beacon>
    );
    }
    function HotspotCard({
    className,
    sideOffset = 10,
    collisionPadding = 16,
    children,
    ...props
    }: HotspotContentProps) {
    const { closeHint } = useTourMessages();
    return (
    <Hotspot.Portal>
    <Hotspot.Content
    data-slot="hotspot-card"
    sideOffset={sideOffset}
    collisionPadding={collisionPadding}
    className={cn(
    'z-50 flex w-[min(18rem,calc(100vw-2rem))] origin-(--tour-content-transform-origin) flex-col gap-1.5 rounded-xl border bg-popover p-4 pr-10 text-sm text-popover-foreground shadow-lg outline-hidden',
    'data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
    'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95',
    className,
    )}
    {...props}
    >
    {children}
    <Hotspot.Close asChild>
    <Button
    variant="ghost"
    size="icon-xs"
    aria-label={closeHint}
    className="absolute top-2.5 right-2.5 text-muted-foreground"
    >
    <X />
    </Button>
    </Hotspot.Close>
    </Hotspot.Content>
    </Hotspot.Portal>
    );
    }
    function HotspotTitle({ className, ...props }: React.ComponentProps<'p'>) {
    return <p className={cn('leading-snug font-semibold', className)} {...props} />;
    }
    function HotspotDescription({ className, ...props }: React.ComponentProps<'p'>) {
    return <p className={cn('leading-relaxed text-muted-foreground', className)} {...props} />;
    }
    export interface HotspotHintProps extends Omit<HotspotRootProps, 'children'> {
    title?: React.ReactNode;
    children?: React.ReactNode;
    /** Accessible name of the hint dialog. Default: the title when it's a string. */
    label?: string;
    /** Accessible name of the beacon button. Default: "Show hint". */
    beaconLabel?: string;
    side?: HotspotContentProps['side'];
    align?: HotspotContentProps['align'];
    }
    /** Beacon + popover in one: `<HotspotHint target="#export" title="New">…</HotspotHint>`. */
    function HotspotHint({
    title,
    children,
    label,
    beaconLabel,
    side,
    align,
    ...props
    }: HotspotHintProps) {
    return (
    <Hotspot.Root {...props}>
    <HotspotBeacon label={beaconLabel} />
    <HotspotCard
    aria-label={label ?? (typeof title === 'string' ? title : undefined)}
    side={side}
    align={align}
    >
    {title && <HotspotTitle>{title}</HotspotTitle>}
    {children && <HotspotDescription>{children}</HotspotDescription>}
    </HotspotCard>
    </Hotspot.Root>
    );
    }
    export { HotspotBeacon, HotspotCard, HotspotDescription, HotspotHint, HotspotTitle };