-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(OnyxDataGrid): Expose Feature API (#2059)
Relates to #1852 - Added `features` prop, which exposes the `useDataGridFeature` API to allow devs to use custom and pre-defined features - Expose onyx provided data-grid features via a re-export called `DataGridFeatures` - Added `DataGridFeatures.useSorting` feature, with support for custom configuration - Fixed issue where `OnyxDataGrid` didn't update on sort change: A deep watcher is necessary, even when a non-shallow ref is used
- Loading branch information
Showing
14 changed files
with
909 additions
and
698 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"sit-onyx": minor | ||
--- | ||
|
||
feat(OnyxDataGrid): Added `features` prop which exposes the `useDataGridFeature` API to allow devs to use custom and pre-defined features | ||
feat(OnyxDataGrid): Expose onyx provided features via a re-export called `DataGridFeatures` | ||
feat(OnyxDataGrid): Added `DataGridFeatures.useSorting` feature, with support for custom configuration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/sit-onyx/src/components/OnyxDataGrid/features/all.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./sorting/types"; | ||
|
||
export { useDataGridSorting as useSorting } from "./sorting/sorting"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/sit-onyx/src/components/OnyxDataGrid/features/sorting/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { type MaybeRef, type MaybeRefOrGetter } from "vue"; | ||
import type { DataGridEntry } from "../../types"; | ||
|
||
export type SortDirection = "asc" | "desc" | "none"; | ||
|
||
/** | ||
* A function to compare two values of type T. | ||
* The returned number value indicates the relative order of two values: | ||
* -1: less than, 0: equal to, 1: greater than | ||
*/ | ||
export type Compare<T> = (a: T, b: T) => number; | ||
|
||
/** | ||
* The values by which the data is currently sorted. | ||
* A `undefined` column or a direction of "none" means no sorting is applied. | ||
*/ | ||
export type SortState<TEntry extends DataGridEntry> = { | ||
/** | ||
* The column which is used to sort by. | ||
* `undefined` means no sorting is applied. | ||
*/ | ||
column: keyof TEntry | undefined; | ||
/** | ||
* The sorting direction by which the `column` is sorted. | ||
* `none` means no sorting is applied. | ||
*/ | ||
direction: SortDirection; | ||
}; | ||
|
||
/** | ||
* Per column sorting configuration. | ||
* If at least one column has configuration, sorting must be explicitly enabled for all columns. | ||
*/ | ||
export type SortColumnOptions<TEntry extends DataGridEntry> = { | ||
[TKey in keyof TEntry]?: { | ||
/** | ||
* If sorting is enabled for this column. | ||
*/ | ||
enabled: boolean; | ||
/** | ||
* A custom sorting function for this column. | ||
* By default the `Intl.Collator` with the current locale is used. | ||
*/ | ||
sortFunc?: Compare<TEntry[TKey]>; | ||
}; | ||
}; | ||
|
||
/** | ||
* The options of the sorting feature for the OnyxDataGrid component. | ||
*/ | ||
export type SortOptions<TEntry extends DataGridEntry> = { | ||
/** | ||
* The currently applied sorting. Will be updated by the data grid, can be used for reading, updating and watching the applied sorting. | ||
*/ | ||
sortState?: MaybeRef<SortState<TEntry>>; | ||
/** | ||
* The options for each column, including whether sorting is enabled and a custom sorting function. If undefined, sorting is enabled for all columns (default). | ||
*/ | ||
columns?: MaybeRefOrGetter<SortColumnOptions<TEntry>>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.