@hashicorp/design-system-components
Version:
Helios Design System Components
91 lines (90 loc) • 4.26 kB
TypeScript
/**
* Copyright IBM Corp. 2021, 2025
* SPDX-License-Identifier: MPL-2.0
*/
import Component from '@glimmer/component';
import type { WithBoundArgs } from '@glint/template';
import type Owner from '@ember/owner';
import { HdsTableDensityValues, HdsTableThSortOrderValues, HdsTableVerticalAlignmentValues } from './types.ts';
import HdsTableTr from './tr';
import HdsTableTh from './th';
import HdsTableThSort from './th-sort';
import HdsTableTd from './td';
import type { HdsTableColumn, HdsTableDensities, HdsTableHorizontalAlignment, HdsTableOnSelectionChangeSignature, HdsTableSortingFunction, HdsTableThSortOrder, HdsTableVerticalAlignment, HdsTableModel } from './types.ts';
import type { HdsFormCheckboxBaseSignature } from '../form/checkbox/base';
import type HdsIntlService from '../../../services/hds-intl.ts';
export declare const DENSITIES: HdsTableDensities[];
export declare const DEFAULT_DENSITY = HdsTableDensityValues.Medium;
export declare const VALIGNMENTS: HdsTableVerticalAlignment[];
export declare const DEFAULT_VALIGN = HdsTableVerticalAlignmentValues.Top;
export interface HdsTableSignature<T = HdsTableModel> {
Args: {
align?: HdsTableHorizontalAlignment;
caption?: string;
columns?: HdsTableColumn[];
density?: HdsTableDensities;
identityKey?: string;
isFixedLayout?: boolean;
isSelectable?: boolean;
isStriped?: boolean;
model?: T[];
onSelectionChange?: (selection: HdsTableOnSelectionChangeSignature) => void;
onSort?: (sortBy: string, sortOrder: HdsTableThSortOrder) => void;
selectionAriaLabelSuffix?: string;
sortBy?: string;
selectableColumnKey?: string;
sortedMessageText?: string;
sortOrder?: HdsTableThSortOrder;
valign?: HdsTableVerticalAlignment;
};
Blocks: {
head?: [
{
Tr?: WithBoundArgs<typeof HdsTableTr, 'selectionScope' | 'isSelectable' | 'onSelectionChange' | 'didInsert' | 'willDestroy' | 'selectionAriaLabelSuffix' | 'onClickSortBySelected' | 'sortBySelectedOrder'>;
Th?: typeof HdsTableTh;
ThSort?: typeof HdsTableThSort;
sortBy?: string;
sortOrder?: HdsTableThSortOrder;
setSortBy?: (column: string) => void;
}
];
body?: [
{
Td?: WithBoundArgs<typeof HdsTableTd, 'align'>;
Tr?: WithBoundArgs<typeof HdsTableTr, 'selectionScope' | 'isSelectable' | 'onSelectionChange' | 'didInsert' | 'willDestroy' | 'selectionAriaLabelSuffix'>;
Th?: WithBoundArgs<typeof HdsTableTh, 'scope'>;
data?: T;
rowIndex?: number;
sortBy?: string;
sortOrder?: HdsTableThSortOrder;
}
];
};
Element: HTMLTableElement;
}
export default class HdsTable<T = HdsTableModel> extends Component<HdsTableSignature<T>> {
readonly hdsIntl: HdsIntlService;
sortBy: string | undefined;
sortOrder: "desc" | "asc" | HdsTableThSortOrderValues;
private _selectAllCheckbox?;
private _selectableRows;
private _isSelectAllCheckboxSelected?;
constructor(owner: Owner, args: HdsTableSignature<T>['Args']);
get getSortCriteria(): string | HdsTableSortingFunction<unknown>;
get identityKey(): string | undefined;
get sortedMessageText(): string;
get isStriped(): boolean;
get isFixedLayout(): boolean;
get density(): HdsTableDensities;
get valign(): HdsTableVerticalAlignment;
get classNames(): string;
setSortBy: (column: string) => void;
onSelectionChangeCallback: (checkbox?: HdsFormCheckboxBaseSignature["Element"], selectionKey?: string) => void;
onSelectionAllChange: () => void;
onSelectionRowChange: (checkbox?: HdsFormCheckboxBaseSignature["Element"], selectionKey?: string) => void;
didInsertSelectAllCheckbox: (checkbox: HdsFormCheckboxBaseSignature["Element"]) => void;
willDestroySelectAllCheckbox: () => void;
didInsertRowCheckbox: (checkbox: HdsFormCheckboxBaseSignature["Element"], selectionKey?: string) => void;
willDestroyRowCheckbox: (selectionKey?: string) => void;
setSelectAllState: () => void;
}