From 9dced984f198bc13cb34cc68835b277ec794a7e7 Mon Sep 17 00:00:00 2001 From: mm <25961416+mlmoravek@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:55:52 +0200 Subject: [PATCH] feat(table): update `thAttrs` and `tdAttrs` properties (#958) --- packages/docs/components/Table.md | 138 +++++++++--------- .../src/components/pagination/Pagination.vue | 4 +- .../pagination/PaginationButton.vue | 4 +- .../__snapshots__/pagination.test.ts.snap | 4 +- packages/oruga/src/components/table/Table.vue | 29 +++- .../src/components/table/TableColumn.vue | 40 +---- .../src/components/table/examples/sticky.vue | 8 +- .../{tablecolumn.ts => tablecolumn.test.ts} | 0 8 files changed, 109 insertions(+), 118 deletions(-) rename packages/oruga/src/components/table/tests/{tablecolumn.ts => tablecolumn.test.ts} (100%) diff --git a/packages/docs/components/Table.md b/packages/docs/components/Table.md index c3421e3a7..31073cbd7 100644 --- a/packages/docs/components/Table.md +++ b/packages/docs/components/Table.md @@ -41,72 +41,74 @@ sidebarDepth: 2 ### Props -| Prop name | Description | Type | Values | Default | -| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| ariaCurrentLabel | Accessibility label for the pagination current page button. | string | - |
table: {
ariaCurrentLabel: undefined
}
|
-| ariaNextLabel | Accessibility label for the pagination next page button. | string | - | table: {
ariaNextLabel: undefined
}
|
-| ariaPageLabel | Accessibility label for the pagination page button. | string | - | table: {
ariaPageLabel: undefined
}
|
-| ariaPreviousLabel | Accessibility label for the pagination previous page button. | string | - | table: {
ariaPreviousLabel: undefined
}
|
-| backendFiltering | Columns won't be filtered with Javascript, use with `searchable` prop to the columns to filter in your backend | boolean | - | table: {
backendFiltering: false
}
|
-| backendPagination | Rows won't be paginated with Javascript, use with `page-change` event to paginate in your backend | boolean | - | false
|
-| backendSorting | Columns won't be sorted with Javascript, use with `sort` event to sort in your backend | boolean | - | table: {
backendSorting: false
}
|
-| bordered | Border to all cells | boolean | - | table: {
bordered: false
}
|
-| checkable | Rows can be checked (multiple) | boolean | - | false
|
-| checkboxPosition | Position of the checkbox when checkable (if checkable) | string | `left`, `right` | table: {
checkboxPosition: "left"
}
|
-| checkboxVariant | Color of the checkbox when checkable (if checkable) | string | `primary`, `info`, `success`, `warning`, `danger`, `and any other custom color` | table: {
checkboxVariant: undefined
}
|
-| checkedRows | Set which rows are checked, use `v-model:checkedRows` to make it two-way binding (if checkable) | T[] | - | Default function (see source code) |
-| columns | Table columns | TableColumn[] | - | Default function (see source code) |
-| currentPage | Current page of table data (if paginated), use `v-model:currentPage` to make it two-way binding | number | - | 1
|
-| customCompare | Define a custom comparison function to check whether two row elements are equal.false
|
-| data | Table data | T[] | - | Default function (see source code) |
-| debounceSearch | Filtering debounce time (in milliseconds) | number | - | table: {
debounceSearch: undefined
}
|
-| defaultSort | Sets the default sort column and order — e.g. ['first_name', 'desc'] | string \| string[] | - | table: {
defaultSort: undefined
}
|
-| defaultSortDirection | Sets the default sort column direction on the first click | string | `asc`, `desc` | table: {
defaultSortDirection: "asc"
}
|
-| detailIcon | Icon name of detail action (if detailed) | string | - | table: {
detailIcon: "chevron-right"
}
|
-| detailTransition | | string | - | table: {
detailTransition: "slide"
}
|
-| detailed | Allow row details | boolean | - | false
|
-| detailedRows | Set which rows have opened details, use `v-model:detailedRows` to make it two-way binding (if detailed).false
|
-| draggableColumn | Allows columns to be draggable | boolean | - | false
|
-| filtersEvent | Add a native event to filter | string | - | ""
|
-| filtersIcon | Icon of the column search input | string | - | table: {
filterIcon: undefined
}
|
-| filtersPlaceholder | Placeholder of the column search input | string | - | table: {
filterPlaceholder: undefined
}
|
-| headerCheckable | Show check/uncheck all checkbox in table header when checkable (if checkable) | boolean | - | true
|
-| height | Table fixed height | number\|string | - | |
-| hoverable | Rows are highlighted when hovering | boolean | - | table: {
hoverable: false
}
|
-| iconPack | Icon pack to use | string | `mdi`, `fa`, `fas and any other custom icon pack` | table: {
iconPack: undefined
}
|
-| isDetailedVisible | Controls the visibility of the trigger that toggles the detailed rows (if detailed) | (row: T) => boolean | - | table: {
isDetailedVisible: (row) => true
}
|
-| isRowCheckable | Custom method to verify if a row is checkable (if checkable) | (row: T) => boolean | - | table: {
isRowCheckable: (row) => true
}
|
-| isRowChecked | Custom method to verify if a row is checked (if checkable). Useful for backend pagination. | (row: T, data: T[]) => boolean | - | |
-| isRowSelectable | Custom method to verify if a row is selectable, works when is selectable | (row: T) => boolean | - | Default function (see source code) |
-| loading | Enable loading state | boolean | - | false
|
-| loadingIcon | Icon for the loading state | string | - | table: {
loadingIcon: "loading"
}
|
-| loadingLabel | Label for the loading state | string | - | table: {
loadingLabel: undefined
}
|
-| mobileBreakpoint | Mobile breakpoint as max-width value | string | - | table: {
mobileBreakpoint: undefined
}
|
-| mobileCards | Rows appears as cards on mobile (collapse rows) | boolean | - | table: {
mobileCards: true
}
|
-| mobileSortPlaceholder | Select placeholder text when nothing is selected (if mobileCards) | string | - | table: {
mobileSortPlaceholder: undefined
}
|
-| narrowed | Makes the cells narrower | boolean | - | table: {
narrowed: false
}
|
-| override | Override existing theme classes completely | boolean | - | |
-| paginated | Adds pagination to the table | boolean | - | table: {
paginated: false
}
|
-| paginationOrder | Pagination buttons order (if paginated) | string | `centered`, `right`, `left` | table: {
paginationOrder: undefined
}
|
-| paginationPosition | Pagination position (if paginated) | string | `bottom`, `top`, `both` | table: {
paginationPosition: "bottom"
}
|
-| paginationRounded | Enable rounded pagination buttons (if paginated) | boolean | - | table: {
paginationRounded: false
}
|
-| paginationSimple | Enable simple style pagination (if paginated) | boolean | - | table: {
paginationSimple: false
}
|
-| paginationSize | Size of pagination (if paginated) | string | `small`, `medium`, `large` | table: {
paginationSize: "small"
}
|
-| perPage | How many rows per page (if paginated) | number\|string | - | table: {
perPage: 20
}
|
-| rowKey | Use a unique key of your data Object for each row. Useful if your data prop has dynamic indices. (id recommended) | string | - | table: {
rowKey: undefined
}
|
-| scrollable | Add a horizontal scrollbar when table is too wide | boolean | - | |
-| selectable | Table can be focused and user can select rows. Rows can be navigate with keyboard arrows and are highlighted when hovering. | boolean | - | table: {
selectable: false
}
|
-| selected | Set which row is selected, use `v-model:selected` to make it two-way binding (if selectable) | T | - | |
-| showDetailIcon | Allow detail icon and column to be visible (if detailed) | boolean | - | table: {
showDetailIcon: true
}
|
-| showHeader | Show header | boolean | - | table: {
showHeader: true
}
|
-| sortIcon | Sets the header sorting icon | string | - | table: {
sortIcon: "arrow-up"
}
|
-| sortIconSize | Sets the size of the sorting icon | string | `small`, `medium`, `large` | table: {
sortIconSize: "small"
}
|
-| stickyCheckbox | Make the checkbox column sticky (if checkable) | boolean | - | false
|
-| stickyHeader | Show a sticky table header | boolean | - | false
|
-| striped | Whether table is striped | boolean | - | table: {
striped: false
}
|
-| total | Total number of table data if backend-pagination is enabled | number | - | 0
|
+| Prop name | Description | Type | Values | Default |
+| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| ariaCurrentLabel | Accessibility label for the pagination current page button. | string | - | table: {
ariaCurrentLabel: undefined
}
|
+| ariaNextLabel | Accessibility label for the pagination next page button. | string | - | table: {
ariaNextLabel: undefined
}
|
+| ariaPageLabel | Accessibility label for the pagination page button. | string | - | table: {
ariaPageLabel: undefined
}
|
+| ariaPreviousLabel | Accessibility label for the pagination previous page button. | string | - | table: {
ariaPreviousLabel: undefined
}
|
+| backendFiltering | Columns won't be filtered with Javascript, use with `searchable` prop to the columns to filter in your backend | boolean | - | table: {
backendFiltering: false
}
|
+| backendPagination | Rows won't be paginated with Javascript, use with `page-change` event to paginate in your backend | boolean | - | false
|
+| backendSorting | Columns won't be sorted with Javascript, use with `sort` event to sort in your backend | boolean | - | table: {
backendSorting: false
}
|
+| bordered | Border to all cells | boolean | - | table: {
bordered: false
}
|
+| checkable | Rows can be checked (multiple) | boolean | - | false
|
+| checkboxPosition | Position of the checkbox when checkable (if checkable) | string | `left`, `right` | table: {
checkboxPosition: "left"
}
|
+| checkboxVariant | Color of the checkbox when checkable (if checkable) | string | `primary`, `info`, `success`, `warning`, `danger`, `and any other custom color` | table: {
checkboxVariant: undefined
}
|
+| checkedRows | Set which rows are checked, use `v-model:checkedRows` to make it two-way binding (if checkable) | T[] | - | Default function (see source code) |
+| columns | Table columns | TableColumn[] | - | Default function (see source code) |
+| currentPage | Current page of table data (if paginated), use `v-model:currentPage` to make it two-way binding | number | - | 1
|
+| customCompare | Define a custom comparison function to check whether two row elements are equal.false
|
+| data | Table data | T[] | - | Default function (see source code) |
+| debounceSearch | Filtering debounce time (in milliseconds) | number | - | table: {
debounceSearch: undefined
}
|
+| defaultSort | Sets the default sort column and order — e.g. ['first_name', 'desc'] | string \| string[] | - | table: {
defaultSort: undefined
}
|
+| defaultSortDirection | Sets the default sort column direction on the first click | string | `asc`, `desc` | table: {
defaultSortDirection: "asc"
}
|
+| detailIcon | Icon name of detail action (if detailed) | string | - | table: {
detailIcon: "chevron-right"
}
|
+| detailTransition | | string | - | table: {
detailTransition: "slide"
}
|
+| detailed | Allow row details | boolean | - | false
|
+| detailedRows | Set which rows have opened details, use `v-model:detailedRows` to make it two-way binding (if detailed).false
|
+| draggableColumn | Allows columns to be draggable | boolean | - | false
|
+| filtersEvent | Add a native event to filter | string | - | ""
|
+| filtersIcon | Icon of the column search input | string | - | table: {
filterIcon: undefined
}
|
+| filtersPlaceholder | Placeholder of the column search input | string | - | table: {
filterPlaceholder: undefined
}
|
+| headerCheckable | Show check/uncheck all checkbox in table header when checkable (if checkable) | boolean | - | true
|
+| height | Table fixed height | number\|string | - | |
+| hoverable | Rows are highlighted when hovering | boolean | - | table: {
hoverable: false
}
|
+| iconPack | Icon pack to use | string | `mdi`, `fa`, `fas and any other custom icon pack` | table: {
iconPack: undefined
}
|
+| isDetailedVisible | Controls the visibility of the trigger that toggles the detailed rows (if detailed) | (row: T) => boolean | - | table: {
isDetailedVisible: (row) => true
}
|
+| isRowCheckable | Custom method to verify if a row is checkable (if checkable) | (row: T) => boolean | - | table: {
isRowCheckable: (row) => true
}
|
+| isRowChecked | Custom method to verify if a row is checked (if checkable). Useful for backend pagination. | (row: T, data: T[]) => boolean | - | |
+| isRowSelectable | Custom method to verify if a row is selectable, works when is selectable | (row: T) => boolean | - | Default function (see source code) |
+| loading | Enable loading state | boolean | - | false
|
+| loadingIcon | Icon for the loading state | string | - | table: {
loadingIcon: "loading"
}
|
+| loadingLabel | Label for the loading state | string | - | table: {
loadingLabel: undefined
}
|
+| mobileBreakpoint | Mobile breakpoint as max-width value | string | - | table: {
mobileBreakpoint: undefined
}
|
+| mobileCards | Rows appears as cards on mobile (collapse rows) | boolean | - | table: {
mobileCards: true
}
|
+| mobileSortPlaceholder | Select placeholder text when nothing is selected (if mobileCards) | string | - | table: {
mobileSortPlaceholder: undefined
}
|
+| narrowed | Makes the cells narrower | boolean | - | table: {
narrowed: false
}
|
+| override | Override existing theme classes completely | boolean | - | |
+| paginated | Adds pagination to the table | boolean | - | table: {
paginated: false
}
|
+| paginationOrder | Pagination buttons order (if paginated) | string | `centered`, `right`, `left` | table: {
paginationOrder: undefined
}
|
+| paginationPosition | Pagination position (if paginated) | string | `bottom`, `top`, `both` | table: {
paginationPosition: "bottom"
}
|
+| paginationRounded | Enable rounded pagination buttons (if paginated) | boolean | - | table: {
paginationRounded: false
}
|
+| paginationSimple | Enable simple style pagination (if paginated) | boolean | - | table: {
paginationSimple: false
}
|
+| paginationSize | Size of pagination (if paginated) | string | `small`, `medium`, `large` | table: {
paginationSize: "small"
}
|
+| perPage | How many rows per page (if paginated) | number\|string | - | table: {
perPage: 20
}
|
+| rowKey | Use a unique key of your data Object for each row. Useful if your data prop has dynamic indices. (id recommended) | string | - | table: {
rowKey: undefined
}
|
+| scrollable | Add a horizontal scrollbar when table is too wide | boolean | - | |
+| selectable | Table can be focused and user can select rows. Rows can be navigate with keyboard arrows and are highlighted when hovering. | boolean | - | table: {
selectable: false
}
|
+| selected | Set which row is selected, use `v-model:selected` to make it two-way binding (if selectable) | T | - | |
+| showDetailIcon | Allow detail icon and column to be visible (if detailed) | boolean | - | table: {
showDetailIcon: true
}
|
+| showHeader | Show header | boolean | - | table: {
showHeader: true
}
|
+| sortIcon | Sets the header sorting icon | string | - | table: {
sortIcon: "arrow-up"
}
|
+| sortIconSize | Sets the size of the sorting icon | string | `small`, `medium`, `large` | table: {
sortIconSize: "small"
}
|
+| stickyCheckbox | Make the checkbox column sticky (if checkable) | boolean | - | false
|
+| stickyHeader | Show a sticky table header | boolean | - | false
|
+| striped | Whether table is striped | boolean | - | table: {
striped: false
}
|
+| tdAttrs | Adds native attributes to column td element of a row | (row: T, column: TableColumn<T>) => object | - | |
+| thAttrs | Adds native attributes to a column th element | (column: TableColumn<T>) => object | - | |
+| total | Total number of table data if backend-pagination is enabled | number | - | 0
|
### Events
@@ -188,8 +190,8 @@ sidebarDepth: 2
| sortable | Enable column sortability | boolean | - | false
|
| sticky | Whether the column is sticky or not | boolean | - | false
|
| subheading | Define a column sub heading | string | - | |
-| tdAttrs | Adds native attributes to td | (row: T, column: typeof props) => object | - | Default function (see source code) |
-| thAttrs | Adds native attributes to th | (column: typeof props) => object | - | Default function (see source code) |
+| tdAttrs | Adds native attributes to td | object | - | |
+| thAttrs | Adds native attributes to th | object | - | |
| visible | Define whether the column is visible or not | boolean | - | true
|
| width | Column fixed width | number\|string | - | |
diff --git a/packages/oruga/src/components/pagination/Pagination.vue b/packages/oruga/src/components/pagination/Pagination.vue
index 9ef9ae31f..5d6df57d5 100644
--- a/packages/oruga/src/components/pagination/Pagination.vue
+++ b/packages/oruga/src/components/pagination/Pagination.vue
@@ -424,7 +424,7 @@ defineExpose({ last, first, prev, next });
v-bind="getPage(currentPage - 1, ariaPreviousLabel)">