/** * External dependencies */ import type { ReactNode } from 'react'; /** * WordPress dependencies */ import { __, sprintf } from '@wordpress/i18n'; import { useState } from '@wordpress/element'; import { info } from '@wordpress/icons'; import { Button, Modal, ToggleControl, __experimentalHeading as Heading, } from '@wordpress/components'; import { Stack, Text } from '@wordpress/ui'; type ItemHelpProps = { title: string; description?: ReactNode; // `readonly` lets callers pass `as const` arrays so their option values keep // their literal types instead of widening to `string`. items?: readonly { label: string; value: string | number | boolean; image?: string; isDefault?: boolean; title?: string; description?: string; }[]; colCount?: string | number; isToggle?: boolean; defaultToggle?: boolean; image?: string; value?: string | number | boolean; // `any` lets callers pass boolean/number/string handlers without // contravariance errors; the component only forwards an item's `value`. onChange?: ( value: any ) => void; }; export default function ItemHelp( { title, description, items = [], colCount = 2, isToggle, defaultToggle, image, value, onChange, }: ItemHelpProps ) { const [ isModalOpen, setIsModalOpen ] = useState( false ); return ( <> { isModalOpen && ( setIsModalOpen( false ) } > { description && ( :

} className="chbe-admin-editor-config-item-help-modal__decription" gap="sm" > { description } ) } { isToggle && ( }> { defaultToggle ? __( 'Defaults to enable.', 'custom-html-block-extension' ) : __( 'Defaults to disable.', 'custom-html-block-extension' ) } ) } { items.length > 0 && (

{ items.map( ( item, index ) => ( { item.isDefault ? sprintf( /* translators: %s is replaced with the setting label. */ __( '%s (Default)', 'custom-html-block-extension' ), item.label ) : item.label } { item.description && }>{ item.description } } ) ) }
) } { image && ( { ) } { isToggle && ( { onChange?.( newValue ); setIsModalOpen( false ); } } label={ title } /> ) }
) }