@geneui/components 3.0.0-next-9ffcb93-16102024 → 3.0.0-next-48d0ef7-31102024

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 (248) hide show
  1. package/Avatar.js +63 -0
  2. package/CHANGELOG.md +7 -0
  3. package/Divider.js +23 -0
  4. package/{GeneUIProvider/index.js → GeneUIProvider.js} +52 -65
  5. package/HelperText.js +69 -0
  6. package/Info.js +64 -0
  7. package/Label.js +38 -0
  8. package/Loader.js +21 -0
  9. package/Pill.js +64 -0
  10. package/TextLink.js +20 -0
  11. package/{index-65217440.js → Tooltip.js} +104 -80
  12. package/{lib → components}/atoms/Avatar/Avatar.d.ts +7 -6
  13. package/components/atoms/Avatar/index.d.ts +1 -0
  14. package/{lib → components}/atoms/Divider/Divider.d.ts +5 -5
  15. package/components/atoms/Divider/index.d.ts +1 -0
  16. package/{lib → components}/atoms/HelperText/HelperText.d.ts +6 -5
  17. package/components/atoms/HelperText/index.d.ts +1 -0
  18. package/{lib → components}/atoms/Info/Info.d.ts +5 -5
  19. package/components/atoms/Info/index.d.ts +1 -0
  20. package/{lib → components}/atoms/Label/Label.d.ts +3 -3
  21. package/components/atoms/Label/index.d.ts +1 -0
  22. package/{lib → components}/atoms/Loader/Loader.d.ts +5 -5
  23. package/components/atoms/Loader/index.d.ts +1 -0
  24. package/{lib → components}/atoms/Pill/Pill.d.ts +7 -6
  25. package/components/atoms/Pill/index.d.ts +1 -0
  26. package/{lib → components}/atoms/TextLink/TextLink.d.ts +5 -5
  27. package/components/atoms/TextLink/index.d.ts +1 -0
  28. package/{lib → components}/molecules/Tooltip/Tooltip.d.ts +26 -21
  29. package/components/molecules/Tooltip/index.d.ts +1 -0
  30. package/components/providers/GeneUIProvider/GeneUIProvider.d.ts +30 -0
  31. package/components/providers/GeneUIProvider/index.d.ts +1 -0
  32. package/hooks/index.d.ts +2 -20
  33. package/hooks/useDebounceCallback/index.d.ts +1 -0
  34. package/hooks/useDebounceCallback/useDebounceCallback.d.ts +2 -0
  35. package/hooks/useEllipsisDetection/index.d.ts +1 -1
  36. package/hooks/useEllipsisDetection/useEllipsisDetection.d.ts +2 -2
  37. package/{index-031ff73c.js → index-ce02421b.js} +4 -4
  38. package/index.d.ts +11 -121
  39. package/index.js +12 -159
  40. package/package.json +24 -43
  41. package/tokens-0abb4e1b.js +6 -0
  42. package/types/index.d.ts +0 -3
  43. package/useEllipsisDetection-46d712b6.js +34 -0
  44. package/ActionableList/index.js +0 -1694
  45. package/AdvancedSearch/index.js +0 -892
  46. package/Alert/index.js +0 -98
  47. package/Avatar/index.js +0 -58
  48. package/Badge/index.js +0 -29
  49. package/Breadcrumb/index.js +0 -130
  50. package/BusyLoader/index.js +0 -31
  51. package/Button/index.js +0 -30
  52. package/Card/index.js +0 -502
  53. package/CardList/index.js +0 -662
  54. package/CellMeasurerCache-80be385d.js +0 -229
  55. package/Charts/index.js +0 -17662
  56. package/Checkbox/index.js +0 -229
  57. package/CheckboxGroup/index.js +0 -203
  58. package/CheckboxGroupWithSearch/index.js +0 -280
  59. package/Collapse/index.js +0 -195
  60. package/ColorPicker/index.js +0 -210
  61. package/ComboBox/index.js +0 -524
  62. package/Copy/index.js +0 -56
  63. package/Counter/index.js +0 -312
  64. package/DateFilter/index.js +0 -183
  65. package/DatePicker/index.js +0 -1229
  66. package/DatePickerInput/index.js +0 -883
  67. package/Divider/index.js +0 -23
  68. package/Drawer/index.js +0 -261
  69. package/Dropdown/index.js +0 -43
  70. package/Editor/index.js +0 -22975
  71. package/Empty/index.js +0 -76
  72. package/ExtendedInput/index.js +0 -590
  73. package/Form/index.js +0 -85
  74. package/FormContainer/index.js +0 -189
  75. package/FormableCheckbox/index.js +0 -24
  76. package/FormableDatePicker/index.js +0 -43
  77. package/FormableDropdown/index.js +0 -50
  78. package/FormableEditor/index.js +0 -26
  79. package/FormableHOC-85f89a81.js +0 -83
  80. package/FormableMultiSelectDropdown/index.js +0 -50
  81. package/FormableNumberInput/index.js +0 -34
  82. package/FormableRadio/index.js +0 -22
  83. package/FormableSwitcher/index.js +0 -22
  84. package/FormableTextInput/index.js +0 -34
  85. package/FormableUploader/index.js +0 -44
  86. package/Grid/index.js +0 -167
  87. package/HelperText/index.js +0 -86
  88. package/Holder/index.js +0 -261
  89. package/Icon/index.js +0 -62
  90. package/Image/index.js +0 -45
  91. package/ImagePreview/index.js +0 -217
  92. package/Info/index.js +0 -41
  93. package/InfoOutline-dd2e89d9.js +0 -29
  94. package/InteractiveWidget/index.js +0 -78
  95. package/KeyValue/index.js +0 -22
  96. package/Label/index.js +0 -48
  97. package/LinkButton/index.js +0 -34
  98. package/Loader/index.js +0 -23
  99. package/Menu/index.js +0 -281
  100. package/MobileNavigation/index.js +0 -94
  101. package/MobilePopup/index.js +0 -182
  102. package/Modal/index.js +0 -251
  103. package/ModuleTitle/index.js +0 -141
  104. package/NavigationMenu/index.js +0 -222
  105. package/Notification/index.js +0 -120
  106. package/Option/index.js +0 -184
  107. package/Overlay/index.js +0 -187
  108. package/Overspread/index.js +0 -291
  109. package/Pagination/index.js +0 -261
  110. package/Paper/index.js +0 -96
  111. package/Pill/index.js +0 -67
  112. package/Popover/index.js +0 -725
  113. package/PopoverV2/index.js +0 -19
  114. package/Portal/index.js +0 -58
  115. package/Products/index.js +0 -115
  116. package/Profile/index.js +0 -589
  117. package/Progress/index.js +0 -200
  118. package/QRCode/index.js +0 -814
  119. package/Radio/index.js +0 -151
  120. package/RadioGroup/index.js +0 -104
  121. package/Range/index.js +0 -191
  122. package/Rating/index.js +0 -174
  123. package/RichEditor/index.js +0 -13
  124. package/RichEditor-78c2617e.js +0 -228
  125. package/Scrollbar/index.js +0 -1585
  126. package/Search/index.js +0 -75
  127. package/SearchWithDropdown/index.js +0 -140
  128. package/Section/index.js +0 -61
  129. package/SkeletonLoader/index.js +0 -81
  130. package/Slider/index.js +0 -261
  131. package/Status/index.js +0 -97
  132. package/Steps/index.js +0 -314
  133. package/SuggestionList/index.js +0 -385
  134. package/Switcher/index.js +0 -193
  135. package/Table/index.js +0 -57
  136. package/TableCompositions/index.js +0 -16995
  137. package/Tabs/index.js +0 -235
  138. package/Tag/index.js +0 -102
  139. package/TextLink/index.js +0 -20
  140. package/Textarea/index.js +0 -242
  141. package/Time/index.js +0 -62
  142. package/TimePicker/index.js +0 -575
  143. package/Timeline/index.js +0 -113
  144. package/Title/index.js +0 -65
  145. package/Toaster/index.js +0 -116
  146. package/Tooltip/index.js +0 -6
  147. package/TransferList/index.js +0 -493
  148. package/Uploader/index.js +0 -992
  149. package/ValidatableCheckbox/index.js +0 -123
  150. package/ValidatableDatePicker/index.js +0 -316
  151. package/ValidatableDropdown/index.js +0 -141
  152. package/ValidatableElements/index.js +0 -67
  153. package/ValidatableMultiSelectDropdown/index.js +0 -152
  154. package/ValidatableNumberInput/index.js +0 -204
  155. package/ValidatableRadio/index.js +0 -116
  156. package/ValidatableSwitcher/index.js +0 -93
  157. package/ValidatableTextInput/index.js +0 -167
  158. package/ValidatableTimeInput/index.js +0 -174
  159. package/ValidatableUploader/index.js +0 -98
  160. package/Widget/index.js +0 -225
  161. package/_commonjsHelpers-24198af3.js +0 -35
  162. package/_rollupPluginBabelHelpers-a83240e1.js +0 -11
  163. package/callAfterDelay-7272faca.js +0 -12
  164. package/checkTimeValidation-e56771be.js +0 -16
  165. package/checkboxRadioSwitcher-5b69d7bd.js +0 -4
  166. package/clsx.m-2bb6df4b.js +0 -3
  167. package/config-1053d64d.js +0 -20
  168. package/configs-00612ce0.js +0 -103
  169. package/configs.js +0 -111
  170. package/dateValidation-67caec66.js +0 -225
  171. package/debounce-4419bc2f.js +0 -17
  172. package/guid-8ddf77b3.js +0 -16
  173. package/hooks/useBodyScroll.js +0 -16
  174. package/hooks/useClick.js +0 -18
  175. package/hooks/useClickOutside.js +0 -25
  176. package/hooks/useDebounce.js +0 -28
  177. package/hooks/useDeviceType.js +0 -17
  178. package/hooks/useDidMount.js +0 -15
  179. package/hooks/useForceUpdate.js +0 -8
  180. package/hooks/useHover.js +0 -20
  181. package/hooks/useImgDownload.js +0 -18
  182. package/hooks/useKeyDown.js +0 -21
  183. package/hooks/useMount.js +0 -13
  184. package/hooks/useMutationObserver.js +0 -21
  185. package/hooks/usePrevious.js +0 -10
  186. package/hooks/useThrottle.js +0 -16
  187. package/hooks/useToggle.js +0 -11
  188. package/hooks/useUpdatableRef.js +0 -14
  189. package/hooks/useUpdate.js +0 -10
  190. package/hooks/useWidth.js +0 -16
  191. package/hooks/useWindowSize.js +0 -40
  192. package/index-122432cd.js +0 -270
  193. package/index-262edd7a.js +0 -77
  194. package/index-2f5aa51e.js +0 -6483
  195. package/index-370f9acd.js +0 -4
  196. package/index-45eafea6.js +0 -90
  197. package/index-480fd7d9.js +0 -10032
  198. package/index-5f37f281.js +0 -168
  199. package/index-73aaa093.js +0 -1940
  200. package/index.mobile.d.ts +0 -14
  201. package/lib/atoms/Avatar/index.d.ts +0 -1
  202. package/lib/atoms/Badge/Badge.d.ts +0 -36
  203. package/lib/atoms/Badge/index.d.ts +0 -1
  204. package/lib/atoms/BusyLoader/BusyLoader.d.ts +0 -32
  205. package/lib/atoms/BusyLoader/BusyLoaderHolderHOC.d.ts +0 -8
  206. package/lib/atoms/BusyLoader/index.d.ts +0 -1
  207. package/lib/atoms/Button/Button.d.ts +0 -70
  208. package/lib/atoms/Button/index.d.ts +0 -1
  209. package/lib/atoms/Divider/index.d.ts +0 -1
  210. package/lib/atoms/Empty/Empty.d.ts +0 -39
  211. package/lib/atoms/Empty/index.d.ts +0 -1
  212. package/lib/atoms/Empty/utils.d.ts +0 -9
  213. package/lib/atoms/HelperText/index.d.ts +0 -1
  214. package/lib/atoms/Image/Image.d.ts +0 -51
  215. package/lib/atoms/Image/index.d.ts +0 -1
  216. package/lib/atoms/ImagePreview/ImagePreview.d.ts +0 -56
  217. package/lib/atoms/ImagePreview/ImagePreviewHOC.d.ts +0 -4
  218. package/lib/atoms/ImagePreview/Magnifier.d.ts +0 -40
  219. package/lib/atoms/ImagePreview/index.d.ts +0 -1
  220. package/lib/atoms/Info/index.d.ts +0 -1
  221. package/lib/atoms/KeyValue/KeyValue.d.ts +0 -29
  222. package/lib/atoms/KeyValue/index.d.ts +0 -1
  223. package/lib/atoms/Label/index.d.ts +0 -1
  224. package/lib/atoms/LinkButton/LinkButton.d.ts +0 -46
  225. package/lib/atoms/LinkButton/index.d.ts +0 -1
  226. package/lib/atoms/Loader/index.d.ts +0 -1
  227. package/lib/atoms/Pill/index.d.ts +0 -1
  228. package/lib/atoms/Rating/DefaultSvg.d.ts +0 -3
  229. package/lib/atoms/Rating/Rating.d.ts +0 -49
  230. package/lib/atoms/Rating/index.d.ts +0 -1
  231. package/lib/atoms/TextLink/index.d.ts +0 -1
  232. package/lib/molecules/Copy/Copy.d.ts +0 -38
  233. package/lib/molecules/Copy/index.d.ts +0 -1
  234. package/lib/molecules/InteractiveWidget/InteractiveWidget.d.ts +0 -70
  235. package/lib/molecules/InteractiveWidget/InteractiveWidgetIcon.d.ts +0 -8
  236. package/lib/molecules/InteractiveWidget/index.d.ts +0 -1
  237. package/lib/molecules/Tooltip/index.d.ts +0 -1
  238. package/lib/providers/GeneUIProvider/GeneUIProvider.d.ts +0 -30
  239. package/lib/providers/GeneUIProvider/index.d.ts +0 -1
  240. package/localization-4ba17032.js +0 -46
  241. package/objectWithoutPropertiesLoose-e1596bdb.js +0 -62
  242. package/rangeAndSlider-693a3d41.js +0 -8684
  243. package/react-beautiful-dnd.esm-b637016a.js +0 -10116
  244. package/react-lifecycles-compat.es-6e1f3768.js +0 -158
  245. package/redux-e591c1b8.js +0 -536
  246. package/tokens-8ab1179c.js +0 -6
  247. package/tslib.es6-f211516f.js +0 -35
  248. package/useEllipsisDetection-c1c9ad94.js +0 -38
package/Time/index.js DELETED
@@ -1,62 +0,0 @@
1
- import { _ as _extends } from '../_rollupPluginBabelHelpers-a83240e1.js';
2
- import React__default, { useMemo, useState, useEffect } from 'react';
3
- import PropTypes from 'prop-types';
4
- import { a as dayjs, d as dayjsWithPlugins } from '../dateValidation-67caec66.js';
5
- import { a as getBrowserTimeFormat } from '../localization-4ba17032.js';
6
- import 'react-dom';
7
- import Icon from '../Icon/index.js';
8
- import { s as styleInject } from '../style-inject.es-746bb8ed.js';
9
- import '../_commonjsHelpers-24198af3.js';
10
- import '../index-031ff73c.js';
11
-
12
- var css_248z = "[data-gene-ui-version=\"2.16.3\"] .time-holder{align-items:center;display:flex;font-weight:600;line-height:3.2rem;white-space:nowrap}[data-gene-ui-version=\"2.16.3\"] .time-holder>*+*{margin:0 0 0 .3rem}html[dir=rtl] .time-holder>*+*{margin:0 .3rem 0 0}";
13
- styleInject(css_248z);
14
-
15
- function Time(_ref) {
16
- let {
17
- format,
18
- showIcon,
19
- startDate,
20
- showSeconds,
21
- ...restProps
22
- } = _ref;
23
- const startDateValue = useMemo(() => startDate && dayjs(startDate), [startDate]);
24
- const difference = useMemo(() => startDateValue ? startDateValue.diff(dayjs()) : 0, [startDateValue]);
25
- const [time, setTime] = useState(() => Date.now() + difference);
26
- const timeFormat = format || getBrowserTimeFormat(showSeconds);
27
- useEffect(() => {
28
- const intervalId = setInterval(() => {
29
- setTime(Date.now() + difference);
30
- }, 1000);
31
- return () => clearInterval(intervalId);
32
- }, [difference]);
33
- return /*#__PURE__*/React__default.createElement("div", _extends({
34
- className: "time-holder"
35
- }, restProps), showIcon && /*#__PURE__*/React__default.createElement(Icon, {
36
- type: "bc-icon-clock"
37
- }), /*#__PURE__*/React__default.createElement("p", null, dayjsWithPlugins(time).format(timeFormat)));
38
- }
39
- Time.propTypes = {
40
- /**
41
- * Displays a clock icon when set to "true"
42
- */
43
- showIcon: PropTypes.bool,
44
- /**
45
- * Display format
46
- */
47
- format: PropTypes.string,
48
- /**
49
- * Display seconds when set to "true"
50
- */
51
- showSeconds: PropTypes.bool,
52
- /**
53
- * Specifing this prop will make the Time atom a counter starting from "startDate"
54
- */
55
- startDate: PropTypes.oneOfType([PropTypes.instanceOf(dayjs), PropTypes.instanceOf(Date), PropTypes.string, PropTypes.number])
56
- };
57
- Time.defaultProps = {
58
- showIcon: false,
59
- showSeconds: true
60
- };
61
-
62
- export { Time as default };
@@ -1,575 +0,0 @@
1
- import { _ as _extends } from '../_rollupPluginBabelHelpers-a83240e1.js';
2
- import React__default, { forwardRef, useRef, useState, useImperativeHandle, useEffect, useMemo, useCallback } from 'react';
3
- import PropTypes from 'prop-types';
4
- import { c as classnames } from '../index-031ff73c.js';
5
- import { f as timePickerConfig, s as screenTypes } from '../configs-00612ce0.js';
6
- import { n as noop } from '../index-5f37f281.js';
7
- import useDeviceType from '../hooks/useDeviceType.js';
8
- import CustomScrollbar from '../Scrollbar/index.js';
9
- import Icon from '../Icon/index.js';
10
- import ExtendedInput from '../ExtendedInput/index.js';
11
- import NumberInput from '../ValidatableNumberInput/index.js';
12
- import '../dateValidation-67caec66.js';
13
- import 'react-dom';
14
- import useKeyDown from '../hooks/useKeyDown.js';
15
- import useClickOutside from '../hooks/useClickOutside.js';
16
- import { P as PopoverV2 } from '../index-73aaa093.js';
17
- import { s as styleInject } from '../style-inject.es-746bb8ed.js';
18
- import '../hooks/useWindowSize.js';
19
- import '../hooks/useDebounce.js';
20
- import '../_commonjsHelpers-24198af3.js';
21
- import '../useEllipsisDetection-c1c9ad94.js';
22
- import '../SuggestionList/index.js';
23
- import '../config-1053d64d.js';
24
- import '../callAfterDelay-7272faca.js';
25
- import '../index-65217440.js';
26
- import '../tslib.es6-f211516f.js';
27
- import '../GeneUIProvider/index.js';
28
- import '../hooks/useMount.js';
29
- import '../index-122432cd.js';
30
- import '../debounce-4419bc2f.js';
31
-
32
- const TimePickerPopover = /*#__PURE__*/forwardRef((_ref, ref) => {
33
- let {
34
- children,
35
- readOnly,
36
- value,
37
- positions,
38
- ...props
39
- } = _ref;
40
- const rootRef = useRef(null);
41
- const [isOpen, setIsOpen] = useState(false);
42
- useImperativeHandle(ref, () => ({
43
- toggleOpen() {
44
- let isPopoverOpen = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : isOpen;
45
- setIsOpen(!isPopoverOpen);
46
- }
47
- }));
48
- const openPopover = () => !readOnly && !isOpen && setIsOpen(true);
49
- const closePopover = () => setIsOpen(false);
50
- useKeyDown(openPopover, [openPopover], rootRef, ['Enter']);
51
- useKeyDown(closePopover, [closePopover], rootRef, ['Tab', 'Escape']);
52
- const handleOutsideClick = useClickOutside(event => {
53
- !rootRef.current.contains(event.target) && closePopover();
54
- });
55
- useEffect(() => {
56
- setIsOpen(false);
57
- }, [value]);
58
- return /*#__PURE__*/React__default.createElement(PopoverV2, _extends({
59
- behave: "open",
60
- scrollbarNeeded: false,
61
- contentRef: handleOutsideClick,
62
- isOpen: isOpen,
63
- position: positions
64
- }, props), /*#__PURE__*/React__default.createElement("div", {
65
- tabIndex: 1,
66
- ref: rootRef,
67
- onClick: openPopover
68
- }, children));
69
- });
70
-
71
- var css_248z = "[data-gene-ui-version=\"2.16.3\"] .time-picker-holder{width:100%}[data-gene-ui-version=\"2.16.3\"] .time-picker-holder.read-only .cursor-pointer{cursor:default}[data-gene-ui-version=\"2.16.3\"] .time-picker-holder.mobile{caret-color:#0000;color:#0000;text-shadow:0 0 0 rgba(var(--background-sc-rgb),.75)}[data-gene-ui-version=\"2.16.3\"] .time-picker-holder.disabled{opacity:.6;pointer-events:none}[data-gene-ui-version=\"2.16.3\"] .time-picker-holder>ul{align-items:center;display:flex;width:100%}[data-gene-ui-version=\"2.16.3\"] .time-picker-holder>ul>li.no-shrink{align-items:center;display:flex;flex-shrink:0;justify-content:center}[data-gene-ui-version=\"2.16.3\"] .time-picker-holder>ul>li.no-shrink>span{display:block;font-weight:600;margin:0 .5rem}[data-gene-ui-version=\"2.16.3\"] .time-picker-holder>ul>li.shrink-auto{flex:auto}[data-gene-ui-version=\"2.16.3\"] .time-picker-holder>ul>li.icon-holder{margin-inline-end:.5rem;width:4rem}[data-gene-ui-version=\"2.16.3\"] .time-picker-drop-holder{display:flex;width:100%}[data-gene-ui-version=\"2.16.3\"] .time-picker-drop-holder>li{width:100%}[data-gene-ui-version=\"2.16.3\"] .time-picker-drop-holder>li+li{border-inline-start:1px solid rgba(var(--background-sc-rgb),.08)}[data-gene-ui-version=\"2.16.3\"] .time-picker-drop{font:600 1.4rem/1.8rem var(--font-family);padding:1rem 0;width:100%}[data-gene-ui-version=\"2.16.3\"] .time-picker-drop ul{width:100%}[data-gene-ui-version=\"2.16.3\"] .time-picker-drop ul li{align-items:center;cursor:pointer;display:flex;height:4rem;justify-content:center;text-align:center;transition:background .4s,color .4s;width:100%}@media (hover:hover){[data-gene-ui-version=\"2.16.3\"] .time-picker-drop ul li:hover{background:rgba(var(--background-sc-rgb),.05)}}[data-gene-ui-version=\"2.16.3\"] .time-picker-drop ul li.active{color:var(--hero)}";
72
- styleInject(css_248z);
73
-
74
- function generateTimeValues(format, max) {
75
- const numbers = [];
76
- const formatLength = format.length;
77
- for (let i = 0; i <= max; i++) {
78
- if (formatLength === 1) {
79
- numbers.push(String(i));
80
- } else {
81
- numbers.push(i < 10 ? "0".concat(i) : String(i));
82
- }
83
- }
84
- return numbers;
85
- }
86
- const checkFormatValidation = (format, value) => format.length === 1 && value.length <= 2 && Number(value[0]) !== 0 || format.length === 2 && value.length === 2;
87
- const checkHourRange = (value, format) => value.length <= 2 && (isLongHour(format) && Number(value) < 24 || isShortHour(format) && Number(value) < 12);
88
-
89
- // seconds and minutes cant be equal or higher then 60
90
- const checkRange = value => value.length <= 2 && Number(value) < 60;
91
- const isLongHour = str => str === 'HH' || str === 'H';
92
- const isShortHour = str => str === 'hh' || str === 'h';
93
- function convertToFormat(value, format, notEmpty) {
94
- if (!value && notEmpty) {
95
- return format.length === 1 ? '0' : '00';
96
- }
97
- if (format.length === 2 && value.length === 1) {
98
- return "0".concat(value);
99
- }
100
- if (format.length === 1 && value.length === 2) {
101
- return Number(value).toString();
102
- }
103
- return value;
104
- }
105
- function TimePicker(_ref) {
106
- let {
107
- value,
108
- onChange,
109
- showSeconds,
110
- appearance,
111
- hourFormat,
112
- minuteFormat,
113
- secondFormat,
114
- separator,
115
- className,
116
- disabled,
117
- readOnly,
118
- screenType,
119
- onBlur,
120
- positions,
121
- ...restProps
122
- } = _ref;
123
- const {
124
- isMobile
125
- } = useDeviceType(screenType);
126
- const [hour, setHour] = useState('');
127
- const [minute, setMinute] = useState('');
128
- const [second, setSecond] = useState('');
129
- const [inputValue, setInputValue] = useState('');
130
- const [minuteFieldError, setMinuteFieldError] = useState(false);
131
- const [secondFieldError, setSecondFieldError] = useState(false);
132
- const [hourFieldError, setHourFieldError] = useState(false);
133
-
134
- // We save every value that selected from popup, because we need to
135
- // close current popup when user select value from popup
136
- const [hourPopupValue, setHourPopupValue] = useState(null);
137
- const [minutePopupValue, setMinutePopupValue] = useState(null);
138
- const [secondPopupValue, setSecondPopupValue] = useState(null);
139
- const childRef = useRef();
140
-
141
- // for replacing special symbols
142
- const numberRegExp = useMemo(() => {
143
- const numberRegExpString = "[^0-9".concat(separator, "]");
144
- return new RegExp(numberRegExpString, 'g');
145
- }, [separator]);
146
- const combinedValue = useCallback(function (hour, minute, second) {
147
- let notEmpty = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
148
- if (hour || minute || second) {
149
- const formated = [convertToFormat(hour, hourFormat, notEmpty), convertToFormat(minute, minuteFormat, notEmpty), convertToFormat(second, secondFormat, notEmpty)];
150
- return showSeconds ? formated.join(separator) : "".concat(formated[0]).concat(separator).concat(formated[1]);
151
- }
152
- return '';
153
- }, [showSeconds, separator, hourFormat, minuteFormat, secondFormat]);
154
- const checkHasError = useCallback((currentValue, format) => !currentValue || !checkFormatValidation(format, currentValue) || !checkRange(currentValue), []);
155
- const checkTimeValidation = useCallback(function (value) {
156
- let needToSetState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
157
- const hasError = checkHasError(value || hour, hourFormat);
158
- needToSetState && setHourFieldError(hasError);
159
- return hasError;
160
- }, [checkHasError, hour, hourFormat]);
161
- const checkMinuteValidation = useCallback(function (value) {
162
- let needToSetState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
163
- const hasError = checkHasError(value || minute, minuteFormat);
164
- needToSetState && setMinuteFieldError(hasError);
165
- return hasError;
166
- }, [checkHasError, minute, minuteFormat]);
167
- const checkSecondValidation = useCallback(function (value) {
168
- let needToSetState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
169
- const hasError = checkHasError(value || second, secondFormat);
170
- needToSetState && showSeconds && setSecondFieldError(hasError);
171
- return !showSeconds || hasError;
172
- }, [checkHasError, second, secondFormat, showSeconds]);
173
- const handleHourPopover = useCallback((e, open) => !open && checkTimeValidation(), [checkTimeValidation]);
174
- const handleMinutePopover = useCallback((e, open) => !open && checkMinuteValidation(), [checkMinuteValidation]);
175
- const handleSecondPopover = useCallback((e, open) => !open && checkSecondValidation(), [checkSecondValidation]);
176
- const handlePopoverToggle = useCallback((e, open) => {
177
- if (open) return;
178
- const timeError = checkTimeValidation();
179
- const minuteError = checkMinuteValidation();
180
- const secondError = checkSecondValidation();
181
-
182
- // need to reset all data when user click outside and any of this fields has error
183
- if (timeError || minuteError || secondError) {
184
- setInputValue('');
185
- setHour('');
186
- setMinute('');
187
- setSecond('');
188
- }
189
- }, [checkTimeValidation, checkMinuteValidation, checkSecondValidation]);
190
- const handleChange = useCallback((e, value) => {
191
- // replacing event target's default value, because we have more then one input
192
- // and value can be changes from popup, too
193
- const changedEvent = {
194
- ...e,
195
- target: {
196
- ...e.target,
197
- value
198
- }
199
- };
200
- onChange(changedEvent);
201
- }, [onChange]);
202
- const handleHourChange = useCallback(e => {
203
- const {
204
- value
205
- } = e.target;
206
- const isInRange = checkHourRange(value, hourFormat);
207
- if (isInRange) {
208
- if (!checkTimeValidation(value, false)) {
209
- setHourFieldError(false);
210
- }
211
- setHour(value);
212
- // second argument needs because we call onChange event immediately after setState
213
- handleChange(e, combinedValue(value, minute, second));
214
- }
215
- }, [hourFormat, checkTimeValidation, handleChange, combinedValue, minute, second]);
216
- const handleMinuteChange = useCallback(e => {
217
- const {
218
- value
219
- } = e.target;
220
- const isInRange = checkRange(value);
221
- if (isInRange) {
222
- if (!checkMinuteValidation(value, false)) {
223
- setMinuteFieldError(false);
224
- }
225
- setMinute(value);
226
- // second argument needs because we call onChange event immediately after setState
227
- handleChange(e, combinedValue(hour, value, second));
228
- }
229
- }, [checkMinuteValidation, handleChange, combinedValue, hour, second]);
230
- const handleSecondChange = useCallback(e => {
231
- const {
232
- value
233
- } = e.target;
234
- const isInRange = checkRange(value);
235
- if (isInRange) {
236
- if (!checkSecondValidation(value, false)) {
237
- setSecondFieldError(false);
238
- }
239
- setSecond(value);
240
- // second argument needs because we call onChange event immediately after setState
241
- handleChange(e, combinedValue(hour, minute, value));
242
- }
243
- }, [checkSecondValidation, handleChange, combinedValue, hour, minute]);
244
- const handleChangeFromPopup = useCallback((e, value, key) => {
245
- let time = '';
246
- if (key === 'second') {
247
- time = combinedValue(hour, minute, value);
248
- setSecondFieldError(false);
249
- setSecondPopupValue(value);
250
- } else if (key === 'hour') {
251
- time = combinedValue(value, minute, second);
252
- setHourFieldError(false);
253
- setHourPopupValue(value);
254
- } else {
255
- time = combinedValue(hour, value, second);
256
- setMinuteFieldError(false);
257
- setMinutePopupValue(value);
258
- }
259
- const values = time.split(separator);
260
- setHour(values[0]);
261
- setMinute(values[1]);
262
- showSeconds && setSecond(values[2]);
263
- setInputValue(time);
264
- handleChange(e, time);
265
- }, [hour, minute, second, separator, showSeconds, handleChange, combinedValue]);
266
- const handleInputChange = e => {
267
- const {
268
- value
269
- } = e.target;
270
-
271
- // replacing special chars that not allowed
272
- const replacedValue = value.replace(numberRegExp, '');
273
- const timeParts = replacedValue.split(separator);
274
- const lastChar = replacedValue[replacedValue.length - 1];
275
- const secondLastChar = replacedValue[replacedValue.length - 2];
276
- if (lastChar === separator && lastChar === secondLastChar) return;
277
- if (value === '') {
278
- setHour('');
279
- setMinute('');
280
- setSecond('');
281
- setInputValue('');
282
- handleChange(e, '');
283
- return;
284
- }
285
- if (typeof timeParts[showSeconds ? 3 : 2] !== 'undefined') return;
286
- if (timeParts.some(item => item.length > 2)) return;
287
- let outOfRange = false;
288
- timeParts[0] && setHour(timeParts[0]);
289
- timeParts[1] && setMinute(timeParts[1]);
290
- showSeconds && timeParts[2] && setSecond(timeParts[2]);
291
- if (typeof timeParts[0] !== 'undefined') {
292
- const isInRange = checkHourRange(timeParts[0], hourFormat);
293
- if (isInRange) {
294
- setHour(timeParts[0]);
295
- } else {
296
- outOfRange = true;
297
- }
298
- }
299
- if (typeof timeParts[1] !== 'undefined') {
300
- const isInRange = checkRange(timeParts[1]);
301
- if (isInRange) {
302
- setMinute(timeParts[1]);
303
- } else {
304
- outOfRange = true;
305
- }
306
- }
307
- if (showSeconds && typeof timeParts[2] !== 'undefined') {
308
- const isInRange = checkRange(timeParts[2]);
309
- if (isInRange) {
310
- setSecond(timeParts[2]);
311
- } else {
312
- outOfRange = true;
313
- }
314
- }
315
- !checkTimeValidation(timeParts[0], false) && setHourFieldError(false);
316
- !checkMinuteValidation(timeParts[1], false) && setMinuteFieldError(false);
317
- (!showSeconds || !checkSecondValidation(timeParts[2], false)) && setSecondFieldError(false);
318
- if (!outOfRange) {
319
- setInputValue(replacedValue);
320
- onChange(e);
321
- }
322
- };
323
- useEffect(() => {
324
- if ((disabled || readOnly) && childRef.current) {
325
- childRef.current.toggleOpen(true);
326
- }
327
- }, [disabled, readOnly]);
328
- useEffect(() => {
329
- if (hour) {
330
- const formattedHour = convertToFormat(hour, hourFormat);
331
- setHour(formattedHour);
332
- setInputValue(combinedValue(formattedHour, minute, second, false));
333
- }
334
- }, [hourFormat]);
335
- useEffect(() => {
336
- if (minute) {
337
- const formattedMinute = convertToFormat(minute, minuteFormat);
338
- setMinute(formattedMinute);
339
- setInputValue(combinedValue(hour, formattedMinute, second, false));
340
- }
341
- }, [minuteFormat]);
342
- useEffect(() => {
343
- if (second) {
344
- const formattedSecond = convertToFormat(second, secondFormat);
345
- setSecond(formattedSecond);
346
- setInputValue(combinedValue(hour, minute, formattedSecond, false));
347
- }
348
- }, [secondFormat]);
349
- useEffect(() => {
350
- if (!inputValue) return;
351
- const [splitHour, splitMinute, splitSecond] = inputValue.split(separator);
352
- !showSeconds && setSecond('');
353
- showSeconds && (inputValue || hour) && !second && setSecond(convertToFormat(second, secondFormat));
354
- setInputValue(combinedValue(splitHour, splitMinute, splitSecond));
355
- }, [showSeconds]);
356
- useEffect(() => {
357
- if (value) {
358
- const [splitHour, splitMinute, splitSecond] = value.split(separator);
359
- splitHour && setHour(splitHour);
360
- splitMinute && setMinute(splitMinute);
361
- showSeconds && splitSecond && setSecond(splitSecond);
362
- setInputValue(value);
363
- }
364
- }, [value, separator, showSeconds]);
365
- const timeDropDown = useMemo(() => function (numbers, active, key) {
366
- return /*#__PURE__*/React__default.createElement("div", {
367
- className: "time-picker-drop"
368
- }, /*#__PURE__*/React__default.createElement(CustomScrollbar, {
369
- autoHeight: true,
370
- autoHeightMax: 200,
371
- size: "small"
372
- }, /*#__PURE__*/React__default.createElement("ul", null, numbers.map(i => /*#__PURE__*/React__default.createElement("li", {
373
- onClick: e => handleChangeFromPopup(e, i, key),
374
- key: i,
375
- className: classnames({
376
- active: i === active
377
- })
378
- }, /*#__PURE__*/React__default.createElement("span", null, i))))));
379
- }, [handleChangeFromPopup]);
380
- const hours = useMemo(() => timeDropDown(generateTimeValues(hourFormat, isLongHour(hourFormat) ? 23 : 11), hour, 'hour'), [timeDropDown, hourFormat, hour]);
381
- const minutes = useMemo(() => timeDropDown(generateTimeValues(minuteFormat, 59), minute, 'minute'), [timeDropDown, minuteFormat, minute]);
382
- const seconds = useMemo(() => timeDropDown(generateTimeValues(secondFormat, 59), second, 'second'), [timeDropDown, secondFormat, second]);
383
- const handleInputBlur = useCallback(event => {
384
- const {
385
- currentTarget: {
386
- value
387
- }
388
- } = event;
389
- let formated = value;
390
- if (value) {
391
- formated = combinedValue(...value.split(separator));
392
- setInputValue(formated);
393
- handleChange(event, formated);
394
- }
395
- onBlur(formated, event);
396
- }, [combinedValue, separator, handleChange, onBlur]);
397
- const handleMultiInputBlur = useCallback(event => {
398
- if (hour || minute || second) {
399
- setHour(convertToFormat(hour, hourFormat, true));
400
- setMinute(convertToFormat(minute, minuteFormat, true));
401
- showSeconds && setSecond(convertToFormat(second, secondFormat, true));
402
- }
403
- onBlur("".concat(hour).concat(hour && minute && ':').concat(minute).concat(minute && second && ':').concat(second), event);
404
- }, [hour, minute, second, onBlur, hourFormat, minuteFormat, showSeconds, secondFormat]);
405
- const signleInputPopoverValue = useMemo(() => showSeconds ? convertToFormat(second, secondFormat, true) : convertToFormat(minute, minuteFormat, true), [second, secondFormat, minute, minuteFormat, showSeconds]);
406
- const handleIconClick = () => childRef.current && !readOnly && !disabled && childRef.current.toggleOpen();
407
- return /*#__PURE__*/React__default.createElement("div", {
408
- className: classnames('time-picker-holder', className, {
409
- 'read-only': readOnly,
410
- mobile: isMobile,
411
- disabled
412
- })
413
- }, appearance === timePickerConfig.appearance[0] ? /*#__PURE__*/React__default.createElement("ul", null, /*#__PURE__*/React__default.createElement("li", {
414
- className: "no-shrink icon-holder"
415
- }, /*#__PURE__*/React__default.createElement(Icon, {
416
- type: "bc-icon-clock"
417
- })), /*#__PURE__*/React__default.createElement("li", {
418
- className: "shrink-auto"
419
- }, /*#__PURE__*/React__default.createElement(TimePickerPopover, {
420
- value: hourPopupValue,
421
- toggleHandler: handleHourPopover,
422
- Content: hours,
423
- readOnly: readOnly,
424
- positions: positions
425
- }, /*#__PURE__*/React__default.createElement(NumberInput, {
426
- value: hour,
427
- isValid: !hourFieldError,
428
- forceAllowValidation: true,
429
- onChange: handleHourChange,
430
- placeholder: hourFormat,
431
- appearance: "minimal",
432
- showNumberIcon: false,
433
- readOnly: readOnly,
434
- writeProtected: isMobile,
435
- onBlur: handleMultiInputBlur
436
- }))), /*#__PURE__*/React__default.createElement("li", {
437
- className: "no-shrink"
438
- }, /*#__PURE__*/React__default.createElement("span", null, separator)), /*#__PURE__*/React__default.createElement("li", {
439
- className: "shrink-auto"
440
- }, /*#__PURE__*/React__default.createElement(TimePickerPopover, {
441
- value: minutePopupValue,
442
- toggleHandler: handleMinutePopover,
443
- Content: minutes,
444
- readOnly: readOnly,
445
- positions: positions
446
- }, /*#__PURE__*/React__default.createElement(NumberInput, {
447
- value: minute,
448
- isValid: !minuteFieldError,
449
- forceAllowValidation: true,
450
- onChange: handleMinuteChange,
451
- placeholder: minuteFormat,
452
- appearance: "minimal",
453
- showNumberIcon: false,
454
- readOnly: readOnly,
455
- writeProtected: isMobile,
456
- onBlur: handleMultiInputBlur
457
- }))), showSeconds && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("li", {
458
- className: "no-shrink"
459
- }, /*#__PURE__*/React__default.createElement("span", null, separator)), /*#__PURE__*/React__default.createElement("li", {
460
- className: "shrink-auto"
461
- }, /*#__PURE__*/React__default.createElement(TimePickerPopover, {
462
- value: secondPopupValue,
463
- toggleHandler: handleSecondPopover,
464
- Content: seconds,
465
- readOnly: readOnly,
466
- positions: positions
467
- }, /*#__PURE__*/React__default.createElement(NumberInput, {
468
- value: second,
469
- forceAllowValidation: true,
470
- isValid: !secondFieldError,
471
- onChange: handleSecondChange,
472
- placeholder: secondFormat,
473
- appearance: "minimal",
474
- showNumberIcon: false,
475
- readOnly: readOnly,
476
- writeProtected: isMobile,
477
- onBlur: handleMultiInputBlur
478
- }))))) : /*#__PURE__*/React__default.createElement(TimePickerPopover, {
479
- toggleHandler: handlePopoverToggle,
480
- readOnly: readOnly,
481
- value: signleInputPopoverValue,
482
- ref: childRef,
483
- Content: /*#__PURE__*/React__default.createElement("ul", {
484
- className: "time-picker-drop-holder"
485
- }, /*#__PURE__*/React__default.createElement("li", null, hours), /*#__PURE__*/React__default.createElement("li", null, minutes), showSeconds && /*#__PURE__*/React__default.createElement("li", null, seconds)),
486
- positions: positions
487
- }, /*#__PURE__*/React__default.createElement(ExtendedInput, _extends({
488
- placeholder: "".concat(hourFormat).concat(separator).concat(minuteFormat).concat(showSeconds ? "".concat(separator).concat(secondFormat) : ''),
489
- icon: "bc-icon-clock",
490
- onChange: handleInputChange,
491
- value: inputValue,
492
- isValid: !(hourFieldError || minuteFieldError || secondFieldError),
493
- itemsDirection: "end",
494
- readOnly: readOnly,
495
- writeProtected: isMobile,
496
- onIconClick: handleIconClick,
497
- clickableIcon: true,
498
- onBlur: handleInputBlur
499
- }, restProps))));
500
- }
501
- TimePicker.propTypes = {
502
- /**
503
- * Define is seconds field will shown or no
504
- */
505
- showSeconds: PropTypes.bool,
506
- /**
507
- * Select view with multiple inputs or with single inputs
508
- */
509
- appearance: PropTypes.oneOf(timePickerConfig.appearance),
510
- /**
511
- * Format for hour field
512
- */
513
- hourFormat: PropTypes.oneOf(['HH', 'H', 'hh', 'h']),
514
- /**
515
- * Format for hour field
516
- */
517
- minuteFormat: PropTypes.oneOf(['mm', 'm']),
518
- /**
519
- * Format for hour field
520
- */
521
- secondFormat: PropTypes.oneOf(['ss', 's']),
522
- /**
523
- * Time field separator
524
- */
525
- separator: PropTypes.string,
526
- /**
527
- * Fires an event when field is changed((event: SyntheticEvent) => void).
528
- */
529
- onChange: PropTypes.func,
530
- /**
531
- * Fires an event when field is blurred((date: Date, event: SyntheticEvent) => void).
532
- */
533
- onBlur: PropTypes.func,
534
- /**
535
- * Additional classname
536
- */
537
- className: PropTypes.string,
538
- /**
539
- * Value for input field
540
- */
541
- value: PropTypes.string,
542
- /**
543
- * disabled for input field
544
- */
545
- disabled: PropTypes.bool,
546
- /**
547
- * Makes Time picker readonly when set to "true"
548
- */
549
- readOnly: PropTypes.bool,
550
- /**
551
- * The switch between mobile and desktop version of Dropdown will be applied automatically, when the prop is not specified.
552
- * When the prop is present it must be changed from outside.
553
- */
554
- screenType: PropTypes.oneOf(screenTypes),
555
- /**
556
- * preferred positions by priority ['bottom','top', 'left', 'right']
557
- * default is ['bottom','top', 'left', 'right']
558
- * if you'd like, you can limit the positions ['top', 'left']
559
- */
560
- positions: PropTypes.array
561
- };
562
- TimePicker.defaultProps = {
563
- appearance: timePickerConfig.appearance[0],
564
- showSeconds: true,
565
- hourFormat: 'HH',
566
- minuteFormat: 'mm',
567
- secondFormat: 'ss',
568
- separator: ':',
569
- onChange: noop,
570
- onBlur: noop,
571
- disabled: false,
572
- readOnly: false
573
- };
574
-
575
- export { TimePicker as default };