/** * WordPress dependencies */ import { Panel, PanelBody, Spinner } from '@wordpress/components'; import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import { Telemetry } from '../../../js/telemetry/telemetry'; import { AiIcon } from '../../common/icons/ai-icon'; import { TitleSuggestion } from './component-title-suggestion'; import { Title, TitleType } from './store'; /** * Props for the Title Suggestions component. * * @since 3.14.0 */ type TitleSuggestionsProps = { suggestions: Title[]; isOpen: boolean; isLoading?: boolean; }; /** * Renders the Title Suggestions collapsible panel. * * @since 3.14.0 * * @param {TitleSuggestionsProps} props The component's props. */ export const TitleSuggestions = ( { suggestions, isOpen, isLoading = false, }: Readonly ): React.JSX.Element => { const [ isCollapsed, setIsCollapsed ] = useState( isOpen ); /** * Toggles the collapse state of the panel. * * @since 3.14.0 */ const toggleCollapse = () => { setIsCollapsed( ! isCollapsed ); Telemetry.trackEvent( 'title_suggestions_suggestions_toggled', { is_open: ! isCollapsed, suggestions: suggestions.length, } ); }; return ( } onToggle={ toggleCollapse } opened={ isCollapsed }>
{ isLoading && (
{ __( 'Loading…', 'wp-parsely' ) }
) } { suggestions.map( ( title ) => ( ) ) }
); };