@cashub/ui 0.48.15 → 0.48.16

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 (2) hide show
  1. package/package.json +1 -1
  2. package/select/Select.js +45 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cashub/ui",
3
- "version": "0.48.15",
3
+ "version": "0.48.16",
4
4
  "private": false,
5
5
  "author": "CasHUB Team",
6
6
  "description": "CasHUB UI components library",
package/select/Select.js CHANGED
@@ -28,7 +28,7 @@ var _Footer = _interopRequireDefault(require("./subComponent/Footer"));
28
28
  var _figure = require("../figure");
29
29
  var _image = require("../image");
30
30
  var _jsxRuntime = require("react/jsx-runtime");
31
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
31
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8;
32
32
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
33
33
  function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
34
34
  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; }
@@ -128,6 +128,31 @@ const Select = _ref => {
128
128
  }
129
129
  return false;
130
130
  }, [displayMode, multiple]);
131
+ const getOptionText = (0, _react.useCallback)(option => {
132
+ return [option.text, option.suffix].filter(text => text || text === 0).join(' ');
133
+ }, []);
134
+ const renderOptionContent = (0, _react.useCallback)(option => {
135
+ var _option$highlightText;
136
+ const text = getOptionText(option);
137
+ const highlightText = (_option$highlightText = option.highlightText) === null || _option$highlightText === void 0 ? void 0 : _option$highlightText.toString();
138
+ if (highlightText && text.includes(highlightText)) {
139
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(OptionLabel, {
140
+ children: text.split(highlightText).map((textPart, index, textParts) => {
141
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
142
+ children: [textPart, index < textParts.length - 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(OptionHighlight, {
143
+ $color: option.highlightColor,
144
+ children: highlightText
145
+ })]
146
+ }, "".concat(highlightText, "-").concat(index));
147
+ })
148
+ });
149
+ }
150
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(OptionLabel, {
151
+ children: [option.text, option.suffix && /*#__PURE__*/(0, _jsxRuntime.jsxs)(OptionBadge, {
152
+ children: ["\xA0", option.suffix]
153
+ })]
154
+ });
155
+ }, [getOptionText]);
131
156
 
132
157
  // set focused option
133
158
  const handleFocusItem = (0, _react.useCallback)(element => {
@@ -272,7 +297,7 @@ const Select = _ref => {
272
297
  }] = selectedOptions;
273
298
  } else {
274
299
  text = selectedOptions.map(value => {
275
- return value.text;
300
+ return getOptionText(value);
276
301
  }).join(', ');
277
302
  }
278
303
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectedMultipleText.default, {
@@ -281,14 +306,14 @@ const Select = _ref => {
281
306
  }
282
307
  if (selectedOptions[0].id === allOptionId) {
283
308
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectedMultipleTags.default, {
284
- content: selectedOptions[0].text,
309
+ content: renderOptionContent(selectedOptions[0]),
285
310
  onClick: event => handleOnDeselect(event, selectedOptions[0].id),
286
311
  disabled: disabled
287
312
  }, selectedOptions[0].id);
288
313
  }
289
314
  return selectedOptions.map(value => {
290
315
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectedMultipleTags.default, {
291
- content: value.text,
316
+ content: renderOptionContent(value),
292
317
  onClick: event => handleOnDeselect(event, value.id),
293
318
  disabled: disabled
294
319
  }, value.id);
@@ -297,11 +322,11 @@ const Select = _ref => {
297
322
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_SelectedSingle.default, {
298
323
  children: [selectedOptions[0].icon && /*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, {
299
324
  src: selectedOptions[0].icon
300
- }), selectedOptions[0].text]
325
+ }), renderOptionContent(selectedOptions[0])]
301
326
  });
302
327
  }
303
328
  return placeholder;
304
- }, [placeholder, handleOnDeselect, multiple, displayMode, selectedOptions, disabled, allOptionId]);
329
+ }, [placeholder, handleOnDeselect, multiple, displayMode, selectedOptions, disabled, allOptionId, getOptionText, renderOptionContent]);
305
330
  const optionItem = (0, _react.useMemo)(() => {
306
331
  if (optionList.length <= 0) return null;
307
332
  return optionList.map(option => {
@@ -313,7 +338,7 @@ const Select = _ref => {
313
338
  id: option.text,
314
339
  children: option.text
315
340
  }), option.child.map(option => {
316
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Option.default, {
341
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Option.default, {
317
342
  role: "option",
318
343
  tabIndex: option.isDisable ? '-1' : '0',
319
344
  id: option.id,
@@ -323,9 +348,7 @@ const Select = _ref => {
323
348
  "aria-selected": option.selected,
324
349
  "aria-disabled": option.isDisable,
325
350
  disabled: option.isDisable,
326
- children: [option.text, option.suffix && /*#__PURE__*/(0, _jsxRuntime.jsxs)(OptionBadge, {
327
- children: ["\xA0", option.suffix]
328
- })]
351
+ children: renderOptionContent(option)
329
352
  }, option.id);
330
353
  })]
331
354
  }, option.text);
@@ -345,12 +368,10 @@ const Select = _ref => {
345
368
  disabled: option.isDisable
346
369
  }), option.icon && /*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, {
347
370
  src: option.icon
348
- }), option.text, option.suffix && /*#__PURE__*/(0, _jsxRuntime.jsxs)(OptionBadge, {
349
- children: ["\xA0", option.suffix]
350
- })]
371
+ }), renderOptionContent(option)]
351
372
  }, option.id);
352
373
  });
353
- }, [optionList, focusedOption, handleOnSelect, showCheckbox]);
374
+ }, [optionList, focusedOption, handleOnSelect, showCheckbox, renderOptionContent]);
354
375
 
355
376
  // show or hide listbox
356
377
  // and set listbox width according to combobox current width
@@ -547,18 +568,18 @@ const Select = _ref => {
547
568
  const tmpFilteredOptions = [];
548
569
  newOptions.forEach(option => {
549
570
  if (option.child && option.child.length > 0) {
550
- const tmpFilteredChildOptions = option.child.filter(option => option.text.toLowerCase().indexOf(search.toLowerCase().trim()) !== -1);
571
+ const tmpFilteredChildOptions = option.child.filter(option => getOptionText(option).toLowerCase().indexOf(search.toLowerCase().trim()) !== -1);
551
572
  if (tmpFilteredChildOptions.length > 0) {
552
573
  tmpFilteredOptions.push(_objectSpread(_objectSpread({}, option), {}, {
553
574
  child: tmpFilteredChildOptions
554
575
  }));
555
576
  }
556
- } else if (option.text.toLowerCase().indexOf(search.toLowerCase().trim()) !== -1) {
577
+ } else if (getOptionText(option).toLowerCase().indexOf(search.toLowerCase().trim()) !== -1) {
557
578
  tmpFilteredOptions.push(option);
558
579
  }
559
580
  });
560
581
  setFilteredOptions(tmpFilteredOptions);
561
- }, [search, newOptions]);
582
+ }, [search, newOptions, getOptionText]);
562
583
  (0, _react.useEffect)(() => {
563
584
  if (display) {
564
585
  setupFocus();
@@ -705,4 +726,11 @@ ExpandArrow.displayName = 'ExpandArrow';
705
726
  const Message = _styledComponents.default.p(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n margin: 0;\n padding: 12px var(--spacing-s);\n"])));
706
727
  Message.displayName = 'Message';
707
728
  const OptionBadge = _styledComponents.default.span(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n color: var(--color-danger);\n font-style: italic;\n"])));
729
+ const OptionLabel = _styledComponents.default.div(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n min-width: 0;\n"])));
730
+ const OptionHighlight = _styledComponents.default.span(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n color: ", ";\n"])), _ref15 => {
731
+ let {
732
+ $color
733
+ } = _ref15;
734
+ return $color || 'var(--color-danger)';
735
+ });
708
736
  var _default = exports.default = Select;