mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
* feat(code-snippet): add copy functionality - docs: add custom feedback copy text example * feat(tile): support disabled state for SelectableTile, RadioTile Closes #539 * build(rollup): add clipboard-copy to globals * feat(copy-button): add copy functionality * feat(content-switcher): deprecate the light prop - docs: remove the light variant example * fix(toolbar-search): remove outer div * feat(search): add searchClass prop * fix(composed-modal): set hasScrollingContent class on ModalBody * docs(data-table): add expandable size examples * feat(tooltip): add TooltipFooter component * fix(time-picker): correctly display invalidText * feat(breadcrumb): support overflow menu * feat(multi-select): export inputRef prop * chore(deps-dev): upgrade carbon-components to v10.32.0 * feat(form): add noMargin prop to FormGroup * docs(tooltip): document TooltipFooter * feat(context-menu): support danger kind for ContextMenuOption * feat(data-table): support rendering empty table header in skeleton * refactor(types): use shorter import path in DataTableSkeleton * feat(data-table): allow sorting to be disabled for a specific header * docs(data-table): update example to desort the Protocol header As an example, it makes more sense because all the values ("http") are the same. * fix(context-menu): set initial y offset of context menu based on window height #577 * fix(context-menu): render submenu based on viewport constraints #577
161 lines
3.5 KiB
TypeScript
161 lines
3.5 KiB
TypeScript
/// <reference types="svelte" />
|
|
import { SvelteComponentTyped } from "svelte";
|
|
|
|
export type DataTableKey = string;
|
|
|
|
export type DataTableValue = any;
|
|
|
|
export interface DataTableEmptyHeader {
|
|
key: DataTableKey;
|
|
empty: boolean;
|
|
display?: (item: Value) => DataTableValue;
|
|
sort?: false | ((a: DataTableValue, b: DataTableValue) => 0 | -1 | 1);
|
|
columnMenu?: boolean;
|
|
}
|
|
|
|
export interface DataTableNonEmptyHeader {
|
|
key: DataTableKey;
|
|
value: DataTableValue;
|
|
display?: (item: Value) => DataTableValue;
|
|
sort?: false | ((a: DataTableValue, b: DataTableValue) => 0 | -1 | 1);
|
|
columnMenu?: boolean;
|
|
}
|
|
|
|
export type DataTableHeader = DataTableNonEmptyHeader | DataTableEmptyHeader;
|
|
|
|
export interface DataTableRow {
|
|
id: any;
|
|
[key: string]: DataTableValue;
|
|
}
|
|
|
|
export type DataTableRowId = string;
|
|
|
|
export interface DataTableCell {
|
|
key: DataTableKey;
|
|
value: DataTableValue;
|
|
}
|
|
|
|
export interface DataTableProps
|
|
extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["div"]> {
|
|
/**
|
|
* Specify the data table headers
|
|
* @default []
|
|
*/
|
|
headers?: DataTableHeader[];
|
|
|
|
/**
|
|
* Specify the rows the data table should render
|
|
* keys defined in `headers` are used for the row ids
|
|
* @default []
|
|
*/
|
|
rows?: DataTableRow[];
|
|
|
|
/**
|
|
* Set the size of the data table
|
|
*/
|
|
size?: "compact" | "short" | "tall";
|
|
|
|
/**
|
|
* Specify the title of the data table
|
|
* @default ""
|
|
*/
|
|
title?: string;
|
|
|
|
/**
|
|
* Specify the description of the data table
|
|
* @default ""
|
|
*/
|
|
description?: string;
|
|
|
|
/**
|
|
* Set to `true` to use zebra styles
|
|
* @default false
|
|
*/
|
|
zebra?: boolean;
|
|
|
|
/**
|
|
* Set to `true` for the sortable variant
|
|
* @default false
|
|
*/
|
|
sortable?: boolean;
|
|
|
|
/**
|
|
* Set to `true` for the expandable variant
|
|
* Automatically set to `true` if `batchExpansion` is `true`
|
|
* @default false
|
|
*/
|
|
expandable?: boolean;
|
|
|
|
/**
|
|
* Set to `true` to enable batch expansion
|
|
* @default false
|
|
*/
|
|
batchExpansion?: boolean;
|
|
|
|
/**
|
|
* Specify the row ids to be expanded
|
|
* @default []
|
|
*/
|
|
expandedRowIds?: DataTableRowId[];
|
|
|
|
/**
|
|
* Set to `true` for the radio selection variant
|
|
* @default false
|
|
*/
|
|
radio?: boolean;
|
|
|
|
/**
|
|
* Set to `true` for the selectable variant
|
|
* Automatically set to `true` if `radio` or `batchSelection` are `true`
|
|
* @default false
|
|
*/
|
|
selectable?: boolean;
|
|
|
|
/**
|
|
* Set to `true` to enable batch selection
|
|
* @default false
|
|
*/
|
|
batchSelection?: boolean;
|
|
|
|
/**
|
|
* Specify the row ids to be selected
|
|
* @default []
|
|
*/
|
|
selectedRowIds?: DataTableRowId[];
|
|
|
|
/**
|
|
* Set to `true` to enable a sticky header
|
|
* @default false
|
|
*/
|
|
stickyHeader?: boolean;
|
|
}
|
|
|
|
export default class DataTable extends SvelteComponentTyped<
|
|
DataTableProps,
|
|
{
|
|
click: CustomEvent<{
|
|
header?: DataTableHeader;
|
|
row?: DataTableRow;
|
|
cell?: DataTableCell;
|
|
}>;
|
|
["click:header--expand"]: CustomEvent<{ expanded: boolean }>;
|
|
["click:header"]: CustomEvent<{
|
|
header: DataTableHeader;
|
|
sortDirection?: "ascending" | "descending" | "none";
|
|
}>;
|
|
["click:row"]: CustomEvent<DataTableRow>;
|
|
["mouseenter:row"]: CustomEvent<DataTableRow>;
|
|
["mouseleave:row"]: CustomEvent<DataTableRow>;
|
|
["click:row--expand"]: CustomEvent<{
|
|
expanded: boolean;
|
|
row: DataTableRow;
|
|
}>;
|
|
["click:cell"]: CustomEvent<DataTableCell>;
|
|
},
|
|
{
|
|
default: {};
|
|
cell: { row: DataTableRow; cell: DataTableCell };
|
|
["cell-header"]: { header: DataTableNonEmptyHeader };
|
|
["expanded-row"]: { row: DataTableRow };
|
|
}
|
|
> {}
|