@muraldevkit/ui-toolkit 4.81.0 → 4.83.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/dist/cjs/components/grid/MrlCol/MrlCol.js +61 -55
- package/dist/cjs/components/grid/MrlCol/MrlCol.js.map +1 -1
- package/dist/cjs/components/grid/MrlGrid/MrlGrid.js +8 -5
- package/dist/cjs/components/grid/MrlGrid/MrlGrid.js.map +1 -1
- package/dist/cjs/components/grid/MrlRow/MrlRow.js +10 -8
- package/dist/cjs/components/grid/MrlRow/MrlRow.js.map +1 -1
- package/dist/cjs/components/grid/constants.js +47 -9
- package/dist/cjs/components/grid/constants.js.map +1 -1
- package/dist/cjs/components/multi-filter/MrlMultiFilter/MrlMultiFilter.js +232 -0
- package/dist/cjs/components/multi-filter/MrlMultiFilter/MrlMultiFilter.js.map +1 -0
- package/dist/cjs/components/multi-filter/MrlMultiFilter/MrlMultiFilter.module.scss.js +8 -0
- package/dist/cjs/components/multi-filter/MrlMultiFilter/MrlMultiFilter.module.scss.js.map +1 -0
- package/dist/cjs/components/multi-filter/MrlMultiFilterContext/MrlMultiFilterContext.js +302 -0
- package/dist/cjs/components/multi-filter/MrlMultiFilterContext/MrlMultiFilterContext.js.map +1 -0
- package/dist/cjs/components/multi-filter/MrlMultiFilterField/MrlMultiFilterField.js +122 -0
- package/dist/cjs/components/multi-filter/MrlMultiFilterField/MrlMultiFilterField.js.map +1 -0
- package/dist/cjs/components/multi-filter/MrlMultiFilterField/MrlMultiFilterField.module.scss.js +8 -0
- package/dist/cjs/components/multi-filter/MrlMultiFilterField/MrlMultiFilterField.module.scss.js.map +1 -0
- package/dist/cjs/components/multi-filter/MrlMultiFilterTrigger/MrlMultiFilterTrigger.js +83 -0
- package/dist/cjs/components/multi-filter/MrlMultiFilterTrigger/MrlMultiFilterTrigger.js.map +1 -0
- package/dist/cjs/components/multi-filter/utils.js +30 -0
- package/dist/cjs/components/multi-filter/utils.js.map +1 -0
- package/dist/cjs/components/popover/MrlPopover/MrlPopover.js +16 -5
- package/dist/cjs/components/popover/MrlPopover/MrlPopover.js.map +1 -1
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/components/grid/MrlCol/MrlCol.js +62 -56
- package/dist/esm/components/grid/MrlCol/MrlCol.js.map +1 -1
- package/dist/esm/components/grid/MrlGrid/MrlGrid.js +8 -5
- package/dist/esm/components/grid/MrlGrid/MrlGrid.js.map +1 -1
- package/dist/esm/components/grid/MrlRow/MrlRow.js +10 -8
- package/dist/esm/components/grid/MrlRow/MrlRow.js.map +1 -1
- package/dist/esm/components/grid/constants.js +46 -9
- package/dist/esm/components/grid/constants.js.map +1 -1
- package/dist/esm/components/multi-filter/MrlMultiFilter/MrlMultiFilter.js +207 -0
- package/dist/esm/components/multi-filter/MrlMultiFilter/MrlMultiFilter.js.map +1 -0
- package/dist/esm/components/multi-filter/MrlMultiFilter/MrlMultiFilter.module.scss.js +4 -0
- package/dist/esm/components/multi-filter/MrlMultiFilter/MrlMultiFilter.module.scss.js.map +1 -0
- package/dist/esm/components/multi-filter/MrlMultiFilterContext/MrlMultiFilterContext.js +276 -0
- package/dist/esm/components/multi-filter/MrlMultiFilterContext/MrlMultiFilterContext.js.map +1 -0
- package/dist/esm/components/multi-filter/MrlMultiFilterField/MrlMultiFilterField.js +97 -0
- package/dist/esm/components/multi-filter/MrlMultiFilterField/MrlMultiFilterField.js.map +1 -0
- package/dist/esm/components/multi-filter/MrlMultiFilterField/MrlMultiFilterField.module.scss.js +4 -0
- package/dist/esm/components/multi-filter/MrlMultiFilterField/MrlMultiFilterField.module.scss.js.map +1 -0
- package/dist/esm/components/multi-filter/MrlMultiFilterTrigger/MrlMultiFilterTrigger.js +58 -0
- package/dist/esm/components/multi-filter/MrlMultiFilterTrigger/MrlMultiFilterTrigger.js.map +1 -0
- package/dist/esm/components/multi-filter/utils.js +28 -0
- package/dist/esm/components/multi-filter/utils.js.map +1 -0
- package/dist/esm/components/popover/MrlPopover/MrlPopover.js +16 -5
- package/dist/esm/components/popover/MrlPopover/MrlPopover.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/styles/MrlMultiFilter/module.scss +30 -0
- package/dist/styles/MrlMultiFilterField/module.scss +7 -0
- package/dist/styles/MrlSidebar/module.scss +2 -2
- package/dist/styles/grid/global.scss +97 -2
- package/dist/styles.css +3 -7
- package/dist/types/components/grid/MrlCol/MrlCol.d.ts +4 -6
- package/dist/types/components/grid/MrlCol/index.d.ts +1 -1
- package/dist/types/components/grid/MrlGrid/MrlGrid.d.ts +9 -4
- package/dist/types/components/grid/MrlGrid/index.d.ts +1 -1
- package/dist/types/components/grid/MrlRow/MrlRow.d.ts +7 -7
- package/dist/types/components/grid/MrlRow/index.d.ts +1 -1
- package/dist/types/components/grid/constants.d.ts +56 -13
- package/dist/types/components/grid/index.d.ts +1 -1
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/multi-filter/MrlMultiFilter/MrlMultiFilter.d.ts +166 -0
- package/dist/types/components/multi-filter/MrlMultiFilter/index.d.ts +1 -0
- package/dist/types/components/multi-filter/MrlMultiFilterContext/MrlMultiFilterContext.d.ts +141 -0
- package/dist/types/components/multi-filter/MrlMultiFilterContext/index.d.ts +1 -0
- package/dist/types/components/multi-filter/MrlMultiFilterField/MrlMultiFilterField.d.ts +121 -0
- package/dist/types/components/multi-filter/MrlMultiFilterField/index.d.ts +1 -0
- package/dist/types/components/multi-filter/MrlMultiFilterTrigger/MrlMultiFilterTrigger.d.ts +52 -0
- package/dist/types/components/multi-filter/MrlMultiFilterTrigger/index.d.ts +1 -0
- package/dist/types/components/multi-filter/index.d.ts +4 -0
- package/dist/types/components/multi-filter/utils.d.ts +8 -0
- package/dist/types/components/popover/MrlPopover/MrlPopover.d.ts +7 -1
- package/package.json +1 -1
- package/dist/styles/grid/variables.scss +0 -26
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { slicedToArray as _slicedToArray, objectSpread2 as _objectSpread2 } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { focusFirstInvalidField } from '../utils.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Values of the filters, keyed by field name.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* One field of the draft.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Filters as a value and a required flag per field. Used for the draft being edited and for
|
|
15
|
+
* the applied filters.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Fields that failed validation, keyed by field name.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Whether a value counts as empty. `false` is a value, so it is not empty.
|
|
24
|
+
*
|
|
25
|
+
* @param value - The field value.
|
|
26
|
+
* @returns Whether the value is empty.
|
|
27
|
+
*/
|
|
28
|
+
var isMrlMultiFilterValueEmpty = value => value === null || value === undefined || value === '' || Array.isArray(value) && value.length === 0;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns the plain values of a draft, without the required flags. A common `transform`.
|
|
32
|
+
*
|
|
33
|
+
* @param draft - The draft.
|
|
34
|
+
* @returns The values, keyed by field name.
|
|
35
|
+
*/
|
|
36
|
+
var getDraftValues = draft => Object.fromEntries(Object.entries(draft).map(_ref => {
|
|
37
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
38
|
+
name = _ref2[0],
|
|
39
|
+
field = _ref2[1];
|
|
40
|
+
return [name, field.value];
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Removes one field's error.
|
|
45
|
+
*
|
|
46
|
+
* @param errors - The current errors.
|
|
47
|
+
* @param name - The field name.
|
|
48
|
+
* @returns The errors without that field.
|
|
49
|
+
*/
|
|
50
|
+
var withoutError = (errors, name) => {
|
|
51
|
+
if (!errors[name]) return errors;
|
|
52
|
+
var next = _objectSpread2({}, errors);
|
|
53
|
+
delete next[name];
|
|
54
|
+
return next;
|
|
55
|
+
};
|
|
56
|
+
var mrlMultiFilterReducer = (state, action) => {
|
|
57
|
+
switch (action.type) {
|
|
58
|
+
case 'SET_FIELD_VALUE':
|
|
59
|
+
{
|
|
60
|
+
// Editing a field clears its error.
|
|
61
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
62
|
+
draft: _objectSpread2(_objectSpread2({}, state.draft), {}, {
|
|
63
|
+
[action.name]: _objectSpread2(_objectSpread2({}, state.draft[action.name]), {}, {
|
|
64
|
+
value: action.value
|
|
65
|
+
})
|
|
66
|
+
}),
|
|
67
|
+
errors: withoutError(state.errors, action.name)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
case 'SET_REQUIRED':
|
|
71
|
+
{
|
|
72
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
73
|
+
draft: _objectSpread2(_objectSpread2({}, state.draft), {}, {
|
|
74
|
+
[action.name]: _objectSpread2(_objectSpread2({}, state.draft[action.name]), {}, {
|
|
75
|
+
required: action.required
|
|
76
|
+
})
|
|
77
|
+
}),
|
|
78
|
+
errors: action.required ? state.errors : withoutError(state.errors, action.name)
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
case 'SET_ERRORS':
|
|
82
|
+
{
|
|
83
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
84
|
+
errors: action.errors
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
case 'APPLY':
|
|
88
|
+
{
|
|
89
|
+
// Controlled: the applied draft only changes when the consumer passes a new one.
|
|
90
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
91
|
+
applied: action.controlled ? state.applied : state.draft,
|
|
92
|
+
errors: {}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
case 'CANCEL':
|
|
96
|
+
{
|
|
97
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
98
|
+
draft: state.applied,
|
|
99
|
+
errors: {}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
case 'RESET':
|
|
103
|
+
{
|
|
104
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
105
|
+
draft: action.draft,
|
|
106
|
+
errors: {}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
case 'SYNC_APPLIED':
|
|
110
|
+
{
|
|
111
|
+
return {
|
|
112
|
+
applied: action.applied,
|
|
113
|
+
draft: action.applied,
|
|
114
|
+
errors: {}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
default:
|
|
118
|
+
return state;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The context value. Every function keeps its identity across renders, so it can be passed to
|
|
124
|
+
* effects and callbacks without changing on each draft edit. `getDraft` and `validate` read the
|
|
125
|
+
* latest draft, including edits made earlier in the same event handler.
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Context for the MrlMultiFilter component.
|
|
130
|
+
*
|
|
131
|
+
* Holds the draft (the filters being edited), the last applied draft and the validation
|
|
132
|
+
* errors. The provider wraps the trigger and the popover, outside the popover content, so the
|
|
133
|
+
* applied draft survives the popover content unmounting. It is used internally by the
|
|
134
|
+
* MrlMultiFilterContextProvider and can be accessed via the useMrlMultiFilterContext hook.
|
|
135
|
+
*/
|
|
136
|
+
var MrlMultiFilterContext = /*#__PURE__*/React.createContext(undefined);
|
|
137
|
+
/**
|
|
138
|
+
* MrlMultiFilterContextProvider component.
|
|
139
|
+
*
|
|
140
|
+
* @param props - The component props.
|
|
141
|
+
* @returns The MrlMultiFilterContextProvider component.
|
|
142
|
+
*/
|
|
143
|
+
function MrlMultiFilterContextProvider(props) {
|
|
144
|
+
var appliedDraft = props.appliedDraft,
|
|
145
|
+
children = props.children,
|
|
146
|
+
initialDraft = props.initialDraft;
|
|
147
|
+
var startDraft = appliedDraft !== null && appliedDraft !== void 0 ? appliedDraft : initialDraft;
|
|
148
|
+
/**
|
|
149
|
+
* The latest state lives in a ref, updated as soon as an action runs, and is mirrored into
|
|
150
|
+
* React state to re-render. Reading the ref lets `getDraft` and `validate` see edits made
|
|
151
|
+
* earlier in the same event handler, e.g. `setFieldValue(...); apply();`. React state alone
|
|
152
|
+
* only updates on the next render.
|
|
153
|
+
*/
|
|
154
|
+
var stateRef = React.useRef({
|
|
155
|
+
applied: startDraft,
|
|
156
|
+
draft: startDraft,
|
|
157
|
+
errors: {}
|
|
158
|
+
});
|
|
159
|
+
var _React$useState = React.useState(stateRef.current),
|
|
160
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
161
|
+
state = _React$useState2[0],
|
|
162
|
+
setState = _React$useState2[1];
|
|
163
|
+
var dispatch = React.useCallback(action => {
|
|
164
|
+
stateRef.current = mrlMultiFilterReducer(stateRef.current, action);
|
|
165
|
+
setState(stateRef.current);
|
|
166
|
+
}, []);
|
|
167
|
+
var fieldsRef = React.useRef(new Map());
|
|
168
|
+
|
|
169
|
+
// Controlled: the applied draft comes from the prop. Read it from the prop, not the state,
|
|
170
|
+
// so the badge does not wait for the sync below.
|
|
171
|
+
var applied = appliedDraft !== null && appliedDraft !== void 0 ? appliedDraft : state.applied;
|
|
172
|
+
|
|
173
|
+
// Controlled: a new applied draft replaces the applied draft in the state and the draft,
|
|
174
|
+
// e.g. when filters are cleared from outside the popover. Keeping it in the state lets
|
|
175
|
+
// Cancel go back to it without depending on the prop.
|
|
176
|
+
var previousAppliedDraftRef = React.useRef(appliedDraft);
|
|
177
|
+
React.useEffect(() => {
|
|
178
|
+
if (appliedDraft === previousAppliedDraftRef.current) return;
|
|
179
|
+
previousAppliedDraftRef.current = appliedDraft;
|
|
180
|
+
if (appliedDraft) dispatch({
|
|
181
|
+
applied: appliedDraft,
|
|
182
|
+
type: 'SYNC_APPLIED'
|
|
183
|
+
});
|
|
184
|
+
}, [appliedDraft, dispatch]);
|
|
185
|
+
|
|
186
|
+
// Stable: they only dispatch or read the ref. `commit` only changes when switching between controlled and
|
|
187
|
+
// uncontrolled.
|
|
188
|
+
// Same check as `applied` above, so a `null` from untyped code counts as uncontrolled.
|
|
189
|
+
var controlled = appliedDraft != null;
|
|
190
|
+
var commit = React.useCallback(() => dispatch({
|
|
191
|
+
controlled,
|
|
192
|
+
type: 'APPLY'
|
|
193
|
+
}), [controlled, dispatch]);
|
|
194
|
+
var discard = React.useCallback(() => dispatch({
|
|
195
|
+
type: 'CANCEL'
|
|
196
|
+
}), [dispatch]);
|
|
197
|
+
var getDraft = React.useCallback(() => stateRef.current.draft, []);
|
|
198
|
+
var reset = React.useCallback(draft => dispatch({
|
|
199
|
+
draft,
|
|
200
|
+
type: 'RESET'
|
|
201
|
+
}), [dispatch]);
|
|
202
|
+
var setFieldValue = React.useCallback((name, value) => dispatch({
|
|
203
|
+
name,
|
|
204
|
+
type: 'SET_FIELD_VALUE',
|
|
205
|
+
value
|
|
206
|
+
}), [dispatch]);
|
|
207
|
+
var setRequired = React.useCallback((name, required) => dispatch({
|
|
208
|
+
name,
|
|
209
|
+
required,
|
|
210
|
+
type: 'SET_REQUIRED'
|
|
211
|
+
}), [dispatch]);
|
|
212
|
+
|
|
213
|
+
// Stable, so fields do not re-register on every draft change.
|
|
214
|
+
var registerField = React.useCallback((name, element) => {
|
|
215
|
+
fieldsRef.current.set(name, element);
|
|
216
|
+
return () => {
|
|
217
|
+
if (fieldsRef.current.get(name) === element) fieldsRef.current.delete(name);
|
|
218
|
+
};
|
|
219
|
+
}, []);
|
|
220
|
+
var validate = React.useCallback(() => {
|
|
221
|
+
var draft = stateRef.current.draft;
|
|
222
|
+
var errors = {};
|
|
223
|
+
Object.keys(draft).forEach(name => {
|
|
224
|
+
var field = draft[name];
|
|
225
|
+
if (field.required && isMrlMultiFilterValueEmpty(field.value)) errors[name] = true;
|
|
226
|
+
});
|
|
227
|
+
dispatch({
|
|
228
|
+
errors,
|
|
229
|
+
type: 'SET_ERRORS'
|
|
230
|
+
});
|
|
231
|
+
focusFirstInvalidField(fieldsRef.current, errors);
|
|
232
|
+
return Object.keys(errors).length === 0;
|
|
233
|
+
}, [dispatch]);
|
|
234
|
+
var contextValue = React.useMemo(() => _objectSpread2(_objectSpread2({}, state), {}, {
|
|
235
|
+
applied,
|
|
236
|
+
commit,
|
|
237
|
+
discard,
|
|
238
|
+
getDraft,
|
|
239
|
+
registerField,
|
|
240
|
+
reset,
|
|
241
|
+
setFieldValue,
|
|
242
|
+
setRequired,
|
|
243
|
+
validate
|
|
244
|
+
}), [applied, commit, discard, getDraft, registerField, reset, setFieldValue, setRequired, state, validate]);
|
|
245
|
+
return /*#__PURE__*/React.createElement(MrlMultiFilterContext.Provider, {
|
|
246
|
+
value: contextValue
|
|
247
|
+
}, children);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Custom hook to use the MrlMultiFilterContext.
|
|
252
|
+
*
|
|
253
|
+
* This hook provides access to the MrlMultiFilterContext value. React context cannot be
|
|
254
|
+
* generic, so pass the filter values type to get a typed draft.
|
|
255
|
+
*
|
|
256
|
+
* @returns The MrlMultiFilterContext value.
|
|
257
|
+
* @throws Will throw an error if used outside of a MrlMultiFilterContextProvider.
|
|
258
|
+
*/
|
|
259
|
+
var useMrlMultiFilterContext = () => {
|
|
260
|
+
var context = React.useContext(MrlMultiFilterContext);
|
|
261
|
+
if (!context) {
|
|
262
|
+
throw new Error('useMrlMultiFilterContext must be used within a MrlMultiFilterContextProvider');
|
|
263
|
+
}
|
|
264
|
+
return context;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Same as useMrlMultiFilterContext, but returns `undefined` outside a provider, so
|
|
269
|
+
* MrlMultiFilterField also works on its own.
|
|
270
|
+
*
|
|
271
|
+
* @returns The MrlMultiFilterContext value, or `undefined`.
|
|
272
|
+
*/
|
|
273
|
+
var useOptionalMrlMultiFilterContext = () => React.useContext(MrlMultiFilterContext);
|
|
274
|
+
|
|
275
|
+
export { MrlMultiFilterContextProvider, getDraftValues, isMrlMultiFilterValueEmpty, useMrlMultiFilterContext, useOptionalMrlMultiFilterContext };
|
|
276
|
+
//# sourceMappingURL=MrlMultiFilterContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MrlMultiFilterContext.js","sources":["../../../../../src/components/multi-filter/MrlMultiFilterContext/MrlMultiFilterContext.tsx"],"sourcesContent":["import * as React from 'react';\nimport { focusFirstInvalidField } from '../utils';\n\n/**\n * Values of the filters, keyed by field name.\n */\nexport type MrlMultiFilterValues = Record<string, unknown>;\n\n/**\n * One field of the draft.\n */\nexport type MrlMultiFilterDraftField<V> = {\n\t/**\n\t * Whether Apply is blocked while the value is empty (`null`, `undefined`, `''` or `[]`;\n\t * `false` is not empty). Defaults to `false`. Change it at runtime with `setRequired`.\n\t */\n\trequired?: boolean;\n\t/**\n\t * The field's value.\n\t */\n\tvalue: V;\n};\n\n/**\n * Filters as a value and a required flag per field. Used for the draft being edited and for\n * the applied filters.\n */\nexport type MrlMultiFilterDraft<T extends MrlMultiFilterValues> = {\n\t[K in keyof T]: MrlMultiFilterDraftField<T[K]>;\n};\n\n/**\n * Fields that failed validation, keyed by field name.\n */\nexport type MrlMultiFilterErrors<T extends MrlMultiFilterValues> = Partial<Record<keyof T, true>>;\n\ntype MrlMultiFilterState<T extends MrlMultiFilterValues> = {\n\t/**\n\t * The last applied draft. Cancel sets the draft back to it. When controlled, it follows\n\t * `appliedDraft`.\n\t */\n\tapplied: MrlMultiFilterDraft<T>;\n\t/**\n\t * The draft being edited. MrlMultiFilter sets it back to the applied draft on each open.\n\t */\n\tdraft: MrlMultiFilterDraft<T>;\n\t/**\n\t * Fields that failed validation.\n\t */\n\terrors: MrlMultiFilterErrors<T>;\n};\n\ntype MrlMultiFilterAction<T extends MrlMultiFilterValues> =\n\t| { name: keyof T; type: 'SET_FIELD_VALUE'; value: T[keyof T] }\n\t| { name: keyof T; required: boolean; type: 'SET_REQUIRED' }\n\t| { errors: MrlMultiFilterErrors<T>; type: 'SET_ERRORS' }\n\t| { controlled: boolean; type: 'APPLY' }\n\t| { type: 'CANCEL' }\n\t| { draft: MrlMultiFilterDraft<T>; type: 'RESET' }\n\t| { applied: MrlMultiFilterDraft<T>; type: 'SYNC_APPLIED' };\n\n/**\n * Whether a value counts as empty. `false` is a value, so it is not empty.\n *\n * @param value - The field value.\n * @returns Whether the value is empty.\n */\nexport const isMrlMultiFilterValueEmpty = (value: unknown): boolean =>\n\tvalue === null ||\n\tvalue === undefined ||\n\tvalue === '' ||\n\t(Array.isArray(value) && value.length === 0);\n\n/**\n * Returns the plain values of a draft, without the required flags. A common `transform`.\n *\n * @param draft - The draft.\n * @returns The values, keyed by field name.\n */\nexport const getDraftValues = <T extends MrlMultiFilterValues>(draft: MrlMultiFilterDraft<T>): T =>\n\tObject.fromEntries(\n\t\tObject.entries(draft).map(([name, field]) => [\n\t\t\tname,\n\t\t\t(field as MrlMultiFilterDraftField<unknown>).value\n\t\t])\n\t) as T;\n\n/**\n * Removes one field's error.\n *\n * @param errors - The current errors.\n * @param name - The field name.\n * @returns The errors without that field.\n */\nconst withoutError = <T extends MrlMultiFilterValues>(\n\terrors: MrlMultiFilterErrors<T>,\n\tname: keyof T\n): MrlMultiFilterErrors<T> => {\n\tif (!errors[name]) return errors;\n\tconst next = { ...errors };\n\tdelete next[name];\n\treturn next;\n};\n\nconst mrlMultiFilterReducer = <T extends MrlMultiFilterValues>(\n\tstate: MrlMultiFilterState<T>,\n\taction: MrlMultiFilterAction<T>\n): MrlMultiFilterState<T> => {\n\tswitch (action.type) {\n\t\tcase 'SET_FIELD_VALUE': {\n\t\t\t// Editing a field clears its error.\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tdraft: {\n\t\t\t\t\t...state.draft,\n\t\t\t\t\t[action.name]: { ...state.draft[action.name], value: action.value }\n\t\t\t\t},\n\t\t\t\terrors: withoutError(state.errors, action.name)\n\t\t\t};\n\t\t}\n\t\tcase 'SET_REQUIRED': {\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tdraft: {\n\t\t\t\t\t...state.draft,\n\t\t\t\t\t[action.name]: { ...state.draft[action.name], required: action.required }\n\t\t\t\t},\n\t\t\t\terrors: action.required ? state.errors : withoutError(state.errors, action.name)\n\t\t\t};\n\t\t}\n\t\tcase 'SET_ERRORS': {\n\t\t\treturn { ...state, errors: action.errors };\n\t\t}\n\t\tcase 'APPLY': {\n\t\t\t// Controlled: the applied draft only changes when the consumer passes a new one.\n\t\t\treturn { ...state, applied: action.controlled ? state.applied : state.draft, errors: {} };\n\t\t}\n\t\tcase 'CANCEL': {\n\t\t\treturn { ...state, draft: state.applied, errors: {} };\n\t\t}\n\t\tcase 'RESET': {\n\t\t\treturn { ...state, draft: action.draft, errors: {} };\n\t\t}\n\t\tcase 'SYNC_APPLIED': {\n\t\t\treturn { applied: action.applied, draft: action.applied, errors: {} };\n\t\t}\n\t\tdefault:\n\t\t\treturn state;\n\t}\n};\n\n/**\n * The context value. Every function keeps its identity across renders, so it can be passed to\n * effects and callbacks without changing on each draft edit. `getDraft` and `validate` read the\n * latest draft, including edits made earlier in the same event handler.\n */\nexport type MrlMultiFilterContextValue<T extends MrlMultiFilterValues> = MrlMultiFilterState<T> & {\n\t/**\n\t * Saves the draft as the applied one and clears the errors. Call `validate` first.\n\t */\n\tcommit: () => void;\n\t/**\n\t * Sets the draft back to the last applied draft and clears the errors.\n\t */\n\tdiscard: () => void;\n\t/**\n\t * Returns the latest draft. Unlike `draft`, it includes edits made earlier in the same event\n\t * handler, before React re-renders.\n\t */\n\tgetDraft: () => MrlMultiFilterDraft<T>;\n\t/**\n\t * Registers a field's element, so validation can focus it. Returns a function that\n\t * unregisters it.\n\t */\n\tregisterField: (name: keyof T, element: HTMLElement) => () => void;\n\t/**\n\t * Replaces the draft and clears the errors.\n\t */\n\treset: (draft: MrlMultiFilterDraft<T>) => void;\n\t/**\n\t * Updates one field's value in the draft and clears its error.\n\t */\n\tsetFieldValue: <K extends keyof T>(name: K, value: T[K]) => void;\n\t/**\n\t * Updates one field's required flag in the draft. Turning it off clears the field's error.\n\t */\n\tsetRequired: (name: keyof T, required: boolean) => void;\n\t/**\n\t * Checks the required fields of the latest draft. Marks the empty ones and focuses the first\n\t * of them.\n\t *\n\t * @returns Whether the draft is valid.\n\t */\n\tvalidate: () => boolean;\n};\n\n/**\n * Context for the MrlMultiFilter component.\n *\n * Holds the draft (the filters being edited), the last applied draft and the validation\n * errors. The provider wraps the trigger and the popover, outside the popover content, so the\n * applied draft survives the popover content unmounting. It is used internally by the\n * MrlMultiFilterContextProvider and can be accessed via the useMrlMultiFilterContext hook.\n */\nconst MrlMultiFilterContext = React.createContext<\n\tMrlMultiFilterContextValue<MrlMultiFilterValues> | undefined\n>(undefined);\n\ntype MrlMultiFilterContextProviderProps<T extends MrlMultiFilterValues> = {\n\t/**\n\t * Controls the applied draft. When it changes, the draft is replaced by it, dropping any\n\t * unapplied edits. When omitted, the provider keeps the applied draft itself.\n\t */\n\tappliedDraft?: MrlMultiFilterDraft<T>;\n\tchildren: React.ReactNode;\n\t/**\n\t * The draft and the applied draft start from it, unless `appliedDraft` is given. Later\n\t * changes are ignored.\n\t */\n\tinitialDraft: MrlMultiFilterDraft<T>;\n};\n\n/**\n * MrlMultiFilterContextProvider component.\n *\n * @param props - The component props.\n * @returns The MrlMultiFilterContextProvider component.\n */\nexport function MrlMultiFilterContextProvider<T extends MrlMultiFilterValues>(\n\tprops: MrlMultiFilterContextProviderProps<T>\n): JSX.Element {\n\tconst { appliedDraft, children, initialDraft } = props;\n\n\tconst startDraft = appliedDraft ?? initialDraft;\n\t/**\n\t * The latest state lives in a ref, updated as soon as an action runs, and is mirrored into\n\t * React state to re-render. Reading the ref lets `getDraft` and `validate` see edits made\n\t * earlier in the same event handler, e.g. `setFieldValue(...); apply();`. React state alone\n\t * only updates on the next render.\n\t */\n\tconst stateRef = React.useRef<MrlMultiFilterState<T>>({\n\t\tapplied: startDraft,\n\t\tdraft: startDraft,\n\t\terrors: {}\n\t});\n\tconst [state, setState] = React.useState(stateRef.current);\n\tconst dispatch = React.useCallback((action: MrlMultiFilterAction<T>) => {\n\t\tstateRef.current = mrlMultiFilterReducer(stateRef.current, action);\n\t\tsetState(stateRef.current);\n\t}, []);\n\tconst fieldsRef = React.useRef(new Map<keyof T, HTMLElement>());\n\n\t// Controlled: the applied draft comes from the prop. Read it from the prop, not the state,\n\t// so the badge does not wait for the sync below.\n\tconst applied = appliedDraft ?? state.applied;\n\n\t// Controlled: a new applied draft replaces the applied draft in the state and the draft,\n\t// e.g. when filters are cleared from outside the popover. Keeping it in the state lets\n\t// Cancel go back to it without depending on the prop.\n\tconst previousAppliedDraftRef = React.useRef(appliedDraft);\n\tReact.useEffect(() => {\n\t\tif (appliedDraft === previousAppliedDraftRef.current) return;\n\t\tpreviousAppliedDraftRef.current = appliedDraft;\n\t\tif (appliedDraft) dispatch({ applied: appliedDraft, type: 'SYNC_APPLIED' });\n\t}, [appliedDraft, dispatch]);\n\n\t// Stable: they only dispatch or read the ref. `commit` only changes when switching between controlled and\n\t// uncontrolled.\n\t// Same check as `applied` above, so a `null` from untyped code counts as uncontrolled.\n\tconst controlled = appliedDraft != null;\n\tconst commit = React.useCallback(\n\t\t() => dispatch({ controlled, type: 'APPLY' }),\n\t\t[controlled, dispatch]\n\t);\n\tconst discard = React.useCallback(() => dispatch({ type: 'CANCEL' }), [dispatch]);\n\tconst getDraft = React.useCallback(() => stateRef.current.draft, []);\n\tconst reset = React.useCallback(\n\t\t(draft: MrlMultiFilterDraft<T>) => dispatch({ draft, type: 'RESET' }),\n\t\t[dispatch]\n\t);\n\tconst setFieldValue = React.useCallback(\n\t\t<K extends keyof T>(name: K, value: T[K]) => dispatch({ name, type: 'SET_FIELD_VALUE', value }),\n\t\t[dispatch]\n\t);\n\tconst setRequired = React.useCallback(\n\t\t(name: keyof T, required: boolean) => dispatch({ name, required, type: 'SET_REQUIRED' }),\n\t\t[dispatch]\n\t);\n\n\t// Stable, so fields do not re-register on every draft change.\n\tconst registerField = React.useCallback((name: keyof T, element: HTMLElement) => {\n\t\tfieldsRef.current.set(name, element);\n\t\treturn () => {\n\t\t\tif (fieldsRef.current.get(name) === element) fieldsRef.current.delete(name);\n\t\t};\n\t}, []);\n\n\tconst validate = React.useCallback(() => {\n\t\tconst { draft } = stateRef.current;\n\t\tconst errors: MrlMultiFilterErrors<T> = {};\n\t\t(Object.keys(draft) as (keyof T)[]).forEach((name) => {\n\t\t\tconst field = draft[name];\n\t\t\tif (field.required && isMrlMultiFilterValueEmpty(field.value)) errors[name] = true;\n\t\t});\n\t\tdispatch({ errors, type: 'SET_ERRORS' });\n\n\t\tfocusFirstInvalidField(fieldsRef.current, errors);\n\n\t\treturn Object.keys(errors).length === 0;\n\t}, [dispatch]);\n\n\tconst contextValue = React.useMemo<MrlMultiFilterContextValue<T>>(\n\t\t() => ({\n\t\t\t...state,\n\t\t\tapplied,\n\t\t\tcommit,\n\t\t\tdiscard,\n\t\t\tgetDraft,\n\t\t\tregisterField,\n\t\t\treset,\n\t\t\tsetFieldValue,\n\t\t\tsetRequired,\n\t\t\tvalidate\n\t\t}),\n\t\t[\n\t\t\tapplied,\n\t\t\tcommit,\n\t\t\tdiscard,\n\t\t\tgetDraft,\n\t\t\tregisterField,\n\t\t\treset,\n\t\t\tsetFieldValue,\n\t\t\tsetRequired,\n\t\t\tstate,\n\t\t\tvalidate\n\t\t]\n\t);\n\n\treturn (\n\t\t<MrlMultiFilterContext.Provider\n\t\t\tvalue={contextValue as unknown as MrlMultiFilterContextValue<MrlMultiFilterValues>}\n\t\t>\n\t\t\t{children}\n\t\t</MrlMultiFilterContext.Provider>\n\t);\n}\n\n/**\n * Custom hook to use the MrlMultiFilterContext.\n *\n * This hook provides access to the MrlMultiFilterContext value. React context cannot be\n * generic, so pass the filter values type to get a typed draft.\n *\n * @returns The MrlMultiFilterContext value.\n * @throws Will throw an error if used outside of a MrlMultiFilterContextProvider.\n */\nexport const useMrlMultiFilterContext = <\n\tT extends MrlMultiFilterValues = MrlMultiFilterValues\n>(): MrlMultiFilterContextValue<T> => {\n\tconst context = React.useContext(MrlMultiFilterContext);\n\tif (!context) {\n\t\tthrow new Error('useMrlMultiFilterContext must be used within a MrlMultiFilterContextProvider');\n\t}\n\treturn context as unknown as MrlMultiFilterContextValue<T>;\n};\n\n/**\n * Same as useMrlMultiFilterContext, but returns `undefined` outside a provider, so\n * MrlMultiFilterField also works on its own.\n *\n * @returns The MrlMultiFilterContext value, or `undefined`.\n */\nexport const useOptionalMrlMultiFilterContext = ():\n\t| MrlMultiFilterContextValue<MrlMultiFilterValues>\n\t| undefined => React.useContext(MrlMultiFilterContext);\n"],"names":["isMrlMultiFilterValueEmpty","value","undefined","Array","isArray","length","getDraftValues","draft","Object","fromEntries","entries","map","_ref","_ref2","_slicedToArray","name","field","withoutError","errors","next","_objectSpread","mrlMultiFilterReducer","state","action","type","required","applied","controlled","MrlMultiFilterContext","React","createContext","MrlMultiFilterContextProvider","props","appliedDraft","children","initialDraft","startDraft","stateRef","useRef","_React$useState","useState","current","_React$useState2","setState","dispatch","useCallback","fieldsRef","Map","previousAppliedDraftRef","useEffect","commit","discard","getDraft","reset","setFieldValue","setRequired","registerField","element","set","get","delete","validate","keys","forEach","focusFirstInvalidField","contextValue","useMemo","createElement","Provider","useMrlMultiFilterContext","context","useContext","Error","useOptionalMrlMultiFilterContext"],"mappings":";;;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAaA;AACA;AACA;AACA;;AAKA;AACA;AACA;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,0BAA0B,GAAIC,KAAc,IACxDA,KAAK,KAAK,IAAI,IACdA,KAAK,KAAKC,SAAS,IACnBD,KAAK,KAA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ACbH,KAAK;IACLC,aAAa;IACbC,WAAW;AACXM,IAAAA;GAAQ,CACP,EACF,CACCnC,OAAO,EACPwB,MAAM,EACNC,OAAO,EACPC,QAAQ,EACRI,aAAa,EACbH,KAAK,EACLC,aAAa,EACbC,WAAW,EACXjC,KAAK,EACLuC,QAAQ,CAEV,CAAC;AAED,EAAA,oBACChC,KAAA,CAAAsC,aAAA,CAACvC,qBAAqB,CAACwC,QAAQ,EAAA;AAC9BnE,IAAAA,KAAK,EAAEgE;AAA4E,GAAA,EAElF/B,QAC8B,CAAC;AAEnC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMmC,wBAAwB,GAAGA,MAEF;AACrC,EAAA,IAAMC,OAAO,GAAGzC,KAAK,CAAC0C,UAAU,CAAC3C,qBAAqB,CAAC;EACvD,IAAI,CAAC0C,OAAO,EAAE;AACb,IAAA,MAAM,IAAIE,KAAK,CAAC,8EAA8E,CAAC;AAChG,EAAA;AACA,EAAA,OAAOF,OAAO;AACf;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMG,gCAAgC,GAAGA,MAEhC5C,KAAK,CAAC0C,UAAU,CAAC3C,qBAAqB;;;;"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { objectWithoutProperties as _objectWithoutProperties, extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
import styles from './MrlMultiFilterField.module.scss.js';
|
|
5
|
+
import { MrlInlineMessage } from '../../notification/MrlInlineMessage/MrlInlineMessage.js';
|
|
6
|
+
import { useOptionalMrlMultiFilterContext } from '../MrlMultiFilterContext/MrlMultiFilterContext.js';
|
|
7
|
+
import { getUniqueId } from '../../../utils/setAttributes/setAttributes.js';
|
|
8
|
+
|
|
9
|
+
var _excluded = ["children", "className", "data-qa", "errorMessage", "field", "requiredMessage"];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A field of the MrlMultiFilter draft, returned by `getField` from its render prop.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A field that never shows an error: plain children, no `errorMessage`.
|
|
17
|
+
*
|
|
18
|
+
* Docgen merges the JSDoc of the union members (this one first), so each comment below is
|
|
19
|
+
* written to read on its own and as the first part of the merged description.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A field that can show an error: `children` must be a function so the consumer can link the
|
|
24
|
+
* error message to the form element.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A field bound to the MrlMultiFilter draft through `field`.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* MrlMultiFilterField component.
|
|
33
|
+
*
|
|
34
|
+
* Wraps a single filter control of the MrlMultiFilter and shows an inline error message
|
|
35
|
+
* below it when `errorMessage` is set. `errorMessage` requires `children` to be a render
|
|
36
|
+
* function, which receives `errorId` and `hasError` so the error is always linked to the form
|
|
37
|
+
* element and its invalid state matches the message. Pass `field={getField('name')}` from the
|
|
38
|
+
* MrlMultiFilter render prop to bind the field to the draft: the function then also receives
|
|
39
|
+
* the typed `value`, `setValue` and `required`, and the required error is shown on Apply.
|
|
40
|
+
*
|
|
41
|
+
* @param props - The component props.
|
|
42
|
+
* @returns The MrlMultiFilterField component.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
// Overloads, so TypeScript types the render function of a bound and an unbound field.
|
|
46
|
+
function MrlMultiFilterField(props) {
|
|
47
|
+
var children = props.children,
|
|
48
|
+
className = props.className,
|
|
49
|
+
dataQa = props['data-qa'],
|
|
50
|
+
errorMessage = props.errorMessage,
|
|
51
|
+
field = props.field,
|
|
52
|
+
requiredMessage = props.requiredMessage,
|
|
53
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
54
|
+
var context = useOptionalMrlMultiFilterContext();
|
|
55
|
+
var registerField = context === null || context === void 0 ? void 0 : context.registerField;
|
|
56
|
+
var name = field === null || field === void 0 ? void 0 : field.name;
|
|
57
|
+
var elementRef = React.useRef(null);
|
|
58
|
+
var errorIdRef = React.useRef(getUniqueId('mrl-multi-filter-field-error'));
|
|
59
|
+
|
|
60
|
+
// Register the element, so validation can focus the field.
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
if (name === undefined || !registerField || !elementRef.current) return;
|
|
63
|
+
return registerField(name, elementRef.current);
|
|
64
|
+
}, [name, registerField]);
|
|
65
|
+
var requiredError = field !== null && field !== void 0 && field.error ? requiredMessage !== null && requiredMessage !== void 0 ? requiredMessage : field.error : undefined;
|
|
66
|
+
var message = errorMessage !== null && errorMessage !== void 0 ? errorMessage : requiredError;
|
|
67
|
+
var hasError = Boolean(message);
|
|
68
|
+
var errorId = hasError ? errorIdRef.current : undefined;
|
|
69
|
+
var renderChildren = () => {
|
|
70
|
+
if (typeof children !== 'function') return children;
|
|
71
|
+
if (!field) {
|
|
72
|
+
return children({
|
|
73
|
+
errorId,
|
|
74
|
+
hasError
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return children({
|
|
78
|
+
errorId,
|
|
79
|
+
hasError,
|
|
80
|
+
required: field.required,
|
|
81
|
+
setValue: field.setValue,
|
|
82
|
+
value: field.value
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
86
|
+
className: classnames(styles['MrlMultiFilterField'], 'MrlMultiFilterField', className),
|
|
87
|
+
"data-qa": dataQa,
|
|
88
|
+
ref: elementRef
|
|
89
|
+
}), renderChildren(), errorId && /*#__PURE__*/React.createElement(MrlInlineMessage, {
|
|
90
|
+
id: errorId,
|
|
91
|
+
kind: "error",
|
|
92
|
+
message: message
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { MrlMultiFilterField };
|
|
97
|
+
//# sourceMappingURL=MrlMultiFilterField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MrlMultiFilterField.js","sources":["../../../../../src/components/multi-filter/MrlMultiFilterField/MrlMultiFilterField.tsx"],"sourcesContent":["import * as React from 'react';\nimport classnames from 'classnames';\nimport styles from './MrlMultiFilterField.module.scss';\nimport { MrlInlineMessage } from '../../notification/MrlInlineMessage/MrlInlineMessage';\nimport { useOptionalMrlMultiFilterContext } from '../MrlMultiFilterContext/MrlMultiFilterContext';\nimport { DataQa } from '../../../utils/dataQa';\nimport { getUniqueId } from '../../../utils/setAttributes/setAttributes';\n\nexport type MrlMultiFilterFieldRenderProps = {\n\t/**\n\t * Id of the rendered error message, or `undefined` when there is no error. Pass it to the\n\t * form element's `aria-errormessage` (with `aria-invalid`) or `aria-describedby` so the\n\t * error is announced with the field.\n\t */\n\terrorId?: string;\n\t/**\n\t * Whether the field is showing an error. Pass it to the form element's `hasError` (or\n\t * `aria-invalid`) so its error styles and invalid state match the message.\n\t */\n\thasError: boolean;\n};\n\n/**\n * A field of the MrlMultiFilter draft, returned by `getField` from its render prop.\n */\nexport type MrlMultiFilterFieldBinding<V> = {\n\t/**\n\t * The required error message, set while the field is required and empty after Apply.\n\t */\n\terror?: string;\n\t/**\n\t * Name of the field in the draft.\n\t */\n\tname: string;\n\t/**\n\t * Whether the field is required.\n\t */\n\trequired: boolean;\n\t/**\n\t * Updates the field's value in the draft.\n\t */\n\tsetValue: (value: V) => void;\n\t/**\n\t * The field's value in the draft.\n\t */\n\tvalue: V;\n};\n\nexport type MrlMultiFilterFieldBoundRenderProps<V> = MrlMultiFilterFieldRenderProps &\n\tPick<MrlMultiFilterFieldBinding<V>, 'required' | 'setValue' | 'value'>;\n\n/**\n * A field that never shows an error: plain children, no `errorMessage`.\n *\n * Docgen merges the JSDoc of the union members (this one first), so each comment below is\n * written to read on its own and as the first part of the merged description.\n */\ntype MrlMultiFilterFieldWithoutErrorProps = {\n\t/**\n\t * The field content, usually a label and a form element.\n\t */\n\tchildren?: React.ReactNode;\n\t/**\n\t * Error message shown below the field. When omitted, no error is rendered.\n\t */\n\terrorMessage?: never;\n\t/**\n\t * Binds the field to the MrlMultiFilter draft. Pass `getField('name')` from the\n\t * MrlMultiFilter render prop.\n\t */\n\tfield?: never;\n\t/**\n\t * Message shown when the field is required and empty on Apply. Defaults to the\n\t * MrlMultiFilter `requiredMessage`.\n\t */\n\trequiredMessage?: never;\n};\n\n/**\n * A field that can show an error: `children` must be a function so the consumer can link the\n * error message to the form element.\n */\ntype MrlMultiFilterFieldWithErrorProps = Omit<\n\tMrlMultiFilterFieldWithoutErrorProps,\n\t'children' | 'errorMessage'\n> & {\n\t/**\n\t * To show an error, pass a function instead. It receives `errorId` and `hasError`: pass\n\t * them to the form element's `aria-errormessage` and `hasError` (or `aria-invalid`).\n\t */\n\tchildren: (renderProps: MrlMultiFilterFieldRenderProps) => React.ReactNode;\n\t/**\n\t * Requires `children` to be a function, so the message can be linked to the form element.\n\t */\n\terrorMessage?: string;\n};\n\n/**\n * A field bound to the MrlMultiFilter draft through `field`.\n */\ntype MrlMultiFilterFieldBoundProps<V> = {\n\t/**\n\t * With `field`, the function also receives `value`, `setValue` and `required`.\n\t */\n\tchildren: (renderProps: MrlMultiFilterFieldBoundRenderProps<V>) => React.ReactNode;\n\t/**\n\t * Takes precedence over the required error.\n\t */\n\terrorMessage?: string;\n\t/**\n\t * Must come from the same MrlMultiFilter.\n\t */\n\tfield: MrlMultiFilterFieldBinding<V>;\n\t/**\n\t * Overrides it for this field.\n\t */\n\trequiredMessage?: string;\n};\n\ntype MrlMultiFilterFieldBaseProps = Omit<React.ComponentPropsWithoutRef<'div'>, 'children'> &\n\tDataQa;\n\nexport type MrlMultiFilterFieldProps<V = unknown> = (\n\t| MrlMultiFilterFieldWithoutErrorProps\n\t| MrlMultiFilterFieldWithErrorProps\n\t| MrlMultiFilterFieldBoundProps<V>\n) &\n\tMrlMultiFilterFieldBaseProps;\n\n/**\n * MrlMultiFilterField component.\n *\n * Wraps a single filter control of the MrlMultiFilter and shows an inline error message\n * below it when `errorMessage` is set. `errorMessage` requires `children` to be a render\n * function, which receives `errorId` and `hasError` so the error is always linked to the form\n * element and its invalid state matches the message. Pass `field={getField('name')}` from the\n * MrlMultiFilter render prop to bind the field to the draft: the function then also receives\n * the typed `value`, `setValue` and `required`, and the required error is shown on Apply.\n *\n * @param props - The component props.\n * @returns The MrlMultiFilterField component.\n */\nexport function MrlMultiFilterField<V>(\n\tprops: MrlMultiFilterFieldBoundProps<V> & MrlMultiFilterFieldBaseProps\n): React.ReactElement;\nexport function MrlMultiFilterField(\n\tprops: (MrlMultiFilterFieldWithoutErrorProps | MrlMultiFilterFieldWithErrorProps) &\n\t\tMrlMultiFilterFieldBaseProps\n): React.ReactElement;\n// Overloads, so TypeScript types the render function of a bound and an unbound field.\nexport function MrlMultiFilterField<V>(props: MrlMultiFilterFieldProps<V>): React.ReactElement {\n\tconst {\n\t\tchildren,\n\t\tclassName,\n\t\t['data-qa']: dataQa,\n\t\terrorMessage,\n\t\tfield,\n\t\trequiredMessage,\n\t\t...rest\n\t} = props;\n\n\tconst context = useOptionalMrlMultiFilterContext();\n\tconst registerField = context?.registerField;\n\tconst name = field?.name;\n\n\tconst elementRef = React.useRef<HTMLDivElement>(null);\n\tconst errorIdRef = React.useRef<string>(getUniqueId('mrl-multi-filter-field-error'));\n\n\t// Register the element, so validation can focus the field.\n\tReact.useEffect(() => {\n\t\tif (name === undefined || !registerField || !elementRef.current) return;\n\t\treturn registerField(name, elementRef.current);\n\t}, [name, registerField]);\n\n\tconst requiredError = field?.error ? (requiredMessage ?? field.error) : undefined;\n\tconst message = errorMessage ?? requiredError;\n\tconst hasError = Boolean(message);\n\tconst errorId = hasError ? errorIdRef.current : undefined;\n\n\tconst renderChildren = () => {\n\t\tif (typeof children !== 'function') return children;\n\t\tif (!field) {\n\t\t\treturn (children as MrlMultiFilterFieldWithErrorProps['children'])({ errorId, hasError });\n\t\t}\n\t\treturn (children as MrlMultiFilterFieldBoundProps<V>['children'])({\n\t\t\terrorId,\n\t\t\thasError,\n\t\t\trequired: field.required,\n\t\t\tsetValue: field.setValue,\n\t\t\tvalue: field.value\n\t\t});\n\t};\n\n\treturn (\n\t\t<div\n\t\t\t{...rest}\n\t\t\tclassName={classnames(styles['MrlMultiFilterField'], 'MrlMultiFilterField', className)}\n\t\t\tdata-qa={dataQa}\n\t\t\tref={elementRef}\n\t\t>\n\t\t\t{renderChildren()}\n\t\t\t{errorId && <MrlInlineMessage id={errorId} kind=\"error\" message={message} />}\n\t\t</div>\n\t);\n}\n"],"names":["MrlMultiFilterField","props","children","className","dataQa","errorMessage","field","requiredMessage","rest","_objectWithoutProperties","_excluded","context","useOptionalMrlMultiFilterContext","registerField","name","elementRef","React","useRef","errorIdRef","getUniqueId","useEffect","undefined","current","requiredError","error","message","hasError","Boolean","errorId","renderChildren","required","setValue","value","createElement","_extends","classnames","styles","ref","MrlInlineMessage","id","kind"],"mappings":";;;;;;;;;;AAsBA;AACA;AACA;;AA2BA;AACA;AACA;AACA;AACA;AACA;;AAsBA;AACA;AACA;AACA;;AAgBA;AACA;AACA;;AA8BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACO,SAASA,mBAAmBA,CAAIC,KAAkC,EAAsB;AAC9F,EAAA,IACCC,QAAQ,GAOLD,KAAK,CAPRC,QAAQ;IACRC,SAAS,GAMNF,KAAK,CANRE,SAAS;IACIC,MAAM,GAKhBH,KAAK,CALP,SAAS,CAAA;IACVI,YAAY,GAITJ,KAAK,CAJRI,YAAY;IACZC,KAAK,GAGFL,KAAK,CAHRK,KAAK;IACLC,eAAe,GAEZN,KAAK,CAFRM,eAAe;AACZC,IAAAA,IAAI,GAAAC,wBAAA,CACJR,KAAK,EAAAS,SAAA,CAAA;AAET,EAAA,IAAMC,OAAO,GAAGC,gCAAgC,EAAE;EAClD,IAAMC,aAAa,GAAGF,OAAO,KAAA,IAAA,IAAPA,OAAO,KAAA,MAAA,GAAA,MAA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jE0B,OAAO;MACPF,QAAQ;MACRI,QAAQ,EAAExB,KAAK,CAACwB,QAAQ;MACxBC,QAAQ,EAAEzB,KAAK,CAACyB,QAAQ;MACxBC,KAAK,EAAE1B,KAAK,CAAC0B;AACd,KAAC,CAAC;EACH,CAAC;AAED,EAAA,oBACChB,KAAA,CAAAiB,aAAA,CAAA,KAAA,EAAAC,QAAA,KACK1B,IAAI,EAAA;IACRL,SAAS,EAAEgC,UAAU,CAACC,MAAM,CAAC,qBAAqB,CAAC,EAAE,qBAAqB,EAAEjC,SAAS,CAAE;AACvF,IAAA,SAAA,EAASC,MAAO;AAChBiC,IAAAA,GAAG,EAAEtB;GAAW,CAAA,EAEfc,cAAc,EAAE,EAChBD,OAAO,iBAAIZ,KAAA,CAAAiB,aAAA,CAACK,gBAAgB,EAAA;AAACC,IAAAA,EAAE,EAAEX,OAAQ;AAACY,IAAAA,IAAI,EAAC,OAAO;AAACf,IAAAA,OAAO,EAAEA;AAAQ,GAAE,CACvE,CAAC;AAER;;;;"}
|
package/dist/esm/components/multi-filter/MrlMultiFilterField/MrlMultiFilterField.module.scss.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MrlMultiFilterField.module.scss.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import classnames from 'classnames';
|
|
3
|
+
import { refine } from '@muraldevkit/ds-icons';
|
|
4
|
+
import { MrlButton } from '../../button/MrlButton/MrlButton.js';
|
|
5
|
+
import { MrlBadgeNotification } from '../../badge/MrlBadgeNotification/MrlBadgeNotification.js';
|
|
6
|
+
import { MrlSvg } from '../../svg/MrlSvg/MrlSvg.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* MrlMultiFilterTrigger component.
|
|
10
|
+
*
|
|
11
|
+
* The button that opens the MrlMultiFilter. Shows the refine icon after the label and,
|
|
12
|
+
* when filters are active, a numeric badge with the active filter count.
|
|
13
|
+
*
|
|
14
|
+
* @param props - The component props.
|
|
15
|
+
* @returns The MrlMultiFilterTrigger component.
|
|
16
|
+
*/
|
|
17
|
+
var MrlMultiFilterTrigger = /*#__PURE__*/React.forwardRef(function MrlMultiFilterTrigger(props, ref) {
|
|
18
|
+
var className = props.className,
|
|
19
|
+
_props$activeFiltersC = props.activeFiltersCount,
|
|
20
|
+
activeFiltersCount = _props$activeFiltersC === void 0 ? 0 : _props$activeFiltersC,
|
|
21
|
+
dataQa = props['data-qa'],
|
|
22
|
+
_props$isOpen = props.isOpen,
|
|
23
|
+
isOpen = _props$isOpen === void 0 ? false : _props$isOpen,
|
|
24
|
+
notificationText = props.notificationText,
|
|
25
|
+
_props$size = props.size,
|
|
26
|
+
size = _props$size === void 0 ? 'small' : _props$size,
|
|
27
|
+
state = props.state,
|
|
28
|
+
text = props.text;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* `controlledState` overrides `state` in MrlButton, so both are folded into it. Always
|
|
32
|
+
* passing it also stops MrlButton from toggling its own selected state on click.
|
|
33
|
+
*/
|
|
34
|
+
var isDisabled = state === 'disabled';
|
|
35
|
+
var controlledState = isOpen ? isDisabled ? 'selected-disabled' : 'selected' : isDisabled ? 'disabled' : 'default';
|
|
36
|
+
return /*#__PURE__*/React.createElement(MrlButton, {
|
|
37
|
+
badge: activeFiltersCount > 0 ? /*#__PURE__*/React.createElement(MrlBadgeNotification, {
|
|
38
|
+
notificationText: notificationText !== null && notificationText !== void 0 ? notificationText : "".concat(activeFiltersCount, " active filters"),
|
|
39
|
+
number: activeFiltersCount
|
|
40
|
+
}) : undefined,
|
|
41
|
+
className: classnames('MrlMultiFilterTrigger', className),
|
|
42
|
+
controlledState: controlledState,
|
|
43
|
+
"data-qa": dataQa,
|
|
44
|
+
icon: /*#__PURE__*/React.createElement(MrlSvg, {
|
|
45
|
+
svg: refine
|
|
46
|
+
}),
|
|
47
|
+
iconPos: "after",
|
|
48
|
+
kind: "ghost",
|
|
49
|
+
ref: ref,
|
|
50
|
+
size: size,
|
|
51
|
+
text: text,
|
|
52
|
+
toggleAria: "expanded",
|
|
53
|
+
toggleStyle: "default"
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export { MrlMultiFilterTrigger };
|
|
58
|
+
//# sourceMappingURL=MrlMultiFilterTrigger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MrlMultiFilterTrigger.js","sources":["../../../../../src/components/multi-filter/MrlMultiFilterTrigger/MrlMultiFilterTrigger.tsx"],"sourcesContent":["import * as React from 'react';\nimport classnames from 'classnames';\nimport { refine } from '@muraldevkit/ds-icons';\nimport { MrlButton, MrlButtonProps } from '../../button/MrlButton/MrlButton';\nimport { MrlBadgeNotification } from '../../badge/MrlBadgeNotification/MrlBadgeNotification';\nimport { DSIconType, MrlSvg } from '../../svg/MrlSvg/MrlSvg';\nimport { DataQa } from '../../../utils/dataQa';\n\nexport type MrlMultiFilterTriggerProps = {\n\t/**\n\t * Number of active filters. When greater than 0, a numeric badge is shown on the icon.\n\t */\n\tactiveFiltersCount?: number;\n\t/**\n\t * Whether the filter controlled by this trigger is open. Shows the selected toggle style\n\t * and sets `aria-expanded` on the button. The trigger never toggles this by itself.\n\t */\n\tisOpen?: boolean;\n\t/**\n\t * Text announced to screen reader users for the badge.\n\t * Defaults to `${activeFiltersCount} active filters`.\n\t */\n\tnotificationText?: string;\n\t/**\n\t * Interaction state of the trigger button. Only `default` and `disabled` apply.\n\t */\n\tstate?: Extract<MrlButtonProps['state'], 'default' | 'disabled'>;\n} & Pick<MrlButtonProps, 'className' | 'size' | 'text'> &\n\tDataQa;\n\n/**\n * MrlMultiFilterTrigger component.\n *\n * The button that opens the MrlMultiFilter. Shows the refine icon after the label and,\n * when filters are active, a numeric badge with the active filter count.\n *\n * @param props - The component props.\n * @returns The MrlMultiFilterTrigger component.\n */\nexport const MrlMultiFilterTrigger = React.forwardRef<\n\tHTMLButtonElement,\n\tMrlMultiFilterTriggerProps\n>(function MrlMultiFilterTrigger(props, ref) {\n\tconst {\n\t\tclassName,\n\t\tactiveFiltersCount = 0,\n\t\t['data-qa']: dataQa,\n\t\tisOpen = false,\n\t\tnotificationText,\n\t\tsize = 'small',\n\t\tstate,\n\t\ttext\n\t} = props;\n\n\t/**\n\t * `controlledState` overrides `state` in MrlButton, so both are folded into it. Always\n\t * passing it also stops MrlButton from toggling its own selected state on click.\n\t */\n\tconst isDisabled = state === 'disabled';\n\tconst controlledState: MrlButtonProps['controlledState'] = isOpen\n\t\t? isDisabled\n\t\t\t? 'selected-disabled'\n\t\t\t: 'selected'\n\t\t: isDisabled\n\t\t\t? 'disabled'\n\t\t\t: 'default';\n\n\treturn (\n\t\t<MrlButton\n\t\t\tbadge={\n\t\t\t\tactiveFiltersCount > 0 ? (\n\t\t\t\t\t<MrlBadgeNotification\n\t\t\t\t\t\tnotificationText={notificationText ?? `${activeFiltersCount} active filters`}\n\t\t\t\t\t\tnumber={activeFiltersCount}\n\t\t\t\t\t/>\n\t\t\t\t) : undefined\n\t\t\t}\n\t\t\tclassName={classnames('MrlMultiFilterTrigger', className)}\n\t\t\tcontrolledState={controlledState}\n\t\t\tdata-qa={dataQa}\n\t\t\ticon={<MrlSvg svg={refine as DSIconType} />}\n\t\t\ticonPos=\"after\"\n\t\t\tkind=\"ghost\"\n\t\t\tref={ref}\n\t\t\tsize={size}\n\t\t\ttext={text}\n\t\t\ttoggleAria=\"expanded\"\n\t\t\ttoggleStyle=\"default\"\n\t\t/>\n\t);\n});\n"],"names":["MrlMultiFilterTrigger","React","forwardRef","props","ref","className","_props$activeFiltersC","activeFiltersCount","dataQa","_props$isOpen","isOpen","notificationText","_props$size","size","state","text","isDisabled","controlledState","createElement","MrlButton","badge","MrlBadgeNotification","concat","number","undefined","classnames","icon","MrlSvg","svg","refine","iconPos","kind","toggleAria","toggleStyle"],"mappings":";;;;;;;AA8BA;AACA;AACA;AACA;AACA;AACA;A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UAAU,CAAC,uBAAuB,EAAEpB,SAAS,CAAE;AAC1DY,IAAAA,eAAe,EAAEA,eAAgB;AACjC,IAAA,SAAA,EAAST,MAAO;AAChBkB,IAAAA,IAAI,eAAEzB,KAAA,CAAAiB,aAAA,CAACS,MAAM,EAAA;AAACC,MAAAA,GAAG,EAAEC;AAAqB,KAAE,CAAE;AAC5CC,IAAAA,OAAO,EAAC,OAAO;AACfC,IAAAA,IAAI,EAAC,OAAO;AACZ3B,IAAAA,GAAG,EAAEA,GAAI;AACTS,IAAAA,IAAI,EAAEA,IAAK;AACXE,IAAAA,IAAI,EAAEA,IAAK;AACXiB,IAAAA,UAAU,EAAC,UAAU;AACrBC,IAAAA,WAAW,EAAC;AAAS,GACrB,CAAC;AAEJ,CAAC;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { slicedToArray as _slicedToArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
import { FOCUSABLE_ELEMENTS_SELECTOR } from '../../utils/trapFocus/index.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Focuses the first focusable element of the first invalid field, in document order, so it
|
|
6
|
+
* does not depend on the order the fields registered in.
|
|
7
|
+
*
|
|
8
|
+
* @param fields - The registered field elements, keyed by field name.
|
|
9
|
+
* @param errors - The fields that failed validation, keyed by field name.
|
|
10
|
+
*/
|
|
11
|
+
var focusFirstInvalidField = (fields, errors) => {
|
|
12
|
+
var _firstInvalid$querySe;
|
|
13
|
+
var _filter$map$sort = [...fields].filter(_ref => {
|
|
14
|
+
var _ref2 = _slicedToArray(_ref, 1),
|
|
15
|
+
name = _ref2[0];
|
|
16
|
+
return errors[name];
|
|
17
|
+
}).map(_ref3 => {
|
|
18
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
19
|
+
element = _ref4[1];
|
|
20
|
+
return element;
|
|
21
|
+
}).sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1),
|
|
22
|
+
_filter$map$sort2 = _slicedToArray(_filter$map$sort, 1),
|
|
23
|
+
firstInvalid = _filter$map$sort2[0];
|
|
24
|
+
firstInvalid === null || firstInvalid === void 0 ? void 0 : (_firstInvalid$querySe = firstInvalid.querySelector(FOCUSABLE_ELEMENTS_SELECTOR)) === null || _firstInvalid$querySe === void 0 ? void 0 : _firstInvalid$querySe.focus();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { focusFirstInvalidField };
|
|
28
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/components/multi-filter/utils.ts"],"sourcesContent":["import { FOCUSABLE_ELEMENTS_SELECTOR } from '../../utils/trapFocus';\n\n/**\n * Focuses the first focusable element of the first invalid field, in document order, so it\n * does not depend on the order the fields registered in.\n *\n * @param fields - The registered field elements, keyed by field name.\n * @param errors - The fields that failed validation, keyed by field name.\n */\nexport const focusFirstInvalidField = <K extends PropertyKey>(\n\tfields: Map<K, HTMLElement>,\n\terrors: Partial<Record<K, true>>\n): void => {\n\tconst [firstInvalid] = [...fields]\n\t\t.filter(([name]) => errors[name])\n\t\t.map(([, element]) => element)\n\t\t.sort((a, b) => (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1));\n\tfirstInvalid?.querySelector<HTMLElement>(FOCUSABLE_ELEMENTS_SELECTOR)?.focus();\n};\n"],"names":["focusFirstInvalidField","fields","errors","_firstInvalid$querySe","_filter$map$sort","filter","_ref","_ref2","_slicedToArray","name","map","_ref3","_ref4","element","sort","a","b","compareDocumentPosition","Node","DOCUMENT_POSITION_FOLLOWING","_filter$map$sort2","firstInvalid","querySelector","FOCUSABLE_ELEMENTS_SELECTOR","focus"],"mappings":";;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;IACaA,sBAAsB,GAAGA,CACrCC,MAA2B,EAC3BC,MAAgC,KACtB;AAAA,EAAA,IAAAC,qBAAA;EACV,IAAAC,gBAAA,GAAuB,CAAC,GAAGH,MAAM,CAAC,CAChCI,MAAM,CAACC,IAAA,IAAA;AAAA,MAAA,IAAAC,KAAA,GAAAC,cAAA,CAAAF,IAAA,EAAA,CAAA,CAAA;AAAEG,QAAAA,IAAI,GAAAF,KAAA,CAAA,CAAA,CAAA;MAAA,OAAML,MAAM,CAACO,IAAI,CAAC;IAAA,CAAA,CAAC,CAChCC,GAAG,CAACC,KAAA,IAAA;AAAA,MAAA,IAAAC,KAAA,GAAAJ,cAAA,CAAAG,KAAA,EAAA,CAAA,CAAA;AAAIE,QAAAA,OAAO,GAAAD,KAAA,CAAA,CAAA,CAAA;AAAA,MAAA,OAAMC,OAAO;IAAA,CAAA,CAAC,CAC7BC,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAMD,CAAC,CAACE,uBAAuB,CAACD,CAAC,CAAC,GAAGE,IAAI,CAACC,2BAA2B,GAAG,EAAE,GAAG,CAAE,CAAC;IAAAC,iBAAA,GAAAZ,cAAA,CAAAJ,gBAAA,EAAA,CAAA,CAAA;AAHrFiB,IAAAA,YAAY,GAAAD,iBAAA,CAAA,CAAA,CAAA;AAInBC,EAAAA,YAAY,aAAZA,YAAY,KAAA,MAAA,GAAA,MAAA,GAAA,CAAAlB,qBAAA,GAAZkB,YAAY,CAAEC,aAAa,CAAcC,2BAA2B,CAAC,cAAApB,qBAAA,KAAA,MAAA,GAAA,MAAA,GAArEA,qBAAA,CAAuEqB,KAAK,EAAE;AAC/E;;;;"}
|
|
@@ -27,8 +27,17 @@ import { isElementAriaDisabled } from '../../../utils/isElementAriaDisabled/isEl
|
|
|
27
27
|
import { findAdjacentInteractiveElement } from '../../../utils/findAdjacentInteractiveElement/findAdjacentInteractiveElement.js';
|
|
28
28
|
import { preventDefault } from '../../../utils/preventDefault/preventDefault.js';
|
|
29
29
|
|
|
30
|
-
var _excluded = ["alignment", "ariaLabel", "ariaLabelledBy", "children", "className", "customPosition", "disableClickToOpen", "disableClickOutside", "disableFlipping", "disableFocusTrap", "hasCloseButton", "spacing", "id", "isSubMenu", "actionState", "position", "point", "portalProps", "kind", "offset", "onClose", "onOpen", "eventId", "triggerRef"];
|
|
30
|
+
var _excluded = ["alignment", "ariaLabel", "ariaLabelledBy", "children", "className", "customPosition", "disableClickToOpen", "disableClickOutside", "disableFlipping", "disableFocusTrap", "hasCloseButton", "spacing", "id", "isSubMenu", "actionState", "position", "point", "portalProps", "kind", "role", "offset", "onClose", "onOpen", "eventId", "triggerRef"];
|
|
31
31
|
var POPOVER_CLICKOUTSIDE_WHITELIST = ['#mrl-select-portal', '#mrl-popover-menu-portal', ".".concat(SELECT_MENU_LIST_CLASS_NAME), ".".concat(MULTI_SELECT_MENU_LIST_CLASS_NAME)];
|
|
32
|
+
var ARIA_HASPOPUP_ROLES = new Set(['dialog', 'grid', 'listbox', 'menu', 'tree']);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Maps the popover role to the trigger's `aria-haspopup`, falling back to the generic 'true'.
|
|
36
|
+
* @param {React.AriaRole} role - The role of the popover container
|
|
37
|
+
* @returns {string} The `aria-haspopup` value
|
|
38
|
+
*/
|
|
39
|
+
var getAriaHasPopup = role => role && ARIA_HASPOPUP_ROLES.has(role) ? role : 'true';
|
|
40
|
+
|
|
32
41
|
/**
|
|
33
42
|
* MrlPopover
|
|
34
43
|
*
|
|
@@ -74,6 +83,7 @@ function MrlPopover(_ref) {
|
|
|
74
83
|
} : _ref$portalProps,
|
|
75
84
|
_ref$kind = _ref.kind,
|
|
76
85
|
kind = _ref$kind === void 0 ? 'primary' : _ref$kind,
|
|
86
|
+
role = _ref.role,
|
|
77
87
|
offset = _ref.offset,
|
|
78
88
|
onClose = _ref.onClose,
|
|
79
89
|
onOpen = _ref.onOpen,
|
|
@@ -244,15 +254,15 @@ function MrlPopover(_ref) {
|
|
|
244
254
|
}, [closeMenu, isSubMenu, toggleMenuKey, toggleMenuTrigger, triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.current, hideMenuHover, showMenuHover, hasCloseButton, handleClose]);
|
|
245
255
|
|
|
246
256
|
/**
|
|
247
|
-
*
|
|
248
|
-
* Restore the previous DOM value when the trigger changes or this popover unmounts so host-owned
|
|
257
|
+
* Announce the popover's role on the trigger when it is a valid `aria-haspopup` value, otherwise
|
|
258
|
+
* fall back to the generic 'true' (see ARIA in HTML). Restore the previous DOM value when the trigger changes or this popover unmounts so host-owned
|
|
249
259
|
* ARIA (e.g. aria-haspopup="menu") is not left stale after a callout dismisses.
|
|
250
260
|
*/
|
|
251
261
|
React.useEffect(() => {
|
|
252
262
|
var el = triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.current;
|
|
253
263
|
if (!el) return;
|
|
254
264
|
var previousValue = el.getAttribute('aria-haspopup');
|
|
255
|
-
el.setAttribute('aria-haspopup',
|
|
265
|
+
el.setAttribute('aria-haspopup', getAriaHasPopup(role));
|
|
256
266
|
|
|
257
267
|
// Restore the previous value of the aria-haspopup attribute when the callout is removed from the DOM
|
|
258
268
|
return () => {
|
|
@@ -263,7 +273,7 @@ function MrlPopover(_ref) {
|
|
|
263
273
|
}
|
|
264
274
|
};
|
|
265
275
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
266
|
-
}, [triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.current]);
|
|
276
|
+
}, [triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.current, role]);
|
|
267
277
|
React.useEffect(() => {
|
|
268
278
|
var el = triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.current;
|
|
269
279
|
if (!el) return;
|
|
@@ -374,6 +384,7 @@ function MrlPopover(_ref) {
|
|
|
374
384
|
"aria-labelledby": ariaLabelledBy,
|
|
375
385
|
className: menuClasses,
|
|
376
386
|
id: id,
|
|
387
|
+
role: role,
|
|
377
388
|
tabIndex: -1,
|
|
378
389
|
style: _objectSpread2(_objectSpread2(_objectSpread2({}, positionStyles), style), hideUntilPositionedStyles),
|
|
379
390
|
onKeyDown: handleMenuKey,
|