import { useTranslation } from 'react-i18next'; import React, { useCallback } from 'react'; import { useId } from '../hooks/useId'; import { AISignpostIcon } from '../icons/AISignpostIcon'; import { CloseIcon } from '../icons/CloseIcon'; /** * Props for the built-in AI signpost component. * * @public */ export interface AISignpostProps { /** Icon displayed before the signpost label. Defaults to the SDK's AI signpost icon. */ icon?: React.JSX.Element, /** Label displayed in the signpost button. */ label?: string, /** Header displayed in the signpost popover. */ popoverHeader?: string, /** Body displayed in the signpost popover. */ popoverBody?: string } interface InternalAISignpostProps { icon?: React.JSX.Element, label?: string, ariaLabel: string, popoverHeader: string, popoverBody: string, popoverAlignment?: 'left' | 'right' } /** * Displays AI signpost content. */ export function AISignpost({ icon, label, ariaLabel, popoverHeader, popoverBody, popoverAlignment = 'left' }: InternalAISignpostProps): React.JSX.Element { const { t } = useTranslation(); const [isOpen, setIsOpen] = React.useState(false); const popoverId = useId('ai-signpost-popover'); const popoverHeaderId = useId('ai-signpost-popover-header'); const popoverDescriptionId = useId('ai-signpost-popover-description'); const handleSignpostClick = useCallback(() => { setIsOpen(current => !current); }, []); const onSignpostClose = useCallback(() => { setIsOpen(false); }, []); const popoverAlignmentClass = popoverAlignment === 'right' ? 'right-0' : 'left-0'; return (
{isOpen && ( )}
); }