linear-react-components-ui 1.1.25-beta.6 → 1.1.25-beta.7
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/lib/{BaseMask-78847f45.d.ts → BaseMask-0c14ef51.d.ts} +1 -1
- package/lib/{Cnpj-8366781f.d.ts → Cnpj-53bfd6ab.d.ts} +2 -1
- package/lib/{Cpf-3dfd54eb.d.ts → Cpf-019b21e0.d.ts} +2 -1
- package/lib/{Phone-1962c0f2.d.ts → Phone-2bb0b397.d.ts} +1 -1
- package/lib/{ZipCode-be9c5b3b.d.ts → ZipCode-09460e18.d.ts} +1 -1
- package/lib/index-19761a50.d.ts +26 -0
- package/lib/{index-6fcf446c.d.ts → index-208e7f62.d.ts} +20 -2
- package/lib/{index-02a27c19.d.ts → index-3b70931d.d.ts} +20 -2
- package/lib/index-4bda404f.d.ts +42 -0
- package/lib/{index-25b80f32.d.ts → index-7dfa8924.d.ts} +1 -1
- package/lib/{index-6f5c772d.d.ts → index-9e576346.d.ts} +1 -1
- package/lib/{index-696662fe.d.ts → index-afb7b5a9.d.ts} +1 -1
- package/lib/inputs2/checkboxfield/index.d.ts +2 -3
- package/lib/inputs2/checkboxfield/index.js +125 -32
- package/lib/inputs2/colorfield/index.d.ts +5 -6
- package/lib/inputs2/date/datefield/index.js +322 -34
- package/lib/inputs2/date/datefield/types.d.ts +3 -5
- package/lib/inputs2/date/dateperiodfield/index.js +587 -34
- package/lib/inputs2/date/dateperiodfield/types.d.ts +3 -5
- package/lib/inputs2/filefield/index.d.ts +5 -6
- package/lib/inputs2/index.d.ts +15 -18
- package/lib/inputs2/mask/BaseMask.d.ts +5 -6
- package/lib/inputs2/mask/Cnpj.d.ts +6 -7
- package/lib/inputs2/mask/Cnpj.js +21 -18
- package/lib/inputs2/mask/Cpf.d.ts +6 -7
- package/lib/inputs2/mask/Cpf.js +19 -12
- package/lib/inputs2/mask/Phone.d.ts +6 -7
- package/lib/inputs2/mask/ZipCode.d.ts +6 -7
- package/lib/inputs2/numberfield/currency.d.ts +4 -5
- package/lib/inputs2/numberfield/decimal.d.ts +4 -5
- package/lib/inputs2/numberfield/index.d.ts +4 -5
- package/lib/inputs2/numberfield/types.d.ts +4 -5
- package/lib/inputs2/radiofield/index.d.ts +1 -1
- package/lib/inputs2/radiofield/index.js +126 -25
- package/lib/inputs2/radiofield/types.d.ts +4 -6
- package/lib/inputs2/selectfield/index.d.ts +1 -1
- package/lib/inputs2/selectfield/index.js +502 -35
- package/lib/inputs2/selectfield/types.d.ts +6 -8
- package/lib/inputs2/textareafield/index.d.ts +3 -4
- package/lib/inputs2/textareafield/index.js +154 -30
- package/lib/inputs2/textfield/index.d.ts +4 -5
- package/lib/inputs2/textfield/index.js +120 -30
- package/package.json +1 -1
- package/lib/index-053f615b.d.ts +0 -26
- package/lib/index-7159df18.d.ts +0 -21
- package/lib/inputs2/checkboxfield/base.d.ts +0 -29
- package/lib/inputs2/checkboxfield/base.js +0 -134
- package/lib/inputs2/date/datefield/base.d.ts +0 -13
- package/lib/inputs2/date/datefield/base.js +0 -330
- package/lib/inputs2/date/dateperiodfield/base.d.ts +0 -13
- package/lib/inputs2/date/dateperiodfield/base.js +0 -595
- package/lib/inputs2/radiofield/base.d.ts +0 -12
- package/lib/inputs2/radiofield/base.js +0 -156
- package/lib/inputs2/selectfield/base.d.ts +0 -11
- package/lib/inputs2/selectfield/base.js +0 -513
- package/lib/inputs2/textareafield/base.d.ts +0 -26
- package/lib/inputs2/textareafield/base.js +0 -166
- package/lib/inputs2/textfield/base.d.ts +0 -26
- package/lib/inputs2/textfield/base.js +0 -131
|
@@ -29,56 +29,523 @@ Object.defineProperty(exports, "RightSlot", {
|
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
require("../../assets/styles/selectfield.scss");
|
|
32
|
-
var _react =
|
|
32
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
33
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
34
|
+
var _uuid = require("uuid");
|
|
35
|
+
var _reactDom = require("react-dom");
|
|
36
|
+
var _hint = _interopRequireDefault(require("../../hint"));
|
|
33
37
|
var _gridlayout = _interopRequireDefault(require("../../gridlayout"));
|
|
38
|
+
var _popover = _interopRequireWildcard(require("../../popover"));
|
|
39
|
+
var _tooltip = require("../../tooltip");
|
|
40
|
+
var _helpers = require("../../form2/helpers");
|
|
34
41
|
var _permissionValidations = require("../../permissionValidations");
|
|
35
42
|
var _slot = require("../slot");
|
|
43
|
+
var _listbox = require("./listbox");
|
|
44
|
+
var _triggers = require("./triggers");
|
|
45
|
+
var _selections = require("./selections");
|
|
46
|
+
var _context = require("./context");
|
|
36
47
|
var _options = require("./options");
|
|
37
48
|
var _item = require("./item");
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
const _excluded = ["
|
|
49
|
+
var _types = require("./types");
|
|
50
|
+
var _helpers2 = require("./helpers");
|
|
51
|
+
const _excluded = ["name", "label", "errors", "children", "gridLayout", "onChange", "tooltip", "tooltipPosition", "tooltipWidth", "hintPosition", "themePopover", "popoverAlign", "skeletonize", "striped", "undigitable", "externalSearch", "openDropdownOnFocus", "showClearButton", "textAlign", "searchOnDropdown", "onSearch", "permissionAttr", "customClass", "customClassLabel", "customClassWrapper", "customClassInputContainer", "onDeniedActions", "notFoundFilterLabel", "multipleInputLabelEmpty", "multipleInputLabelManySelection", "searchInputPlaceholder", "dropdownAlignButton"];
|
|
41
52
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
53
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
42
54
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
43
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
44
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
45
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
46
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
47
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
48
55
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
49
56
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
const SELECT_FIELD_CONTROLS_ID = "select-field-controls-".concat((0, _uuid.v1)());
|
|
58
|
+
const Input = exports.Input = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
59
|
+
var _props$hint, _props$hint2;
|
|
60
|
+
const {
|
|
61
|
+
name,
|
|
62
|
+
label,
|
|
63
|
+
errors,
|
|
64
|
+
children,
|
|
54
65
|
gridLayout,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
onChange,
|
|
67
|
+
tooltip,
|
|
68
|
+
tooltipPosition,
|
|
69
|
+
tooltipWidth,
|
|
70
|
+
hintPosition = 'below',
|
|
71
|
+
themePopover = 'light',
|
|
72
|
+
popoverAlign = 'left',
|
|
73
|
+
skeletonize = false,
|
|
74
|
+
striped = false,
|
|
75
|
+
undigitable = false,
|
|
76
|
+
externalSearch = false,
|
|
77
|
+
openDropdownOnFocus = true,
|
|
78
|
+
showClearButton = true,
|
|
79
|
+
textAlign = 'left',
|
|
80
|
+
searchOnDropdown = false,
|
|
81
|
+
onSearch = undefined,
|
|
82
|
+
permissionAttr = undefined,
|
|
83
|
+
customClass = '',
|
|
84
|
+
customClassLabel = '',
|
|
85
|
+
customClassWrapper = '',
|
|
86
|
+
customClassInputContainer = '',
|
|
87
|
+
onDeniedActions = undefined,
|
|
88
|
+
notFoundFilterLabel = 'Nenhuma opção encontrada.',
|
|
89
|
+
multipleInputLabelEmpty = 'Nenhum registro selecionado',
|
|
90
|
+
multipleInputLabelManySelection = 'Múltiplos registros selecionados',
|
|
91
|
+
searchInputPlaceholder = 'Pesquisar registros',
|
|
92
|
+
dropdownAlignButton = 'left'
|
|
93
|
+
} = props,
|
|
94
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
59
95
|
const onDenied = _react.default.useMemo(() => {
|
|
60
|
-
return onDeniedActions || (0, _permissionValidations.actionsOnPermissionDenied)(
|
|
96
|
+
return onDeniedActions || (0, _permissionValidations.actionsOnPermissionDenied)(_helpers2.options, permissionAttr);
|
|
61
97
|
}, [onDeniedActions, permissionAttr]);
|
|
62
98
|
const {
|
|
63
99
|
hideContent,
|
|
64
100
|
unvisible
|
|
65
101
|
} = onDenied;
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
102
|
+
const [inputValue, setInputValue] = _react.default.useState('');
|
|
103
|
+
const [filterValue, setFilterValue] = _react.default.useState('');
|
|
104
|
+
const [listBoxOpen, setListBoxOpen] = _react.default.useState(false);
|
|
105
|
+
const [activeDescendant, setActiveDescendant] = _react.default.useState(undefined);
|
|
106
|
+
const isMultipleDefault = _lodash.default.isEqual(props === null || props === void 0 ? void 0 : props.multiple, _types.MultipleVariantEnum.default);
|
|
107
|
+
const isMultipleWithCheckboxes = _lodash.default.isEqual(props === null || props === void 0 ? void 0 : props.multiple, _types.MultipleVariantEnum.checkboxes);
|
|
108
|
+
const isMultipleSelect = isMultipleDefault || isMultipleWithCheckboxes;
|
|
109
|
+
const liSelectedRef = _react.default.useRef(null);
|
|
110
|
+
const selectFieldRoot = _react.default.useRef(null);
|
|
111
|
+
const selectInputRef = _react.default.useRef(null);
|
|
112
|
+
const selectListBoxRef = _react.default.useRef(null);
|
|
113
|
+
const selectContainerRef = _react.default.useRef(null);
|
|
114
|
+
const selectSearchInputRef = _react.default.useRef(null);
|
|
115
|
+
const listOptionsMap = _react.default.useMemo(() => {
|
|
116
|
+
const optionsMap = new Map();
|
|
117
|
+
_react.default.Children.forEach(children, child => {
|
|
118
|
+
if (/*#__PURE__*/_react.default.isValidElement(child)) {
|
|
119
|
+
optionsMap.set(child.props.value, child.props.label);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return optionsMap;
|
|
123
|
+
}, [children]);
|
|
124
|
+
_react.default.useEffect(() => {
|
|
125
|
+
if (isMultipleWithCheckboxes) {
|
|
126
|
+
setInputValue(multipleInputLabelEmpty);
|
|
127
|
+
}
|
|
128
|
+
}, []);
|
|
129
|
+
_react.default.useEffect(() => {
|
|
130
|
+
if (openDropdownOnFocus && listBoxOpen) {
|
|
131
|
+
requestAnimationFrame(() => {
|
|
132
|
+
if (isMultipleWithCheckboxes) {
|
|
133
|
+
var _selectSearchInputRef, _selectSearchInputRef2;
|
|
134
|
+
(_selectSearchInputRef = selectSearchInputRef.current) === null || _selectSearchInputRef === void 0 ? void 0 : (_selectSearchInputRef2 = _selectSearchInputRef.focus) === null || _selectSearchInputRef2 === void 0 ? void 0 : _selectSearchInputRef2.call(_selectSearchInputRef);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}, [listBoxOpen]);
|
|
139
|
+
_react.default.useEffect(() => {
|
|
140
|
+
if (!isMultipleWithCheckboxes && !(props !== null && props !== void 0 && props.value)) setInputValue('');
|
|
141
|
+
if (!(props !== null && props !== void 0 && props.value) || document.activeElement === selectInputRef.current) return;
|
|
142
|
+
const lazyInputValue = listOptionsMap.get(rest.value);
|
|
143
|
+
if (!isMultipleWithCheckboxes) setInputValue(lazyInputValue !== null && lazyInputValue !== void 0 ? lazyInputValue : '');
|
|
144
|
+
if (isMultipleWithCheckboxes) {
|
|
145
|
+
const firstSelectionLabel = listOptionsMap.get(props === null || props === void 0 ? void 0 : props.value[0]);
|
|
146
|
+
switch (_lodash.default.size(props === null || props === void 0 ? void 0 : props.value)) {
|
|
147
|
+
case 0:
|
|
148
|
+
return setInputValue(multipleInputLabelEmpty);
|
|
149
|
+
case 1:
|
|
150
|
+
return setInputValue(firstSelectionLabel !== null && firstSelectionLabel !== void 0 ? firstSelectionLabel : '');
|
|
151
|
+
default:
|
|
152
|
+
return setInputValue(multipleInputLabelManySelection);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}, [props === null || props === void 0 ? void 0 : props.value, listOptionsMap]);
|
|
156
|
+
const hasLabel = !_lodash.default.isEmpty(props === null || props === void 0 ? void 0 : props.label);
|
|
157
|
+
const hasHintMessages = Boolean((_props$hint = props.hint) === null || _props$hint === void 0 ? void 0 : _props$hint.length);
|
|
158
|
+
const hasValidationErrors = Boolean(errors === null || errors === void 0 ? void 0 : errors.length);
|
|
159
|
+
const isReadOnly = Boolean(props.readOnly || onDenied.readOnly);
|
|
160
|
+
const isDisabled = Boolean(props.disabled || onDenied.disabled);
|
|
161
|
+
const {
|
|
162
|
+
childrenItems
|
|
163
|
+
} = _react.default.useMemo(() => {
|
|
164
|
+
const itens = [];
|
|
165
|
+
_react.default.Children.map(children, (childElement, index) => {
|
|
166
|
+
if (/*#__PURE__*/_react.default.isValidElement(childElement)) {
|
|
167
|
+
var _childElement$key;
|
|
168
|
+
const clonedChild = /*#__PURE__*/_react.default.cloneElement(childElement, {
|
|
169
|
+
key: (_childElement$key = childElement.key) !== null && _childElement$key !== void 0 ? _childElement$key : "child-item-".concat(index + 1)
|
|
170
|
+
});
|
|
171
|
+
if (childElement.type === _item.Item) itens.push(clonedChild);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
childrenItems: itens
|
|
176
|
+
};
|
|
177
|
+
}, [children, isDisabled]);
|
|
178
|
+
const {
|
|
179
|
+
leftSlotElements,
|
|
180
|
+
rightSlotElements
|
|
181
|
+
} = _react.default.useMemo(() => {
|
|
182
|
+
const left = [];
|
|
183
|
+
const right = [];
|
|
184
|
+
_react.default.Children.map(children, (childElement, index) => {
|
|
185
|
+
if (/*#__PURE__*/_react.default.isValidElement(childElement)) {
|
|
186
|
+
var _childElement$key2;
|
|
187
|
+
const clonedChild = /*#__PURE__*/_react.default.cloneElement(childElement, {
|
|
188
|
+
key: (_childElement$key2 = childElement.key) !== null && _childElement$key2 !== void 0 ? _childElement$key2 : "slot-".concat(index),
|
|
189
|
+
disabled: isDisabled,
|
|
190
|
+
'aria-disabled': isDisabled
|
|
191
|
+
});
|
|
192
|
+
if (childElement.type === _slot.LeftSlot) left.push(clonedChild);
|
|
193
|
+
if (childElement.type === _slot.RightSlot) right.push(clonedChild);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return {
|
|
197
|
+
leftSlotElements: left,
|
|
198
|
+
rightSlotElements: right
|
|
199
|
+
};
|
|
200
|
+
}, [children, isDisabled]);
|
|
201
|
+
const {
|
|
202
|
+
optionItens
|
|
203
|
+
} = _react.default.useMemo(() => {
|
|
204
|
+
const itens = [];
|
|
205
|
+
_react.default.Children.map(children, (childElement, index) => {
|
|
206
|
+
if (/*#__PURE__*/_react.default.isValidElement(childElement)) {
|
|
207
|
+
var _childElement$key3;
|
|
208
|
+
const clonedChildItem = /*#__PURE__*/_react.default.cloneElement(childElement, {
|
|
209
|
+
key: (_childElement$key3 = childElement.key) !== null && _childElement$key3 !== void 0 ? _childElement$key3 : "option-list-".concat(index),
|
|
210
|
+
disabled: isDisabled
|
|
211
|
+
});
|
|
212
|
+
if (childElement.type === _options.Options) itens.push(clonedChildItem);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return {
|
|
216
|
+
optionItens: itens
|
|
217
|
+
};
|
|
218
|
+
}, [children, isDisabled]);
|
|
219
|
+
const hasLeftSlotElements = Boolean(leftSlotElements === null || leftSlotElements === void 0 ? void 0 : leftSlotElements.length);
|
|
220
|
+
const hasRightSlotElements = Boolean(rightSlotElements === null || rightSlotElements === void 0 ? void 0 : rightSlotElements.length);
|
|
221
|
+
const handleCloseListBox = () => {
|
|
222
|
+
setListBoxOpen(false);
|
|
223
|
+
setFilterValue('');
|
|
224
|
+
};
|
|
225
|
+
const handleOpenListBox = () => {
|
|
226
|
+
var _$toString;
|
|
227
|
+
const currentValue = !isMultipleSelect ? props === null || props === void 0 ? void 0 : props.value : _lodash.default.orderBy([...props.value], value => _lodash.default.toNumber(value), ['asc'])[0];
|
|
228
|
+
setActiveDescendant((_$toString = _lodash.default.toString(currentValue)) !== null && _$toString !== void 0 ? _$toString : undefined);
|
|
229
|
+
};
|
|
230
|
+
const handleChangeListBoxState = () => {
|
|
231
|
+
setListBoxOpen(prevState => {
|
|
232
|
+
if (prevState) {
|
|
233
|
+
setFilterValue('');
|
|
234
|
+
}
|
|
235
|
+
if (selectInputRef.current !== document.activeElement) {
|
|
236
|
+
var _selectInputRef$curre, _selectInputRef$curre2;
|
|
237
|
+
selectInputRef === null || selectInputRef === void 0 ? void 0 : (_selectInputRef$curre = selectInputRef.current) === null || _selectInputRef$curre === void 0 ? void 0 : (_selectInputRef$curre2 = _selectInputRef$curre.focus) === null || _selectInputRef$curre2 === void 0 ? void 0 : _selectInputRef$curre2.call(_selectInputRef$curre);
|
|
238
|
+
}
|
|
239
|
+
return !prevState;
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
const handleChangeLiSelected = liElement => {
|
|
243
|
+
liSelectedRef.current = liElement;
|
|
244
|
+
};
|
|
245
|
+
const handleOnChange = (value, inputLabel, addOrRemove) => {
|
|
246
|
+
let multipleValue = props === null || props === void 0 ? void 0 : props.value;
|
|
247
|
+
if (!addOrRemove) multipleValue = _lodash.default.union(props.value, [value]);
|
|
248
|
+
if (addOrRemove) multipleValue = _lodash.default.without(props.value, value);
|
|
249
|
+
const changedValue = !isMultipleSelect ? value : _lodash.default.orderBy(multipleValue, multiValue => _lodash.default.toNumber(multiValue), ['asc']);
|
|
250
|
+
const syntheticEvent = {
|
|
251
|
+
target: {
|
|
252
|
+
name,
|
|
253
|
+
value: changedValue
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(syntheticEvent);
|
|
257
|
+
if (!isMultipleSelect) {
|
|
258
|
+
setListBoxOpen(false);
|
|
259
|
+
setFilterValue('');
|
|
260
|
+
setInputValue(inputLabel !== null && inputLabel !== void 0 ? inputLabel : '');
|
|
261
|
+
if (document.activeElement === selectSearchInputRef.current) {
|
|
262
|
+
var _selectInputRef$curre3, _selectInputRef$curre4;
|
|
263
|
+
selectInputRef === null || selectInputRef === void 0 ? void 0 : (_selectInputRef$curre3 = selectInputRef.current) === null || _selectInputRef$curre3 === void 0 ? void 0 : (_selectInputRef$curre4 = _selectInputRef$curre3.focus) === null || _selectInputRef$curre4 === void 0 ? void 0 : _selectInputRef$curre4.call(_selectInputRef$curre3);
|
|
264
|
+
setListBoxOpen(false);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
const handleCheckMultiple = checkOrUncheckAll => {
|
|
269
|
+
const checkAll = Boolean(checkOrUncheckAll);
|
|
270
|
+
let allValues = [];
|
|
271
|
+
listOptionsMap.forEach((__, key) => allValues.push(key));
|
|
272
|
+
const value = checkAll ? allValues : [];
|
|
273
|
+
const syntheticEvent = {
|
|
274
|
+
target: {
|
|
275
|
+
name,
|
|
276
|
+
value
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(syntheticEvent);
|
|
280
|
+
};
|
|
281
|
+
const handleClearValue = () => {
|
|
282
|
+
const resetValue = !isMultipleSelect ? '' : [];
|
|
283
|
+
const syntheticEvent = {
|
|
284
|
+
target: {
|
|
285
|
+
name,
|
|
286
|
+
value: resetValue
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(syntheticEvent);
|
|
290
|
+
setListBoxOpen(false);
|
|
291
|
+
if (!isMultipleSelect) {
|
|
292
|
+
setFilterValue('');
|
|
293
|
+
setInputValue('');
|
|
294
|
+
}
|
|
295
|
+
if (isMultipleWithCheckboxes) {
|
|
296
|
+
setInputValue(multipleInputLabelEmpty);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
const handleOnBlur = event => {
|
|
300
|
+
var _props$onBlur;
|
|
301
|
+
props === null || props === void 0 ? void 0 : (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 ? void 0 : _props$onBlur.call(props, event);
|
|
302
|
+
if (!event.relatedTarget || event.relatedTarget !== selectSearchInputRef.current) {
|
|
303
|
+
setListBoxOpen(false);
|
|
304
|
+
}
|
|
305
|
+
setFilterValue('');
|
|
306
|
+
};
|
|
307
|
+
const handleOnFocus = event => {
|
|
308
|
+
var _props$onFocus;
|
|
309
|
+
props === null || props === void 0 ? void 0 : (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 ? void 0 : _props$onFocus.call(props, event);
|
|
310
|
+
if (openDropdownOnFocus) {
|
|
311
|
+
setListBoxOpen(true);
|
|
312
|
+
handleOpenListBox();
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
const handleOnChangeInput = event => {
|
|
316
|
+
setFilterValue(event.target.value);
|
|
317
|
+
setInputValue(event.target.value);
|
|
318
|
+
};
|
|
319
|
+
const handleOnPaste = event => {
|
|
320
|
+
if (undigitable || isMultipleWithCheckboxes) {
|
|
321
|
+
event.preventDefault();
|
|
322
|
+
} else {
|
|
323
|
+
var _props$onPaste;
|
|
324
|
+
(_props$onPaste = props.onPaste) === null || _props$onPaste === void 0 ? void 0 : _props$onPaste.call(props, event);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
const handleOnBeforeInput = event => {
|
|
328
|
+
if (undigitable || isMultipleWithCheckboxes) {
|
|
329
|
+
event.preventDefault();
|
|
330
|
+
} else {
|
|
331
|
+
var _props$onBeforeInput;
|
|
332
|
+
(_props$onBeforeInput = props.onBeforeInput) === null || _props$onBeforeInput === void 0 ? void 0 : _props$onBeforeInput.call(props, event);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
const handleOnSearch = event => {
|
|
336
|
+
if (externalSearch) {
|
|
337
|
+
onSearch === null || onSearch === void 0 ? void 0 : onSearch(event);
|
|
338
|
+
} else {
|
|
339
|
+
setFilterValue(event.target.value);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
const handleOnKeyDown = event => {
|
|
343
|
+
var _props$onKeyDown;
|
|
344
|
+
props === null || props === void 0 ? void 0 : (_props$onKeyDown = props.onKeyDown) === null || _props$onKeyDown === void 0 ? void 0 : _props$onKeyDown.call(props, event);
|
|
345
|
+
const notUndigitableKeys = [_types.Keys.backspace, _types.Keys.delete];
|
|
346
|
+
if (undigitable && notUndigitableKeys.includes(event.key)) {
|
|
347
|
+
event.preventDefault();
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const shouldOpenByTyping = (0, _helpers2.isTypingKey)(event) || event.key === _types.Keys.arrowDown;
|
|
351
|
+
if (shouldOpenByTyping && selectInputRef.current === document.activeElement) {
|
|
352
|
+
if (event.key === _types.Keys.arrowDown) {
|
|
353
|
+
event.preventDefault();
|
|
354
|
+
}
|
|
355
|
+
requestAnimationFrame(() => {
|
|
356
|
+
var _selectListBoxRef$cur, _ulListElement$queryS;
|
|
357
|
+
const ulListElement = (_selectListBoxRef$cur = selectListBoxRef.current) === null || _selectListBoxRef$cur === void 0 ? void 0 : _selectListBoxRef$cur.querySelector('ul[role="listbox"]');
|
|
358
|
+
const liElementsFiltered = (_ulListElement$queryS = ulListElement === null || ulListElement === void 0 ? void 0 : ulListElement.querySelectorAll('li[data-state-filtered="true"]')) !== null && _ulListElement$queryS !== void 0 ? _ulListElement$queryS : [];
|
|
359
|
+
if (!listBoxOpen && event.key === _types.Keys.arrowDown) {
|
|
360
|
+
var _$toString2;
|
|
361
|
+
const currentValue = !isMultipleSelect ? props === null || props === void 0 ? void 0 : props.value : _lodash.default.orderBy([...props.value], value => _lodash.default.toNumber(value), ['asc'])[0];
|
|
362
|
+
setActiveDescendant((_$toString2 = _lodash.default.toString(currentValue)) !== null && _$toString2 !== void 0 ? _$toString2 : undefined);
|
|
363
|
+
} else {
|
|
364
|
+
var _liElementsFiltered$, _liElementsFiltered$2;
|
|
365
|
+
setActiveDescendant((_liElementsFiltered$ = (_liElementsFiltered$2 = liElementsFiltered[0]) === null || _liElementsFiltered$2 === void 0 ? void 0 : _liElementsFiltered$2.id) !== null && _liElementsFiltered$ !== void 0 ? _liElementsFiltered$ : undefined);
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
if (!listBoxOpen) {
|
|
369
|
+
setListBoxOpen(true);
|
|
370
|
+
handleOpenListBox();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (listBoxOpen && _helpers2.NAVIGATION_KEYS.includes(event.key)) {
|
|
374
|
+
event.preventDefault();
|
|
375
|
+
}
|
|
376
|
+
requestAnimationFrame(() => {
|
|
377
|
+
var _selectListBoxRef$cur2, _ulListElement$queryS2, _selectInputRef$curre5;
|
|
378
|
+
const ulListElement = (_selectListBoxRef$cur2 = selectListBoxRef.current) === null || _selectListBoxRef$cur2 === void 0 ? void 0 : _selectListBoxRef$cur2.querySelector('ul[role="listbox"]');
|
|
379
|
+
const liElementsFiltered = (_ulListElement$queryS2 = ulListElement === null || ulListElement === void 0 ? void 0 : ulListElement.querySelectorAll('li[data-state-filtered="true"]')) !== null && _ulListElement$queryS2 !== void 0 ? _ulListElement$queryS2 : [];
|
|
380
|
+
const currentElementIndex = Array.from(liElementsFiltered).findIndex(liElement => liElement.id === activeDescendant);
|
|
381
|
+
let nextElementIndex = currentElementIndex;
|
|
382
|
+
if (listBoxOpen) {
|
|
383
|
+
if (_helpers2.NAVIGATION_KEYS.includes(event.key)) {
|
|
384
|
+
switch (event.key) {
|
|
385
|
+
case _types.Keys.escape:
|
|
386
|
+
setListBoxOpen(false);
|
|
387
|
+
setFilterValue('');
|
|
388
|
+
(_selectInputRef$curre5 = selectInputRef.current) === null || _selectInputRef$curre5 === void 0 ? void 0 : _selectInputRef$curre5.focus();
|
|
389
|
+
if (event.target === selectSearchInputRef.current) {
|
|
390
|
+
setListBoxOpen(false);
|
|
391
|
+
}
|
|
392
|
+
break;
|
|
393
|
+
case _types.Keys.arrowDown:
|
|
394
|
+
nextElementIndex = Math.min(currentElementIndex + 1, liElementsFiltered.length - 1);
|
|
395
|
+
break;
|
|
396
|
+
case _types.Keys.arrowUp:
|
|
397
|
+
nextElementIndex = Math.max(currentElementIndex - 1, 0);
|
|
398
|
+
break;
|
|
399
|
+
case _types.Keys.enter:
|
|
400
|
+
if (activeDescendant) {
|
|
401
|
+
const selectedLIOption = liElementsFiltered[nextElementIndex];
|
|
402
|
+
if (selectedLIOption) {
|
|
403
|
+
selectedLIOption.click();
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
break;
|
|
407
|
+
default:
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
const nextLIOption = liElementsFiltered[nextElementIndex];
|
|
411
|
+
if (nextLIOption) {
|
|
412
|
+
var _nextLIOption$id;
|
|
413
|
+
setActiveDescendant((_nextLIOption$id = nextLIOption === null || nextLIOption === void 0 ? void 0 : nextLIOption.id) !== null && _nextLIOption$id !== void 0 ? _nextLIOption$id : '');
|
|
414
|
+
nextLIOption.scrollIntoView({
|
|
415
|
+
block: 'nearest'
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
} else return null;
|
|
420
|
+
});
|
|
421
|
+
};
|
|
422
|
+
const contextValues = _react.default.useMemo(() => ({
|
|
423
|
+
selectFieldId: SELECT_FIELD_CONTROLS_ID,
|
|
424
|
+
label: props.label,
|
|
425
|
+
striped,
|
|
426
|
+
listBoxOpen,
|
|
427
|
+
filterValue,
|
|
428
|
+
isDisabled,
|
|
429
|
+
liSelectedRef,
|
|
430
|
+
selectInputRef,
|
|
431
|
+
selectSearchInputRef,
|
|
432
|
+
handleOnSearch,
|
|
433
|
+
searchOnDropdown,
|
|
434
|
+
nameSelect: String(props.name),
|
|
435
|
+
valueSelect: props === null || props === void 0 ? void 0 : props.value,
|
|
436
|
+
activeDescendant,
|
|
437
|
+
handleOnChange,
|
|
438
|
+
handleOnKeyDown,
|
|
439
|
+
selectContainerRef,
|
|
440
|
+
handleCloseListBox,
|
|
441
|
+
notFoundFilterLabel,
|
|
442
|
+
handleChangeLiSelected,
|
|
443
|
+
isMultipleSelect,
|
|
444
|
+
isMultipleDefault,
|
|
445
|
+
isMultipleWithCheckboxes,
|
|
446
|
+
searchInputPlaceholder,
|
|
447
|
+
showClearButton,
|
|
448
|
+
dropdownAlignButton,
|
|
449
|
+
handleClearValue,
|
|
450
|
+
handleCheckMultiple,
|
|
451
|
+
handleChangeListBoxState,
|
|
452
|
+
optionItens
|
|
453
|
+
}), [striped, listBoxOpen, isDisabled, filterValue, props === null || props === void 0 ? void 0 : props.name, props === null || props === void 0 ? void 0 : props.value, activeDescendant, notFoundFilterLabel, searchOnDropdown, isMultipleSelect, showClearButton, isMultipleDefault, isMultipleWithCheckboxes, searchInputPlaceholder, dropdownAlignButton, optionItens]);
|
|
454
|
+
if (unvisible || hideContent) return null;
|
|
455
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_gridlayout.default, {
|
|
456
|
+
cols: gridLayout
|
|
457
|
+
}, /*#__PURE__*/_react.default.createElement(_context.SelectFieldContext.Provider, {
|
|
458
|
+
value: contextValues
|
|
459
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
460
|
+
ref: selectFieldRoot,
|
|
461
|
+
"data-testid": "test-select-field-root",
|
|
462
|
+
className: "select-field-root ".concat(customClassWrapper),
|
|
463
|
+
"data-state-error": hasValidationErrors,
|
|
464
|
+
"data-state-hint-position": hintPosition
|
|
465
|
+
}, hasLabel && /*#__PURE__*/_react.default.createElement("span", {
|
|
466
|
+
className: "root-label ".concat(customClassLabel),
|
|
467
|
+
"data-state-skeletonize": skeletonize
|
|
468
|
+
}, /*#__PURE__*/_react.default.createElement("label", {
|
|
469
|
+
"data-testid": "test-select-field-label",
|
|
470
|
+
className: "label",
|
|
471
|
+
title: label,
|
|
472
|
+
htmlFor: name,
|
|
473
|
+
"aria-disabled": isDisabled,
|
|
474
|
+
"aria-readonly": isReadOnly,
|
|
475
|
+
"data-state-input-required": props.required
|
|
476
|
+
}, label), hasHintMessages && hintPosition === 'onLabelRight' && !skeletonize && /*#__PURE__*/_react.default.createElement(_popover.default, {
|
|
477
|
+
customClass: "label-popover",
|
|
478
|
+
theme: themePopover,
|
|
479
|
+
align: popoverAlign,
|
|
480
|
+
iconColor: "#03bde2"
|
|
481
|
+
}, /*#__PURE__*/_react.default.createElement(_popover.PopoverText, {
|
|
482
|
+
text: (_props$hint2 = props === null || props === void 0 ? void 0 : props.hint) !== null && _props$hint2 !== void 0 ? _props$hint2 : ''
|
|
483
|
+
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
484
|
+
ref: selectContainerRef,
|
|
485
|
+
className: "container ".concat(customClassInputContainer),
|
|
486
|
+
"aria-expanded": listBoxOpen,
|
|
487
|
+
"data-state-skeletonize": skeletonize
|
|
488
|
+
}, hasLeftSlotElements && !skeletonize && leftSlotElements, /*#__PURE__*/_react.default.createElement("div", {
|
|
489
|
+
className: "input-root"
|
|
490
|
+
}, /*#__PURE__*/_react.default.createElement("input", _extends({}, rest, {
|
|
491
|
+
ref: (0, _helpers.mergeRefs)(ref, selectInputRef),
|
|
492
|
+
readOnly: props.readOnly || undigitable,
|
|
493
|
+
className: "input ".concat(customClass),
|
|
494
|
+
placeholder: rest.placeholder,
|
|
495
|
+
"data-state-error": hasValidationErrors,
|
|
496
|
+
"data-state-multiple": isMultipleSelect,
|
|
497
|
+
"data-state-read-only": isReadOnly,
|
|
498
|
+
"data-state-text-align": textAlign,
|
|
499
|
+
"data-state-undigitable": undigitable,
|
|
500
|
+
"data-state-skeletonize": skeletonize,
|
|
501
|
+
"data-state-multiple-with-checkboxes": isMultipleWithCheckboxes,
|
|
502
|
+
id: name,
|
|
503
|
+
type: "text",
|
|
504
|
+
role: "combobox",
|
|
505
|
+
multiple: false,
|
|
506
|
+
"data-testid": "test-select-field-input",
|
|
507
|
+
"aria-autocomplete": "list",
|
|
508
|
+
"aria-expanded": listBoxOpen,
|
|
509
|
+
"aria-controls": SELECT_FIELD_CONTROLS_ID,
|
|
510
|
+
"aria-activedescendant": activeDescendant,
|
|
511
|
+
tabIndex: !isReadOnly && !skeletonize ? 0 : -1,
|
|
512
|
+
value: inputValue,
|
|
513
|
+
onBlur: handleOnBlur,
|
|
514
|
+
onFocus: handleOnFocus,
|
|
515
|
+
onKeyDown: handleOnKeyDown,
|
|
516
|
+
onChange: handleOnChangeInput,
|
|
517
|
+
onPaste: handleOnPaste,
|
|
518
|
+
onBeforeInput: handleOnBeforeInput
|
|
519
|
+
})), isMultipleDefault && /*#__PURE__*/_react.default.createElement(_selections.Selections, {
|
|
520
|
+
isDisabled: isDisabled,
|
|
521
|
+
isReadOnly: isReadOnly,
|
|
522
|
+
listOfOptionsToSelect: listOptionsMap
|
|
523
|
+
})), hasRightSlotElements && !skeletonize && rightSlotElements, /*#__PURE__*/_react.default.createElement("div", {
|
|
524
|
+
className: "triggers",
|
|
525
|
+
"data-state-disabled": isDisabled,
|
|
526
|
+
"data-state-read-only": isReadOnly,
|
|
527
|
+
"data-state-skeletonize": skeletonize
|
|
528
|
+
}, /*#__PURE__*/_react.default.createElement(_triggers.Triggers, null)), listBoxOpen && !hideContent && /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/_react.default.createElement(_listbox.ListBox, {
|
|
529
|
+
ref: selectListBoxRef
|
|
530
|
+
}, childrenItems), document.body)), hintPosition === 'below' && /*#__PURE__*/_react.default.createElement(_hint.default, {
|
|
531
|
+
customClass: "hint",
|
|
532
|
+
skeletonize: skeletonize,
|
|
533
|
+
description: props.hint,
|
|
534
|
+
disabled: isDisabled,
|
|
535
|
+
visible: hasHintMessages
|
|
536
|
+
}), hasValidationErrors && /*#__PURE__*/_react.default.createElement("span", {
|
|
537
|
+
"data-testid": "test-select-field-list-errors",
|
|
538
|
+
className: "error",
|
|
539
|
+
"data-state-skeletonize": skeletonize,
|
|
540
|
+
"aria-describedby": String(name).concat('-errors')
|
|
541
|
+
}, errors === null || errors === void 0 ? void 0 : errors.map((error, index) => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
|
|
542
|
+
key: "".concat(index + 1, "-").concat(error)
|
|
543
|
+
}, error, "\xA0")))))), /*#__PURE__*/_react.default.createElement(_tooltip.Tooltip, {
|
|
544
|
+
targetRef: selectInputRef,
|
|
545
|
+
text: tooltip,
|
|
546
|
+
position: tooltipPosition,
|
|
547
|
+
width: tooltipWidth,
|
|
548
|
+
space: tooltipPosition === 'right' ? 64 : undefined
|
|
549
|
+
}));
|
|
83
550
|
});
|
|
84
551
|
Input.displayName = 'SelectFieldInput';
|
|
@@ -18,13 +18,8 @@ declare enum Keys {
|
|
|
18
18
|
delete = "Delete",
|
|
19
19
|
spaceBar = " "
|
|
20
20
|
}
|
|
21
|
-
type InputHTMLProps = Omit<React.
|
|
22
|
-
interface SelectFieldInputProps extends
|
|
23
|
-
gridLayout?: string;
|
|
24
|
-
permissionAttr?: PermissionAttr;
|
|
25
|
-
onDeniedActions?: OnDenied;
|
|
26
|
-
}
|
|
27
|
-
interface SelectFieldInputBaseProps extends InputHTMLProps, ITooltipCommonProps {
|
|
21
|
+
type InputHTMLProps = Omit<React.ComponentProps<'input'>, 'multiple' | 'type'>;
|
|
22
|
+
interface SelectFieldInputProps extends InputHTMLProps, ITooltipCommonProps {
|
|
28
23
|
skeletonize?: boolean;
|
|
29
24
|
undigitable?: boolean;
|
|
30
25
|
externalSearch?: boolean;
|
|
@@ -36,6 +31,7 @@ interface SelectFieldInputBaseProps extends InputHTMLProps, ITooltipCommonProps
|
|
|
36
31
|
errors?: string[];
|
|
37
32
|
striped?: boolean;
|
|
38
33
|
hint?: string;
|
|
34
|
+
gridLayout?: string;
|
|
39
35
|
notFoundFilterLabel?: string;
|
|
40
36
|
customClass?: string;
|
|
41
37
|
customClassLabel?: string;
|
|
@@ -48,9 +44,11 @@ interface SelectFieldInputBaseProps extends InputHTMLProps, ITooltipCommonProps
|
|
|
48
44
|
hintPosition?: HintPosition;
|
|
49
45
|
themePopover?: ColorTheme;
|
|
50
46
|
popoverAlign?: Extract<Position, 'left' | 'right'>;
|
|
47
|
+
permissionAttr?: PermissionAttr;
|
|
48
|
+
onDeniedActions?: OnDenied;
|
|
51
49
|
dropdownAlignButton?: Extract<Position, 'left' | 'right'>;
|
|
52
50
|
onSearch?: (event?: React.ChangeEvent<HTMLInputElement>) => void;
|
|
53
51
|
multiple?: keyof typeof MultipleVariantEnum;
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
export { Keys, MultipleVariantEnum,
|
|
54
|
+
export { Keys, MultipleVariantEnum, SelectFieldInputProps };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import 'react';
|
|
2
|
-
import '../../@types/PermissionAttr.js';
|
|
3
|
-
export { LeftSlot, RightSlot } from '../slot/index.js';
|
|
4
|
-
import './base.js';
|
|
5
|
-
export { I as Input, T as TextAreaFieldInputProps } from '../../index-6fcf446c.js';
|
|
6
2
|
import '../../@types/Align.js';
|
|
7
3
|
import '../../@types/ColorStyles.js';
|
|
8
4
|
import '../../@types/Position.js';
|
|
5
|
+
import '../../@types/PermissionAttr.js';
|
|
6
|
+
export { LeftSlot, RightSlot } from '../slot/index.js';
|
|
9
7
|
import '../../tooltip/types.js';
|
|
8
|
+
export { I as Input, T as TextAreaFieldInputProps } from '../../index-208e7f62.js';
|