import type { TableColumn as TableColumnWSR } from '@wix/design-system'; import type { Field, KeyedItem, SortMode, SortOrder } from '@wix/bex-core'; import { CSSProperties, ReactNode } from 'react'; import type { FieldType } from '../utils/fieldTypePrefixIcons'; import type { ValidationRule } from '../state/EditableTable/types'; type TableColumnBase = Omit< TableColumnWSR, 'sortDescending' | 'sortable' | 'infoTooltipProps' | 'style' | 'titleSuffix' > & { style?: | CSSProperties | (( column: TableColumnWSR, rowData: KeyedItem, rowNum: number, ) => CSSProperties); reorderDisabled?: boolean; defaultSortOrder?: SortOrder; sortMode?: SortMode; searchable?: boolean; infoTooltipProps?: TableColumnWSR['infoTooltipProps'] & { panelContent?: ReactNode; }; mobile?: ColumnMobileConfig; /** * The field type string used to resolve a prefix icon for the column. * Cairo maps this to the appropriate icon internally. * @external */ fieldType?: FieldType; /** * Whether the field contains personally identifiable information. * @external */ isPii?: boolean; /** * only for cms. Whether this is a system-managed field. * @external */ isSystem?: boolean; /** * Whether this is the primary display field. * @external */ isPrimary?: boolean; /** * Column-level validation rules. When a `required` rule is present, a required indicator is shown in the custom columns panel. * @external */ validation?: ValidationRule[]; }; // disallow specifying `hideable` / `defaultHidden` or setting `hiddenFromCustomColumnsSelection` as false when `id` is missing interface TableColumnOptional extends TableColumnBase { id?: string; name?: string; hiddenFromCustomColumnsSelection?: undefined | true; hideable?: undefined; defaultHidden?: undefined; } // common case for custom column definition interface TableColumnCustom extends TableColumnBase { id: string; name: string; hiddenFromCustomColumnsSelection?: false; hideable?: true; defaultHidden?: boolean; } // allow `name` to be optional when `title` exists interface TableColumnCustomOptionalName extends TableColumnBase { id: string; name?: string; title: TableColumnBase['title']; hiddenFromCustomColumnsSelection?: false; hideable?: true; defaultHidden?: boolean; } // force `defaultHidden=false|undefined` when `hideable=false` interface TableColumnCustomDefaultHidden extends TableColumnBase { id: string; name?: string; title: TableColumnBase['title']; hiddenFromCustomColumnsSelection?: false; hideable: false; defaultHidden?: undefined | false; } export type CustomColumnConfig = | TableColumnOptional | TableColumnCustom | TableColumnCustomDefaultHidden | TableColumnCustomOptionalName; export interface SortableColumnConfig extends TableColumnBase { id: string; sortable: true; } export interface NotSortableColumnConfig extends TableColumnBase { id?: string; sortable?: false; } export type SortableConfig = | SortableColumnConfig | NotSortableColumnConfig; export type TableColumn = CustomColumnConfig & SortableConfig; export type ColumnMobileConfig = | { /** * Which mobile column to display in. * - 'first': Stacks vertically with other 'first' columns * - 'second': Displays as standalone second column * - undefined: Hidden on mobile */ column: 'first'; /** * Sort order within 'first' column (lower appears higher). * Only relevant when column is 'first'. * @default Infinity */ order?: number; } | { /** * Which mobile column to display in. * - 'first': Stacks vertically with other 'first' columns * - 'second': Displays as standalone second column * - undefined: Hidden on mobile */ column?: 'second'; }; export interface Column { /** * A unique identifier for the column. This value is required to enable [custom columns](./?path=/story/features-display-custom-columns--overview) or [sortable columns](./?path=/story/features-sort-sortable-columns-sortable-columns--sortable-columns). * @external */ id: string; /** * A name for the column. This value is shown in the [custom columns](./?path=/story/features-display-custom-columns--overview) dropdown. * @external */ name: string; /** * The text to be shown at the top of the column. * @external */ title: TableColumnBase['title']; /** * Hides the column from the custom column selection panel, making it always visible. Relevant for [custom columns](./?path=/story/features-display-custom-columns--overview). * @external */ hiddenFromCustomColumnsSelection?: boolean; /** * When `false`, the column is always selected and displayed. Relevant for [custom columns](./?path=/story/features-display-custom-columns--overview). */ hideable?: boolean; /** * When `true`, search matches in the column's values will be highlighted. Mark a column as searchable only if iy's data is relevant for your search. */ searchable?: boolean; /** * When `true`, disables drag and drop for the column. * @external */ reorderDisabled?: boolean; /** * When `true`, makes the column a [sortable column](./?path=/story/features-sort-sortable-columns-sortable-columns--sortable-columns). * @external */ sortable?: boolean; sortDescending?: boolean; sortMode?: SortMode; /** * Determines the default sort order for the column, either `asc` or `desc`. The column must be a [sortable column](./?path=/story/features-sort-sortable-columns-sortable-columns--sortable-columns). * @external */ defaultSortOrder?: SortOrder; /** * For [custom columns](./?path=/story/features-display-custom-columns--overview), when `true`, this property causes the column to be unchecked and thus not shown by default. This isn't relevant when `hideable` `=` `false`. * @external */ defaultHidden?: boolean; dataExtension?: { id: string; editable: boolean; isPii?: boolean }; /** The source field this column was built from; used to resolve manage actions. */ field?: Field; /** * Whether the field contains personally identifiable information. * @external */ isPii?: boolean; /** * only for cms. Whether this is a system-managed field. * @external */ isSystem?: boolean; /** * Whether this is the primary display field. * @external */ isPrimary?: boolean; /** * Column-level validation rules. When a `required` rule is present, a required indicator is shown in the custom columns panel. * @external */ validation?: ValidationRule[]; infoTooltipProps?: { content?: ReactNode; panelContent?: ReactNode; }; /** * A callback that is called for each row in the data to display the value of this row for the specified column. * @external */ render: TableColumnWSR['render']; width?: TableColumnWSR['width']; style?: TableColumnWSR['style']; /** * Mobile column configuration. Determines how this column is displayed on mobile devices. * - column: 'first' - Stacks vertically with other 'first' columns * - column: 'second' - Displays as standalone second column * - undefined - Hidden on mobile * @external */ mobile?: ColumnMobileConfig; /** * The field type string used to resolve a prefix icon for the column. * Cairo maps this to the appropriate icon internally. * @external */ fieldType?: FieldType; } // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error // @ts-ignore function _tableColumnPublicApiTest( c: TableColumn, ): Omit & Pick, 'id' | 'name'> { return c; }