import clsx from 'clsx'; import { forwardRef } from '@wordpress/element'; import styles from './style.module.scss'; import type { ItemDescriptionProps } from './types'; import { Text } from '../text'; const ITEM_DESCRIPTION_DIRECT_CHILD = Symbol(); type InternalItemDescriptionProps = ItemDescriptionProps & { validationToken?: typeof ITEM_DESCRIPTION_DIRECT_CHILD; }; /** * Adds supporting text below a menu item label. Use it as a direct child * after `Menu.ItemLabel`. * * Keep labels clear on their own. Add a brief description only for essential * context the label cannot convey. Avoid combining a description and a prefix * icon in the same item. */ const ItemDescription = forwardRef< HTMLSpanElement, ItemDescriptionProps >( function MenuItemDescription( props, ref ) { const { className, id, validationToken, ...restProps } = props as InternalItemDescriptionProps; if ( process.env.NODE_ENV !== 'production' && validationToken !== ITEM_DESCRIPTION_DIRECT_CHILD ) { throw new Error( 'Menu.ItemDescription: Missing direct menu item parent. Render as a direct child of a menu item.' ); } return ( ); } ); export { ITEM_DESCRIPTION_DIRECT_CHILD, ItemDescription };