import type { Updater } from '@tanstack/react-table'; import type { FocusEvent as ReactFocusEvent, KeyboardEvent as ReactKeyboardEvent, MouseEvent as ReactMouseEvent } from 'react'; import type { DataTableRowData } from '../../row-data-types.js'; /** * Event that caused a row to become active (e.g. mouse click). * @public */ export type DataTableRowActivationEvent = ReactMouseEvent | ReactKeyboardEvent | ReactFocusEvent; /** * @public */ export interface DataTableRowInteractivityBaseProps { /** * Enables row interactivity. * * @defaultValue false */ interactiveRows?: boolean | { /** * The `autoActivate` setting controls whether a focused row immediately activates it, * making stepping through interactive rows with a keyboard more accessible. * @defaultValue true */ autoActivate?: boolean; /** * Defines a link for an interactive row, enabling navigation to another view or page. * @deprecated Please use onActiveRowChange instead. */ link?: (row: TData) => string; }; /** * Callback triggered when active row is changed. * @param activeRow - the active row's ID. * @param event - the event that caused a row to become active. */ onActiveRowChange?: (activeRow: string | null, event?: DataTableRowActivationEvent) => void; } /** * @public */ export interface DataTableRowInteractivityControlledProps extends DataTableRowInteractivityBaseProps { /** * Lets you control the active row. **/ activeRow?: string | null; defaultActiveRow?: never; } /** * @public */ export interface DataTableRowInteractivityUncontrolledProps extends DataTableRowInteractivityBaseProps { /** * Lets you set the initially active row. **/ defaultActiveRow?: string | null; activeRow?: never; } /** * Options for DataTable row interactivity. * @public */ export type DataTableRowInteractivityProps = DataTableRowInteractivityControlledProps | DataTableRowInteractivityUncontrolledProps; /** * Extension interface for the table options * @internal */ export interface DataTableRowInteractivityOptions { enableRowInteractivity?: boolean; onActiveRowChange?: (updater: Updater, event?: DataTableRowActivationEvent) => void; enableAutoActivation?: boolean; getLinkForRow?: (row: TRow) => string | undefined; } /** * Extension interface for the table state * @internal */ export interface DataTableRowInteractivityState { activeRow?: string | null; } /** * @internal */ export interface DataTableRowInteractivityInstance { /** * Updates the active row state of the table via an update function or value. */ setActiveRow: (updater: Updater, event?: DataTableRowActivationEvent) => void; /** * Updates the currently hovered row. */ setHoveredRow: (rowId: string | null) => void; /** * Gets the currently hovered row. */ getHoveredRow: () => string | null; /** * Handles mouse over events for interactive rows. */ handleInteractiveRowMouseOver: (event: ReactMouseEvent) => void; /** * Handles mouse leave events for interactive rows. */ handleInteractiveRowMouseLeave: (event: ReactMouseEvent) => void; /** * Handles click events for interactive rows. */ handleInteractiveRowClick: (event: ReactMouseEvent) => void; } /** * Extension interface to extend the types of the `Row` from the tanstack table. * @internal */ export interface DataTableRowInteractivityRow { /** * Returns a boolean value if the row can be activated. */ getCanActivateRow: () => boolean; /** * Returns a boolean value if the row is currently activated. */ getIsActivated: () => boolean; /** * Activates the row, if it is not activated. * Deactivates the row, if it is currently activated. */ toggleActivated: (event?: DataTableRowActivationEvent) => void; /** * Returns the link for a given row if available. */ getLinkForRow: () => string | undefined; }