/* eslint-disable @typescript-eslint/no-explicit-any */ export type DeviceBreakpoint = "sm" | "md" | "lg" | "xl"; /** * A means of specifying width by breakpoints. * * By default breakpoints are defined as `sm`, `md`, `lg`, and `xl` but you can * pass in your own breakpoint system if this doesn't fit. * * Specifying a breakpoint as `false` means that it should be _hidden_ at this breakpoint. */ export type IColumnWidthByBreakpoint = Record< T, string | number | false >; /** * Specifying a singular number or string provides a consistent width * (and visibility) across all breakpoints. */ export type IColumnWidth = string | number; /** * Defines a _column_ in a `` */ export interface ITableColumn { /** unique identifier for the column */ id: string | number; /** a human friendly, short name of column */ name: string; /** * tailwind classes can be added to a column and will be applied to * both _header_ and _body_ aspects of this column. */ style: string; /** alignment of text in body (and header) elements */ align: "left" | "right" | "center"; /** alignment of text in header elements; overrides "align" if different */ halign: "left" | "right" | "center"; /** * Allows specifying the width of the given column. * * Using **numeric** values will map to the associated tailwind class. This is the * preferred method but you must ensure that the if you specify `{sm: 64}` that * your tailwind configuration exports a `w-64` class. * * Using **string** values will map directly onto the _style_ of the component and * while this is fine it less styling flexibility than the utility class approach you * get with */ width?: IColumnWidth | IColumnWidthByBreakpoint; /** * Allows consumer of this component to state that the column should be seen as * a _candidate_ for sorting */ sortable?: boolean; } /** * A Row/Record in `` component */ export type ITableRow< T extends Record & { id: string | number } = Record< string, unknown > & { id: string | number; } > = T; /** * Expresses the constraints of a _fluent API_, which are: * * 1. a dictionary of functions (aka, the API), and * 2. which return the same API * * > **Note:** _in order for this type of fluent API to maintain state it should * > wrapped by a `Configuration` type which passes in a accumulator._ */ export type FluentApi = Record T>; export type Configurator = ( c: (api: TFluentApi) => TFluentApi ) => TConfig; /** * A higher order function which establishes an _accumulator_ (aka, localized state) * and then returns a Fluent API which allows a user to use the API to set state. * * Note: _this is typically used inside of a `Configurator` or similarly typed structure_ */ export type FluentAccumulator, TConfig> = ( accumulator: TConfig ) => TApi; export interface ITableClickBase { event: Event; // area: 'header' | 'body' | 'summary' | 'pagination'; // row?: ITableRow; // column?: ITableColumn; } export interface ITableClickBody extends ITableClickBase { area: "body"; row: ITableRow; column: ITableColumn; } export interface ITableClickHeader extends ITableClickBase { area: "header"; column: ITableColumn; } export interface ITableClickSummary extends ITableClickBase { area: "summary"; column: ITableColumn; } export type ITableClick = ITableClickBody | ITableClickHeader | ITableClickSummary; export type ISummaryBuiltIns = "avg" | "mean" | "max" | "min"; /** * A dictionary where keys are the columns which should * have a `summary` property calculated. * * The value of each name/value pair is often a callback or a reference to a * standard statistical function (avg, mean, max, min); in these cases the callback * -- both user provided or built in -- will receive an array values from that * column and calculate a summary value. If this approach is taken there is no * strict need for the user to define the _summary slot_ but if you want to * for formatting reasons then you can. * * Alternatively, you can simply add a `true` value and at this point you will be * required to pass in the _slot_ for that columns summary. * * Summary slots are named in pascalCase in the form of: `summary[Column Name]`. */ export type ITableColumnSummary = Record< string, ((data: unknown[]) => any) | true | ISummaryBuiltIns >;