@bonlineza/luxity-lib 2.35.1 → 2.35.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.
@@ -0,0 +1,973 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react'), require('@bonlineza/b-lib/functions'), require('styled-components'), require('@bonlineza/b-lib/EllipsisLoader'), require('@bonlineza/b-lib/PageReady')) :
3
+ typeof define === 'function' && define.amd ? define(['react', '@bonlineza/b-lib/functions', 'styled-components', '@bonlineza/b-lib/EllipsisLoader', '@bonlineza/b-lib/PageReady'], factory) :
4
+ (global = global || self, global.ConditionSelector = factory(global.React, global.function, global.styled, global.EllipsisLoader, global.PageReady));
5
+ }(this, (function (React, functions, styled, EllipsisLoader, PageReady) { 'use strict';
6
+
7
+ var React__default = 'default' in React ? React['default'] : React;
8
+ var styled__default = 'default' in styled ? styled['default'] : styled;
9
+ EllipsisLoader = EllipsisLoader && Object.prototype.hasOwnProperty.call(EllipsisLoader, 'default') ? EllipsisLoader['default'] : EllipsisLoader;
10
+ PageReady = PageReady && Object.prototype.hasOwnProperty.call(PageReady, 'default') ? PageReady['default'] : PageReady;
11
+
12
+ function _classCallCheck(instance, Constructor) {
13
+ if (!(instance instanceof Constructor)) {
14
+ throw new TypeError("Cannot call a class as a function");
15
+ }
16
+ }
17
+
18
+ function _defineProperties(target, props) {
19
+ for (var i = 0; i < props.length; i++) {
20
+ var descriptor = props[i];
21
+ descriptor.enumerable = descriptor.enumerable || false;
22
+ descriptor.configurable = true;
23
+ if ("value" in descriptor) descriptor.writable = true;
24
+ Object.defineProperty(target, descriptor.key, descriptor);
25
+ }
26
+ }
27
+
28
+ function _createClass(Constructor, protoProps, staticProps) {
29
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
30
+ if (staticProps) _defineProperties(Constructor, staticProps);
31
+ Object.defineProperty(Constructor, "prototype", {
32
+ writable: false
33
+ });
34
+ return Constructor;
35
+ }
36
+
37
+ function _defineProperty(obj, key, value) {
38
+ if (key in obj) {
39
+ Object.defineProperty(obj, key, {
40
+ value: value,
41
+ enumerable: true,
42
+ configurable: true,
43
+ writable: true
44
+ });
45
+ } else {
46
+ obj[key] = value;
47
+ }
48
+
49
+ return obj;
50
+ }
51
+
52
+ function _extends() {
53
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
54
+ for (var i = 1; i < arguments.length; i++) {
55
+ var source = arguments[i];
56
+
57
+ for (var key in source) {
58
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
59
+ target[key] = source[key];
60
+ }
61
+ }
62
+ }
63
+
64
+ return target;
65
+ };
66
+ return _extends.apply(this, arguments);
67
+ }
68
+
69
+ function _inherits(subClass, superClass) {
70
+ if (typeof superClass !== "function" && superClass !== null) {
71
+ throw new TypeError("Super expression must either be null or a function");
72
+ }
73
+
74
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
75
+ constructor: {
76
+ value: subClass,
77
+ writable: true,
78
+ configurable: true
79
+ }
80
+ });
81
+ Object.defineProperty(subClass, "prototype", {
82
+ writable: false
83
+ });
84
+ if (superClass) _setPrototypeOf(subClass, superClass);
85
+ }
86
+
87
+ function _getPrototypeOf(o) {
88
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
89
+ return o.__proto__ || Object.getPrototypeOf(o);
90
+ };
91
+ return _getPrototypeOf(o);
92
+ }
93
+
94
+ function _setPrototypeOf(o, p) {
95
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
96
+ o.__proto__ = p;
97
+ return o;
98
+ };
99
+ return _setPrototypeOf(o, p);
100
+ }
101
+
102
+ function _isNativeReflectConstruct() {
103
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
104
+ if (Reflect.construct.sham) return false;
105
+ if (typeof Proxy === "function") return true;
106
+
107
+ try {
108
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
109
+ return true;
110
+ } catch (e) {
111
+ return false;
112
+ }
113
+ }
114
+
115
+ function _objectWithoutPropertiesLoose(source, excluded) {
116
+ if (source == null) return {};
117
+ var target = {};
118
+ var sourceKeys = Object.keys(source);
119
+ var key, i;
120
+
121
+ for (i = 0; i < sourceKeys.length; i++) {
122
+ key = sourceKeys[i];
123
+ if (excluded.indexOf(key) >= 0) continue;
124
+ target[key] = source[key];
125
+ }
126
+
127
+ return target;
128
+ }
129
+
130
+ function _objectWithoutProperties(source, excluded) {
131
+ if (source == null) return {};
132
+
133
+ var target = _objectWithoutPropertiesLoose(source, excluded);
134
+
135
+ var key, i;
136
+
137
+ if (Object.getOwnPropertySymbols) {
138
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
139
+
140
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
141
+ key = sourceSymbolKeys[i];
142
+ if (excluded.indexOf(key) >= 0) continue;
143
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
144
+ target[key] = source[key];
145
+ }
146
+ }
147
+
148
+ return target;
149
+ }
150
+
151
+ function _assertThisInitialized(self) {
152
+ if (self === void 0) {
153
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
154
+ }
155
+
156
+ return self;
157
+ }
158
+
159
+ function _possibleConstructorReturn(self, call) {
160
+ if (call && (typeof call === "object" || typeof call === "function")) {
161
+ return call;
162
+ } else if (call !== void 0) {
163
+ throw new TypeError("Derived constructors may only return object or undefined");
164
+ }
165
+
166
+ return _assertThisInitialized(self);
167
+ }
168
+
169
+ function _createSuper(Derived) {
170
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
171
+
172
+ return function _createSuperInternal() {
173
+ var Super = _getPrototypeOf(Derived),
174
+ result;
175
+
176
+ if (hasNativeReflectConstruct) {
177
+ var NewTarget = _getPrototypeOf(this).constructor;
178
+
179
+ result = Reflect.construct(Super, arguments, NewTarget);
180
+ } else {
181
+ result = Super.apply(this, arguments);
182
+ }
183
+
184
+ return _possibleConstructorReturn(this, result);
185
+ };
186
+ }
187
+
188
+ function _taggedTemplateLiteral(strings, raw) {
189
+ if (!raw) {
190
+ raw = strings.slice(0);
191
+ }
192
+
193
+ return Object.freeze(Object.defineProperties(strings, {
194
+ raw: {
195
+ value: Object.freeze(raw)
196
+ }
197
+ }));
198
+ }
199
+
200
+ function _toConsumableArray(arr) {
201
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
202
+ }
203
+
204
+ function _arrayWithoutHoles(arr) {
205
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
206
+ }
207
+
208
+ function _iterableToArray(iter) {
209
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
210
+ }
211
+
212
+ function _unsupportedIterableToArray(o, minLen) {
213
+ if (!o) return;
214
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
215
+ var n = Object.prototype.toString.call(o).slice(8, -1);
216
+ if (n === "Object" && o.constructor) n = o.constructor.name;
217
+ if (n === "Map" || n === "Set") return Array.from(o);
218
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
219
+ }
220
+
221
+ function _arrayLikeToArray(arr, len) {
222
+ if (len == null || len > arr.length) len = arr.length;
223
+
224
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
225
+
226
+ return arr2;
227
+ }
228
+
229
+ function _nonIterableSpread() {
230
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
231
+ }
232
+
233
+ var interpretErrorMessage = function interpretErrorMessage(error) {
234
+ var customMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Failed: :error_code';
235
+ var message = customMessage || 'Network Error';
236
+ return message.replace(':error_code', error.status || 'Network Down');
237
+ };
238
+
239
+ var LuxityPageReadyContext = /*#__PURE__*/React__default.createContext({
240
+ data: null
241
+ });
242
+ /**
243
+ * A flavour of PageReady with Luxity customisations
244
+ * 1. the onIsLoading callback is useful to parent components that have more complex data interactions
245
+ * 2. an error message interpreter is supplied from the local helper library
246
+ */
247
+
248
+ var LuxityPageReady = /*#__PURE__*/function (_React$Component) {
249
+ _inherits(LuxityPageReady, _React$Component);
250
+
251
+ var _super = _createSuper(LuxityPageReady);
252
+
253
+ function LuxityPageReady() {
254
+ var _this;
255
+
256
+ _classCallCheck(this, LuxityPageReady);
257
+
258
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
259
+ args[_key] = arguments[_key];
260
+ }
261
+
262
+ _this = _super.call.apply(_super, [this].concat(args));
263
+
264
+ _defineProperty(_assertThisInitialized(_this), "state", {
265
+ data: null
266
+ });
267
+
268
+ _defineProperty(_assertThisInitialized(_this), "refreshPage", function () {
269
+ return _this.pageReadyInstance.initRequest();
270
+ });
271
+
272
+ return _this;
273
+ }
274
+
275
+ _createClass(LuxityPageReady, [{
276
+ key: "render",
277
+ value: function render() {
278
+ var _this2 = this;
279
+
280
+ var _this$props = this.props,
281
+ customErrorMessage = _this$props.customErrorMessage,
282
+ customErrorHandler = _this$props.customErrorHandler,
283
+ getRequestPromise = _this$props.getRequestPromise,
284
+ _onData = _this$props.onData,
285
+ children = _this$props.children;
286
+ var data = this.state.data;
287
+ return /*#__PURE__*/React__default.createElement(PageReady, {
288
+ ref: function ref(inst) {
289
+ _this2.pageReadyInstance = inst;
290
+ },
291
+ onData: function onData(res) {
292
+ _this2.setState({
293
+ data: res.data
294
+ });
295
+
296
+ _onData(res);
297
+ },
298
+ getRequestInstance: function getRequestInstance() {
299
+ _this2.props.onIsLoading(true);
300
+
301
+ return getRequestPromise().then(function (out) {
302
+ _this2.props.onIsLoading(false);
303
+
304
+ return out;
305
+ }).catch(function (oops) {
306
+ _this2.props.onIsLoading(false);
307
+
308
+ return oops;
309
+ });
310
+ },
311
+ customErrorMessage: customErrorMessage,
312
+ customErrorHandler: customErrorHandler,
313
+ renderCustomLoader: function renderCustomLoader() {
314
+ return /*#__PURE__*/React__default.createElement(EllipsisLoader, null);
315
+ },
316
+ errorMessageInterpreter: interpretErrorMessage
317
+ }, /*#__PURE__*/React__default.createElement(LuxityPageReadyContext.Provider, {
318
+ value: {
319
+ data: data
320
+ }
321
+ }, children));
322
+ }
323
+ }]);
324
+
325
+ return LuxityPageReady;
326
+ }(React__default.Component);
327
+
328
+ LuxityPageReady.defaultProps = {
329
+ onIsLoading: function onIsLoading() {
330
+ return null;
331
+ },
332
+ customErrorMessage: '',
333
+ customErrorHandler: function customErrorHandler() {
334
+ return null;
335
+ },
336
+ onData: function onData() {
337
+ return null;
338
+ }
339
+ };
340
+
341
+ var _templateObject, _templateObject2;
342
+ var disabledButtonStyle = styled.css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: not-allowed;\n opacity: 0.4;\n"])));
343
+ var baseButtonStyle = styled.css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding: 1rem 2rem;\n cursor: pointer;\n letter-spacing: 1.3px;\n border-style: none;\n text-transform: uppercase;\n font-size: 12px;\n color: #fff;\n transition: 0.2s ease-in-out;\n outline: none;\n"])));
344
+
345
+ var theme = {
346
+ breakpoints: ['40em', '52em', '64em'],
347
+ space: ['0px', '4px', '8px', '16px', '32px', '64px', '128px', '256px', '512px'],
348
+ fontSizes: ['12px', '14px', '16px', '20px', '24px', '32px', '48px', '64px', '72px'],
349
+ marginPaddings: ['0.5rem', '1rem', '1.5rem', '2rem', '2.5rem', '3rem', '3.5rem', '4rem', '4.5rem', '5rem', '5.5rem', '6rem'],
350
+ letterSpacings: ['-0.5px', '0px', '+0.5px'],
351
+ radii: ['0px', '2px', '4px', '8px'],
352
+ borderRadius: '6px',
353
+ colors: {
354
+ primary: '#000',
355
+ base: '#4e4949',
356
+ baseLt: '#817c7c',
357
+ borderColor: '#d8d8d8',
358
+ ntrlMin: '#fff',
359
+ ntrlMinTen: '#e6e6e6',
360
+ gray: '#efefef',
361
+ darkerGray: '#454141'
362
+ },
363
+ rareStepColors: {
364
+ primary: '#202b58',
365
+ secondary: '#ef5c2d',
366
+ ntrlMin: '#ffffff',
367
+ ntrl40: '#f4f4f4',
368
+ ntrl50: '#808080',
369
+ ntrl60: '#e8e8e8',
370
+ ntrl70: '#252525',
371
+ ntrlMax: '#000000'
372
+ },
373
+ rareStepFontWeights: {
374
+ normal: 400,
375
+ medium: 500,
376
+ semiBold: 600,
377
+ bold: 700
378
+ },
379
+ rareStepFontSize: {
380
+ h1: '36px',
381
+ h2: '30px',
382
+ h3: '24px',
383
+ h4: '20px',
384
+ h5: '16px',
385
+ h6: '14px',
386
+ footerTitle: '16px'
387
+ },
388
+ rareStepPageSizes: {
389
+ mobile: '500px',
390
+ tablet: '768px',
391
+ desktop: '992px',
392
+ screenl: '1280px',
393
+ screenxl: '1680px',
394
+ screenxxl: '1920px',
395
+ container: '1600px'
396
+ }
397
+ };
398
+
399
+ var themed = (function (Component) {
400
+ return /*#__PURE__*/React.forwardRef(function (props, ref) {
401
+ return /*#__PURE__*/React__default.createElement(styled.ThemeProvider, {
402
+ theme: theme
403
+ }, /*#__PURE__*/React__default.createElement(Component, _extends({}, props, {
404
+ ref: ref
405
+ })));
406
+ });
407
+ });
408
+
409
+ var _excluded = ["children"];
410
+
411
+ var _templateObject$1;
412
+ var Button = styled__default.button(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteral(["\n ", ";\n background-color: transparent;\n color: ", ";\n &:hover {\n color: ", ";\n }\n &:disabled {\n ", ";\n color: ", ";\n }\n"])), baseButtonStyle, function (props) {
413
+ return props.theme.colors.base;
414
+ }, function (props) {
415
+ return props.theme.colors.primary;
416
+ }, disabledButtonStyle, function (props) {
417
+ return props.theme.colors.base;
418
+ });
419
+
420
+ var TextButton = function TextButton(_ref) {
421
+ var children = _ref.children,
422
+ restProps = _objectWithoutProperties(_ref, _excluded);
423
+
424
+ return /*#__PURE__*/React__default.createElement(Button, restProps, children);
425
+ };
426
+
427
+ TextButton.defaultProps = {
428
+ type: 'button'
429
+ };
430
+ var TextButton$1 = themed(TextButton);
431
+
432
+ var _excluded$1 = ["children"];
433
+
434
+ var _templateObject$2;
435
+ var Button$1 = styled__default(TextButton$1)(_templateObject$2 || (_templateObject$2 = _taggedTemplateLiteral(["\n color: ", ";\n background-color: ", ";\n &:hover {\n color: ", ";\n background-color: ", ";\n }\n &:disabled {\n background-color: ", ";\n color: ", ";\n }\n"])), function (props) {
436
+ return props.theme.colors.ntrlMin;
437
+ }, function (props) {
438
+ return props.theme.colors.primary;
439
+ }, function (props) {
440
+ return props.theme.colors.base;
441
+ }, function (props) {
442
+ return props.theme.colors.ntrlMin;
443
+ }, function (props) {
444
+ return props.theme.colors.ntrlMin;
445
+ }, function (props) {
446
+ return props.theme.colors.primary;
447
+ });
448
+
449
+ var InvertedTextButton = function InvertedTextButton(_ref) {
450
+ var children = _ref.children,
451
+ restProps = _objectWithoutProperties(_ref, _excluded$1);
452
+
453
+ return /*#__PURE__*/React__default.createElement(Button$1, restProps, children);
454
+ };
455
+
456
+ var InvertedTextButton$1 = themed(InvertedTextButton);
457
+
458
+ var media = {
459
+ xs: '576px',
460
+ sm: '768px',
461
+ md: '992px',
462
+ lg: '1200px'
463
+ };
464
+
465
+ var _templateObject$3, _templateObject2$1;
466
+ var ALL_ITEM = {
467
+ id: 'ALL',
468
+ name: 'ALL'
469
+ };
470
+ var multiSelectorItemMaxHeight = '3rem';
471
+ var multiSelectorItemAnimationDuration = '300ms';
472
+ var multiselectorItemFadeIn = styled.keyframes(_templateObject$3 || (_templateObject$3 = _taggedTemplateLiteral(["\n from {\n margin: 0;\n max-height: 0px;\n opacity: 0;\n }\n to {\n max-height: ", ";\n opacity: 1;\n }\n"])), multiSelectorItemMaxHeight);
473
+ var StyledMultiselector = styled__default.div(_templateObject2$1 || (_templateObject2$1 = _taggedTemplateLiteral(["\n .multiselector__selected-items,\n .multiselector__selectable-items {\n display: flex;\n flex-flow: wrap;\n margin-left: calc(-1 * ", ");\n button {\n &:hover {\n color: ", ";\n background-color: ", ";\n }\n border-color: ", ";\n background-color: ", ";\n color: ", ";\n padding: ", ";\n text-transform: none;\n box-sizing: border-box;\n animation: ", " ease-in-out\n ", " forwards;\n flex-basis: calc(25% - ", ");\n margin-bottom: ", ";\n margin-left: ", ";\n text-overflow: ellipsis;\n overflow-x: hidden;\n min-height: 40px;\n\n @media (max-width: ", ") {\n flex-basis: calc(50% - ", ");\n }\n }\n }\n\n .multiselector__footer {\n display: flex;\n justify-content: center;\n button {\n &:hover {\n color: ", ";\n background-color: ", ";\n }\n background-color: ", ";\n color: ", ";\n }\n }\n"])), function (props) {
474
+ return props.theme.marginPaddings[2];
475
+ }, function (props) {
476
+ return props.theme.colors.ntrlMin;
477
+ }, function (props) {
478
+ return props.theme.colors.primary;
479
+ }, function (props) {
480
+ return props.theme.colors.primary;
481
+ }, function (props) {
482
+ return props.theme.colors.ntrlMin;
483
+ }, function (props) {
484
+ return props.theme.colors.primary;
485
+ }, function (props) {
486
+ return props.theme.marginPaddings[0];
487
+ }, multiSelectorItemAnimationDuration, multiselectorItemFadeIn, function (props) {
488
+ return props.theme.marginPaddings[2];
489
+ }, function (props) {
490
+ return props.theme.marginPaddings[2];
491
+ }, function (props) {
492
+ return props.theme.marginPaddings[2];
493
+ }, media.sm, function (props) {
494
+ return props.theme.marginPaddings[2];
495
+ }, function (props) {
496
+ return props.theme.colors.primary;
497
+ }, function (props) {
498
+ return props.theme.colors.ntrlMin;
499
+ }, function (props) {
500
+ return props.theme.colors.primary;
501
+ }, function (props) {
502
+ return props.theme.colors.ntrlMin;
503
+ });
504
+ /**
505
+ * Multiselector with a GraphQL flavour (TODO: to be revised to make it remote api agnostic)
506
+ */
507
+
508
+ var GraphQLMultiSelector = /*#__PURE__*/function (_React$Component) {
509
+ _inherits(GraphQLMultiSelector, _React$Component);
510
+
511
+ var _super = _createSuper(GraphQLMultiSelector);
512
+
513
+ function GraphQLMultiSelector(props) {
514
+ var _this;
515
+
516
+ _classCallCheck(this, GraphQLMultiSelector);
517
+
518
+ _this = _super.call(this, props);
519
+
520
+ _defineProperty(_assertThisInitialized(_this), "componentDidUpdate", function (prevProps) {
521
+ if (prevProps.graphQuery !== _this.props.graphQuery) {
522
+ _this.makeRequest();
523
+ }
524
+ });
525
+
526
+ _defineProperty(_assertThisInitialized(_this), "makeRequest", function () {
527
+ _this.pageReady.refreshPage();
528
+ });
529
+
530
+ _defineProperty(_assertThisInitialized(_this), "emptySelected", function () {
531
+ return _this.setState({
532
+ selected: [ALL_ITEM]
533
+ });
534
+ });
535
+
536
+ _defineProperty(_assertThisInitialized(_this), "setNewResults", function (res) {
537
+ var selectedIds = _this.state.selected.map(function (sel) {
538
+ return sel.id;
539
+ });
540
+
541
+ var pagination = _this.props.resultProcessor(res);
542
+
543
+ var allSelected = _this.state.selected.some(function (item) {
544
+ return item.id === ALL_ITEM.id;
545
+ });
546
+
547
+ var newList = pagination.data.filter(function (newItem) {
548
+ return !selectedIds.includes(newItem.id);
549
+ });
550
+ newList = allSelected ? newList : [ALL_ITEM].concat(_toConsumableArray(newList));
551
+
552
+ _this.setState({
553
+ list: newList,
554
+ pagination: pagination
555
+ });
556
+ });
557
+
558
+ _defineProperty(_assertThisInitialized(_this), "onAddItem", function (addSelectedItem) {
559
+ _this.setState(function (prevState) {
560
+ var newSelectedList;
561
+ var newList;
562
+
563
+ if (addSelectedItem.id === ALL_ITEM.id) {
564
+ // Clear Selected List
565
+ // and move previous Selected items to list
566
+ newSelectedList = [ALL_ITEM];
567
+ newList = prevState.list.filter(function (item) {
568
+ return item.id !== ALL_ITEM.id;
569
+ }).concat(prevState.selected).sort(function (a, b) {
570
+ return a.id - b.id;
571
+ });
572
+ } else {
573
+ newSelectedList = _toConsumableArray(prevState.selected.filter(function (item) {
574
+ return item.id !== ALL_ITEM.id;
575
+ })).concat(addSelectedItem);
576
+ newList = [ALL_ITEM].concat(_toConsumableArray(prevState.list.filter(function (item) {
577
+ return item.id !== ALL_ITEM.id;
578
+ }).filter(function (item) {
579
+ return item.id !== addSelectedItem.id;
580
+ })));
581
+ }
582
+
583
+ return {
584
+ selected: newSelectedList,
585
+ list: newList
586
+ };
587
+ }, function () {
588
+ _this.props.onChange(_this.state.selected.filter(function (item) {
589
+ return item.id !== ALL_ITEM.id;
590
+ }));
591
+ });
592
+ });
593
+
594
+ _defineProperty(_assertThisInitialized(_this), "onRemoveItem", function (removeSelectedItem) {
595
+ _this.setState(function (prevState) {
596
+ // Cannot remove ALL from selection by unselecting it
597
+ if ((removeSelectedItem === null || removeSelectedItem === void 0 ? void 0 : removeSelectedItem.id) === ALL_ITEM.id) {
598
+ return {};
599
+ }
600
+
601
+ var newSelectedList = prevState.selected.filter(function (item) {
602
+ return item.id !== removeSelectedItem.id;
603
+ });
604
+
605
+ var newList = _toConsumableArray(prevState.list).concat(removeSelectedItem).filter(function (item) {
606
+ return item.id !== ALL_ITEM.id;
607
+ }).sort(function (a, b) {
608
+ return a.id - b.id;
609
+ });
610
+
611
+ return {
612
+ list: newList,
613
+ selected: newSelectedList.length ? newSelectedList : [ALL_ITEM]
614
+ };
615
+ }, function () {
616
+ _this.props.onChange(_this.state.selected.filter(function (item) {
617
+ return item.id !== ALL_ITEM.id;
618
+ }));
619
+ });
620
+ });
621
+
622
+ _defineProperty(_assertThisInitialized(_this), "onIsLoading", function (flag) {
623
+ _this.setState({
624
+ isLoading: flag
625
+ });
626
+ });
627
+
628
+ _defineProperty(_assertThisInitialized(_this), "render", function () {
629
+ var _this$props = _this.props,
630
+ baseClass = _this$props.baseClass,
631
+ ItemRenderer = _this$props.itemRenderer,
632
+ identifier = _this$props.identifier,
633
+ triggerRequest = _this$props.triggerRequest,
634
+ className = _this$props.className;
635
+ var _this$state = _this.state,
636
+ list = _this$state.list,
637
+ selected = _this$state.selected,
638
+ pagination = _this$state.pagination,
639
+ isLoading = _this$state.isLoading;
640
+ return /*#__PURE__*/React__default.createElement(StyledMultiselector, null, /*#__PURE__*/React__default.createElement("div", {
641
+ "data-qe-id": identifier,
642
+ className: "".concat(className, " ").concat(baseClass)
643
+ }, /*#__PURE__*/React__default.createElement("div", {
644
+ className: "".concat(baseClass, "__selected-items")
645
+ }, selected.map(function (item) {
646
+ return /*#__PURE__*/React__default.createElement(ItemRenderer, {
647
+ key: item.id,
648
+ item: item,
649
+ onSelect: _this.onRemoveItem,
650
+ selected: true
651
+ });
652
+ })), /*#__PURE__*/React__default.createElement(LuxityPageReady, {
653
+ ref: function ref(inst) {
654
+ _this.pageReady = inst;
655
+ },
656
+ onData: _this.setNewResults,
657
+ onIsLoading: _this.onIsLoading,
658
+ getRequestPromise: function getRequestPromise() {
659
+ return triggerRequest();
660
+ }
661
+ }), /*#__PURE__*/React__default.createElement("div", {
662
+ className: "".concat(baseClass, "__selectable-items")
663
+ }, list.map(function (item) {
664
+ return /*#__PURE__*/React__default.createElement(ItemRenderer, {
665
+ key: item.id,
666
+ item: item,
667
+ onSelect: _this.onAddItem,
668
+ selected: false
669
+ });
670
+ })), /*#__PURE__*/React__default.createElement("div", {
671
+ className: "".concat(baseClass, "__footer")
672
+ }, /*#__PURE__*/React__default.createElement(InvertedTextButton$1, {
673
+ disabled: isLoading || !pagination.has_more_pages,
674
+ onClick: _this.props.increaseLimit,
675
+ type: "button"
676
+ }, "SHOW MORE"))));
677
+ });
678
+
679
+ _this.state = {
680
+ selected: [ALL_ITEM],
681
+ list: [],
682
+ pagination: {},
683
+ isLoading: false
684
+ };
685
+ return _this;
686
+ }
687
+
688
+ return _createClass(GraphQLMultiSelector);
689
+ }(React__default.Component);
690
+
691
+ GraphQLMultiSelector.defaultProps = {
692
+ baseClass: 'multiselector'
693
+ };
694
+ var GraphQLMultiSelector$1 = themed(GraphQLMultiSelector);
695
+
696
+ var Search = (function (props) {
697
+ return /*#__PURE__*/React__default.createElement("svg", _extends({
698
+ width: "15",
699
+ height: "15",
700
+ viewBox: "0 0 15 15",
701
+ overflow: "visible",
702
+ fill: "none",
703
+ xmlns: "http://www.w3.org/2000/svg"
704
+ }, props), /*#__PURE__*/React__default.createElement("path", {
705
+ d: "M14.82 13.93L11.21 10.32C12.1 9.23 12.64 7.83 12.64 6.31C12.64 2.83 9.81 0 6.32 0C2.83 0 0 2.83 0 6.32C0 9.81 2.83 12.64 6.32 12.64C7.84 12.64 9.23 12.1 10.32 11.21L13.93 14.81C14.17 15.06 14.57 15.06 14.81 14.81C15.06 14.57 15.06 14.18 14.82 13.93ZM6.32 11.38C3.53 11.38 1.25 9.11 1.25 6.32C1.25 3.53 3.52 1.25 6.32 1.25C9.11 1.25 11.39 3.52 11.39 6.32C11.39 9.12 9.11 11.38 6.32 11.38Z",
706
+ fill: "currentColor"
707
+ }));
708
+ });
709
+
710
+ var _templateObject$4, _templateObject2$2;
711
+ var Title = styled__default.h1(_templateObject$4 || (_templateObject$4 = _taggedTemplateLiteral(["\n font-size: ", ";\n font-weight: bold;\n margin-bottom: 0;\n text-transform: uppercase;\n"])), function (props) {
712
+ return props.theme.fontSizes[2];
713
+ });
714
+ var InterestsSubheadingContainer = styled__default.div(_templateObject2$2 || (_templateObject2$2 = _taggedTemplateLiteral(["\n display: flex;\n justify-content: space-between;\n padding-bottom: ", ";\n border-bottom: 1px solid ", ";\n margin-bottom: ", ";\n margin-top: ", ";\n width: 100%;\n align-items: center;\n"])), function (props) {
715
+ return props.theme.marginPaddings[1];
716
+ }, function (props) {
717
+ return props.theme.colors.primary;
718
+ }, function (props) {
719
+ return props.theme.marginPaddings[3];
720
+ }, function (props) {
721
+ return props.theme.marginPaddings[3];
722
+ });
723
+
724
+ var InterestsSubheading = function InterestsSubheading(_ref) {
725
+ var title = _ref.title,
726
+ children = _ref.children,
727
+ className = _ref.className;
728
+ return /*#__PURE__*/React__default.createElement(InterestsSubheadingContainer, {
729
+ className: className
730
+ }, /*#__PURE__*/React__default.createElement(Title, null, title), /*#__PURE__*/React__default.createElement("div", null, children));
731
+ };
732
+
733
+ var _templateObject$5;
734
+
735
+ var Title$1 = function Title(_ref) {
736
+ var baseClass = _ref.baseClass,
737
+ className = _ref.className,
738
+ title = _ref.title,
739
+ searchPlaceHolder = _ref.searchPlaceHolder,
740
+ onSearchChanged = _ref.onSearchChanged;
741
+ return /*#__PURE__*/React__default.createElement(InterestsSubheading, {
742
+ className: "".concat(className, " ").concat(baseClass, "__title"),
743
+ title: title
744
+ }, /*#__PURE__*/React__default.createElement("div", {
745
+ className: "title__search"
746
+ }, /*#__PURE__*/React__default.createElement(Search, null), /*#__PURE__*/React__default.createElement("input", {
747
+ placeholder: searchPlaceHolder,
748
+ type: "text",
749
+ name: "search",
750
+ onChange: onSearchChanged
751
+ })));
752
+ };
753
+
754
+ var StyledTitle = styled__default(Title$1)(_templateObject$5 || (_templateObject$5 = _taggedTemplateLiteral(["\n margin-bottom: ", ";\n font-weight: bold;\n display: flex;\n align-items: center;\n font-size: ", ";\n\n .title__search,\n .title__search {\n display: flex;\n justify-content: center;\n align-items: center;\n min-height: 30px;\n margin-bottom: ", ";\n\n svg {\n margin-left: ", ";\n fill: ", ";\n stroke: ", ";\n }\n\n input {\n width: 140px;\n border: none;\n font-size: ", ";\n transition: 0.2s border-color ease-in-out;\n margin-left: ", ";\n padding: 0;\n\n :focus {\n border-color: ", ";\n border-bottom: none;\n }\n }\n }\n"])), function (props) {
755
+ return props.theme.marginPaddings[2];
756
+ }, function (props) {
757
+ return props.theme.fontSizes[2];
758
+ }, function (props) {
759
+ return props.theme.marginPaddings[0];
760
+ }, function (props) {
761
+ return props.theme.marginPaddings[3];
762
+ }, function (props) {
763
+ return props.theme.colors.primary || '';
764
+ }, function (props) {
765
+ return props.theme.colors.primary || '';
766
+ }, function (props) {
767
+ return props.theme.fontSizes[2];
768
+ }, function (props) {
769
+ return props.theme.marginPaddings[0];
770
+ }, function (props) {
771
+ return props.theme.colors.primary;
772
+ });
773
+ var Title$2 = themed(StyledTitle);
774
+
775
+ var debounceBuilder = functions.debounced(200);
776
+
777
+ /**
778
+ * Luxity flavoured GraphQLMultiselector with text Search, category and limit controls
779
+ */
780
+ var LuxityGraphQLMultiselector = /*#__PURE__*/function (_React$Component) {
781
+ _inherits(LuxityGraphQLMultiselector, _React$Component);
782
+
783
+ var _super = _createSuper(LuxityGraphQLMultiselector);
784
+
785
+ function LuxityGraphQLMultiselector(props) {
786
+ var _this;
787
+
788
+ _classCallCheck(this, LuxityGraphQLMultiselector);
789
+
790
+ _this = _super.call(this, props);
791
+
792
+ _defineProperty(_assertThisInitialized(_this), "multiSelectorRef", /*#__PURE__*/React__default.createRef());
793
+
794
+ _defineProperty(_assertThisInitialized(_this), "increaseLimit", function () {
795
+ _this.setState(function (prevState) {
796
+ return {
797
+ limit: prevState.limit + _this.props.queryLimitIncrement
798
+ };
799
+ });
800
+ });
801
+
802
+ _defineProperty(_assertThisInitialized(_this), "onChange", function (selection) {
803
+ _this.props.onChange(selection);
804
+ });
805
+
806
+ _defineProperty(_assertThisInitialized(_this), "onSearchChanged", function (event) {
807
+ event.preventDefault();
808
+ var searchText = event.target.value;
809
+ debounceBuilder(function () {
810
+ _this.setState({
811
+ nameFilter: searchText
812
+ });
813
+ });
814
+ });
815
+
816
+ _defineProperty(_assertThisInitialized(_this), "render", function () {
817
+ var _this$state = _this.state,
818
+ limit = _this$state.limit,
819
+ category = _this$state.category,
820
+ nameFilter = _this$state.nameFilter;
821
+ var _this$props = _this.props,
822
+ title = _this$props.title,
823
+ baseClass = _this$props.baseClass,
824
+ getGraphQuery = _this$props.getGraphQuery,
825
+ resultProcessor = _this$props.resultProcessor,
826
+ itemRenderer = _this$props.itemRenderer,
827
+ searchPlaceHolder = _this$props.searchPlaceHolder,
828
+ graphApi = _this$props.graphApi,
829
+ identifier = _this$props.identifier,
830
+ requestInstance = _this$props.requestInstance;
831
+ return /*#__PURE__*/React__default.createElement("div", {
832
+ className: baseClass
833
+ }, /*#__PURE__*/React__default.createElement(Title$2, {
834
+ title: title,
835
+ baseClass: baseClass,
836
+ searchPlaceHolder: searchPlaceHolder,
837
+ onSearchChanged: _this.onSearchChanged
838
+ }), /*#__PURE__*/React__default.createElement(React.Fragment, null, /*#__PURE__*/React__default.createElement(GraphQLMultiSelector$1, {
839
+ triggerRequest: function triggerRequest() {
840
+ return requestInstance.post(graphApi, {
841
+ query: getGraphQuery(limit, 1, 'id|desc', category, nameFilter)
842
+ });
843
+ },
844
+ graphQuery: getGraphQuery(limit, 1, 'id|desc', category, nameFilter),
845
+ identifier: identifier,
846
+ ref: _this.multiSelectorRef,
847
+ onChange: _this.onChange,
848
+ resultProcessor: resultProcessor,
849
+ increaseLimit: _this.increaseLimit,
850
+ itemRenderer: itemRenderer
851
+ })));
852
+ });
853
+
854
+ _this.state = {
855
+ limit: props.baseQueryLimit,
856
+ category: props.category,
857
+ nameFilter: ''
858
+ };
859
+ return _this;
860
+ }
861
+
862
+ _createClass(LuxityGraphQLMultiselector, [{
863
+ key: "componentDidUpdate",
864
+ value: function componentDidUpdate(prevProps) {
865
+ var _this$multiSelectorRe;
866
+
867
+ if (prevProps.category !== this.props.category && (_this$multiSelectorRe = this.multiSelectorRef) !== null && _this$multiSelectorRe !== void 0 && _this$multiSelectorRe.current) {
868
+ this.multiSelectorRef.current.emptySelected();
869
+ }
870
+ }
871
+ }], [{
872
+ key: "getDerivedStateFromProps",
873
+ value: function getDerivedStateFromProps(props, prevState) {
874
+ if (prevState.category !== props.category) {
875
+ return {
876
+ category: props.category
877
+ };
878
+ }
879
+
880
+ return null;
881
+ }
882
+ }]);
883
+
884
+ return LuxityGraphQLMultiselector;
885
+ }(React__default.Component);
886
+
887
+ LuxityGraphQLMultiselector.defaultProps = {
888
+ baseClass: '',
889
+ searchPlaceHolder: '',
890
+ queryLimitIncrement: 12,
891
+ baseQueryLimit: 12
892
+ };
893
+
894
+ var _excluded$2 = ["children"];
895
+
896
+ var _templateObject$6;
897
+ var Button$2 = styled__default.button(_templateObject$6 || (_templateObject$6 = _taggedTemplateLiteral(["\n ", ";\n background-color: #fff;\n color: ", ";\n border: 1px solid ", ";\n\n &:disabled {\n ", "\n }\n"])), baseButtonStyle, function (props) {
898
+ return props.theme.colors.primary;
899
+ }, function (props) {
900
+ return props.theme.colors.primary;
901
+ }, disabledButtonStyle);
902
+
903
+ var PrimaryButton = function PrimaryButton(_ref) {
904
+ var children = _ref.children,
905
+ restProps = _objectWithoutProperties(_ref, _excluded$2);
906
+
907
+ return /*#__PURE__*/React__default.createElement(Button$2, restProps, children);
908
+ };
909
+
910
+ var PrimaryButton$1 = themed(PrimaryButton);
911
+
912
+ var _templateObject$7;
913
+ var BaseButton = styled__default.button(_templateObject$7 || (_templateObject$7 = _taggedTemplateLiteral(["\n color: ", ";\n border: 1px solid ", ";\n background-color: ", ";\n &:hover {\n color: ", ";\n background-color: ", ";\n }\n"])), function (props) {
914
+ return props.theme.colors.base;
915
+ }, function (props) {
916
+ return props.theme.colors.borderColor;
917
+ }, function (props) {
918
+ return props.theme.colors.ntrlMin;
919
+ }, function (props) {
920
+ return props.theme.colors.primary;
921
+ }, function (props) {
922
+ return props.theme.colors.ntrlMin;
923
+ });
924
+ var UnselectedButton = themed(BaseButton);
925
+
926
+ var ItemRenderer = function ItemRenderer(_ref) {
927
+ var item = _ref.item,
928
+ onSelect = _ref.onSelect,
929
+ selected = _ref.selected;
930
+ var props = {
931
+ onClick: function onClick(e) {
932
+ e.preventDefault();
933
+ onSelect(item);
934
+ }
935
+ };
936
+ return selected ? /*#__PURE__*/React__default.createElement(PrimaryButton$1, props, item.name) : /*#__PURE__*/React__default.createElement(UnselectedButton, props, item.name);
937
+ };
938
+
939
+ var ConditionSelector = function ConditionSelector(_ref) {
940
+ var onChange = _ref.onChange,
941
+ graphApi = _ref.graphApi,
942
+ itemRenderer = _ref.itemRenderer,
943
+ getGraphQuery = _ref.getGraphQuery,
944
+ requestInstance = _ref.requestInstance;
945
+
946
+ var resultProcessor = function resultProcessor(result) {
947
+ return result.data.data.conditions_list;
948
+ };
949
+
950
+ return /*#__PURE__*/React__default.createElement(LuxityGraphQLMultiselector, {
951
+ title: "Condition",
952
+ queryId: "getCondition",
953
+ baseQueryLimit: 10,
954
+ baseClass: "style-selector",
955
+ identifier: "style-selector",
956
+ searchPlaceHolder: "Search Condition",
957
+ category: "",
958
+ onChange: onChange,
959
+ graphApi: graphApi,
960
+ itemRenderer: itemRenderer,
961
+ getGraphQuery: getGraphQuery,
962
+ resultProcessor: resultProcessor,
963
+ requestInstance: requestInstance
964
+ });
965
+ };
966
+
967
+ ConditionSelector.defaultProps = {
968
+ itemRenderer: ItemRenderer
969
+ };
970
+
971
+ return ConditionSelector;
972
+
973
+ })));