@elliemae/ds-app-picker 1.53.4-rc.0 → 1.53.4-rc.5
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/cjs/AppPickerImpl.js +160 -66
- package/cjs/AppPickerImpl.js.map +1 -1
- package/cjs/DSAppPicker.js +56 -23
- package/cjs/DSAppPicker.js.map +1 -1
- package/cjs/index.js +3 -2
- package/cjs/index.js.map +1 -1
- package/cjs/propTypes.js +30 -0
- package/cjs/propTypes.js.map +1 -0
- package/cjs/utils.js +10 -8
- package/cjs/utils.js.map +1 -1
- package/esm/AppPickerImpl.js +161 -65
- package/esm/AppPickerImpl.js.map +1 -1
- package/esm/DSAppPicker.js +57 -25
- package/esm/DSAppPicker.js.map +1 -1
- package/esm/index.js +3 -2
- package/esm/index.js.map +1 -1
- package/esm/propTypes.js +22 -0
- package/esm/propTypes.js.map +1 -0
- package/esm/utils.js +10 -8
- package/esm/utils.js.map +1 -1
- package/package.json +5 -5
- package/propTypes/package.json +10 -0
package/cjs/AppPickerImpl.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
4
|
-
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
5
3
|
var React = require('react');
|
|
6
4
|
var lodash = require('lodash');
|
|
7
5
|
var dsClassnames = require('@elliemae/ds-classnames');
|
|
@@ -9,113 +7,207 @@ var utils = require('./utils.js');
|
|
|
9
7
|
|
|
10
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
9
|
|
|
12
|
-
var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
|
|
13
|
-
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
14
10
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
15
11
|
|
|
12
|
+
/* eslint-disable react/prop-types */
|
|
16
13
|
var blockName = 'app-picker';
|
|
17
14
|
var Wrapper = dsClassnames.aggregatedClasses('div')(blockName, 'wrapper');
|
|
18
15
|
var Grid = dsClassnames.aggregatedClasses('div')(blockName, 'grid');
|
|
19
16
|
var Row = dsClassnames.aggregatedClasses('div')(blockName, 'row');
|
|
20
|
-
var Chip = dsClassnames.aggregatedClasses('
|
|
21
|
-
var disabled = _ref.disabled
|
|
22
|
-
|
|
17
|
+
var Chip = dsClassnames.aggregatedClasses('button')(blockName, 'chip', function (_ref) {
|
|
18
|
+
var disabled = _ref.disabled,
|
|
19
|
+
selected = _ref.selected;
|
|
20
|
+
return {
|
|
21
|
+
disabled: disabled,
|
|
22
|
+
selected: selected
|
|
23
|
+
};
|
|
23
24
|
});
|
|
24
25
|
var ChipLabel = dsClassnames.aggregatedClasses('p')(blockName, 'chip-label');
|
|
25
26
|
var Separator = dsClassnames.aggregatedClasses('hr')(blockName, 'separator');
|
|
26
27
|
var SectionTitle = dsClassnames.aggregatedClasses('p')(blockName, 'section-title');
|
|
27
28
|
|
|
28
|
-
var AppPickerImpl = function AppPickerImpl(
|
|
29
|
-
var
|
|
30
|
-
apps =
|
|
31
|
-
|
|
32
|
-
customApps =
|
|
33
|
-
|
|
34
|
-
sectionTitle =
|
|
35
|
-
|
|
36
|
-
customSectionTitle =
|
|
37
|
-
|
|
38
|
-
close =
|
|
29
|
+
var AppPickerImpl = function AppPickerImpl(_ref2) {
|
|
30
|
+
var _ref2$apps = _ref2.apps,
|
|
31
|
+
apps = _ref2$apps === void 0 ? [] : _ref2$apps,
|
|
32
|
+
_ref2$customApps = _ref2.customApps,
|
|
33
|
+
customApps = _ref2$customApps === void 0 ? [] : _ref2$customApps,
|
|
34
|
+
_ref2$sectionTitle = _ref2.sectionTitle,
|
|
35
|
+
sectionTitle = _ref2$sectionTitle === void 0 ? 'APPLICATIONS' : _ref2$sectionTitle,
|
|
36
|
+
_ref2$customSectionTi = _ref2.customSectionTitle,
|
|
37
|
+
customSectionTitle = _ref2$customSectionTi === void 0 ? 'CUSTOM APPLICATIONS' : _ref2$customSectionTi,
|
|
38
|
+
_ref2$close = _ref2.close,
|
|
39
|
+
close = _ref2$close === void 0 ? function () {
|
|
39
40
|
return null;
|
|
40
|
-
} :
|
|
41
|
-
|
|
41
|
+
} : _ref2$close,
|
|
42
|
+
wrapperRef = _ref2.wrapperRef,
|
|
43
|
+
onKeyDown = _ref2.onKeyDown,
|
|
44
|
+
triggerRef = _ref2.triggerRef;
|
|
45
|
+
var allFocusableButtons = React.useRef([]);
|
|
46
|
+
var allButtons = React.useRef([]);
|
|
47
|
+
var selectedButton = React.useRef(null);
|
|
42
48
|
React.useEffect(function () {
|
|
43
|
-
var _wrapperRef$current;
|
|
49
|
+
var _wrapperRef$current, _wrapperRef$current2;
|
|
50
|
+
|
|
51
|
+
wrapperRef === null || wrapperRef === void 0 ? void 0 : (_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.querySelectorAll('.em-ds-app-picker__row').forEach(function (row) {
|
|
52
|
+
var _allButtons$current2, _allButtons$current4, _allButtons$current6;
|
|
53
|
+
|
|
54
|
+
if (row.children[0] && !row.children[0].hasAttribute('disabled')) {
|
|
55
|
+
var _allButtons$current;
|
|
56
|
+
|
|
57
|
+
allButtons === null || allButtons === void 0 ? void 0 : (_allButtons$current = allButtons.current) === null || _allButtons$current === void 0 ? void 0 : _allButtons$current.push(row.children[0]);
|
|
58
|
+
} else allButtons === null || allButtons === void 0 ? void 0 : (_allButtons$current2 = allButtons.current) === null || _allButtons$current2 === void 0 ? void 0 : _allButtons$current2.push(null);
|
|
59
|
+
|
|
60
|
+
if (row.children[1] && !row.children[1].hasAttribute('disabled')) {
|
|
61
|
+
var _allButtons$current3;
|
|
62
|
+
|
|
63
|
+
allButtons === null || allButtons === void 0 ? void 0 : (_allButtons$current3 = allButtons.current) === null || _allButtons$current3 === void 0 ? void 0 : _allButtons$current3.push(row.children[1]);
|
|
64
|
+
} else allButtons === null || allButtons === void 0 ? void 0 : (_allButtons$current4 = allButtons.current) === null || _allButtons$current4 === void 0 ? void 0 : _allButtons$current4.push(null);
|
|
65
|
+
|
|
66
|
+
if (row.children[2] && !row.children[2].hasAttribute('disabled')) {
|
|
67
|
+
var _allButtons$current5;
|
|
68
|
+
|
|
69
|
+
allButtons === null || allButtons === void 0 ? void 0 : (_allButtons$current5 = allButtons.current) === null || _allButtons$current5 === void 0 ? void 0 : _allButtons$current5.push(row.children[2]);
|
|
70
|
+
} else allButtons === null || allButtons === void 0 ? void 0 : (_allButtons$current6 = allButtons.current) === null || _allButtons$current6 === void 0 ? void 0 : _allButtons$current6.push(null);
|
|
71
|
+
});
|
|
72
|
+
wrapperRef === null || wrapperRef === void 0 ? void 0 : (_wrapperRef$current2 = wrapperRef.current) === null || _wrapperRef$current2 === void 0 ? void 0 : _wrapperRef$current2.querySelectorAll('button').forEach(function (e, index) {
|
|
73
|
+
if (!e.hasAttribute('disabled')) {
|
|
74
|
+
var _allFocusableButtons$;
|
|
75
|
+
|
|
76
|
+
allFocusableButtons === null || allFocusableButtons === void 0 ? void 0 : (_allFocusableButtons$ = allFocusableButtons.current) === null || _allFocusableButtons$ === void 0 ? void 0 : _allFocusableButtons$.push(e);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (e.getAttribute('aria-selected') === 'true') {
|
|
80
|
+
selectedButton.current = index;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (selectedButton.current) {
|
|
85
|
+
var _wrapperRef$current3;
|
|
44
86
|
|
|
45
|
-
|
|
46
|
-
|
|
87
|
+
wrapperRef === null || wrapperRef === void 0 ? void 0 : (_wrapperRef$current3 = wrapperRef.current) === null || _wrapperRef$current3 === void 0 ? void 0 : _wrapperRef$current3.querySelectorAll('button')[selectedButton.current].focus();
|
|
88
|
+
} else {
|
|
89
|
+
var _allFocusableButtons$2;
|
|
47
90
|
|
|
48
|
-
|
|
49
|
-
|
|
91
|
+
allFocusableButtons === null || allFocusableButtons === void 0 ? void 0 : (_allFocusableButtons$2 = allFocusableButtons.current[0]) === null || _allFocusableButtons$2 === void 0 ? void 0 : _allFocusableButtons$2.focus();
|
|
92
|
+
}
|
|
93
|
+
}, [wrapperRef]);
|
|
94
|
+
var move = React.useCallback(function (position, offset) {
|
|
95
|
+
var newPosition = position + offset;
|
|
50
96
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
97
|
+
if (position + offset < 0) {
|
|
98
|
+
newPosition = allButtons.current.length + position + offset;
|
|
99
|
+
}
|
|
54
100
|
|
|
55
|
-
|
|
101
|
+
if (position + offset > allButtons.current.length - 1) {
|
|
102
|
+
newPosition = position - allButtons.current.length;
|
|
103
|
+
}
|
|
56
104
|
|
|
57
|
-
var
|
|
58
|
-
nextElementSibling = element.nextElementSibling;
|
|
59
|
-
var upRow = parent.previousElementSibling,
|
|
60
|
-
downRow = parent.nextElementSibling;
|
|
105
|
+
var element = allButtons.current[newPosition];
|
|
61
106
|
|
|
62
|
-
|
|
107
|
+
if (element) {
|
|
108
|
+
return element.focus();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return move(newPosition, offset);
|
|
112
|
+
}, []); // eslint-disable-next-line max-statements
|
|
113
|
+
|
|
114
|
+
var handleKeyDown = function handleKeyDown(e) {
|
|
115
|
+
var _triggerRef$current, _allFocusableButtons$3, _allFocusableButtons$4;
|
|
116
|
+
|
|
117
|
+
switch (e.key) {
|
|
63
118
|
case utils.keys.LEFT:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
|
|
121
|
+
for (var index = 0; index < allButtons.current.length; index += 1) {
|
|
122
|
+
if ((allButtons === null || allButtons === void 0 ? void 0 : allButtons.current[index]) === e.target) {
|
|
123
|
+
move(index, -1);
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
68
126
|
}
|
|
69
127
|
|
|
70
128
|
break;
|
|
71
129
|
|
|
72
130
|
case utils.keys.RIGHT:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
131
|
+
e.preventDefault();
|
|
132
|
+
|
|
133
|
+
for (var _index = 0; _index < allButtons.current.length; _index += 1) {
|
|
134
|
+
if (allButtons.current[_index] === e.target) {
|
|
135
|
+
move(_index, 1);
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
77
138
|
}
|
|
78
139
|
|
|
79
140
|
break;
|
|
80
141
|
|
|
81
142
|
case utils.keys.UP:
|
|
82
|
-
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
|
|
145
|
+
for (var _index2 = 0; _index2 < allButtons.current.length; _index2 += 1) {
|
|
146
|
+
if (allButtons.current[_index2] === e.target) {
|
|
147
|
+
move(_index2, -3);
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
83
152
|
break;
|
|
84
153
|
|
|
85
154
|
case utils.keys.DOWN:
|
|
86
|
-
|
|
87
|
-
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
|
|
157
|
+
for (var _index3 = 0; _index3 < allButtons.current.length; _index3 += 1) {
|
|
158
|
+
if (allButtons.current[_index3] === e.target) {
|
|
159
|
+
move(_index3, 3);
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
88
163
|
|
|
89
|
-
case utils.keys.ENTER:
|
|
90
|
-
case utils.keys.SPACE:
|
|
91
|
-
element.click();
|
|
92
164
|
break;
|
|
93
165
|
|
|
94
166
|
case utils.keys.ESC:
|
|
167
|
+
triggerRef === null || triggerRef === void 0 ? void 0 : (_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 ? void 0 : _triggerRef$current.focus();
|
|
95
168
|
close();
|
|
96
169
|
break;
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
170
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
171
|
+
case utils.keys.HOME:
|
|
172
|
+
e.preventDefault();
|
|
173
|
+
allFocusableButtons === null || allFocusableButtons === void 0 ? void 0 : (_allFocusableButtons$3 = allFocusableButtons.current[0]) === null || _allFocusableButtons$3 === void 0 ? void 0 : _allFocusableButtons$3.focus();
|
|
174
|
+
break;
|
|
175
|
+
|
|
176
|
+
case utils.keys.END:
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
allFocusableButtons === null || allFocusableButtons === void 0 ? void 0 : (_allFocusableButtons$4 = allFocusableButtons.current[allFocusableButtons.current.length - 1]) === null || _allFocusableButtons$4 === void 0 ? void 0 : _allFocusableButtons$4.focus();
|
|
179
|
+
break;
|
|
180
|
+
|
|
181
|
+
case utils.keys.TAB:
|
|
182
|
+
if (e.shiftKey) {
|
|
183
|
+
if (e.target === allFocusableButtons.current[0]) {
|
|
184
|
+
var _allFocusableButtons$5;
|
|
185
|
+
|
|
186
|
+
e.preventDefault();
|
|
187
|
+
allFocusableButtons === null || allFocusableButtons === void 0 ? void 0 : (_allFocusableButtons$5 = allFocusableButtons.current[allFocusableButtons.current.length - 1]) === null || _allFocusableButtons$5 === void 0 ? void 0 : _allFocusableButtons$5.focus();
|
|
188
|
+
}
|
|
189
|
+
} else if (e.target === allFocusableButtons.current[allFocusableButtons.current.length - 1]) {
|
|
190
|
+
var _allFocusableButtons$6;
|
|
191
|
+
|
|
192
|
+
e.preventDefault();
|
|
193
|
+
allFocusableButtons === null || allFocusableButtons === void 0 ? void 0 : (_allFocusableButtons$6 = allFocusableButtons.current[0]) === null || _allFocusableButtons$6 === void 0 ? void 0 : _allFocusableButtons$6.focus();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
break;
|
|
104
197
|
}
|
|
105
198
|
};
|
|
106
199
|
|
|
107
|
-
var
|
|
108
|
-
|
|
109
|
-
return target.focus();
|
|
200
|
+
var handleOnClick = function handleOnClick(e, app) {
|
|
201
|
+
if (app.onClick) app.onClick(e, app);
|
|
110
202
|
};
|
|
111
203
|
|
|
112
|
-
var handleOnKeyDownWrapper = function
|
|
113
|
-
|
|
204
|
+
var handleOnKeyDownWrapper = React.useCallback(function (e) {
|
|
205
|
+
if (onKeyDown) onKeyDown(e);
|
|
114
206
|
|
|
115
|
-
if (key === utils.keys.ESC) {
|
|
207
|
+
if (!onKeyDown && e.key === utils.keys.ESC) {
|
|
116
208
|
close();
|
|
117
209
|
}
|
|
118
|
-
};
|
|
210
|
+
}, [onKeyDown, close]);
|
|
119
211
|
|
|
120
212
|
var buildRows = function buildRows(appList) {
|
|
121
213
|
var rows = lodash.chunk(appList, 3); // divides array in subarrays of 3 items
|
|
@@ -126,19 +218,22 @@ var AppPickerImpl = function AppPickerImpl(_ref3) {
|
|
|
126
218
|
}, row.map(function (app, key) {
|
|
127
219
|
var label = app.label,
|
|
128
220
|
disabled = app.disabled,
|
|
221
|
+
selected = app.selected,
|
|
129
222
|
Icon = app.icon;
|
|
130
223
|
return /*#__PURE__*/React__default['default'].createElement(Chip, {
|
|
131
224
|
key: key,
|
|
132
225
|
classProps: {
|
|
133
|
-
disabled: disabled
|
|
226
|
+
disabled: disabled,
|
|
227
|
+
selected: selected
|
|
134
228
|
},
|
|
135
229
|
onClick: function onClick(e) {
|
|
136
230
|
return handleOnClick(e, app);
|
|
137
231
|
},
|
|
138
232
|
onKeyDown: handleKeyDown,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
233
|
+
"data-testid": "app-picker__chip",
|
|
234
|
+
"aria-disabled": disabled,
|
|
235
|
+
disabled: disabled,
|
|
236
|
+
"aria-selected": selected
|
|
142
237
|
}, /*#__PURE__*/React__default['default'].createElement(Icon, {
|
|
143
238
|
className: "app-picker__icon",
|
|
144
239
|
size: "m"
|
|
@@ -158,7 +253,6 @@ var AppPickerImpl = function AppPickerImpl(_ref3) {
|
|
|
158
253
|
|
|
159
254
|
return /*#__PURE__*/React__default['default'].createElement(Wrapper, {
|
|
160
255
|
ref: wrapperRef,
|
|
161
|
-
tabIndex: 0,
|
|
162
256
|
onKeyDown: handleOnKeyDownWrapper,
|
|
163
257
|
"data-testid": "app-picker__wrapper"
|
|
164
258
|
}, /*#__PURE__*/React__default['default'].createElement(SectionTitle, {
|
package/cjs/AppPickerImpl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppPickerImpl.js","sources":["../../src/AppPickerImpl.tsx"],"sourcesContent":["/* eslint-disable react/prop-types */\n/* eslint-disable react/no-array-index-key */\n/* eslint-disable max-lines */\n/* eslint-disable complexity */\n/* eslint-disable no-unused-expressions */\n/* eslint-disable object-curly-newline */\n/* eslint-disable prefer-template */\nimport React, { useEffect, useRef } from 'react';\nimport { chunk } from 'lodash';\nimport { aggregatedClasses } from '@elliemae/ds-classnames';\nimport { keys } from './utils';\nimport { DSAppPickerImplType } from './types/AppPickerTypes';\n\nconst blockName = 'app-picker';\nconst Wrapper = aggregatedClasses('div')(blockName, 'wrapper');\nconst Grid = aggregatedClasses('div')(blockName, 'grid');\nconst Row = aggregatedClasses('div')(blockName, 'row');\nconst Chip = aggregatedClasses('div')(blockName, 'chip', ({ disabled }) => ({\n [disabled]: disabled,\n}));\nconst ChipLabel = aggregatedClasses('p')(blockName, 'chip-label');\nconst Separator = aggregatedClasses('hr')(blockName, 'separator');\nconst SectionTitle = aggregatedClasses('p')(blockName, 'section-title');\n\nconst AppPickerImpl: DSAppPickerImplType = ({\n apps = [],\n customApps = [],\n sectionTitle = 'APPLICATIONS',\n customSectionTitle = 'CUSTOM APPLICATIONS',\n close = () => null,\n}) => {\n const wrapperRef = useRef();\n\n useEffect(() => {\n wrapperRef?.current?.focus();\n }, []);\n\n const handleKeyDown = ({ target: element, which: key }) => {\n const parent = element.parentElement;\n const index = [...parent.children].indexOf(element);\n const { previousElementSibling, nextElementSibling } = element;\n const {\n previousElementSibling: upRow,\n nextElementSibling: downRow,\n } = parent;\n\n switch (key) {\n case keys.LEFT:\n if (previousElementSibling) {\n previousElementSibling.focus();\n } else if (upRow) {\n upRow.lastChild.focus();\n }\n break;\n case keys.RIGHT:\n if (nextElementSibling) {\n nextElementSibling.focus();\n } else if (downRow) {\n downRow.firstChild.focus();\n }\n break;\n case keys.UP:\n upRow?.children[index]?.focus();\n break;\n case keys.DOWN:\n downRow?.children[index]?.focus();\n break;\n case keys.ENTER:\n case keys.SPACE:\n element.click();\n break;\n case keys.ESC:\n close();\n break;\n default:\n break;\n }\n };\n\n const handleOnClick = (e, app) => {\n if (!app.disabled) {\n close();\n app.onClick(e);\n }\n };\n\n const handleOnHover = ({ target }) => target.focus();\n\n const handleOnKeyDownWrapper = ({ key }) => {\n if (key === keys.ESC) {\n close();\n }\n };\n\n const buildRows = (appList) => {\n const rows = chunk(appList, 3); // divides array in subarrays of 3 items\n const formattedRows = rows.map((row, index) => (\n <Row key={index}>\n {row.map((app, key) => {\n const { label, disabled, icon: Icon } = app;\n return (\n <Chip\n key={key}\n classProps={{ disabled }}\n onClick={(e) => handleOnClick(e, app)}\n onKeyDown={handleKeyDown}\n onMouseEnter={handleOnHover}\n tabIndex={0}\n data-testid=\"app-picker__chip\"\n >\n <Icon className=\"app-picker__icon\" size=\"m\" />\n <ChipLabel>{label}</ChipLabel>\n </Chip>\n );\n })}\n </Row>\n ));\n return formattedRows;\n };\n\n const AppsRows = () => buildRows(apps);\n const CustomRows = () => buildRows(customApps);\n\n return (\n <Wrapper\n ref={wrapperRef}\n tabIndex={0}\n onKeyDown={handleOnKeyDownWrapper}\n data-testid=\"app-picker__wrapper\"\n >\n <SectionTitle data-testid=\"app-picker__main-title\">\n {sectionTitle}\n </SectionTitle>\n <Grid data-testid=\"app-picker__main-grid\">\n <AppsRows />\n </Grid>\n {!!customApps.length && (\n <>\n <Separator />\n <SectionTitle data-testid=\"app-picker__custom-title\">\n {customSectionTitle}\n </SectionTitle>\n <Grid data-testid=\"app-picker__custom-grid\">\n <CustomRows />\n </Grid>\n </>\n )}\n </Wrapper>\n );\n};\n\nexport default AppPickerImpl;\n"],"names":["blockName","Wrapper","aggregatedClasses","Grid","Row","Chip","disabled","ChipLabel","Separator","SectionTitle","AppPickerImpl","apps","customApps","sectionTitle","customSectionTitle","close","wrapperRef","useRef","useEffect","current","focus","handleKeyDown","element","target","key","which","parent","parentElement","index","_toConsumableArray","children","indexOf","previousElementSibling","nextElementSibling","upRow","downRow","keys","LEFT","lastChild","RIGHT","firstChild","UP","DOWN","ENTER","SPACE","click","ESC","handleOnClick","e","app","onClick","handleOnHover","handleOnKeyDownWrapper","buildRows","appList","rows","chunk","formattedRows","map","row","React","label","Icon","icon","AppsRows","CustomRows","length"],"mappings":";;;;;;;;;;;;;;;AAaA,IAAMA,SAAS,GAAG,YAAlB;AACA,IAAMC,OAAO,GAAGC,8BAAiB,CAAC,KAAD,CAAjB,CAAyBF,SAAzB,EAAoC,SAApC,CAAhB;AACA,IAAMG,IAAI,GAAGD,8BAAiB,CAAC,KAAD,CAAjB,CAAyBF,SAAzB,EAAoC,MAApC,CAAb;AACA,IAAMI,GAAG,GAAGF,8BAAiB,CAAC,KAAD,CAAjB,CAAyBF,SAAzB,EAAoC,KAApC,CAAZ;AACA,IAAMK,IAAI,GAAGH,8BAAiB,CAAC,KAAD,CAAjB,CAAyBF,SAAzB,EAAoC,MAApC,EAA4C;AAAA,MAAGM,QAAH,QAAGA,QAAH;AAAA,iDACtDA,QADsD,EAC3CA,QAD2C;AAAA,CAA5C,CAAb;AAGA,IAAMC,SAAS,GAAGL,8BAAiB,CAAC,GAAD,CAAjB,CAAuBF,SAAvB,EAAkC,YAAlC,CAAlB;AACA,IAAMQ,SAAS,GAAGN,8BAAiB,CAAC,IAAD,CAAjB,CAAwBF,SAAxB,EAAmC,WAAnC,CAAlB;AACA,IAAMS,YAAY,GAAGP,8BAAiB,CAAC,GAAD,CAAjB,CAAuBF,SAAvB,EAAkC,eAAlC,CAArB;;IAEMU,aAAkC,GAAG,SAArCA,aAAqC,QAMrC;AAAA,yBALJC,IAKI;AAAA,MALJA,IAKI,2BALG,EAKH;AAAA,+B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A1B,KACG/C,YADH,CANF,eASE+C,wCAAC,IAAD;AAAM,mBAAY;AAAlB,kBACEA,wCAAC,QAAD,OADF,CATF,EAYG,CAAC,CAAChD,UAAU,CAACsD,MAAb,iBACCN,+FACEA,wCAAC,SAAD,OADF,eAEEA,wCAAC,YAAD;AAAc,mBAAY;AAA1B,KACG9C,kBADH,CAFF,eAKE8C,wCAAC,IAAD;AAAM,mBAAY;AAAlB,kBACEA,wCAAC,UAAD,OADF,CALF,CAbJ,CADF;AA0BD;;;;"}
|
|
1
|
+
{"version":3,"file":"AppPickerImpl.js","sources":["../../src/AppPickerImpl.tsx"],"sourcesContent":["/* eslint-disable react/prop-types */\n/* eslint-disable react/no-array-index-key */\n/* eslint-disable max-lines */\n/* eslint-disable complexity */\n/* eslint-disable no-unused-expressions */\n/* eslint-disable object-curly-newline */\n/* eslint-disable prefer-template */\nimport React, { useEffect, useCallback, useRef } from 'react';\nimport { chunk } from 'lodash';\nimport { aggregatedClasses } from '@elliemae/ds-classnames';\nimport { keys } from './utils';\nimport { DSAppPickerImplType } from './types/AppPickerTypes';\n\nconst blockName = 'app-picker';\nconst Wrapper = aggregatedClasses('div')(blockName, 'wrapper');\nconst Grid = aggregatedClasses('div')(blockName, 'grid');\nconst Row = aggregatedClasses('div')(blockName, 'row');\nconst Chip = aggregatedClasses('button')(blockName, 'chip', ({ disabled, selected }) => ({\n disabled,\n selected,\n}));\nconst ChipLabel = aggregatedClasses('p')(blockName, 'chip-label');\nconst Separator = aggregatedClasses('hr')(blockName, 'separator');\nconst SectionTitle = aggregatedClasses('p')(blockName, 'section-title');\n\nconst AppPickerImpl: DSAppPickerImplType = ({\n apps = [],\n customApps = [],\n sectionTitle = 'APPLICATIONS',\n customSectionTitle = 'CUSTOM APPLICATIONS',\n close = () => null,\n wrapperRef,\n onKeyDown,\n triggerRef,\n}) => {\n const allFocusableButtons = useRef([]);\n const allButtons = useRef([]);\n const selectedButton = useRef(null);\n\n useEffect(() => {\n wrapperRef?.current?.querySelectorAll('.em-ds-app-picker__row').forEach((row) => {\n if (row.children[0] && !row.children[0].hasAttribute('disabled')) {\n allButtons?.current?.push(row.children[0]);\n } else allButtons?.current?.push(null);\n if (row.children[1] && !row.children[1].hasAttribute('disabled')) {\n allButtons?.current?.push(row.children[1]);\n } else allButtons?.current?.push(null);\n if (row.children[2] && !row.children[2].hasAttribute('disabled')) {\n allButtons?.current?.push(row.children[2]);\n } else allButtons?.current?.push(null);\n });\n\n wrapperRef?.current?.querySelectorAll('button').forEach((e, index) => {\n if (!e.hasAttribute('disabled')) {\n allFocusableButtons?.current?.push(e);\n }\n if (e.getAttribute('aria-selected') === 'true') {\n selectedButton.current = index;\n }\n });\n\n if (selectedButton.current) {\n wrapperRef?.current?.querySelectorAll('button')[selectedButton.current].focus();\n } else {\n allFocusableButtons?.current[0]?.focus();\n }\n }, [wrapperRef]);\n\n const move = useCallback((position, offset) => {\n let newPosition = position + offset;\n if (position + offset < 0) {\n newPosition = allButtons.current.length + position + offset;\n }\n\n if (position + offset > allButtons.current.length - 1) {\n newPosition = position - allButtons.current.length;\n }\n const element = allButtons.current[newPosition];\n if (element) {\n return element.focus();\n }\n return move(newPosition, offset);\n }, []);\n // eslint-disable-next-line max-statements\n const handleKeyDown = (e) => {\n switch (e.key) {\n case keys.LEFT:\n e.preventDefault();\n for (let index = 0; index < allButtons.current.length; index += 1) {\n if (allButtons?.current[index] === e.target) {\n move(index, -1);\n break;\n }\n }\n break;\n case keys.RIGHT:\n e.preventDefault();\n for (let index = 0; index < allButtons.current.length; index += 1) {\n if (allButtons.current[index] === e.target) {\n move(index, 1);\n break;\n }\n }\n break;\n case keys.UP:\n e.preventDefault();\n for (let index = 0; index < allButtons.current.length; index += 1) {\n if (allButtons.current[index] === e.target) {\n move(index, -3);\n break;\n }\n }\n break;\n case keys.DOWN:\n e.preventDefault();\n for (let index = 0; index < allButtons.current.length; index += 1) {\n if (allButtons.current[index] === e.target) {\n move(index, 3);\n break;\n }\n }\n break;\n case keys.ESC:\n triggerRef?.current?.focus();\n close();\n break;\n case keys.HOME:\n e.preventDefault();\n allFocusableButtons?.current[0]?.focus();\n break;\n case keys.END:\n e.preventDefault();\n allFocusableButtons?.current[allFocusableButtons.current.length - 1]?.focus();\n break;\n case keys.TAB:\n if (e.shiftKey) {\n if (e.target === allFocusableButtons.current[0]) {\n e.preventDefault();\n allFocusableButtons?.current[allFocusableButtons.current.length - 1]?.focus();\n }\n } else if (e.target === allFocusableButtons.current[allFocusableButtons.current.length - 1]) {\n e.preventDefault();\n allFocusableButtons?.current[0]?.focus();\n }\n break;\n default:\n break;\n }\n };\n\n const handleOnClick = (e, app) => {\n if (app.onClick) app.onClick(e, app);\n };\n\n const handleOnKeyDownWrapper = useCallback(\n (e) => {\n if (onKeyDown) onKeyDown(e);\n if (!onKeyDown && e.key === keys.ESC) {\n close();\n }\n },\n [onKeyDown, close],\n );\n\n const buildRows = (appList) => {\n const rows = chunk(appList, 3); // divides array in subarrays of 3 items\n const formattedRows = rows.map((row, index) => (\n <Row key={index}>\n {row.map((app, key) => {\n const { label, disabled, selected, icon: Icon } = app;\n return (\n <Chip\n key={key}\n classProps={{ disabled, selected }}\n onClick={(e) => handleOnClick(e, app)}\n onKeyDown={handleKeyDown}\n data-testid=\"app-picker__chip\"\n aria-disabled={disabled}\n disabled={disabled}\n aria-selected={selected}\n >\n <Icon className=\"app-picker__icon\" size=\"m\" />\n <ChipLabel>{label}</ChipLabel>\n </Chip>\n );\n })}\n </Row>\n ));\n return formattedRows;\n };\n\n const AppsRows = () => buildRows(apps);\n const CustomRows = () => buildRows(customApps);\n\n return (\n <Wrapper ref={wrapperRef} onKeyDown={handleOnKeyDownWrapper} data-testid=\"app-picker__wrapper\">\n <SectionTitle data-testid=\"app-picker__main-title\">{sectionTitle}</SectionTitle>\n <Grid data-testid=\"app-picker__main-grid\">\n <AppsRows />\n </Grid>\n {!!customApps.length && (\n <>\n <Separator />\n <SectionTitle data-testid=\"app-picker__custom-title\">{customSectionTitle}</SectionTitle>\n <Grid data-testid=\"app-picker__custom-grid\">\n <CustomRows />\n </Grid>\n </>\n )}\n </Wrapper>\n );\n};\n\nexport default AppPickerImpl;\n"],"names":["blockName","Wrapper","aggregatedClasses","Grid","Row","Chip","disabled","selected","ChipLabel","Separator","SectionTitle","AppPickerImpl","apps","customApps","sectionTitle","customSectionTitle","close","wrapperRef","onKeyDown","triggerRef","allFocusableButtons","useRef","allButtons","selectedButton","useEffect","current","querySelectorAll","forEach","row","children","hasAttribute","push","e","index","getAttribute","focus","move","useCallback","position","offset","newPosition","length","element","handleKeyDown","key","keys","LEFT","preventDefault","target","RIGHT","UP","DOWN","ESC","HOME","END","TAB","shiftKey","handleOnClick","app","onClick","handleOnKeyDownWrapper","buildRows","appList","rows","chunk","formattedRows","map","React","label","Icon","icon","AppsRows","CustomRows"],"mappings":";;;;;;;;;;;AAAA;AAaA,IAAMA,SAAS,GAAG,YAAlB;AACA,IAAMC,OAAO,GAAGC,8BAAiB,CAAC,KAAD,CAAjB,CAAyBF,SAAzB,EAAoC,SAApC,CAAhB;AACA,IAAMG,IAAI,GAAGD,8BAAiB,CAAC,KAAD,CAAjB,CAAyBF,SAAzB,EAAoC,MAApC,CAAb;AACA,IAAMI,GAAG,GAAGF,8BAAiB,CAAC,KAAD,CAAjB,CAAyBF,SAAzB,EAAoC,KAApC,CAAZ;AACA,IAAMK,IAAI,GAAGH,8BAAiB,CAAC,QAAD,CAAjB,CAA4BF,SAA5B,EAAuC,MAAvC,EAA+C;AAAA,MAAGM,QAAH,QAAGA,QAAH;AAAA,MAAaC,QAAb,QAAaA,QAAb;AAAA,SAA6B;AACvFD,IAAAA,QAAQ,EAARA,QADuF;AAEvFC,IAAAA,QAAQ,EAARA;AAFuF,GAA7B;AAAA,CAA/C,CAAb;AAIA,IAAMC,SAAS,GAAGN,8BAAiB,CAAC,GAAD,CAAjB,CAAuBF,SAAvB,EAAkC,YAAlC,CAAlB;AACA,IAAMS,SAAS,GAAGP,8BAAiB,CAAC,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D,CAFF,eAGEoD,wCAAC,IAAD;AAAM,mBAAY;AAAlB,kBACEA,wCAAC,UAAD,OADF,CAHF,CANJ,CADF;AAiBD;;;;"}
|
package/cjs/DSAppPicker.js
CHANGED
|
@@ -2,21 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
5
6
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
6
7
|
var React = require('react');
|
|
7
8
|
var reactDesc = require('react-desc');
|
|
8
9
|
var MenuPicker = require('@elliemae/ds-icons/MenuPicker');
|
|
9
10
|
var DSButton = require('@elliemae/ds-button');
|
|
10
11
|
var DSPopover = require('@elliemae/ds-popover');
|
|
12
|
+
var dsUtilities = require('@elliemae/ds-utilities');
|
|
11
13
|
var AppPickerImpl = require('./AppPickerImpl.js');
|
|
12
|
-
require('
|
|
13
|
-
require('@babel/runtime/helpers/defineProperty');
|
|
14
|
+
var propTypes = require('./propTypes.js');
|
|
14
15
|
require('lodash');
|
|
15
16
|
require('@elliemae/ds-classnames');
|
|
16
17
|
require('./utils.js');
|
|
17
18
|
|
|
18
19
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
20
|
|
|
21
|
+
var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
|
|
20
22
|
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
21
23
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
22
24
|
var MenuPicker__default = /*#__PURE__*/_interopDefaultLegacy(MenuPicker);
|
|
@@ -40,25 +42,58 @@ var DSAppPicker = function DSAppPicker(_ref) {
|
|
|
40
42
|
});
|
|
41
43
|
} : _ref$icon,
|
|
42
44
|
renderTrigger = _ref.renderTrigger,
|
|
43
|
-
|
|
44
|
-
isOpen = _ref$isOpen === void 0 ? false : _ref$isOpen,
|
|
45
|
+
isOpen = _ref.isOpen,
|
|
45
46
|
_ref$onClose = _ref.onClose,
|
|
46
47
|
onClose = _ref$onClose === void 0 ? function () {
|
|
47
48
|
return null;
|
|
48
|
-
} : _ref$onClose
|
|
49
|
+
} : _ref$onClose,
|
|
50
|
+
actionRef = _ref.actionRef,
|
|
51
|
+
onKeyDown = _ref.onKeyDown,
|
|
52
|
+
_ref$onClick = _ref.onClick,
|
|
53
|
+
_onClick = _ref$onClick === void 0 ? function () {
|
|
54
|
+
return null;
|
|
55
|
+
} : _ref$onClick,
|
|
56
|
+
_ref$onClickOutside = _ref.onClickOutside,
|
|
57
|
+
onClickOutside = _ref$onClickOutside === void 0 ? function () {
|
|
58
|
+
return null;
|
|
59
|
+
} : _ref$onClickOutside,
|
|
60
|
+
triggerRef = _ref.triggerRef;
|
|
49
61
|
|
|
50
|
-
var _useState = React.useState(
|
|
62
|
+
var _useState = React.useState(false),
|
|
51
63
|
_useState2 = _slicedToArray__default['default'](_useState, 2),
|
|
52
64
|
open = _useState2[0],
|
|
53
65
|
setOpen = _useState2[1];
|
|
54
66
|
|
|
67
|
+
var wrapperRef = React.useRef(null);
|
|
68
|
+
var defaultTriggerRef = React.useRef(null);
|
|
55
69
|
React.useEffect(function () {
|
|
56
|
-
|
|
57
|
-
|
|
70
|
+
if (actionRef) {
|
|
71
|
+
actionRef.current.focusToIndex = function (index) {
|
|
72
|
+
if (wrapperRef.current) {
|
|
73
|
+
var parent = wrapperRef.current;
|
|
74
|
+
|
|
75
|
+
var buttons = _toConsumableArray__default['default'](parent.querySelectorAll('button'));
|
|
76
|
+
|
|
77
|
+
buttons[index].focus();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}, [actionRef, apps, customApps]);
|
|
58
82
|
|
|
59
83
|
var handleOnClose = function handleOnClose() {
|
|
84
|
+
if (typeof isOpen === 'boolean') {
|
|
85
|
+
setOpen(isOpen);
|
|
86
|
+
} else {
|
|
87
|
+
setOpen(false);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
onClose();
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
var handleOnClickOutside = function handleOnClickOutside(e) {
|
|
60
94
|
setOpen(false);
|
|
61
95
|
onClose();
|
|
96
|
+
onClickOutside(e);
|
|
62
97
|
};
|
|
63
98
|
|
|
64
99
|
var AppPickerContent = function AppPickerContent() {
|
|
@@ -67,7 +102,10 @@ var DSAppPicker = function DSAppPicker(_ref) {
|
|
|
67
102
|
customApps: customApps,
|
|
68
103
|
sectionTitle: sectionTitle,
|
|
69
104
|
customSectionTitle: customSectionTitle,
|
|
70
|
-
close: handleOnClose
|
|
105
|
+
close: handleOnClose,
|
|
106
|
+
wrapperRef: wrapperRef,
|
|
107
|
+
onKeyDown: onKeyDown,
|
|
108
|
+
triggerRef: triggerRef || defaultTriggerRef
|
|
71
109
|
});
|
|
72
110
|
};
|
|
73
111
|
|
|
@@ -78,17 +116,19 @@ var DSAppPicker = function DSAppPicker(_ref) {
|
|
|
78
116
|
id: "app-picker__button",
|
|
79
117
|
buttonType: "text",
|
|
80
118
|
icon: /*#__PURE__*/React__default['default'].createElement(Icon, null),
|
|
81
|
-
innerRef: ref,
|
|
82
|
-
onClick: function onClick() {
|
|
83
|
-
|
|
119
|
+
innerRef: dsUtilities.mergeRefs(ref, defaultTriggerRef),
|
|
120
|
+
onClick: function onClick(e) {
|
|
121
|
+
_onClick(e);
|
|
122
|
+
|
|
123
|
+
setOpen(true);
|
|
84
124
|
}
|
|
85
125
|
});
|
|
86
126
|
};
|
|
87
127
|
|
|
88
128
|
return /*#__PURE__*/React__default['default'].createElement(DSPopover__default['default'], {
|
|
89
129
|
content: /*#__PURE__*/React__default['default'].createElement(AppPickerContent, null),
|
|
90
|
-
isOpen: open,
|
|
91
|
-
onClickOutside:
|
|
130
|
+
isOpen: typeof isOpen === 'boolean' ? isOpen : open,
|
|
131
|
+
onClickOutside: handleOnClickOutside,
|
|
92
132
|
placement: "bottom",
|
|
93
133
|
interactionType: "click",
|
|
94
134
|
renderTrigger: RenderTrigger,
|
|
@@ -100,16 +140,9 @@ var DSAppPicker = function DSAppPicker(_ref) {
|
|
|
100
140
|
});
|
|
101
141
|
};
|
|
102
142
|
|
|
103
|
-
|
|
104
|
-
apps: reactDesc.PropTypes.array.description('Main items. Format: [{ label:string, icon:component, onClick:func, disabled:bool }]').isRequired,
|
|
105
|
-
customApps: reactDesc.PropTypes.array.description('Custom items. Format: [{ label:string, icon:component, onClick:func, disabled:bool }]'),
|
|
106
|
-
sectionTitle: reactDesc.PropTypes.string.description('main section title').defaultValue('APPLICATIONS'),
|
|
107
|
-
customSectionTitle: reactDesc.PropTypes.string.description('custom section title').defaultValue('CUSTOM APPLICATIONS'),
|
|
108
|
-
icon: reactDesc.PropTypes.func.description('trigger button s icon').defaultValue(MenuPicker__default['default'])
|
|
109
|
-
};
|
|
110
|
-
DSAppPicker.propTypes = appPickerProps;
|
|
143
|
+
DSAppPicker.propTypes = propTypes.propTypes;
|
|
111
144
|
var AppPickerWithSchema = reactDesc.describe(DSAppPicker);
|
|
112
|
-
AppPickerWithSchema.propTypes =
|
|
145
|
+
AppPickerWithSchema.propTypes = propTypes.propTypes;
|
|
113
146
|
|
|
114
147
|
exports.AppPickerWithSchema = AppPickerWithSchema;
|
|
115
148
|
exports.DSAppPicker = DSAppPicker;
|