@payfit/unity-components
Version:
62 lines (61 loc) • 3.08 kB
TypeScript
import { default as React, ReactNode } from 'react';
import { MenuItemProps as MenuItemAriaComponentProps } from 'react-aria-components/Menu';
import { DataAttributes } from '../../../types/DataAttributes.js';
export interface MenuItemProps extends DataAttributes {
/** The visible label or a React Aria render function for the item. */
children?: MenuItemAriaComponentProps['children'];
/** Identifies the item in a collection or selection model. */
id?: MenuItemAriaComponentProps['id'];
/** Supplies the accessible text value and the browser title for truncated labels. */
textValue?: MenuItemAriaComponentProps['textValue'];
/** Truncates a string label to one line when it exceeds the available width. */
isTruncated?: boolean;
/** Turns the item into a navigation link. */
href?: MenuItemAriaComponentProps['href'];
target?: MenuItemAriaComponentProps['target'];
rel?: MenuItemAriaComponentProps['rel'];
/** Runs when the user activates the item. */
onAction?: MenuItemAriaComponentProps['onAction'];
/** Disables activation and removes the item from keyboard interaction. */
isDisabled?: MenuItemAriaComponentProps['isDisabled'];
/** Renders a fixed-size visual slot before the item content. */
prefix?: ReactNode;
/** Adds classes to the item root. */
className?: string;
/** Renders trailing content, such as a Unity `Badge`. */
suffix?: ReactNode;
}
/**
* Renders one action or link in a keyboard-navigable Unity menu.
*
* Compose `RawMenuItem` inside `MenuContent` for standard menu actions. Use
* `prefix` for a leading icon and `suffix` for trailing content such as a
* badge. When the item opens a `MenuSubmenu`, Unity appends the submenu caret
* after the suffix.
* @param props - Item label, action, link, and optional visual slots.
* @param props.children - The visible label or a React Aria render function.
* @param props.prefix - A leading icon or custom React node.
* @param props.suffix - A trailing badge or custom React node.
* @param props.textValue - The full accessible text and browser title for a truncated label.
* @param props.isTruncated - Truncates a string label within the available item width and uses `textValue` as its browser title.
* @see {@link MenuItemProps} for all available props.
* @see {@link MenuSubmenu} for nested menu actions.
* @example
* ```tsx
* import { Badge, MenuContent, RawMenuItem } from '@payfit/unity-components'
*
* <MenuContent>
* <RawMenuItem suffix={<Badge variant="success">New</Badge>}>
* Import
* </RawMenuItem>
* </MenuContent>
* ```
* @remarks
* Set `isTruncated` to truncate a string label within the available item width.
* The native `title` attribute is taken directly from `textValue`, so provide
* the complete label there when the visual children are truncated or do not
* expose a plain text label to React Aria.
*/
export declare const RawMenuItem: React.ForwardRefExoticComponent<MenuItemProps & {
children?: ReactNode | undefined;
} & React.RefAttributes<HTMLDivElement>>;