diff --git a/docs/components/table.md b/docs/components/table.md index be648130..5a34182d 100644 --- a/docs/components/table.md +++ b/docs/components/table.md @@ -60,7 +60,7 @@ const options = useTable({ ## Usage -Import `` component and `useTable` composable. Create table object with `useTable` composable and pass it to the `:options` props of the `STable` component. Here is the relatively simple table definitions. +Import `` component and `useTable` composable. Create a table object with `useTable` composable and pass it to the `:options` props of the `STable` component. Here are the relatively simple table definitions. ```vue + + + + diff --git a/lib/composables/Table.ts b/lib/composables/Table.ts index bc667d4e..ed39f9cb 100644 --- a/lib/composables/Table.ts +++ b/lib/composables/Table.ts @@ -49,6 +49,7 @@ export type TableColumnCellFn = (value: V, record: R) => TableCell export type TableCell = | TableCellText + | TableCellNumber | TableCellDay | TableCellPill | TableCellPills @@ -60,6 +61,7 @@ export type TableCell = export type TableCellType = | 'text' + | 'number' | 'day' | 'pill' | 'pills' @@ -78,12 +80,23 @@ export interface TableCellText extends TableCellBase { icon?: any value?: string | null | ((value: any, record: any) => string | null) link?(value: any, record: any): string - color?: TableCellTextColor | ((value: any, record: any) => TableCellTextColor) - iconColor?: TableCellTextColor | ((value: any, record: any) => TableCellTextColor) + color?: TableCellValueColor | ((value: any, record: any) => TableCellValueColor) + iconColor?: TableCellValueColor | ((value: any, record: any) => TableCellValueColor) onClick?(value: any, record: any): void } -export type TableCellTextColor = +export interface TableCellNumber extends TableCellBase { + type: 'number' + icon?: any + value?: number | null + separator?: boolean + link?: string | null + color?: TableCellValueColor + iconColor?: TableCellValueColor + onClick?(value: any, record: any): void +} + +export type TableCellValueColor = | 'neutral' | 'soft' | 'mute' diff --git a/stories/components/STable.01_Playground.story.vue b/stories/components/STable.01_Playground.story.vue index 14ad5368..a26241b2 100644 --- a/stories/components/STable.01_Playground.story.vue +++ b/stories/components/STable.01_Playground.story.vue @@ -74,6 +74,16 @@ const dropdownType = createDropdown([ } ]) +const dropdownWidth = createDropdown([ + { + type: 'menu', + options: [ + { label: 'Sort ascending (A...Z)', onClick: () => updateSort('width', 'asc') }, + { label: 'Sort descending (Z...A)', onClick: () => updateSort('width', 'desc') } + ] + } +]) + const dropdownTagsSelected = ref([]) const dropdownTags = createDropdown([ @@ -113,6 +123,7 @@ const data = [ link: 'https://example.com', status: 'Published', type: 'Photo', + width: 1280, createdAt: '2022-10-10', tags: ['Info', 'News', 'Latest'] }, @@ -121,6 +132,7 @@ const data = [ link: 'https://example.com', status: 'Draft', type: 'Icon', + width: 1280, createdAt: '2022-10-09', tags: ['Info'] }, @@ -129,6 +141,7 @@ const data = [ link: 'https://example.com', status: 'Published', type: 'Photo', + width: 1920, createdAt: '2022-10-02', tags: ['Info', 'News'] }, @@ -137,6 +150,7 @@ const data = [ link: 'https://example.com', status: 'Published', type: 'Illustration', + width: 768, createdAt: '2022-09-12', tags: ['Info', 'News'] }, @@ -145,6 +159,7 @@ const data = [ link: 'https://example.com', status: 'Archived', type: 'Other', + width: 512, createdAt: '2022-09-08', tags: ['Info'] } @@ -162,7 +177,14 @@ const orderedData = computed(() => { }) const table = useTable({ - orders: ['name', 'status', 'type', 'tags', 'createdAt'], + orders: [ + 'name', + 'status', + 'type', + 'width', + 'tags', + 'createdAt' + ], columns: { name: { @@ -194,6 +216,15 @@ const table = useTable({ cell: { type: 'text', color: 'soft' } }, + width: { + label: 'Width', + dropdown: dropdownWidth, + cell: { + type: 'number', + separator: true + } + }, + createdAt: { label: 'Created at', dropdown: dropdownCreatedAt, @@ -267,7 +298,8 @@ function updateTagsFilter(value: string) {