@commercetools-uikit/filters 19.15.0 → 19.17.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.
- package/README.md +194 -9
- package/dist/commercetools-uikit-filters.cjs.dev.js +545 -71
- package/dist/commercetools-uikit-filters.cjs.prod.js +501 -41
- package/dist/commercetools-uikit-filters.esm.js +528 -71
- package/dist/declarations/src/export-types.d.ts +1 -0
- package/dist/declarations/src/filter-menu/filter-menu.d.ts +6 -1
- package/dist/declarations/src/filter-menu/index.d.ts +1 -0
- package/dist/declarations/src/filters.d.ts +34 -26
- package/dist/declarations/src/index.d.ts +1 -0
- package/package.json +14 -11
package/README.md
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
## Description
|
|
7
7
|
|
|
8
|
-
The `Filters` component
|
|
8
|
+
The `Filters` component pattern is a component that provides the controls to filter the items in a table or list.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
- Available filter controls are configured in the `filters` array. Each `filter` object includes a `filterMenuConfiguration` object, in which the inputs that allow the user to select a value for that filter are defined.
|
|
11
|
+
|
|
12
|
+
- The selected values for each filter are passed to the component in the `appliedFilters` array. Values in the `appliedFilters` array will be displayed in each filter's menu button.
|
|
11
13
|
|
|
12
14
|
## Installation
|
|
13
15
|
|
|
@@ -34,14 +36,197 @@ npm --save install react
|
|
|
34
36
|
```jsx
|
|
35
37
|
import Filters from '@commercetools-uikit/filters';
|
|
36
38
|
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
/** Input for a specific filter, provided by parent application */
|
|
40
|
+
import FirstFilterInput from 'path/to/first/filter/input'; // eslint-disable-line import/no-unresolved
|
|
41
|
+
|
|
42
|
+
/** Input for search query, provided by parent application */
|
|
43
|
+
import SearchInput from 'path/to/search/input'; // eslint-disable-line import/no-unresolved
|
|
44
|
+
|
|
45
|
+
/** Input for a specific filter, provided by parent application */
|
|
46
|
+
import SecondFilterInput from 'path/to/second/filter/input'; // eslint-disable-line import/no-unresolved
|
|
47
|
+
|
|
48
|
+
/** Filter and search state, provided by parent application (does not have to be hook)
|
|
49
|
+
see storybook code block for more in depth example of simple state management */
|
|
50
|
+
import useFilterState from 'path/to/your/filter/state'; // eslint-disable-line import/no-unresolved
|
|
51
|
+
|
|
52
|
+
const FiltersExample = () => {
|
|
53
|
+
const {
|
|
54
|
+
// change handler for FirstFilterInput
|
|
55
|
+
onFirstFilterInputChange,
|
|
56
|
+
// callback to clear FirstFilterInput value
|
|
57
|
+
onClearFirstFilterInput,
|
|
58
|
+
// value of FirstFilterInput
|
|
59
|
+
firstFilterInputValue,
|
|
60
|
+
// change handler for SecondFilterInput
|
|
61
|
+
onSecondFilterInputChange,
|
|
62
|
+
// callback to clear SecondFilterInput value
|
|
63
|
+
onClearSecondFilterInput,
|
|
64
|
+
// value of SecondFilterInput
|
|
65
|
+
secondFilterInputValue,
|
|
66
|
+
// callback to clear all filter inputs and selected values
|
|
67
|
+
onClearAllFilters,
|
|
68
|
+
// selected/applied values of all filters
|
|
69
|
+
selectedFilterValues,
|
|
70
|
+
} = useFilterState();
|
|
71
|
+
|
|
72
|
+
const filters = [
|
|
73
|
+
{
|
|
74
|
+
key: 'firstFilter',
|
|
75
|
+
label: 'First Filter',
|
|
76
|
+
filterMenuConfiguration: {
|
|
77
|
+
renderMenuBody: () => (
|
|
78
|
+
<FirstFilterInput
|
|
79
|
+
onChange={onFirstFilterInputChange}
|
|
80
|
+
value={firstFilterInputValue}
|
|
81
|
+
/>
|
|
82
|
+
),
|
|
83
|
+
onClearRequest: onClearFirstFilterInput,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
key: 'secondFilter',
|
|
88
|
+
label: 'Second Filter',
|
|
89
|
+
filterMenuConfiguration: {
|
|
90
|
+
renderMenuBody: () => (
|
|
91
|
+
<SecondFilterInput
|
|
92
|
+
onChange={onSecondFilterInputChange}
|
|
93
|
+
value={secondFilterInputValue}
|
|
94
|
+
/>
|
|
95
|
+
),
|
|
96
|
+
onClearRequest: onClearSecondFilterInput,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<Filters
|
|
103
|
+
appliedFilters={selectedFilterValues}
|
|
104
|
+
filters={filters}
|
|
105
|
+
onClearAllRequest={onClearAllFilters}
|
|
106
|
+
renderSearchComponent={<SearchInput />}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export default FiltersExample;
|
|
41
112
|
```
|
|
42
113
|
|
|
43
114
|
## Properties
|
|
44
115
|
|
|
45
|
-
| Props
|
|
46
|
-
|
|
|
47
|
-
| `
|
|
116
|
+
| Props | Type | Required | Default | Description |
|
|
117
|
+
| ----------------------- | ---------------------------------------------------------------------------------- | :------: | ------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
118
|
+
| `appliedFilters` | `Array: TAppliedFilter[]`<br/>[See signature.](#signature-appliedFilters) | ✅ | | array of applied filters, each containing a unique key and an array of values. |
|
|
119
|
+
| `filters` | `Array: TFilterConfiguration[]`<br/>[See signature.](#signature-filters) | ✅ | | configuration for the available filters. |
|
|
120
|
+
| `filterGroups` | `Array: TFilterGroupConfiguration[]`<br/>[See signature.](#signature-filterGroups) | | | optional configuration for filter groups. |
|
|
121
|
+
| `onClearAllRequest` | `Function`<br/>[See signature.](#signature-onClearAllRequest) | ✅ | | controls the `clear all` (added filters) button from the menu list, meant to clear the parent application's filter state |
|
|
122
|
+
| `onAddFilterRequest` | `Function`<br/>[See signature.](#signature-onAddFilterRequest) | | | optional callback when the add filter button is clicked |
|
|
123
|
+
| `renderSearchComponent` | `ReactNode` | ✅ | | function to render a search input, selectable from applicable UI Kit components. |
|
|
124
|
+
| `defaultOpen` | `boolean` | | `false` | controls whether the filters list is initially open |
|
|
125
|
+
|
|
126
|
+
## Signatures
|
|
127
|
+
|
|
128
|
+
### Signature `appliedFilters`
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
{
|
|
132
|
+
/**
|
|
133
|
+
* unique identifier for the filter
|
|
134
|
+
*/
|
|
135
|
+
filterKey: string;
|
|
136
|
+
/**
|
|
137
|
+
* the values applied to this filter by the user
|
|
138
|
+
*/
|
|
139
|
+
values: TAppliedFilterValue[];
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Signature `filters`
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
{
|
|
147
|
+
/**
|
|
148
|
+
* unique identifier for the filter
|
|
149
|
+
*/
|
|
150
|
+
key: string;
|
|
151
|
+
/**
|
|
152
|
+
* formatted message to display the filter name
|
|
153
|
+
*/
|
|
154
|
+
label: ReactNode;
|
|
155
|
+
/**
|
|
156
|
+
* formatted message to display the selected operator value
|
|
157
|
+
*/
|
|
158
|
+
operatorLabel?: ReactNode;
|
|
159
|
+
/**
|
|
160
|
+
* configuration object for the filter menu.
|
|
161
|
+
*/
|
|
162
|
+
filterMenuConfiguration: {
|
|
163
|
+
/**
|
|
164
|
+
* the input in which the user selects values for the filter
|
|
165
|
+
*/
|
|
166
|
+
renderMenuBody: () => ReactNode;
|
|
167
|
+
/**
|
|
168
|
+
* the input in which the user can select which operator should be used for this filter
|
|
169
|
+
*/
|
|
170
|
+
renderOperatorsInput?: () => ReactNode;
|
|
171
|
+
/**
|
|
172
|
+
* optional button that allows the user to apply selected filter values
|
|
173
|
+
*/
|
|
174
|
+
renderApplyButton?: () => ReactNode;
|
|
175
|
+
/**
|
|
176
|
+
* controls whether `clear` button in Menu Body Footer is displayed
|
|
177
|
+
*/
|
|
178
|
+
onClearRequest: (
|
|
179
|
+
event?: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>
|
|
180
|
+
) => void;
|
|
181
|
+
/**
|
|
182
|
+
* controls whether `sort` button in Menu Body Header is displayed
|
|
183
|
+
*/
|
|
184
|
+
onSortRequest?: (
|
|
185
|
+
event?: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>
|
|
186
|
+
) => void;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* optional key to group filters together.
|
|
190
|
+
*/
|
|
191
|
+
groupKey?: string;
|
|
192
|
+
/**
|
|
193
|
+
* indicates whether filter menu can be removed from filters
|
|
194
|
+
*/
|
|
195
|
+
isPersistent?: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* indicates whether the filter is disabled
|
|
198
|
+
*/
|
|
199
|
+
isDisabled?: boolean;
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Signature `filterGroups`
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
{
|
|
207
|
+
/**
|
|
208
|
+
* unique identifier for the filter group
|
|
209
|
+
*/
|
|
210
|
+
key: string;
|
|
211
|
+
/**
|
|
212
|
+
* formatted message to display the filter group name
|
|
213
|
+
*/
|
|
214
|
+
label: ReactNode;
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Signature `onClearAllRequest`
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
(
|
|
222
|
+
event?: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>
|
|
223
|
+
) => void
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Signature `onAddFilterRequest`
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
(
|
|
230
|
+
event?: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>
|
|
231
|
+
) => void
|
|
232
|
+
```
|