@cashub/ui 0.45.0 → 0.45.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cashub/ui",
3
- "version": "0.45.0",
3
+ "version": "0.45.1",
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;
31
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
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; }
@@ -83,7 +83,11 @@ const Select = _ref => {
83
83
  } = (0, _hooks.useCustomPopper)(comboboxElement, listBoxElement);
84
84
  const newOptions = (0, _react.useMemo)(() => {
85
85
  if (!options) return;
86
- const newOptions = [...options];
86
+ const newOptions = options.map(item => {
87
+ return _objectSpread({
88
+ isDisable: false
89
+ }, item);
90
+ });
87
91
  if (options.length > 0 && multiple && enableSelectAll) {
88
92
  newOptions.unshift({
89
93
  id: allOptionId,
@@ -92,6 +96,9 @@ const Select = _ref => {
92
96
  }
93
97
  return newOptions;
94
98
  }, [options, multiple, enableSelectAll, allOptionId]);
99
+ const enabledOptions = (0, _react.useMemo)(() => {
100
+ return newOptions.filter(item => !item.isDisable);
101
+ }, [newOptions]);
95
102
 
96
103
  // parse all value to string
97
104
  // for subsequently determine whether it is a selected item
@@ -108,13 +115,13 @@ const Select = _ref => {
108
115
  return '';
109
116
  }, [selected]);
110
117
  const selectedAllOptions = (0, _react.useMemo)(() => {
111
- if (multiple && enableSelectAll && parsedSelected.length + 1 === newOptions.length) {
118
+ if (multiple && enableSelectAll && parsedSelected.length + 1 === enabledOptions.length) {
112
119
  const selectedAllOptions = [...parsedSelected];
113
120
  selectedAllOptions.unshift(allOptionId);
114
121
  return selectedAllOptions;
115
122
  }
116
123
  return parsedSelected;
117
- }, [multiple, enableSelectAll, newOptions.length, parsedSelected, allOptionId]);
124
+ }, [multiple, enableSelectAll, enabledOptions.length, parsedSelected, allOptionId]);
118
125
  const showCheckbox = (0, _react.useMemo)(() => {
119
126
  if (multiple && displayMode === 'text') {
120
127
  return true;
@@ -175,18 +182,37 @@ const Select = _ref => {
175
182
  const handleOnSelect = (0, _react.useCallback)((event, value) => {
176
183
  event.stopPropagation();
177
184
  if (disabled === true) return;
185
+ const targetOption = newOptions.find(_ref2 => {
186
+ let {
187
+ id,
188
+ child
189
+ } = _ref2;
190
+ return id === value || child && child.find(_ref3 => {
191
+ let {
192
+ id
193
+ } = _ref3;
194
+ return id === value;
195
+ });
196
+ });
197
+ const actualOpt = targetOption !== null && targetOption !== void 0 && targetOption.child ? targetOption.child.find(_ref4 => {
198
+ let {
199
+ id
200
+ } = _ref4;
201
+ return id === value;
202
+ }) : targetOption;
203
+ if (actualOpt !== null && actualOpt !== void 0 && actualOpt.isDisable) return;
178
204
 
179
205
  // 選取選項
180
206
  // 點選 all 全選
181
207
  if (multiple) {
182
- if (value.toString() === allOptionId && selectedAllOptions.length < newOptions.length) {
183
- for (let index = 1; index < newOptions.length; index += 1) {
184
- onSelect(newOptions[index].id);
208
+ if (value.toString() === allOptionId && selectedAllOptions.length < enabledOptions.length) {
209
+ for (let index = 1; index < enabledOptions.length; index += 1) {
210
+ onSelect(enabledOptions[index].id);
185
211
  }
186
212
  }
187
213
  if (value.toString() !== allOptionId && !selectedAllOptions.includes(value.toString())) {
188
214
  // 選取一個選項,變成全選
189
- if (selectedAllOptions.length + 2 === newOptions.length) {
215
+ if (selectedAllOptions.length + 2 === enabledOptions.length) {
190
216
  onSelect(value);
191
217
  } else {
192
218
  // 選取特定選項
@@ -196,14 +222,14 @@ const Select = _ref => {
196
222
 
197
223
  // 刪除選項
198
224
  // 點選 all 刪除全選
199
- if (value.toString() === allOptionId && selectedAllOptions.length === newOptions.length) {
200
- for (let index = 0; index < newOptions.length; index += 1) {
201
- onDeselect(newOptions[index].id);
225
+ if (value.toString() === allOptionId && selectedAllOptions.length === enabledOptions.length) {
226
+ for (let index = 0; index < enabledOptions.length; index += 1) {
227
+ onDeselect(enabledOptions[index].id);
202
228
  }
203
229
  }
204
230
  if (value.toString() !== allOptionId && selectedAllOptions.includes(value.toString())) {
205
231
  // 原本是 all 全選後來刪除其中一個選項
206
- if (selectedAllOptions.length === newOptions.length) {
232
+ if (selectedAllOptions.length === enabledOptions.length) {
207
233
  onDeselect(value);
208
234
  } else {
209
235
  // 刪除特定選項
@@ -217,7 +243,7 @@ const Select = _ref => {
217
243
  }
218
244
  comboboxElement.focus();
219
245
  setSearch('');
220
- }, [disabled, onSelect, comboboxElement, selectedAllOptions, onDeselect, newOptions, allOptionId, multiple]);
246
+ }, [disabled, onSelect, comboboxElement, selectedAllOptions, onDeselect, newOptions, allOptionId, multiple, enabledOptions]);
221
247
  const handleOnDeselect = (0, _react.useCallback)((event, value) => {
222
248
  event.stopPropagation();
223
249
  if (disabled === true) return;
@@ -287,32 +313,41 @@ const Select = _ref => {
287
313
  id: option.text,
288
314
  children: option.text
289
315
  }), option.child.map(option => {
290
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Option.default, {
316
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Option.default, {
291
317
  role: "option",
292
- tabIndex: "0",
318
+ tabIndex: option.isDisable ? '-1' : '0',
293
319
  id: option.id,
294
- onClick: event => handleOnSelect(event, option.id),
320
+ onClick: event => !option.isDisable && handleOnSelect(event, option.id),
295
321
  focus: focusedOption && focusedOption.id === option.id.toString(),
296
322
  selected: option.selected,
297
323
  "aria-selected": option.selected,
298
- children: option.text
324
+ "aria-disabled": option.isDisable,
325
+ disabled: option.isDisable,
326
+ children: [option.text, option.suffix && /*#__PURE__*/(0, _jsxRuntime.jsxs)(OptionBadge, {
327
+ children: ["\xA0", option.suffix]
328
+ })]
299
329
  }, option.id);
300
330
  })]
301
331
  }, option.text);
302
332
  }
303
333
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Option.default, {
304
334
  role: "option",
305
- tabIndex: "0",
335
+ tabIndex: option.isDisable ? '-1' : '0',
306
336
  id: option.id,
307
- onClick: event => handleOnSelect(event, option.id),
337
+ onClick: event => !option.isDisable && handleOnSelect(event, option.id),
308
338
  focus: focusedOption && focusedOption.id === option.id.toString(),
309
339
  selected: option.selected,
310
340
  "aria-selected": option.selected,
341
+ "aria-disabled": option.isDisable,
342
+ disabled: option.isDisable,
311
343
  children: [showCheckbox && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Checkbox.default, {
312
- selected: option.selected
344
+ selected: option.selected,
345
+ disabled: option.isDisable
313
346
  }), option.icon && /*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, {
314
347
  src: option.icon
315
- }), option.text]
348
+ }), option.text, option.suffix && /*#__PURE__*/(0, _jsxRuntime.jsxs)(OptionBadge, {
349
+ children: ["\xA0", option.suffix]
350
+ })]
316
351
  }, option.id);
317
352
  });
318
353
  }, [optionList, focusedOption, handleOnSelect, showCheckbox]);
@@ -337,6 +372,7 @@ const Select = _ref => {
337
372
  if (!display) {
338
373
  handleToggle();
339
374
  } else if (focusedOption) {
375
+ if (focusedOption.getAttribute('aria-disabled') === 'true') return;
340
376
  handleOnSelect(event, focusedOption.id);
341
377
  }
342
378
  break;
@@ -350,7 +386,10 @@ const Select = _ref => {
350
386
  if (!focusedOption) {
351
387
  return;
352
388
  }
353
- const previousItem = findPreviousItem(focusedOption);
389
+ let previousItem = findPreviousItem(focusedOption);
390
+ while (previousItem && previousItem.getAttribute('aria-disabled') === 'true') {
391
+ previousItem = findPreviousItem(previousItem);
392
+ }
354
393
  if (previousItem) {
355
394
  handleFocusItem(previousItem);
356
395
  }
@@ -361,7 +400,10 @@ const Select = _ref => {
361
400
  if (!focusedOption) {
362
401
  return;
363
402
  }
364
- const nextItem = findNextItem(focusedOption);
403
+ let nextItem = findNextItem(focusedOption);
404
+ while (nextItem && nextItem.getAttribute('aria-disabled') === 'true') {
405
+ nextItem = findNextItem(nextItem);
406
+ }
365
407
  if (nextItem) {
366
408
  handleFocusItem(nextItem);
367
409
  }
@@ -593,10 +635,10 @@ const Select = _ref => {
593
635
  })
594
636
  });
595
637
  };
596
- const Icon = _ref2 => {
638
+ const Icon = _ref5 => {
597
639
  let {
598
640
  src
599
- } = _ref2;
641
+ } = _ref5;
600
642
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
601
643
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_figure.IconFigure, {
602
644
  size: "medium",
@@ -609,50 +651,50 @@ const Icon = _ref2 => {
609
651
  }), "\xA0"]
610
652
  });
611
653
  };
612
- const Combobox = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n min-height: 36px;\n cursor: pointer;\n position: relative;\n background: transparent;\n color: var(--font-on-background);\n font-size: var(--font-body1);\n border: var(--border-width) solid var(--border-color);\n border-radius: var(--border-radius-l);\n padding: 0 calc(var(--spacing-s) * 2 + 8px) 0 var(--spacing-s);\n\n &:focus {\n ", ";\n }\n\n ", "\n\n ", "\n\n ", "\n ", "\n \n ", ";\n\n ", "\n\n ", "\n\n ", "\n"])), _ref3 => {
654
+ const Combobox = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n min-height: 36px;\n cursor: pointer;\n position: relative;\n background: transparent;\n color: var(--font-on-background);\n font-size: var(--font-body1);\n border: var(--border-width) solid var(--border-color);\n border-radius: var(--border-radius-l);\n padding: 0 calc(var(--spacing-s) * 2 + 8px) 0 var(--spacing-s);\n\n &:focus {\n ", ";\n }\n\n ", "\n\n ", "\n\n ", "\n ", "\n \n ", ";\n\n ", "\n\n ", "\n\n ", "\n"])), _ref6 => {
613
655
  let {
614
656
  disabled
615
- } = _ref3;
657
+ } = _ref6;
616
658
  return !disabled && "\n border-color: var(--color-primary);\n outline: none;\n ";
617
- }, _ref4 => {
659
+ }, _ref7 => {
618
660
  let {
619
661
  flexGrow
620
- } = _ref4;
662
+ } = _ref7;
621
663
  return !flexGrow && 'min-width: 160px;';
622
- }, _ref5 => {
664
+ }, _ref8 => {
623
665
  let {
624
666
  $display
625
- } = _ref5;
667
+ } = _ref8;
626
668
  return $display && "\n border-color: var(--color-primary);\n outline: none;\n ";
627
- }, _ref6 => {
669
+ }, _ref9 => {
628
670
  let {
629
671
  disabled
630
- } = _ref6;
672
+ } = _ref9;
631
673
  return disabled && 'cursor: not-allowed;opacity: 0.5;';
632
- }, _ref7 => {
674
+ }, _ref10 => {
633
675
  let {
634
676
  placeholder
635
- } = _ref7;
677
+ } = _ref10;
636
678
  return placeholder && 'color: var(--font-on-mute);';
637
- }, _ref8 => {
679
+ }, _ref11 => {
638
680
  let {
639
681
  fullWidth
640
- } = _ref8;
682
+ } = _ref11;
641
683
  return fullWidth ? 'width: 100%' : 'max-width: 320px';
642
- }, _ref9 => {
684
+ }, _ref12 => {
643
685
  let {
644
686
  large
645
- } = _ref9;
687
+ } = _ref12;
646
688
  return large && "\n height: 40px;\n padding: 12px calc(var(--spacing-s) * 2 + 8px) 12px var(--spacing-s);\n ";
647
- }, _ref10 => {
689
+ }, _ref13 => {
648
690
  let {
649
691
  $fill
650
- } = _ref10;
692
+ } = _ref13;
651
693
  return $fill && "\n background: var(--color-background2);\n border-color: transparent;\n ";
652
- }, _ref11 => {
694
+ }, _ref14 => {
653
695
  let {
654
696
  fillReverse
655
- } = _ref11;
697
+ } = _ref14;
656
698
  return fillReverse && "\n background: var(--color-background1);\n border-color: transparent;\n ";
657
699
  });
658
700
  Combobox.displayName = 'Combobox';
@@ -662,4 +704,5 @@ const ExpandArrow = (0, _styledComponents.default)(_ti.TiArrowSortedDown)(_templ
662
704
  ExpandArrow.displayName = 'ExpandArrow';
663
705
  const Message = _styledComponents.default.p(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n margin: 0;\n padding: 12px var(--spacing-s);\n"])));
664
706
  Message.displayName = 'Message';
707
+ const OptionBadge = _styledComponents.default.span(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n color: var(--color-danger);\n font-style: italic;\n"])));
665
708
  var _default = exports.default = Select;
@@ -5,16 +5,21 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
8
- var _templateObject, _templateObject2;
8
+ var _templateObject, _templateObject2, _templateObject3;
9
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
10
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
11
  function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
12
- const Option = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n max-width: 100%;\n word-break: break-all;\n padding: 12px var(--spacing-s);\n background: var(--color-background1);\n transition: background 0.3s;\n\n &:hover {\n background: var(--color-hover);\n }\n\n ", "\n"])), _ref => {
12
+ const Option = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n max-width: 100%;\n word-break: break-all;\n padding: 12px var(--spacing-s);\n background: var(--color-background1);\n transition: background 0.3s;\n\n &:hover {\n background: var(--color-hover);\n }\n\n ", "\n\n ", "\n"])), _ref => {
13
13
  let {
14
14
  selected,
15
15
  focus
16
16
  } = _ref;
17
17
  return (selected || focus) && (0, _styledComponents.css)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n background: var(--color-hover);\n "])));
18
+ }, _ref2 => {
19
+ let {
20
+ disabled
21
+ } = _ref2;
22
+ return disabled && (0, _styledComponents.css)(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n cursor: not-allowed;\n opacity: 0.5;\n pointer-events: none;\n "])));
18
23
  });
19
24
  Option.displayName = 'Option';
20
25
  var _default = exports.default = Option;