@grafana/ui
Version:
Grafana Components Library
47 lines (46 loc) • 2.03 kB
TypeScript
import { type CSSProperties, type JSX } from 'react';
import * as React from 'react';
import { type ActionModel, type LinkModel } from '@grafana/data';
import { type OpenMenuTrigger } from '../ContextMenu/WithContextMenu';
export interface DataLinksContextMenuProps {
children: (props: DataLinksContextMenuApi) => JSX.Element;
links: () => LinkModel[];
style?: CSSProperties;
/**
* @deprecated Will be removed in a future version
*/
actions?: ActionModel[];
}
/**
* Props consumers spread on the focusable element that opens the data-links menu.
* Intentionally `Partial<...>` of the underlying handler types so the props can
* be applied to either an HTML element (`<button>`) or an SVG element (`<g>`,
* `<a>`) without TS gymnastics on the consumer side.
*
* Use these for the multi-link case to get keyboard accessibility (Enter/Space
* to open the menu) and the correct ARIA semantics for free.
*/
export interface DataLinksMenuTriggerProps {
role: 'button';
tabIndex: 0;
'aria-haspopup': 'menu';
onClick: (event: React.MouseEvent<Element>) => void;
onKeyDown: (event: React.KeyboardEvent<Element>) => void;
}
export interface DataLinksContextMenuApi {
/**
* Opens the menu, anchored to either a pointer event, an `Element`, or an
* explicit `{x, y}`. Most consumers should prefer spreading `triggerProps`
* onto a focusable element instead of wiring `openMenu` manually.
*/
openMenu?: (trigger: OpenMenuTrigger) => void;
targetClassName?: string;
/**
* Spread onto the focusable trigger element to make the menu keyboard- and
* screen-reader-accessible (Enter/Space to open, `role="button"`,
* `aria-haspopup="menu"`). Only present when the menu has more than one
* link — for a single link the component renders a real `<a>` itself.
*/
triggerProps?: DataLinksMenuTriggerProps;
}
export declare const DataLinksContextMenu: ({ children, links, style }: DataLinksContextMenuProps) => JSX.Element;