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