wini-web-components 2.2.8 → 2.3.2

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.
Files changed (63) hide show
  1. package/dist/component/button/button.d.ts +16 -16
  2. package/dist/component/button/button.js +39 -39
  3. package/dist/component/calendar/calendar.d.ts +30 -46
  4. package/dist/component/calendar/calendar.js +437 -432
  5. package/dist/component/checkbox/checkbox.d.ts +24 -22
  6. package/dist/component/checkbox/checkbox.js +120 -81
  7. package/dist/component/component-status.d.ts +8 -8
  8. package/dist/component/component-status.js +39 -39
  9. package/dist/component/date-picker/date-picker.d.ts +25 -36
  10. package/dist/component/date-picker/date-picker.js +362 -359
  11. package/dist/component/dialog/dialog.d.ts +36 -34
  12. package/dist/component/dialog/dialog.js +99 -97
  13. package/dist/component/import-file/import-file.d.ts +24 -36
  14. package/dist/component/import-file/import-file.js +154 -119
  15. package/dist/component/infinite-scroll/infinite-scroll.d.ts +17 -17
  16. package/dist/component/infinite-scroll/infinite-scroll.js +103 -103
  17. package/dist/component/input-multi-select/input-multi-select.d.ts +21 -38
  18. package/dist/component/input-multi-select/input-multi-select.js +334 -323
  19. package/dist/component/input-opt/input-opt.d.ts +21 -21
  20. package/dist/component/input-opt/input-opt.js +157 -147
  21. package/dist/component/number-picker/number-picker.d.ts +19 -19
  22. package/dist/component/number-picker/number-picker.js +137 -127
  23. package/dist/component/pagination/pagination.d.ts +13 -13
  24. package/dist/component/pagination/pagination.js +93 -82
  25. package/dist/component/popup/popup.d.ts +33 -33
  26. package/dist/component/popup/popup.js +138 -105
  27. package/dist/component/progress-bar/progress-bar.d.ts +16 -16
  28. package/dist/component/progress-bar/progress-bar.js +35 -36
  29. package/dist/component/progress-circle/progress-circle.d.ts +14 -14
  30. package/dist/component/progress-circle/progress-circle.js +30 -31
  31. package/dist/component/radio-button/radio-button.d.ts +20 -20
  32. package/dist/component/radio-button/radio-button.js +64 -64
  33. package/dist/component/rating/rating.d.ts +23 -23
  34. package/dist/component/rating/rating.js +73 -74
  35. package/dist/component/select1/select1.d.ts +31 -50
  36. package/dist/component/select1/select1.js +320 -309
  37. package/dist/component/slider/slider.d.ts +31 -31
  38. package/dist/component/slider/slider.js +80 -81
  39. package/dist/component/switch/switch.d.ts +23 -23
  40. package/dist/component/switch/switch.js +80 -81
  41. package/dist/component/table/table.d.ts +51 -51
  42. package/dist/component/table/table.js +119 -119
  43. package/dist/component/tag/tag.d.ts +17 -17
  44. package/dist/component/tag/tag.js +39 -39
  45. package/dist/component/text/text.d.ts +16 -16
  46. package/dist/component/text/text.js +51 -51
  47. package/dist/component/text-area/text-area.d.ts +28 -28
  48. package/dist/component/text-area/text-area.js +83 -73
  49. package/dist/component/text-field/text-field.d.ts +33 -33
  50. package/dist/component/text-field/text-field.js +107 -97
  51. package/dist/component/toast-noti/toast-noti.d.ts +5 -5
  52. package/dist/component/toast-noti/toast-noti.js +28 -28
  53. package/dist/component/wini-icon/winicon.d.ts +16 -16
  54. package/dist/component/wini-icon/winicon.js +121 -112
  55. package/dist/form/login/view.d.ts +40 -40
  56. package/dist/form/login/view.js +66 -65
  57. package/dist/i18n.d.ts +2 -0
  58. package/dist/i18n.js +125 -0
  59. package/dist/index.d.ts +32 -31
  60. package/dist/index.js +1 -1
  61. package/dist/language/i18n.d.ts +2 -0
  62. package/dist/language/i18n.js +125 -0
  63. package/package.json +5 -3
@@ -1,323 +1,334 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
- if (k2 === undefined) k2 = k;
30
- var desc = Object.getOwnPropertyDescriptor(m, k);
31
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
- desc = { enumerable: true, get: function() { return m[k]; } };
33
- }
34
- Object.defineProperty(o, k2, desc);
35
- }) : (function(o, m, k, k2) {
36
- if (k2 === undefined) k2 = k;
37
- o[k2] = m[k];
38
- }));
39
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
- Object.defineProperty(o, "default", { enumerable: true, value: v });
41
- }) : function(o, v) {
42
- o["default"] = v;
43
- });
44
- var __importStar = (this && this.__importStar) || function (mod) {
45
- if (mod && mod.__esModule) return mod;
46
- var result = {};
47
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
48
- __setModuleDefault(result, mod);
49
- return result;
50
- };
51
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
52
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
53
- return new (P || (P = Promise))(function (resolve, reject) {
54
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
55
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
56
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
57
- step((generator = generator.apply(thisArg, _arguments || [])).next());
58
- });
59
- };
60
- var __generator = (this && this.__generator) || function (thisArg, body) {
61
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
62
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
63
- function verb(n) { return function (v) { return step([n, v]); }; }
64
- function step(op) {
65
- if (f) throw new TypeError("Generator is already executing.");
66
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
67
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
68
- if (y = 0, t) op = [op[0] & 2, t.value];
69
- switch (op[0]) {
70
- case 0: case 1: t = op; break;
71
- case 4: _.label++; return { value: op[1], done: false };
72
- case 5: _.label++; y = op[1]; op = [0]; continue;
73
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
74
- default:
75
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
76
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
77
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
78
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
79
- if (t[2]) _.ops.pop();
80
- _.trys.pop(); continue;
81
- }
82
- op = body.call(thisArg, _);
83
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
84
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
85
- }
86
- };
87
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
88
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
89
- if (ar || !(i in from)) {
90
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
91
- ar[i] = from[i];
92
- }
93
- }
94
- return to.concat(ar || Array.prototype.slice.call(from));
95
- };
96
- var __importDefault = (this && this.__importDefault) || function (mod) {
97
- return (mod && mod.__esModule) ? mod : { "default": mod };
98
- };
99
- Object.defineProperty(exports, "__esModule", { value: true });
100
- exports.SelectMultiple = void 0;
101
- var react_1 = __importStar(require("react"));
102
- var react_dom_1 = __importDefault(require("react-dom"));
103
- var input_multi_select_module_css_1 = __importDefault(require("./input-multi-select.module.css"));
104
- var checkbox_1 = require("../checkbox/checkbox");
105
- var text_1 = require("../text/text");
106
- var winicon_1 = require("../wini-icon/winicon");
107
- ;
108
- var SelectMultiple = /** @class */ (function (_super) {
109
- __extends(SelectMultiple, _super);
110
- function SelectMultiple(props) {
111
- var _this = this;
112
- var _a;
113
- _this = _super.call(this, props) || this;
114
- _this.containerRef = (0, react_1.createRef)();
115
- _this.state = {
116
- value: (_a = props.value) !== null && _a !== void 0 ? _a : [],
117
- options: props.options,
118
- offset: {
119
- x: 0,
120
- y: 0,
121
- height: 0,
122
- width: 0,
123
- bottom: 0,
124
- left: 0,
125
- right: 0,
126
- top: 0,
127
- toJSON: function () {
128
- throw new Error('Function not implemented.');
129
- }
130
- },
131
- isOpen: false,
132
- onSelect: null,
133
- };
134
- _this.onCheck = _this.onCheck.bind(_this);
135
- _this.search = _this.search.bind(_this);
136
- _this.onClickItem = _this.onClickItem.bind(_this);
137
- return _this;
138
- }
139
- SelectMultiple.prototype.onCheck = function (value, list) {
140
- var newValue = [];
141
- if (value) {
142
- newValue = __spreadArray(__spreadArray([], this.state.value, true), list.map(function (e) { return e.id; }), true);
143
- }
144
- else {
145
- newValue = this.state.value.filter(function (vl) { return list.every(function (e) { return vl !== e.id; }); });
146
- }
147
- this.setState(__assign(__assign({}, this.state), { value: newValue }));
148
- if (this.props.onChange)
149
- this.props.onChange(newValue);
150
- };
151
- SelectMultiple.prototype.search = function (ev) {
152
- var _a;
153
- return __awaiter(this, void 0, void 0, function () {
154
- var res;
155
- return __generator(this, function (_b) {
156
- switch (_b.label) {
157
- case 0:
158
- if (!ev.target.value.trim().length) return [3 /*break*/, 4];
159
- if (!((_a = this.props) === null || _a === void 0 ? void 0 : _a.handleSearch)) return [3 /*break*/, 2];
160
- return [4 /*yield*/, this.props.handleSearch(ev.target.value.trim())];
161
- case 1:
162
- res = _b.sent();
163
- this.setState(__assign(__assign({}, this.state), { search: res }));
164
- return [3 /*break*/, 3];
165
- case 2:
166
- this.setState(__assign(__assign({}, this.state), { search: this.props.options.filter(function (e) { return typeof e.name === "string" && e.name.toLowerCase().includes(ev.target.value.trim().toLowerCase()); }) }));
167
- _b.label = 3;
168
- case 3: return [3 /*break*/, 5];
169
- case 4:
170
- this.setState(__assign(__assign({}, this.state), { search: undefined }));
171
- _b.label = 5;
172
- case 5: return [2 /*return*/];
173
- }
174
- });
175
- });
176
- };
177
- SelectMultiple.prototype.onClickItem = function (ev, item) {
178
- var _a, _b;
179
- ev.stopPropagation();
180
- var newValue = this.state.value.filter(function (vl) { return vl !== item; });
181
- this.setState(__assign(__assign(__assign({}, this.state), { value: newValue }), (this.state.isOpen ? {} : {
182
- isOpen: true,
183
- style: undefined,
184
- offset: (_b = (_a = this.containerRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect(),
185
- })));
186
- if (this.props.onChange)
187
- this.props.onChange(newValue);
188
- };
189
- SelectMultiple.prototype.renderOptions = function (item) {
190
- var _this = this;
191
- var _a, _b;
192
- var children = [];
193
- if (!item.parentId)
194
- children = ((_a = this.state.search) !== null && _a !== void 0 ? _a : this.state.options).filter(function (e) { return e.parentId === item.id; });
195
- //
196
- return react_1.default.createElement("div", { key: item.id, className: 'col', style: { width: '100%' } },
197
- react_1.default.createElement("div", { className: "".concat(input_multi_select_module_css_1.default['select-tile'], " row ").concat(item.disabled ? input_multi_select_module_css_1.default["disabled"] : ""), style: { paddingLeft: item.parentId ? '4.4rem' : undefined }, onClick: children.length ? function () {
198
- if (_this.state.search) {
199
- _this.setState(__assign(__assign({}, _this.state), { search: _this.state.search.map(function (e) {
200
- if (e.id === item.id)
201
- return __assign(__assign({}, e), { isOpen: !item.isOpen });
202
- else
203
- return e;
204
- }) }));
205
- }
206
- else {
207
- _this.setState(__assign(__assign({}, _this.state), { options: _this.state.options.map(function (e) {
208
- if (e.id === item.id)
209
- return __assign(__assign({}, e), { isOpen: !item.isOpen });
210
- else
211
- return e;
212
- }) }));
213
- }
214
- } : undefined },
215
- ((_b = this.state.search) !== null && _b !== void 0 ? _b : this.state.options).some(function (e) { return e.parentId; }) && react_1.default.createElement("div", { className: 'row', style: { width: '1.4rem', height: '1.4rem' } }, children.length ? react_1.default.createElement(winicon_1.Winicon, { src: item.isOpen ? 'fill/arrows/triangle-down' : 'fill/arrows/triangle-right', size: '1.2rem' }) : null),
216
- react_1.default.createElement(checkbox_1.Checkbox, { disabled: item.disabled, value: children.length ? (children.every(function (e) { return _this.state.value.includes(e.id); }) ? true : children.some(function (e) { return _this.state.value.includes(e.id); }) ? undefined : false) : this.state.value.includes(item.id), onChange: function (v) { _this.onCheck(v, __spreadArray([item], children, true)); }, size: '2rem' }),
217
- react_1.default.createElement(text_1.Text, { className: 'body-3' }, item.name)),
218
- react_1.default.createElement("div", { className: 'col', style: { display: item.isOpen ? "flex" : "none", width: '100%' } }, children.map(function (e) { return _this.renderOptions(e); })));
219
- };
220
- SelectMultiple.prototype.componentDidUpdate = function (prevProps, prevState) {
221
- var _a, _b, _c, _d, _e;
222
- if (prevProps.options !== this.props.options)
223
- this.setState(__assign(__assign({}, this.state), { options: this.props.options }));
224
- if (prevProps.value !== this.props.value)
225
- this.setState(__assign(__assign({}, this.state), { value: (_a = this.props.value) !== null && _a !== void 0 ? _a : [] }));
226
- //
227
- if (this.state.isOpen && (prevState.isOpen !== this.state.isOpen || prevState.value.length !== this.state.value.length)) {
228
- var thisPopupRect = (_b = document.body.querySelector(":scope > .select-multi-popup")) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect();
229
- if (thisPopupRect) {
230
- var style = void 0;
231
- if (prevState.isOpen !== this.state.isOpen && thisPopupRect.right > document.body.offsetWidth) {
232
- style = {
233
- top: this.state.offset.y + this.state.offset.height + 2 + 'px',
234
- right: document.body.offsetWidth - this.state.offset.right + 'px'
235
- };
236
- }
237
- var _bottom = thisPopupRect.bottom - 8;
238
- var thisContainerRect = (_c = this.containerRef.current) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect();
239
- if (thisContainerRect) {
240
- if (prevState.value.length !== this.state.value.length) {
241
- _bottom = thisContainerRect.bottom + 2 + thisPopupRect.height;
242
- style = __assign(__assign({}, (style !== null && style !== void 0 ? style : {})), { top: "".concat(thisContainerRect.bottom + 2, "px") });
243
- }
244
- if (_bottom > document.body.offsetHeight) {
245
- style = __assign(__assign({}, (style !== null && style !== void 0 ? style : {})), { top: "".concat(thisContainerRect.y - 2 - thisPopupRect.height, "px") });
246
- }
247
- }
248
- if (style) {
249
- (_d = style.left) !== null && _d !== void 0 ? _d : (style.left = style.right ? undefined : "".concat(this.state.offset.x, "px"));
250
- (_e = style.width) !== null && _e !== void 0 ? _e : (style.width = "".concat(this.state.offset.width, "px"));
251
- this.setState(__assign(__assign({}, this.state), { style: style }));
252
- }
253
- }
254
- }
255
- };
256
- SelectMultiple.prototype.render = function () {
257
- var _this = this;
258
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
259
- return react_1.default.createElement("div", { id: this.props.id, ref: this.containerRef, className: "".concat(input_multi_select_module_css_1.default['select-multi-container'], " row ").concat(this.props.disabled ? input_multi_select_module_css_1.default['disabled'] : '', " ").concat(((_a = this.props.helperText) === null || _a === void 0 ? void 0 : _a.length) && input_multi_select_module_css_1.default['helper-text'], " ").concat((_b = this.props.className) !== null && _b !== void 0 ? _b : 'body-3'), "helper-text": this.props.helperText, style: this.props.style ? __assign(__assign({}, { '--helper-text-color': (_c = this.props.helperTextColor) !== null && _c !== void 0 ? _c : '#e14337' }), this.props.style) : { '--helper-text-color': (_d = this.props.helperTextColor) !== null && _d !== void 0 ? _d : '#e14337' }, onClick: function () {
260
- var _a, _b;
261
- if (!_this.state.isOpen)
262
- _this.setState(__assign(__assign({}, _this.state), { isOpen: true, style: undefined, offset: (_b = (_a = _this.containerRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect() }));
263
- } },
264
- react_1.default.createElement("div", { className: 'row', style: { flexWrap: 'wrap', flex: 1, width: '100%', gap: '0.6rem 0.4rem' } },
265
- this.state.value.map(function (item) {
266
- var optionItem = _this.props.options.find(function (e) { return e.id === item; });
267
- return react_1.default.createElement("div", { key: item, className: "row ".concat(input_multi_select_module_css_1.default['selected-item-value']), onClick: (optionItem === null || optionItem === void 0 ? void 0 : optionItem.disabled) ? undefined : function (ev) { return _this.onClickItem(ev, item); } },
268
- react_1.default.createElement(text_1.Text, { style: { color: "var(--neutral-text-title-color)", fontSize: '1.2rem', lineHeight: '1.4rem' } }, optionItem === null || optionItem === void 0 ? void 0 : optionItem.name),
269
- react_1.default.createElement(winicon_1.Winicon, { src: "outline/user interface/e-remove", size: '1.2rem' }));
270
- }),
271
- (!this.state.value.length || this.state.isOpen) && react_1.default.createElement("input", { autoFocus: this.state.value.length > 0, onChange: this.search, placeholder: this.state.value.length ? undefined : this.props.placeholder, onBlur: function (ev) {
272
- if (_this.state.onSelect)
273
- ev.target.focus();
274
- else
275
- _this.setState(__assign(__assign({}, _this.state), { isOpen: false, onSelect: null }));
276
- } })),
277
- this.props.showClearValueButton && this.state.value.length ? react_1.default.createElement("button", { type: 'button', className: 'row', style: { padding: '0.4rem' }, onClick: function (ev) {
278
- ev.stopPropagation();
279
- if (_this.state.value.length)
280
- _this.setState(__assign(__assign({}, _this.state), { isOpen: true, value: [] }));
281
- } },
282
- react_1.default.createElement(winicon_1.Winicon, { src: "outline/user interface/c-remove", size: '1.6rem' })) : react_1.default.createElement("div", { ref: function (iconRef) {
283
- if ((iconRef === null || iconRef === void 0 ? void 0 : iconRef.parentElement) && iconRef.parentElement.getBoundingClientRect().width < 100)
284
- iconRef.style.display = "none";
285
- }, className: 'row' },
286
- react_1.default.createElement(winicon_1.Winicon, { src: this.state.isOpen ? "fill/arrows/up-arrow" : "fill/arrows/down-arrow", size: '1.2rem' })),
287
- this.state.isOpen &&
288
- react_dom_1.default.createPortal(react_1.default.createElement("div", { className: "".concat(input_multi_select_module_css_1.default['select-multi-popup'], " select-multi-popup col ").concat((_e = this.props.popupClassName) !== null && _e !== void 0 ? _e : ""), style: (_f = this.state.style) !== null && _f !== void 0 ? _f : {
289
- top: this.state.offset.y + this.state.offset.height + 2 + 'px',
290
- left: this.state.offset.x + 'px',
291
- width: this.state.offset.width,
292
- }, onMouseOver: function (ev) { return _this.setState(__assign(__assign({}, _this.state), { onSelect: ev.target })); }, onMouseOut: function () { return _this.setState(__assign(__assign({}, _this.state), { onSelect: null })); } },
293
- react_1.default.createElement("div", { style: { padding: '1.2rem 1.6rem', width: '100%', borderBottom: '1px solid #161D2414' } }, (function () {
294
- var _a, _b;
295
- var _list = ((_b = (_a = _this.state.search) !== null && _a !== void 0 ? _a : _this.props.options) !== null && _b !== void 0 ? _b : []);
296
- var isSelectedAll = _list.every(function (item) { return _this.state.value.some(function (vl) { return vl === item.id; }); });
297
- return react_1.default.createElement(text_1.Text, { onClick: function () {
298
- var newValue = [];
299
- if (_list.length) {
300
- if (isSelectedAll) {
301
- newValue = _this.state.value.filter(function (vl) { return _list.every(function (item) { return vl !== item.id || item.disabled; }); });
302
- }
303
- else {
304
- newValue = __spreadArray(__spreadArray([], _this.state.value, true), _list.filter(function (item) { return _this.state.value.every(function (vl) { return vl !== item.id; }) && !item.disabled; }).map(function (e) { return e.id; }), true);
305
- }
306
- }
307
- _this.setState(__assign(__assign({}, _this.state), { value: newValue }));
308
- if (_this.props.onChange)
309
- _this.props.onChange(newValue);
310
- }, className: 'button-text-3', style: { color: _list.length ? 'var(--infor-main-color)' : 'var(--neutral-text-title-color)' } }, _list.length && isSelectedAll ? 'Remove all' : 'Select all');
311
- })()),
312
- react_1.default.createElement("div", { className: "col ".concat(input_multi_select_module_css_1.default['select-body']), onScroll: this.props.handleLoadmore ? function (ev) {
313
- if (_this.props.handleLoadmore) {
314
- var scrollElement = ev.target;
315
- _this.props.handleLoadmore(Math.round(scrollElement.offsetHeight + scrollElement.scrollTop) >= (scrollElement.scrollHeight - 1), ev);
316
- }
317
- } : undefined },
318
- ((_g = this.state.search) !== null && _g !== void 0 ? _g : this.state.options).filter(function (e) { return !e.parentId; }).map(function (item) { return _this.renderOptions(item); }),
319
- (((_h = this.state.search) === null || _h === void 0 ? void 0 : _h.length) === 0 || ((_j = this.props.options) === null || _j === void 0 ? void 0 : _j.length) === 0) && (react_1.default.createElement("div", { className: input_multi_select_module_css_1.default['no-results-found'] }, "No result found")))), document.body));
320
- };
321
- return SelectMultiple;
322
- }(react_1.default.Component));
323
- exports.SelectMultiple = SelectMultiple;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
41
+ }) : function(o, v) {
42
+ o["default"] = v;
43
+ });
44
+ var __importStar = (this && this.__importStar) || (function () {
45
+ var ownKeys = function(o) {
46
+ ownKeys = Object.getOwnPropertyNames || function (o) {
47
+ var ar = [];
48
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
49
+ return ar;
50
+ };
51
+ return ownKeys(o);
52
+ };
53
+ return function (mod) {
54
+ if (mod && mod.__esModule) return mod;
55
+ var result = {};
56
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
57
+ __setModuleDefault(result, mod);
58
+ return result;
59
+ };
60
+ })();
61
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
62
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
63
+ return new (P || (P = Promise))(function (resolve, reject) {
64
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
65
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
66
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
67
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
68
+ });
69
+ };
70
+ var __generator = (this && this.__generator) || function (thisArg, body) {
71
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
72
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
73
+ function verb(n) { return function (v) { return step([n, v]); }; }
74
+ function step(op) {
75
+ if (f) throw new TypeError("Generator is already executing.");
76
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
77
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
78
+ if (y = 0, t) op = [op[0] & 2, t.value];
79
+ switch (op[0]) {
80
+ case 0: case 1: t = op; break;
81
+ case 4: _.label++; return { value: op[1], done: false };
82
+ case 5: _.label++; y = op[1]; op = [0]; continue;
83
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
84
+ default:
85
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
86
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
87
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
88
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
89
+ if (t[2]) _.ops.pop();
90
+ _.trys.pop(); continue;
91
+ }
92
+ op = body.call(thisArg, _);
93
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
94
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
95
+ }
96
+ };
97
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
98
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
99
+ if (ar || !(i in from)) {
100
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
101
+ ar[i] = from[i];
102
+ }
103
+ }
104
+ return to.concat(ar || Array.prototype.slice.call(from));
105
+ };
106
+ var __importDefault = (this && this.__importDefault) || function (mod) {
107
+ return (mod && mod.__esModule) ? mod : { "default": mod };
108
+ };
109
+ Object.defineProperty(exports, "__esModule", { value: true });
110
+ exports.SelectMultiple = void 0;
111
+ var react_1 = __importStar(require("react"));
112
+ var react_dom_1 = __importDefault(require("react-dom"));
113
+ var input_multi_select_module_css_1 = __importDefault(require("./input-multi-select.module.css"));
114
+ var checkbox_1 = require("../checkbox/checkbox");
115
+ var text_1 = require("../text/text");
116
+ var winicon_1 = require("../wini-icon/winicon");
117
+ var react_i18next_1 = require("react-i18next");
118
+ ;
119
+ var TSelectMultiple = /** @class */ (function (_super) {
120
+ __extends(TSelectMultiple, _super);
121
+ function TSelectMultiple(props) {
122
+ var _a;
123
+ var _this = _super.call(this, props) || this;
124
+ _this.containerRef = (0, react_1.createRef)();
125
+ _this.state = {
126
+ value: (_a = props.value) !== null && _a !== void 0 ? _a : [],
127
+ options: props.options,
128
+ offset: {
129
+ x: 0,
130
+ y: 0,
131
+ height: 0,
132
+ width: 0,
133
+ bottom: 0,
134
+ left: 0,
135
+ right: 0,
136
+ top: 0,
137
+ toJSON: function () {
138
+ throw new Error('Function not implemented.');
139
+ }
140
+ },
141
+ isOpen: false,
142
+ onSelect: null,
143
+ };
144
+ _this.onCheck = _this.onCheck.bind(_this);
145
+ _this.search = _this.search.bind(_this);
146
+ _this.onClickItem = _this.onClickItem.bind(_this);
147
+ return _this;
148
+ }
149
+ TSelectMultiple.prototype.onCheck = function (value, list) {
150
+ var newValue = [];
151
+ if (value) {
152
+ newValue = __spreadArray(__spreadArray([], this.state.value, true), list.map(function (e) { return e.id; }), true);
153
+ }
154
+ else {
155
+ newValue = this.state.value.filter(function (vl) { return list.every(function (e) { return vl !== e.id; }); });
156
+ }
157
+ this.setState(__assign(__assign({}, this.state), { value: newValue }));
158
+ if (this.props.onChange)
159
+ this.props.onChange(newValue);
160
+ };
161
+ TSelectMultiple.prototype.search = function (ev) {
162
+ return __awaiter(this, void 0, void 0, function () {
163
+ var res;
164
+ var _a;
165
+ return __generator(this, function (_b) {
166
+ switch (_b.label) {
167
+ case 0:
168
+ if (!ev.target.value.trim().length) return [3 /*break*/, 4];
169
+ if (!((_a = this.props) === null || _a === void 0 ? void 0 : _a.handleSearch)) return [3 /*break*/, 2];
170
+ return [4 /*yield*/, this.props.handleSearch(ev.target.value.trim())];
171
+ case 1:
172
+ res = _b.sent();
173
+ this.setState(__assign(__assign({}, this.state), { search: res }));
174
+ return [3 /*break*/, 3];
175
+ case 2:
176
+ this.setState(__assign(__assign({}, this.state), { search: this.props.options.filter(function (e) { return typeof e.name === "string" && e.name.toLowerCase().includes(ev.target.value.trim().toLowerCase()); }) }));
177
+ _b.label = 3;
178
+ case 3: return [3 /*break*/, 5];
179
+ case 4:
180
+ this.setState(__assign(__assign({}, this.state), { search: undefined }));
181
+ _b.label = 5;
182
+ case 5: return [2 /*return*/];
183
+ }
184
+ });
185
+ });
186
+ };
187
+ TSelectMultiple.prototype.onClickItem = function (ev, item) {
188
+ var _a, _b;
189
+ ev.stopPropagation();
190
+ var newValue = this.state.value.filter(function (vl) { return vl !== item; });
191
+ this.setState(__assign(__assign(__assign({}, this.state), { value: newValue }), (this.state.isOpen ? {} : {
192
+ isOpen: true,
193
+ style: undefined,
194
+ offset: (_b = (_a = this.containerRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect(),
195
+ })));
196
+ if (this.props.onChange)
197
+ this.props.onChange(newValue);
198
+ };
199
+ TSelectMultiple.prototype.renderOptions = function (item) {
200
+ var _this = this;
201
+ var _a, _b;
202
+ var children = [];
203
+ if (!item.parentId)
204
+ children = ((_a = this.state.search) !== null && _a !== void 0 ? _a : this.state.options).filter(function (e) { return e.parentId === item.id; });
205
+ //
206
+ return react_1.default.createElement("div", { key: item.id, className: 'col', style: { width: '100%' } },
207
+ react_1.default.createElement("div", { className: "".concat(input_multi_select_module_css_1.default['select-tile'], " row ").concat(item.disabled ? input_multi_select_module_css_1.default["disabled"] : ""), style: { paddingLeft: item.parentId ? '4.4rem' : undefined }, onClick: children.length ? function () {
208
+ if (_this.state.search) {
209
+ _this.setState(__assign(__assign({}, _this.state), { search: _this.state.search.map(function (e) {
210
+ if (e.id === item.id)
211
+ return __assign(__assign({}, e), { isOpen: !item.isOpen });
212
+ else
213
+ return e;
214
+ }) }));
215
+ }
216
+ else {
217
+ _this.setState(__assign(__assign({}, _this.state), { options: _this.state.options.map(function (e) {
218
+ if (e.id === item.id)
219
+ return __assign(__assign({}, e), { isOpen: !item.isOpen });
220
+ else
221
+ return e;
222
+ }) }));
223
+ }
224
+ } : undefined },
225
+ ((_b = this.state.search) !== null && _b !== void 0 ? _b : this.state.options).some(function (e) { return e.parentId; }) && react_1.default.createElement("div", { className: 'row', style: { width: '1.4rem', height: '1.4rem' } }, children.length ? react_1.default.createElement(winicon_1.Winicon, { src: item.isOpen ? 'fill/arrows/triangle-down' : 'fill/arrows/triangle-right', size: '1.2rem' }) : null),
226
+ react_1.default.createElement(checkbox_1.Checkbox, { disabled: item.disabled, value: children.length ? (children.every(function (e) { return _this.state.value.includes(e.id); }) ? true : children.some(function (e) { return _this.state.value.includes(e.id); }) ? undefined : false) : this.state.value.includes(item.id), onChange: function (v) { _this.onCheck(v, __spreadArray([item], children, true)); }, size: '2rem' }),
227
+ react_1.default.createElement(text_1.Text, { className: 'body-3' }, item.name)),
228
+ react_1.default.createElement("div", { className: 'col', style: { display: item.isOpen ? "flex" : "none", width: '100%' } }, children.map(function (e) { return _this.renderOptions(e); })));
229
+ };
230
+ TSelectMultiple.prototype.componentDidUpdate = function (prevProps, prevState) {
231
+ var _a, _b, _c, _d, _e;
232
+ if (prevProps.options !== this.props.options)
233
+ this.setState(__assign(__assign({}, this.state), { options: this.props.options }));
234
+ if (prevProps.value !== this.props.value)
235
+ this.setState(__assign(__assign({}, this.state), { value: (_a = this.props.value) !== null && _a !== void 0 ? _a : [] }));
236
+ //
237
+ if (this.state.isOpen && (prevState.isOpen !== this.state.isOpen || prevState.value.length !== this.state.value.length)) {
238
+ var thisPopupRect = (_b = document.body.querySelector(":scope > .select-multi-popup")) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect();
239
+ if (thisPopupRect) {
240
+ var style = void 0;
241
+ if (prevState.isOpen !== this.state.isOpen && thisPopupRect.right > document.body.offsetWidth) {
242
+ style = {
243
+ top: this.state.offset.y + this.state.offset.height + 2 + 'px',
244
+ right: document.body.offsetWidth - this.state.offset.right + 'px'
245
+ };
246
+ }
247
+ var _bottom = thisPopupRect.bottom - 8;
248
+ var thisContainerRect = (_c = this.containerRef.current) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect();
249
+ if (thisContainerRect) {
250
+ if (prevState.value.length !== this.state.value.length) {
251
+ _bottom = thisContainerRect.bottom + 2 + thisPopupRect.height;
252
+ style = __assign(__assign({}, (style !== null && style !== void 0 ? style : {})), { top: "".concat(thisContainerRect.bottom + 2, "px") });
253
+ }
254
+ if (_bottom > document.body.offsetHeight) {
255
+ style = __assign(__assign({}, (style !== null && style !== void 0 ? style : {})), { top: "".concat(thisContainerRect.y - 2 - thisPopupRect.height, "px") });
256
+ }
257
+ }
258
+ if (style) {
259
+ (_d = style.left) !== null && _d !== void 0 ? _d : (style.left = style.right ? undefined : "".concat(this.state.offset.x, "px"));
260
+ (_e = style.width) !== null && _e !== void 0 ? _e : (style.width = "".concat(this.state.offset.width, "px"));
261
+ this.setState(__assign(__assign({}, this.state), { style: style }));
262
+ }
263
+ }
264
+ }
265
+ };
266
+ TSelectMultiple.prototype.render = function () {
267
+ var _this = this;
268
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
269
+ var t = this.props.t;
270
+ return react_1.default.createElement("div", { id: this.props.id, ref: this.containerRef, className: "".concat(input_multi_select_module_css_1.default['select-multi-container'], " row ").concat(this.props.disabled ? input_multi_select_module_css_1.default['disabled'] : '', " ").concat(((_a = this.props.helperText) === null || _a === void 0 ? void 0 : _a.length) && input_multi_select_module_css_1.default['helper-text'], " ").concat((_b = this.props.className) !== null && _b !== void 0 ? _b : 'body-3'), "helper-text": this.props.helperText, style: this.props.style ? __assign(__assign({}, { '--helper-text-color': (_c = this.props.helperTextColor) !== null && _c !== void 0 ? _c : '#e14337' }), this.props.style) : { '--helper-text-color': (_d = this.props.helperTextColor) !== null && _d !== void 0 ? _d : '#e14337' }, onClick: function () {
271
+ var _a, _b;
272
+ if (!_this.state.isOpen)
273
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: true, style: undefined, offset: (_b = (_a = _this.containerRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect() }));
274
+ } },
275
+ react_1.default.createElement("div", { className: 'row', style: { flexWrap: 'wrap', flex: 1, width: '100%', gap: '0.6rem 0.4rem' } },
276
+ this.state.value.map(function (item) {
277
+ var optionItem = _this.props.options.find(function (e) { return e.id === item; });
278
+ return react_1.default.createElement("div", { key: item, className: "row ".concat(input_multi_select_module_css_1.default['selected-item-value']), onClick: (optionItem === null || optionItem === void 0 ? void 0 : optionItem.disabled) ? undefined : function (ev) { return _this.onClickItem(ev, item); } },
279
+ react_1.default.createElement(text_1.Text, { style: { color: "var(--neutral-text-title-color)", fontSize: '1.2rem', lineHeight: '1.4rem' } }, optionItem === null || optionItem === void 0 ? void 0 : optionItem.name),
280
+ react_1.default.createElement(winicon_1.Winicon, { src: "outline/user interface/e-remove", size: '1.2rem' }));
281
+ }),
282
+ (!this.state.value.length || this.state.isOpen) && react_1.default.createElement("input", { autoFocus: this.state.value.length > 0, onChange: this.search, placeholder: this.state.value.length ? undefined : this.props.placeholder, onBlur: function (ev) {
283
+ if (_this.state.onSelect)
284
+ ev.target.focus();
285
+ else
286
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: false, onSelect: null }));
287
+ } })),
288
+ this.props.showClearValueButton && this.state.value.length ? react_1.default.createElement("button", { type: 'button', className: 'row', style: { padding: '0.4rem' }, onClick: function (ev) {
289
+ ev.stopPropagation();
290
+ if (_this.state.value.length)
291
+ _this.setState(__assign(__assign({}, _this.state), { isOpen: true, value: [] }));
292
+ } },
293
+ react_1.default.createElement(winicon_1.Winicon, { src: "outline/user interface/c-remove", size: '1.6rem' })) : react_1.default.createElement("div", { ref: function (iconRef) {
294
+ if ((iconRef === null || iconRef === void 0 ? void 0 : iconRef.parentElement) && iconRef.parentElement.getBoundingClientRect().width < 100)
295
+ iconRef.style.display = "none";
296
+ }, className: 'row' },
297
+ react_1.default.createElement(winicon_1.Winicon, { src: this.state.isOpen ? "fill/arrows/up-arrow" : "fill/arrows/down-arrow", size: '1.2rem' })),
298
+ this.state.isOpen &&
299
+ react_dom_1.default.createPortal(react_1.default.createElement("div", { className: "".concat(input_multi_select_module_css_1.default['select-multi-popup'], " select-multi-popup col ").concat((_e = this.props.popupClassName) !== null && _e !== void 0 ? _e : ""), style: (_f = this.state.style) !== null && _f !== void 0 ? _f : {
300
+ top: this.state.offset.y + this.state.offset.height + 2 + 'px',
301
+ left: this.state.offset.x + 'px',
302
+ width: this.state.offset.width,
303
+ }, onMouseOver: function (ev) { return _this.setState(__assign(__assign({}, _this.state), { onSelect: ev.target })); }, onMouseOut: function () { return _this.setState(__assign(__assign({}, _this.state), { onSelect: null })); } },
304
+ react_1.default.createElement("div", { style: { padding: '1.2rem 1.6rem', width: '100%', borderBottom: '1px solid #161D2414' } }, (function () {
305
+ var _a, _b;
306
+ var _list = ((_b = (_a = _this.state.search) !== null && _a !== void 0 ? _a : _this.props.options) !== null && _b !== void 0 ? _b : []);
307
+ var isSelectedAll = _list.every(function (item) { return _this.state.value.some(function (vl) { return vl === item.id; }); });
308
+ return react_1.default.createElement(text_1.Text, { onClick: function () {
309
+ var newValue = [];
310
+ if (_list.length) {
311
+ if (isSelectedAll) {
312
+ newValue = _this.state.value.filter(function (vl) { return _list.every(function (item) { return vl !== item.id || item.disabled; }); });
313
+ }
314
+ else {
315
+ newValue = __spreadArray(__spreadArray([], _this.state.value, true), _list.filter(function (item) { return _this.state.value.every(function (vl) { return vl !== item.id; }) && !item.disabled; }).map(function (e) { return e.id; }), true);
316
+ }
317
+ }
318
+ _this.setState(__assign(__assign({}, _this.state), { value: newValue }));
319
+ if (_this.props.onChange)
320
+ _this.props.onChange(newValue);
321
+ }, className: 'button-text-3', style: { color: _list.length ? 'var(--infor-main-color)' : 'var(--neutral-text-title-color)' } }, _list.length && isSelectedAll ? "".concat(t("remove"), " ").concat(t("all").toLowerCase()) : "".concat(t("select"), " ").concat(t("all").toLowerCase()));
322
+ })()),
323
+ react_1.default.createElement("div", { className: "col ".concat(input_multi_select_module_css_1.default['select-body']), onScroll: this.props.handleLoadmore ? function (ev) {
324
+ if (_this.props.handleLoadmore) {
325
+ var scrollElement = ev.target;
326
+ _this.props.handleLoadmore(Math.round(scrollElement.offsetHeight + scrollElement.scrollTop) >= (scrollElement.scrollHeight - 1), ev);
327
+ }
328
+ } : undefined },
329
+ ((_g = this.state.search) !== null && _g !== void 0 ? _g : this.state.options).filter(function (e) { return !e.parentId; }).map(function (item) { return _this.renderOptions(item); }),
330
+ (((_h = this.state.search) === null || _h === void 0 ? void 0 : _h.length) === 0 || ((_j = this.props.options) === null || _j === void 0 ? void 0 : _j.length) === 0) && (react_1.default.createElement("div", { className: input_multi_select_module_css_1.default['no-results-found'] }, t("noResultFound"))))), document.body));
331
+ };
332
+ return TSelectMultiple;
333
+ }(react_1.default.Component));
334
+ exports.SelectMultiple = (0, react_i18next_1.withTranslation)()(TSelectMultiple);