import type { DataTableRowData } from '../../row-data-types.js'; /** * Threshold configuration that can be applied to highlight something matching the id. * @public */ export type DataTableThresholdRule = { comparator: 'greater-than' | 'less-than' | 'greater-than-or-equal-to' | 'less-than-or-equal-to' | 'equal-to' | 'not-equal-to'; value: number; /** Accessor string or function to pick the value from the rowData that should be compared against. */ accessor?: string | ((row: TData) => number); } | { /** The operator being used to compare the object value with the threshold value. */ comparator: 'equal-to' | 'not-equal-to'; /** The threshold value to compare the object value to. */ value: string; /** Accessor string or function to pick the value from the rowData that should be compared against. */ accessor?: string | ((row: TData) => string); } | { /** Custom comparator function that is called with the row data. */ comparator: (rowData: TData) => boolean; }; /** * Threshold configuration to highlight something matching the id. * @public */ export type DataTableSingleColumnThreshold = DataTableThresholdRule & { rules?: never; color?: string; backgroundColor?: string; }; /** * Threshold configuration to highlight something matching the id. * @public */ export type DataTableCombinedColumnThresholds = { rules: DataTableThresholdRule[]; color?: string; backgroundColor?: string; }; /** * Threshold configuration that can be applied to highlight something matching the id. * @public */ export type DataTableColumnThreshold = DataTableSingleColumnThreshold | DataTableCombinedColumnThresholds; /** * Threshold configuration to highlight something matching the id. * @public */ export type DataTableSingleRowThreshold = DataTableThresholdRule & { rules?: never; } & ({ type: 'pill'; color: string; } | { type: 'highlight'; backgroundColor?: string; color?: string; }); /** * Threshold configuration to highlight something matching the id. * @public */ export type DataTableCombinedRowThresholds = { rules: DataTableThresholdRule[]; } & ({ type: 'pill'; color: string; } | { type: 'highlight'; backgroundColor?: string; color?: string; }); /** * Threshold configuration that can be applied to highlight something matching the id. * @public */ export type DataTableRowThreshold = DataTableSingleRowThreshold | DataTableCombinedRowThresholds; /** * Extension interface to extend the tanstack table with row level thresholds . * @public */ export interface DataTableThresholdProps { /** * Configures the thresholds used for the rows highlighting. */ rowThresholds?: DataTableRowThreshold[]; } /** * Extension interface to extend the types from the tanstack table options to support row level thresholds. * @internal */ export interface DataTableRowThresholdOptions { /** * Defines if there are thresholds configured on the tables instance. */ hasThresholds?: boolean; /** * Normalized row threshold options. */ rowThresholds?: DataTableThresholdsNormalizedRule[]; } /** * Extension interface to extend the types of the columnDefinition from the tanstack table * to support column level thresholds. * @public */ export interface DataTableThresholdColumnDef { /** * Configures the thresholds used for the cell highlighting. */ thresholds?: DataTableColumnThreshold[]; } /** * Extension interface to extend the types of the `Row` from the tanstack table. * @internal */ export interface DataTableThresholdRow { /** * Get the threshold colors for the row. */ getThresholdColors: () => { color?: string; backgroundColor?: string; } | null; /** * Get the pill color for the row threshold. */ getThresholdPill: () => string | null; } /** * Extension interface to extend the types of the `Column` from the tanstack table * @internal */ export interface DataTableThresholdColumn { /** * Returns the normalized threshold rules on a column level. */ getThresholdRules: () => Array> | null; } /** * Extension interface to extend the types of the `Cell` from the tanstack table. * @internal */ export interface DataTableThresholdCell { /** * Get the threshold color and backgroundColor for the cell. */ getThresholdColors: () => { color?: string; backgroundColor?: string; }; } /** * @internal * Internal normalized threshold rules. */ export interface DataTableThresholdsNormalizedRule { /** * Text or pill color for the threshold */ color?: string; /** * Background color for the cell */ backgroundColor?: string; /** * Threshold rules array. */ rules: Array<{ /** * Accessor function that, given the rowData returns a value that can be compared against. */ accessor?: (row: TData) => unknown; /** Comparison value of a given rule. */ value?: unknown; /** Simple comparator definition or function for a threshold comparison. */ comparator: ('greater-than' | 'less-than' | 'greater-than-or-equal-to' | 'less-than-or-equal-to' | 'equal-to' | 'not-equal-to') | ((row: TData) => boolean); }>; /** * Optional part for the row highlight types. */ type?: 'pill' | 'highlight'; }