@luscii-healthtech/web-ui 7.0.0 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ import { CategorisedFilters, FilterGenerator, TransformedSortingOption } from "./FilterBarProps.type";
2
+ /**
3
+ * Generates the list of filters based on the data (see this as what you'd like to be filtered in your component).
4
+ *
5
+ * @param dataToGenerateFiltersFrom - The data (list of entities) that will be used to create the filters.
6
+ * @param groupers a list of functions used to create the filters dropdown
7
+ * @returns {CategorisedFilters} a list of filters properly grouped.
8
+ */
9
+ export declare function getFilterGroups<T extends unknown[]>(dataToGenerateFiltersFrom: T, groupers: FilterGenerator<T[number]>[]): CategorisedFilters;
10
+ /**
11
+ *
12
+ * @param filterKey the key of the categorized filter (eg. color, size, brand) - which one of them are you gonna check.
13
+ * @param categorizedFilters the array of categorized filters the FilterBar component needs
14
+ * @param attributeGetter the getter to retrieve the attribute to be filtered on, this allow maximum flexibility on how to process
15
+ * filters on any level of nesting if necessary.
16
+ * @returns a predicate to be used in the filter function
17
+ * @example
18
+ *
19
+ * const sizeFilterPredicate = createFilterPredicate<TShirtFromApi>("size", filtersOptions, (item) => item.meta.size);
20
+ * const filteredBySize = items.filter(sizeFilterPredicate);
21
+ *
22
+ */
23
+ export declare const createFilterPredicate: <T extends object>(filterKey: keyof T, categorizedFilters: CategorisedFilters, attributeGetter: (item: T) => string) => (item: T) => boolean;
24
+ /**
25
+ * Creates a sorting function to be used on a specific object attribute.
26
+ *
27
+ * @param getter the getter function to retrieve the attribute used in the sorting
28
+ * @param order if ascending or descending
29
+ * @returns the sorting comparer function to be used in Array.sort
30
+ */
31
+ export declare const createSortingComparer: <T extends object>(getter: (item: T) => string | number, order?: "asc" | "desc") => (itemA: T, itemB: T) => number;
32
+ export declare const applySorting: <T extends object[]>(sortable: T, sortingOptions: TransformedSortingOption[]) => T;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * The object used to create a filter dropdown in the component.
3
+ * This is used based on the dataset passed to FilterBar, so we always calculate the filters
4
+ * looking at the data.
5
+ */
6
+ export type FilterGenerator<T> = {
7
+ id: string;
8
+ label: string;
9
+ /**
10
+ *
11
+ * @param data the value from the dataset entry that will be used for the filter
12
+ * @returns the string value for the desired filter
13
+ *
14
+ * @example
15
+ *
16
+ * ```json
17
+ * {
18
+ id: "brand",
19
+ label: "Brand",
20
+ filterValuePredicate: (tshirt: TShirtFromApi) => tshirt.brand,
21
+ }
22
+ * ```
23
+ * in the above, all unique values from `brand` will be used to populate the `Brand` filter.
24
+ */
25
+ filterValuePredicate: (data: T) => string;
26
+ };
27
+ /**
28
+ * Allows customization of labels related to filter.
29
+ *
30
+ */
31
+ export type FilterBarLocalization = {
32
+ /**
33
+ * The string prefix displayed when a sorting value is selected in the menu.
34
+ *
35
+ * @default "Sorted by:"
36
+ * @example
37
+ *
38
+ * `sortedByLabel`: "Sorted by: "
39
+ *
40
+ * Example of sorting options
41
+ * - Name
42
+ * - Email (selected)
43
+ * - Date of birth
44
+ *
45
+ * UI shows: `Sorted by: Email`.
46
+ */
47
+ sortedByLabel: string;
48
+ /**
49
+ * The string for unselected state of the sorting options.
50
+ *
51
+ * @default "Sort"
52
+ */
53
+ sortLabel: string;
54
+ /**
55
+ * The string for the active filters and the mobile filter menu label.
56
+ *
57
+ * @default "Filters"
58
+ */
59
+ filtersLabel: string;
60
+ };
61
+ export type TransformedFilterOption = {
62
+ id: string;
63
+ label: string;
64
+ value: string;
65
+ isChecked: boolean;
66
+ };
67
+ export type TransformedFilterOptions = TransformedFilterOption[];
68
+ type CategorisedFilter = {
69
+ key: string;
70
+ label: string;
71
+ options: TransformedFilterOptions;
72
+ };
73
+ export type CategorisedFilters = CategorisedFilter[];
74
+ export type TransformedSortingOption = {
75
+ id: string;
76
+ label: string;
77
+ value: string;
78
+ isChecked: boolean;
79
+ sortingCompare: (itemA: any, itemB: any) => number;
80
+ };
81
+ export type TransformedSortingOptions = TransformedSortingOption[];
82
+ export type OnFilterBarFilterChange = (params: {
83
+ category: string;
84
+ changedFilterOption: TransformedFilterOption;
85
+ }) => void;
86
+ export type OnFilterBarSortingChange = (changedSortingOption: TransformedSortingOption) => void;
87
+ export type FilterBarProps = {
88
+ categorizedFilters: CategorisedFilters;
89
+ sortingOptions: TransformedSortingOptions;
90
+ onFilterChange: (updatedFilters: CategorisedFilters) => void;
91
+ onSortingChange: (updatedSortingOptions: TransformedSortingOptions) => void;
92
+ localization: FilterBarLocalization;
93
+ };
94
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luscii-healthtech/web-ui",
3
- "version": "7.0.0",
3
+ "version": "7.2.0",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "Joris Janssen"