import { type Component, type MaybeRef, type MaybeRefOrGetter } from 'vue' import { type Mode as ButtonMode } from '../components/SButton.vue' import { type State as IndicatorState } from '../components/SIndicator.vue' import { type ColorMode } from '../support/Color' import { type Day } from '../support/Day' import { type Align } from '../support/InputText' import { type DropdownSection } from './Dropdown' import { type Position } from './Tooltip' export interface Table< O extends string = string, R extends Record = any, SR extends Record = any > { records?: MaybeRef orders: MaybeRef columns: MaybeRef> summary?: MaybeRef indexField?: keyof R loading?: MaybeRef rowSize?: MaybeRef borderless?: MaybeRef disableSelection?: (record: R) => boolean menu?: MaybeRef header?: MaybeRef footer?: MaybeRef total?: MaybeRef page?: MaybeRef perPage?: MaybeRef borderSize?: MaybeRef onPrev?(): void onNext?(): void } export type TableColumns< O extends string, R extends Record, SR extends Record > = { [K in O]: TableColumn } export interface TableColumn { label?: string className?: string dropdown?: DropdownSection[] freeze?: boolean width?: string grow?: boolean resizable?: boolean cell?: TableCell | TableColumnCellFn summaryCell?: TableCell | TableColumnCellFn show?: MaybeRefOrGetter } export type TableColumnCellFn = (value: V, record: R) => TableCell export type TableCell = | TableCellText | TableCellNumber | TableCellPath | TableCellDay | TableCellPill | TableCellPills | TableCellState | TableCellIndicator | TableCellAvatar | TableCellAvatars | TableCellCustom | TableCellEmpty | TableCellComponent | TableCellActions export type TableCellType = | 'text' | 'number' | 'path' | 'day' | 'pill' | 'pills' | 'state' | 'indicator' | 'avatar' | 'avatars' | 'custom' | 'empty' | 'component' | 'actions' export interface TableCellBase { type: TableCellType } export interface TableCellText extends TableCellBase { type: 'text' align?: Align icon?: Component value?: string | null link?: string | null color?: TableCellValueColor iconColor?: TableCellValueColor onClick?(value: V, record: R): void } export interface TableCellNumber extends TableCellBase { type: 'number' align?: Align icon?: Component value?: number | null separator?: boolean /** * Caps the displayed fractional digits using * `Intl.NumberFormat`-style "maximum fractional digits" semantics. * `null` / `undefined` shows the value as-is (no rounding). */ maximumFractionDigits?: number | null link?: string | null color?: TableCellValueColor iconColor?: TableCellValueColor onClick?(value: V, record: R): void } export interface TableCellPath extends TableCellBase { type: 'path' segments: TableCellPathSegment[] } export interface TableCellPathSegment { text: string link?: string | null color?: TableCellValueColor onClick?(): void } export type TableCellValueColor = ColorMode | 'soft' export interface TableCellDay extends TableCellBase { type: 'day' align?: Align value?: Day | null format?: string color?: 'neutral' | 'soft' | 'mute' } export interface TableCellPill extends TableCellBase { type: 'pill' value?: string color?: TableCellPillColor } export type TableCellPillColor = ColorMode export interface TableCellPills extends TableCellBase { type: 'pills' pills: TableCellPillItem[] } export interface TableCellPillItem { label: string color?: TableCellPillColor } export interface TableCellAvatar extends TableCellBase { type: 'avatar' image?: string | null name?: string | null link?: string | null color?: 'neutral' | 'soft' | 'mute' onClick?(value: V, record: R): void } export interface TableCellAvatars extends TableCellBase { type: 'avatars' avatars: TableCellAvatarsOption[] color?: 'neutral' | 'soft' | 'mute' avatarCount?: number nameCount?: number tooltip?: boolean | { position?: Position } } export interface TableCellAvatarsOption { image?: string | null name?: string | null } export interface TableCellCustom extends TableCellBase { type: 'custom' } export interface TableCellEmpty extends TableCellBase { type: 'empty' } export interface TableCellComponent extends TableCellBase { type: 'component' component: Component props?: Record } export interface TableCellState extends TableCellBase { type: 'state' label: string mode?: ColorMode } export interface TableCellIndicator extends TableCellBase { type: 'indicator' state: IndicatorState label?: string | null } export interface TableCellActions extends TableCellBase { type: 'actions' actions: TableCellAction[] } export interface TableCellAction { mode?: ButtonMode icon?: Component iconMode?: ButtonMode label?: string labelMode?: ButtonMode onClick(record: R): void show?(record: R): boolean } export interface TableMenu { label: string state?: 'inactive' | 'active' | 'indicate' dropdown: DropdownSection[] } export interface TableHeaderAction { show?: boolean mode?: ButtonMode label: string labelMode?: ButtonMode onClick(): void } export function useTable< O extends string, R extends Record, SR extends Record >(options: Table): Table { return options }