@cashub/ui 0.4.2 → 0.6.0

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 (200) hide show
  1. package/Tab/Tab.js +28 -0
  2. package/Tab/TabContext.js +12 -0
  3. package/Tab/TabList.js +47 -0
  4. package/Tab/TabPanel.js +85 -0
  5. package/Tab/TabTab.js +63 -0
  6. package/Tab/index.js +24 -0
  7. package/animate/Collapse.js +1 -1
  8. package/animate/NumberCounter.js +1 -1
  9. package/assets/font/helvetica/Helvetica.ttf +0 -0
  10. package/assets/font/nanumGothic/NanumGothic-Bold.ttf +0 -0
  11. package/assets/font/nanumGothic/NanumGothic-ExtraBold.ttf +0 -0
  12. package/assets/font/nanumGothic/NanumGothic-Regular.ttf +0 -0
  13. package/assets/icons/app-management.png +0 -0
  14. package/assets/icons/burger.png +0 -0
  15. package/assets/icons/map_icon1.png +0 -0
  16. package/assets/icons/map_icon4.png +0 -0
  17. package/assets/images/bg-chart-circle.png +0 -0
  18. package/assets/images/bg-chart-triangle.png +0 -0
  19. package/assets/images/cashub-logo-only.png +0 -0
  20. package/assets/images/logo-cashub.png +0 -0
  21. package/assets/images/map.png +0 -0
  22. package/assets/images/qrcode.png +0 -0
  23. package/backdrop/index.js +31 -0
  24. package/badge/BadgeFill.js +3 -3
  25. package/billing/BarChart.js +58 -0
  26. package/billing/Grid.js +49 -0
  27. package/billing/Header2.js +28 -0
  28. package/billing/Header3.js +44 -0
  29. package/billing/Paragraph.js +39 -0
  30. package/billing/ParagraphGroup.js +25 -0
  31. package/billing/ParagraphText.js +31 -0
  32. package/billing/Section.js +60 -0
  33. package/billing/SectionBody.js +20 -0
  34. package/billing/SectionHeader.js +31 -0
  35. package/billing/__stories__/BarChart.stories.js_bak +46 -0
  36. package/billing/__stories__/Grid.stories.js_bak +57 -0
  37. package/billing/__stories__/Header2.stories.js_bak +62 -0
  38. package/billing/__stories__/Header3.stories.js_bak +69 -0
  39. package/billing/__stories__/Paragraph.stories.js_bak +84 -0
  40. package/billing/__stories__/ParagraphGroup.stories.js_bak +68 -0
  41. package/billing/__stories__/ParagraphText.stories.js_bak +64 -0
  42. package/billing/__stories__/Section.stories.js_bak +115 -0
  43. package/billing/__stories__/SectionBody.stories.js_bak +62 -0
  44. package/billing/__stories__/SectionHeader.stories.js-bak +68 -0
  45. package/breadcrumb/Breadcrumb.js +11 -6
  46. package/button/IconButton.js +1 -1
  47. package/callout/Callout.js +36 -0
  48. package/callout/index.js +15 -0
  49. package/chart/BarChart.js +130 -0
  50. package/chart/DoughnutChart.js +59 -0
  51. package/chart/LineChart.js +121 -0
  52. package/chart/SingleBarChart.js +31 -0
  53. package/chart/index.js +39 -0
  54. package/container/FlexContainer.js +25 -0
  55. package/container/index.js +15 -0
  56. package/cropper/Cropper.js +1 -1
  57. package/datetimePicker/Accordion.js +342 -0
  58. package/datetimePicker/CustomTimeInput.js +77 -0
  59. package/datetimePicker/DatePicker.js +413 -0
  60. package/datetimePicker/DatePickerV2.js +456 -0
  61. package/datetimePicker/DateTimePickerContext.js +12 -0
  62. package/datetimePicker/DatetimePicker.js +80 -0
  63. package/datetimePicker/DatetimePickerV2.js +478 -0
  64. package/datetimePicker/TimeInput.js +37 -0
  65. package/datetimePicker/TimePicker.js +324 -0
  66. package/datetimePicker/accordion/Month.js +190 -0
  67. package/datetimePicker/accordion/Year.js +247 -0
  68. package/datetimePicker/hooks/index.js +31 -0
  69. package/datetimePicker/hooks/useChangeNumber.js +55 -0
  70. package/datetimePicker/hooks/useDecrease.js +54 -0
  71. package/datetimePicker/hooks/useIncrease.js +54 -0
  72. package/datetimePicker/index.js +47 -0
  73. package/datetimePicker/provider/constant.js +44 -0
  74. package/datetimePicker/utils/GMTDate.js +23 -0
  75. package/datetimePicker/utils/pad.js +17 -0
  76. package/descriptionList/DescriptionDetail.js +22 -0
  77. package/descriptionList/DescriptionList.js +22 -0
  78. package/descriptionList/DescriptionTerm.js +19 -0
  79. package/descriptionList/index.js +31 -0
  80. package/divider/Divider.js +25 -0
  81. package/divider/index.js +15 -0
  82. package/dropdown/Dropdown.js +92 -0
  83. package/dropdown/DropdownButtonOption.js +19 -0
  84. package/dropdown/DropdownContent.js +94 -0
  85. package/dropdown/DropdownContext.js +12 -0
  86. package/dropdown/DropdownDivOption.js +19 -0
  87. package/dropdown/DropdownItem.js +32 -0
  88. package/dropdown/DropdownLinkOption.js +20 -0
  89. package/dropdown/DropdownToggle.js +58 -0
  90. package/dropdown/index.js +53 -0
  91. package/dropzone/FileDropzone.js +24 -24
  92. package/dropzone/ImageDropzone.js +33 -33
  93. package/form/Label.js +1 -1
  94. package/form/Searchbox.js +4 -4
  95. package/geolocation/MapInteractor.js +41 -0
  96. package/geolocation/MapSearchBoxControl.js +100 -0
  97. package/geolocation/ReverseGeolocation.js +160 -0
  98. package/geolocation/index.js +23 -0
  99. package/grid/Column.js +33 -0
  100. package/grid/Grid.js +28 -0
  101. package/grid/index.js +23 -0
  102. package/heading/Heading1.js +22 -0
  103. package/heading/Heading2.js +25 -0
  104. package/heading/Heading3.js +7 -4
  105. package/heading/index.js +31 -0
  106. package/icon/IconFigure.js +36 -0
  107. package/icon/index.js +15 -0
  108. package/iconbox/ApplicationIconBox.js +51 -0
  109. package/iconbox/IconBox.js +56 -0
  110. package/iconbox/IconBoxFigure.js +37 -0
  111. package/iconbox/IconBoxImage.js +32 -0
  112. package/iconbox/IconBoxV2.js +42 -0
  113. package/iconbox/index.js +31 -0
  114. package/image/UploadImage.js +2 -2
  115. package/index.js +377 -0
  116. package/jsoneditor/JsonEditor.js +53 -0
  117. package/jsoneditor/index.js +15 -0
  118. package/layout/Backdrop.js +25 -0
  119. package/layout/Container.js +34 -0
  120. package/layout/Footer.js +32 -0
  121. package/layout/Logo.js +34 -0
  122. package/layout/MenuIcon.js +43 -0
  123. package/link/LinkSpan.js +57 -0
  124. package/link/index.js +15 -0
  125. package/map/CustomLeafletMapContainer.js +23 -0
  126. package/map/LeafletMap.js +224 -0
  127. package/map/index.js +23 -0
  128. package/modal/StateModal.js +2 -2
  129. package/modal/TitleModal.js +4 -4
  130. package/module/geolocation/api.js +51 -0
  131. package/module/message/index.js +59 -0
  132. package/package.json +16 -1
  133. package/paginate/Paginate.js +110 -0
  134. package/paginate/index.js +15 -0
  135. package/popover/Popover.js +122 -0
  136. package/popover/index.js +15 -0
  137. package/qrcode/QRCode.js +57 -0
  138. package/qrcode/QRCodeContainter.js +34 -0
  139. package/qrcode/index.js +23 -0
  140. package/ribbon/Ribbon.js +28 -0
  141. package/ribbon/index.js +15 -0
  142. package/section/Section.js +67 -0
  143. package/section/SectionBody.js +38 -0
  144. package/section/SectionHeader.js +42 -0
  145. package/section/SectionToolbar.js +22 -0
  146. package/section/index.js +50 -0
  147. package/select/ListBox.js +26 -0
  148. package/select/Option.js +28 -0
  149. package/select/OptionGroup.js +20 -0
  150. package/select/Options.js +25 -0
  151. package/select/SearchBox.js +52 -0
  152. package/select/Select.js +630 -0
  153. package/select/SelectedMultiple.js +34 -0
  154. package/select/SelectedSingle.js +20 -0
  155. package/select/index.js +15 -0
  156. package/services/api/index.js +73 -0
  157. package/styles/header.style.js +11 -0
  158. package/styles/sidebar.style.js +18 -0
  159. package/styles/theme/dark.theme.js +95 -0
  160. package/styles/theme/index.js +16 -0
  161. package/table/ImageBox.js +39 -0
  162. package/table/Logo.js +40 -0
  163. package/table/PermissionTable.js +42 -0
  164. package/table/Table.js +377 -0
  165. package/table/TableFooter.js +19 -0
  166. package/table/TableFooterInfo.js +19 -0
  167. package/table/TableFooterPager.js +19 -0
  168. package/table/TableHeadCell.js +39 -0
  169. package/table/TableSort.js +34 -0
  170. package/table/hooks/index.js +31 -0
  171. package/table/hooks/useLimitChange.js +34 -0
  172. package/table/hooks/usePageChange.js +33 -0
  173. package/table/hooks/useSortChange.js +35 -0
  174. package/table/index.js +31 -0
  175. package/tagify/Tags.js +55 -0
  176. package/tagify/index.js +15 -0
  177. package/text/Paragraph.js +37 -0
  178. package/text/index.js +15 -0
  179. package/timeline/Timeline.js +51 -0
  180. package/timeline/index.js +15 -0
  181. package/toast/CustomToastContainer.js +20 -0
  182. package/toast/index.js +23 -0
  183. package/tooltip/Tooltip.js +154 -0
  184. package/tooltip/index.js +15 -0
  185. package/utils/array/generateRange.js +19 -0
  186. package/utils/chart/customTooltip.js +89 -0
  187. package/utils/chart/padEmptyChartBar.js +48 -0
  188. package/utils/dataURLtoFile.js +23 -6
  189. package/utils/format/datetimeFormat.js +70 -0
  190. package/utils/format/formatDate.js +46 -0
  191. package/utils/format/formatSize.js +1 -1
  192. package/utils/getBase64.js +2 -5
  193. package/utils/hooks/useCustomPopper.js +49 -0
  194. package/utils/hooks/useForkRef.js +28 -0
  195. package/utils/hooks/usePagination.js +86 -0
  196. package/utils/image/resize.js +7 -7
  197. package/utils/react/setRef.js +17 -0
  198. package/utils/regex/check.js +13 -0
  199. package/wizard/Wizard.js +210 -0
  200. package/wizard/index.js +15 -0
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
11
+
12
+ var _go = require("react-icons/go");
13
+
14
+ var _inputPlaceholder = _interopRequireDefault(require("../styles/mixin/inputPlaceholder"));
15
+
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+
18
+ var _templateObject, _templateObject2, _templateObject3;
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
23
+
24
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
25
+
26
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
27
+
28
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
29
+
30
+ var SearchBox = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
31
+ var handleClick = function handleClick(event) {
32
+ event.stopPropagation();
33
+ };
34
+
35
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Wrapper, {
36
+ onClick: handleClick,
37
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_go.GoSearch, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(SearchInput, _objectSpread({
38
+ type: "text",
39
+ ref: ref
40
+ }, props))]
41
+ });
42
+ });
43
+
44
+ var Wrapper = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n padding: var(--spacing-xs);\n\n > svg {\n color: var(--font-on-mute);\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n left: calc(var(--spacing-s) + var(--spacing-xs));\n }\n"])));
45
+
46
+ Wrapper.displayName = 'Wrapper';
47
+
48
+ var SearchInput = _styledComponents.default.input(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n background: var(--color-background1);\n color: var(--color-white);\n border-radius: var(--border-radius-l);\n border: var(--border-width) solid var(--border-color);\n outline: none;\n width: 100%;\n padding: 10px var(--spacing-s) 10px calc(var(--spacing-s) * 2 + 8px);\n max-height: 36px;\n\n &:disabled {\n cursor: not-allowed;\n }\n\n ", "\n"])), (0, _inputPlaceholder.default)(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n color: var(--font-on-mute);\n "]))));
49
+
50
+ SearchInput.displayName = 'SearchInput';
51
+ var _default = SearchBox;
52
+ exports.default = _default;
@@ -0,0 +1,630 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _reactOutsideClickHandler = _interopRequireDefault(require("react-outside-click-handler"));
11
+
12
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
13
+
14
+ var _lodash = _interopRequireDefault(require("lodash.uniqueid"));
15
+
16
+ var _media = _interopRequireDefault(require("../styles/mixin/media"));
17
+
18
+ var _ti = require("react-icons/ti");
19
+
20
+ var _md = require("react-icons/md");
21
+
22
+ var _useCustomPopper2 = _interopRequireDefault(require("../utils/hooks/useCustomPopper"));
23
+
24
+ var _keycode = _interopRequireDefault(require("../utils/aria/keycode"));
25
+
26
+ var _SelectedSingle = _interopRequireDefault(require("./SelectedSingle"));
27
+
28
+ var _SelectedMultiple = _interopRequireDefault(require("./SelectedMultiple"));
29
+
30
+ var _ListBox = _interopRequireDefault(require("./ListBox"));
31
+
32
+ var _SearchBox = _interopRequireDefault(require("./SearchBox"));
33
+
34
+ var _Options = _interopRequireDefault(require("./Options"));
35
+
36
+ var _OptionGroup = _interopRequireDefault(require("./OptionGroup"));
37
+
38
+ var _Option = _interopRequireDefault(require("./Option"));
39
+
40
+ var _jsxRuntime = require("react/jsx-runtime");
41
+
42
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
43
+
44
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
45
+
46
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
47
+
48
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
49
+
50
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
51
+
52
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
53
+
54
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
55
+
56
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
57
+
58
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
59
+
60
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
61
+
62
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
63
+
64
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
65
+
66
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
67
+
68
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
69
+
70
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
71
+
72
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
73
+
74
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
75
+
76
+ var Select = function Select(_ref) {
77
+ var options = _ref.options,
78
+ selected = _ref.selected,
79
+ onSelect = _ref.onSelect,
80
+ onDeselect = _ref.onDeselect,
81
+ _ref$multiple = _ref.multiple,
82
+ multiple = _ref$multiple === void 0 ? false : _ref$multiple,
83
+ _ref$allowClear = _ref.allowClear,
84
+ allowClear = _ref$allowClear === void 0 ? false : _ref$allowClear,
85
+ _ref$allowSearch = _ref.allowSearch,
86
+ allowSearch = _ref$allowSearch === void 0 ? true : _ref$allowSearch,
87
+ disabled = _ref.disabled,
88
+ _ref$placeholder = _ref.placeholder,
89
+ placeholder = _ref$placeholder === void 0 ? '' : _ref$placeholder,
90
+ fullWidth = _ref.fullWidth,
91
+ large = _ref.large,
92
+ fill = _ref.fill,
93
+ fillReverse = _ref.fillReverse;
94
+
95
+ var _useState = (0, _react.useState)((0, _lodash.default)('select-')),
96
+ _useState2 = _slicedToArray(_useState, 1),
97
+ id = _useState2[0];
98
+
99
+ var _useState3 = (0, _react.useState)(false),
100
+ _useState4 = _slicedToArray(_useState3, 2),
101
+ display = _useState4[0],
102
+ setDisplay = _useState4[1];
103
+
104
+ var _useState5 = (0, _react.useState)(null),
105
+ _useState6 = _slicedToArray(_useState5, 2),
106
+ listBoxElement = _useState6[0],
107
+ setListBoxElement = _useState6[1];
108
+
109
+ var _useState7 = (0, _react.useState)(null),
110
+ _useState8 = _slicedToArray(_useState7, 2),
111
+ dropdownElement = _useState8[0],
112
+ setDropdownElement = _useState8[1];
113
+
114
+ var optionsElementRef = (0, _react.useRef)(null);
115
+ var searchBoxElement = (0, _react.useRef)(null);
116
+
117
+ var _useState9 = (0, _react.useState)(0),
118
+ _useState10 = _slicedToArray(_useState9, 2),
119
+ listBoxWidth = _useState10[0],
120
+ setListBoxWidth = _useState10[1];
121
+
122
+ var _useState11 = (0, _react.useState)([]),
123
+ _useState12 = _slicedToArray(_useState11, 2),
124
+ optionList = _useState12[0],
125
+ setOptionList = _useState12[1];
126
+
127
+ var _useState13 = (0, _react.useState)(null),
128
+ _useState14 = _slicedToArray(_useState13, 2),
129
+ focusedOption = _useState14[0],
130
+ setFocusedOption = _useState14[1];
131
+
132
+ var _useState15 = (0, _react.useState)([]),
133
+ _useState16 = _slicedToArray(_useState15, 2),
134
+ selectedOptions = _useState16[0],
135
+ setSelectedOptions = _useState16[1];
136
+
137
+ var _useState17 = (0, _react.useState)(options),
138
+ _useState18 = _slicedToArray(_useState17, 2),
139
+ filteredOptions = _useState18[0],
140
+ setFilteredOptions = _useState18[1];
141
+
142
+ var _useState19 = (0, _react.useState)(''),
143
+ _useState20 = _slicedToArray(_useState19, 2),
144
+ search = _useState20[0],
145
+ setSearch = _useState20[1];
146
+
147
+ var _useCustomPopper = (0, _useCustomPopper2.default)(listBoxElement, dropdownElement),
148
+ styles = _useCustomPopper.styles,
149
+ attributes = _useCustomPopper.attributes,
150
+ state = _useCustomPopper.state,
151
+ update = _useCustomPopper.update; // parse all value to string
152
+ // for subsequently determine whether it is a selected item
153
+
154
+
155
+ var parsedSelected = (0, _react.useMemo)(function () {
156
+ if (selected || selected === 0) {
157
+ // multiple value
158
+ if (Array.isArray(selected) && selected.length > 0) {
159
+ return selected.map(function (value) {
160
+ return value.toString();
161
+ });
162
+ } // single value
163
+
164
+
165
+ return selected.toString();
166
+ }
167
+ }, [selected]); // set focused option
168
+
169
+ var handleFocusItem = (0, _react.useCallback)(function (element) {
170
+ if (!optionsElementRef.current) return;
171
+ setFocusedOption(element);
172
+ var container = optionsElementRef.current;
173
+
174
+ if (container.scrollHeight > container.clientHeight) {
175
+ var scrollBottom = container.clientHeight + container.scrollTop;
176
+ var elementBottom = element.offsetTop + element.offsetHeight;
177
+
178
+ if (elementBottom > scrollBottom) {
179
+ container.scrollTop = elementBottom - container.clientHeight;
180
+ } else if (element.offsetTop < container.scrollTop) {
181
+ container.scrollTop = element.offsetTop;
182
+ }
183
+ }
184
+ }, []);
185
+ var focusFirstItem = (0, _react.useCallback)(function () {
186
+ var firstItem = dropdownElement.querySelector('[role="option"]');
187
+
188
+ if (firstItem) {
189
+ handleFocusItem(firstItem);
190
+ }
191
+ }, [dropdownElement, handleFocusItem]);
192
+ var setupFocus = (0, _react.useCallback)(function () {
193
+ if (!dropdownElement) return;
194
+ var selectedItem = dropdownElement.querySelector('[aria-selected="true"]');
195
+
196
+ if (selectedItem) {
197
+ handleFocusItem(selectedItem);
198
+ } else if (optionList.length > 0) {
199
+ focusFirstItem();
200
+ } else {
201
+ setFocusedOption(null);
202
+ }
203
+ }, [dropdownElement, handleFocusItem, focusFirstItem, optionList]);
204
+ var findPreviousItem = (0, _react.useCallback)(function (currentItem) {
205
+ var allItem = _toConsumableArray(dropdownElement.querySelectorAll('[role="option"]'));
206
+
207
+ var currentItemIndex = allItem.indexOf(currentItem);
208
+ var previousItem = null;
209
+
210
+ if (currentItemIndex !== -1 && currentItemIndex > 0) {
211
+ previousItem = allItem[currentItemIndex - 1];
212
+ }
213
+
214
+ return previousItem;
215
+ }, [dropdownElement]);
216
+ var findNextItem = (0, _react.useCallback)(function (currentItem) {
217
+ var allItem = _toConsumableArray(dropdownElement.querySelectorAll('[role="option"]'));
218
+
219
+ var currentItemIndex = allItem.indexOf(currentItem);
220
+ var nextItem = null;
221
+
222
+ if (currentItemIndex !== -1 && currentItemIndex < allItem.length - 1) {
223
+ nextItem = allItem[currentItemIndex + 1];
224
+ }
225
+
226
+ return nextItem;
227
+ }, [dropdownElement]);
228
+ var handleOnSelect = (0, _react.useCallback)(function (event, value) {
229
+ event.stopPropagation();
230
+ if (disabled === true) return;
231
+ onSelect(value);
232
+ setSearch('');
233
+ setDisplay(false);
234
+ }, [disabled, onSelect]);
235
+ var handleOnDeselect = (0, _react.useCallback)(function (event, value) {
236
+ event.stopPropagation();
237
+ if (disabled === true) return;
238
+ onDeselect(value);
239
+ }, [disabled, onDeselect]); // list all selected option
240
+
241
+ var selectedItem = (0, _react.useMemo)(function () {
242
+ if (selectedOptions.length > 0) {
243
+ if (multiple) {
244
+ return selectedOptions.map(function (value) {
245
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectedMultiple.default, {
246
+ content: value.text,
247
+ onClick: function onClick(event) {
248
+ return handleOnDeselect(event, value.id);
249
+ }
250
+ }, value.id);
251
+ });
252
+ }
253
+
254
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectedSingle.default, {
255
+ children: selectedOptions[0].text
256
+ });
257
+ }
258
+
259
+ return placeholder;
260
+ }, [placeholder, handleOnDeselect, multiple, selectedOptions]);
261
+ var optionItem = (0, _react.useMemo)(function () {
262
+ if (optionList.length <= 0) return null;
263
+ return optionList.map(function (option) {
264
+ if (option.child && option.child.length > 0) {
265
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_OptionGroup.default, {
266
+ "aria-labelledby": option.text,
267
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Option.default, {
268
+ role: "presentation",
269
+ id: option.text,
270
+ children: option.text
271
+ }), option.child.map(function (option) {
272
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Option.default, {
273
+ role: "option",
274
+ tabIndex: "0",
275
+ id: option.id,
276
+ onClick: function onClick(event) {
277
+ return handleOnSelect(event, option.id);
278
+ },
279
+ focus: focusedOption && focusedOption.id === option.id.toString(),
280
+ selected: option.selected,
281
+ "aria-selected": option.selected,
282
+ children: option.text
283
+ }, option.id);
284
+ })]
285
+ }, option.text);
286
+ }
287
+
288
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Option.default, {
289
+ role: "option",
290
+ tabIndex: "0",
291
+ id: option.id,
292
+ onClick: function onClick(event) {
293
+ return handleOnSelect(event, option.id);
294
+ },
295
+ focus: focusedOption && focusedOption.id === option.id.toString(),
296
+ selected: option.selected,
297
+ "aria-selected": option.selected,
298
+ children: option.text
299
+ }, option.id);
300
+ });
301
+ }, [optionList, focusedOption, handleOnSelect]); // show or hide dropdown
302
+ // and set dropdown width according to listbox current width
303
+
304
+ var handleToggle = function handleToggle() {
305
+ if (disabled === true) return;
306
+ var tmpDisplay = !display;
307
+
308
+ if (!tmpDisplay) {
309
+ setFocusedOption(null);
310
+ }
311
+
312
+ setDisplay(tmpDisplay);
313
+ update();
314
+ }; // handle keyboard interaction
315
+
316
+
317
+ var handleKeyUp = function handleKeyUp(event) {
318
+ var key = event.keyCode;
319
+
320
+ switch (key) {
321
+ case _keycode.default.ENTER:
322
+ if (!display) {
323
+ handleToggle();
324
+ } else if (focusedOption) {
325
+ handleOnSelect(event, focusedOption.id);
326
+ }
327
+
328
+ break;
329
+
330
+ case _keycode.default.ESCAPE:
331
+ if (display) {
332
+ handleToggle();
333
+ }
334
+
335
+ break;
336
+
337
+ case _keycode.default.UP:
338
+ {
339
+ if (!focusedOption) {
340
+ return;
341
+ }
342
+
343
+ var previousItem = findPreviousItem(focusedOption);
344
+
345
+ if (previousItem) {
346
+ handleFocusItem(previousItem);
347
+ }
348
+
349
+ break;
350
+ }
351
+
352
+ case _keycode.default.DOWN:
353
+ {
354
+ if (!focusedOption) {
355
+ return;
356
+ }
357
+
358
+ var nextItem = findNextItem(focusedOption);
359
+
360
+ if (nextItem) {
361
+ handleFocusItem(nextItem);
362
+ }
363
+
364
+ break;
365
+ }
366
+
367
+ case _keycode.default.END:
368
+ {
369
+ event.preventDefault();
370
+ var itemList = dropdownElement.querySelectorAll('[role="option"]');
371
+
372
+ if (itemList.length) {
373
+ handleFocusItem(itemList[itemList.length - 1]);
374
+ }
375
+
376
+ break;
377
+ }
378
+
379
+ case _keycode.default.HOME:
380
+ event.preventDefault();
381
+ focusFirstItem();
382
+ break;
383
+
384
+ default:
385
+ break;
386
+ }
387
+ };
388
+
389
+ var handleKeyDown = function handleKeyDown(event) {
390
+ var key = event.keyCode;
391
+
392
+ switch (key) {
393
+ case _keycode.default.ENTER:
394
+ case _keycode.default.ESCAPE:
395
+ case _keycode.default.UP:
396
+ case _keycode.default.DOWN:
397
+ case _keycode.default.END:
398
+ case _keycode.default.HOME:
399
+ event.preventDefault();
400
+ break;
401
+
402
+ default:
403
+ break;
404
+ }
405
+ }; // handle search keyword change
406
+
407
+
408
+ var handleSearchChange = function handleSearchChange(event) {
409
+ setSearch(event.target.value);
410
+ }; // determine selected option(s)
411
+
412
+
413
+ (0, _react.useEffect)(function () {
414
+ if (!options) return;
415
+ var tmpSelectedOptions = [];
416
+ options.forEach(function (option) {
417
+ if (option.child && option.child.length > 0) {
418
+ option.child.forEach(function (option) {
419
+ if (multiple && parsedSelected.includes(option.id.toString())) {
420
+ tmpSelectedOptions.push(option);
421
+ } else if (parsedSelected === option.id.toString()) {
422
+ tmpSelectedOptions.push(option);
423
+ }
424
+ });
425
+ } else {
426
+ if (multiple && parsedSelected.includes(option.id.toString())) {
427
+ tmpSelectedOptions.push(option);
428
+ } else if (parsedSelected === option.id.toString()) {
429
+ tmpSelectedOptions.push(option);
430
+ }
431
+ }
432
+
433
+ return false;
434
+ });
435
+ setSelectedOptions(tmpSelectedOptions);
436
+ }, [options, parsedSelected, multiple]);
437
+ (0, _react.useEffect)(function () {
438
+ if (update) {
439
+ setTimeout(function () {
440
+ update();
441
+ }, 100);
442
+ }
443
+ }, [update, listBoxWidth]); // observe element resized
444
+
445
+ (0, _react.useEffect)(function () {
446
+ if (!listBoxElement) return;
447
+ var resizeObserverInstance = new ResizeObserver(function (entries) {
448
+ var _iterator = _createForOfIteratorHelper(entries),
449
+ _step;
450
+
451
+ try {
452
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
453
+ var entry = _step.value;
454
+
455
+ if (entry.target) {
456
+ var borderBoxSize = entry.target.clientWidth;
457
+ setListBoxWidth(borderBoxSize);
458
+ }
459
+ }
460
+ } catch (err) {
461
+ _iterator.e(err);
462
+ } finally {
463
+ _iterator.f();
464
+ }
465
+ });
466
+ resizeObserverInstance.observe(listBoxElement);
467
+ return function () {
468
+ // unobserve element
469
+ resizeObserverInstance.unobserve(listBoxElement);
470
+ };
471
+ }, [listBoxElement]); // re-setup focus when option list changed and update popper position
472
+
473
+ (0, _react.useEffect)(function () {
474
+ setupFocus();
475
+ if (update) update();
476
+ }, [setupFocus, optionList, update]); // parse option list when filtered options change
477
+
478
+ (0, _react.useEffect)(function () {
479
+ if (!filteredOptions) return;
480
+ setOptionList(filteredOptions.map(function (option) {
481
+ if (option.child && option.child.length > 0) {
482
+ return _objectSpread(_objectSpread({}, option), {}, {
483
+ child: option.child.map(function (option) {
484
+ var selected = false;
485
+
486
+ if (multiple && parsedSelected.includes(option.id.toString())) {
487
+ selected = true;
488
+ } else if (parsedSelected === option.id.toString()) {
489
+ selected = true;
490
+ }
491
+
492
+ return _objectSpread(_objectSpread({}, option), {}, {
493
+ selected: selected
494
+ });
495
+ })
496
+ });
497
+ }
498
+
499
+ var selected = false;
500
+
501
+ if (multiple && parsedSelected.includes(option.id.toString())) {
502
+ selected = true;
503
+ } else if (parsedSelected === option.id.toString()) {
504
+ selected = true;
505
+ }
506
+
507
+ return _objectSpread(_objectSpread({}, option), {}, {
508
+ selected: selected
509
+ });
510
+ }));
511
+ }, [filteredOptions, multiple, parsedSelected]); // filter options on search keyword changed
512
+
513
+ (0, _react.useEffect)(function () {
514
+ var tmpFilteredOptions = [];
515
+ options.forEach(function (option) {
516
+ if (option.child && option.child.length > 0) {
517
+ var tmpFilteredChildOptions = option.child.filter(function (option) {
518
+ return option.text.toLowerCase().indexOf(search.toLowerCase()) !== -1;
519
+ });
520
+
521
+ if (tmpFilteredChildOptions.length > 0) {
522
+ tmpFilteredOptions.push(_objectSpread(_objectSpread({}, option), {}, {
523
+ child: tmpFilteredChildOptions
524
+ }));
525
+ }
526
+ } else if (option.text.toLowerCase().indexOf(search.toLowerCase()) !== -1) {
527
+ tmpFilteredOptions.push(option);
528
+ }
529
+ });
530
+ setFilteredOptions(tmpFilteredOptions);
531
+ }, [search, options]);
532
+ (0, _react.useEffect)(function () {
533
+ if (display) {
534
+ setupFocus();
535
+
536
+ if (allowSearch) {
537
+ searchBoxElement.current.focus();
538
+ }
539
+ }
540
+ }, [setupFocus, display, allowSearch]);
541
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactOutsideClickHandler.default, {
542
+ onOutsideClick: function onOutsideClick() {
543
+ setDisplay(false);
544
+ },
545
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Combobox, {
546
+ role: "combobox",
547
+ tabIndex: "0",
548
+ "aria-haspopup": "listbox",
549
+ "aria-expanded": display,
550
+ "aria-owns": id,
551
+ ref: setListBoxElement,
552
+ onClick: handleToggle,
553
+ onKeyUp: handleKeyUp,
554
+ onKeyDown: handleKeyDown,
555
+ $display: display,
556
+ disabled: disabled,
557
+ fullWidth: fullWidth,
558
+ large: large,
559
+ $fill: fill,
560
+ fillReverse: fillReverse,
561
+ children: [selectedItem, selectedOptions.length > 0 && !multiple && !disabled && allowClear && /*#__PURE__*/(0, _jsxRuntime.jsx)(CloseButton, {
562
+ onClick: function onClick() {
563
+ onSelect('');
564
+ }
565
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(ExpandArrow, {
566
+ "aria-haspopup": "listbox",
567
+ "aria-expanded": display
568
+ })]
569
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ListBox.default, _objectSpread(_objectSpread({
570
+ role: "listbox",
571
+ tabIndex: "0",
572
+ id: id,
573
+ ref: setDropdownElement,
574
+ onKeyUp: handleKeyUp,
575
+ onKeyDown: handleKeyDown,
576
+ width: listBoxWidth,
577
+ $display: display,
578
+ style: styles.popper
579
+ }, attributes.popper), {}, {
580
+ placement: state && state.placement,
581
+ children: [allowSearch && /*#__PURE__*/(0, _jsxRuntime.jsx)(_SearchBox.default, {
582
+ ref: searchBoxElement,
583
+ placeholder: "Search",
584
+ onChange: handleSearchChange,
585
+ value: search
586
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Options.default, {
587
+ ref: optionsElementRef,
588
+ allowSearch: allowSearch,
589
+ children: optionItem || /*#__PURE__*/(0, _jsxRuntime.jsx)(Message, {
590
+ children: "No results found"
591
+ })
592
+ })]
593
+ }))]
594
+ });
595
+ };
596
+
597
+ var Combobox = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n min-height: 36px;\n min-width: 160px;\n cursor: pointer;\n position: relative;\n background: transparent;\n color: var(--color-white);\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"])), function (_ref2) {
598
+ var disabled = _ref2.disabled;
599
+ return !disabled && "\n border-color: var(--color-primary);\n outline: none;\n ";
600
+ }, function (_ref3) {
601
+ var $display = _ref3.$display;
602
+ return $display && "\n border-color: var(--color-primary);\n outline: none;\n ";
603
+ }, function (_ref4) {
604
+ var disabled = _ref4.disabled;
605
+ return disabled && 'cursor: not-allowed;opacity: 0.5;';
606
+ }, function (_ref5) {
607
+ var fullWidth = _ref5.fullWidth;
608
+ return fullWidth ? 'width: 100%' : 'max-width: 320px';
609
+ }, function (_ref6) {
610
+ var large = _ref6.large;
611
+ return large && "\n height: 40px;\n padding: 12px calc(var(--spacing-s) * 2 + 8px) 12px var(--spacing-s);\n ";
612
+ }, function (_ref7) {
613
+ var $fill = _ref7.$fill;
614
+ return $fill && "\n background: var(--color-background2);\n border-color: transparent;\n ";
615
+ }, function (_ref8) {
616
+ var fillReverse = _ref8.fillReverse;
617
+ return fillReverse && "\n background: var(--color-background1);\n border-color: transparent;\n ";
618
+ });
619
+
620
+ Combobox.displayName = 'Combobox';
621
+ var CloseButton = (0, _styledComponents.default)(_md.MdClose)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n color: var(--color-primary);\n font-size: var(--font-body1);\n right: var(--spacing-l);\n\n ", ";\n"])), _media.default.tablet(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n right: calc(var(--spacing) + var(--spacing-s));\n "]))));
622
+ CloseButton.displayName = 'CloseButton';
623
+ var ExpandArrow = (0, _styledComponents.default)(_ti.TiArrowSortedDown)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n color: var(--color-primary);\n font-size: var(--font-body1);\n right: var(--spacing-s);\n"])));
624
+ ExpandArrow.displayName = 'ExpandArrow';
625
+
626
+ var Message = _styledComponents.default.p(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n margin: 0;\n padding: 12px var(--spacing-s);\n"])));
627
+
628
+ Message.displayName = 'Message';
629
+ var _default = Select;
630
+ exports.default = _default;