@geneui/components 2.11.2 → 2.12.2

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} +290 -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 +53 -0
  10. package/{Card.js → Card/index.js} +82 -94
  11. package/{CardList.js → CardList/index.js} +120 -165
  12. package/{CellMeasurerCache-b786dd93.js → CellMeasurerCache-3741d716.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} +45 -43
  22. package/{DatePicker.js → DatePicker/index.js} +106 -108
  23. package/{index-0199942c.js → DatePickerInput/index.js} +114 -100
  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 +83 -0
  31. package/{FormContainer.js → FormContainer/index.js} +25 -26
  32. package/FormableCheckbox/index.js +26 -0
  33. package/FormableDatePicker/index.js +41 -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 +289 -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/PopoverV2/index.js +18 -0
  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-8b0f7ccd.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} +131 -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 +555 -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} +44 -42
  103. package/ValidatableDropdown/index.js +139 -0
  104. package/ValidatableElements/index.js +65 -0
  105. package/ValidatableMultiSelectDropdown/index.js +150 -0
  106. package/{ValidatableNumberInput.js → ValidatableNumberInput/index.js} +41 -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-8c98317a.js → index-11eea761.js} +678 -752
  135. package/index-2ad83e03.js +4 -0
  136. package/index-34e47647.js +10054 -0
  137. package/index-45eafea6.js +90 -0
  138. package/{index-5e96cb4d.js → index-462461c0.js} +50 -48
  139. package/{index-ac59cb10.js → index-a0e4e333.js} +6 -6
  140. package/{index-e8776f3d.js → index-b1e429a7.js} +1 -1
  141. package/index.d.ts +115 -0
  142. package/index.js +137 -113
  143. package/index.mobile.d.ts +16 -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.2\"] .time-holder{align-items:center;display:flex;font-weight:600;line-height:3.2rem;white-space:nowrap}[data-gene-ui-version=\"2.12.2\"] .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,555 @@
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 { P as PopoverV2 } from '../index-462461c0.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 '../index-122432cd.js';
28
+ import '../debounce-4419bc2f.js';
29
+
30
+ function TimePickerPopover(_ref) {
31
+ let {
32
+ children,
33
+ readOnly,
34
+ value,
35
+ positions,
36
+ ...props
37
+ } = _ref;
38
+ const rootRef = useRef(null);
39
+ const [isOpen, setIsOpen] = useState(false);
40
+ const openPopover = () => !readOnly && setIsOpen(true);
41
+ const closePopover = () => setIsOpen(false);
42
+ useKeyDown(openPopover, [openPopover], rootRef, ['Enter']);
43
+ useKeyDown(closePopover, [closePopover], rootRef, ['Tab', 'Escape']);
44
+ const handleOutsideClick = useClickOutside(event => {
45
+ !rootRef.current.contains(event.target) && closePopover();
46
+ });
47
+
48
+ // We need to close popup every time when
49
+ // user select some value from current popup
50
+ useEffect(() => {
51
+ setIsOpen(false);
52
+ }, [value]);
53
+ return /*#__PURE__*/React__default.createElement(PopoverV2, _extends({
54
+ behave: "open",
55
+ scrollbarNeeded: false,
56
+ contentRef: handleOutsideClick,
57
+ isOpen: isOpen,
58
+ position: positions
59
+ }, props), /*#__PURE__*/React__default.createElement("div", {
60
+ tabIndex: 1,
61
+ ref: rootRef,
62
+ onClick: openPopover
63
+ }, children));
64
+ }
65
+
66
+ var css_248z = "[data-gene-ui-version=\"2.12.2\"] .time-picker-holder{width:100%}[data-gene-ui-version=\"2.12.2\"] .time-picker-holder.read-only .cursor-pointer{cursor:default}[data-gene-ui-version=\"2.12.2\"] .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.2\"] .time-picker-holder.disabled{opacity:.6;pointer-events:none}[data-gene-ui-version=\"2.12.2\"] .time-picker-holder>ul{align-items:center;display:flex;width:100%}[data-gene-ui-version=\"2.12.2\"] .time-picker-holder>ul>li.no-shrink{align-items:center;display:flex;flex-shrink:0;justify-content:center}[data-gene-ui-version=\"2.12.2\"] .time-picker-holder>ul>li.no-shrink>span{display:block;font-weight:600;margin:0 .5rem}[data-gene-ui-version=\"2.12.2\"] .time-picker-holder>ul>li.shrink-auto{flex:auto}[data-gene-ui-version=\"2.12.2\"] .time-picker-holder>ul>li.icon-holder{margin-inline-end:.5rem;width:4rem}[data-gene-ui-version=\"2.12.2\"] .time-picker-drop-holder{display:flex;width:100%}[data-gene-ui-version=\"2.12.2\"] .time-picker-drop-holder>li{width:100%}[data-gene-ui-version=\"2.12.2\"] .time-picker-drop-holder>li+li{border-inline-start:1px solid rgba(var(--background-sc-rgb),.08)}[data-gene-ui-version=\"2.12.2\"] .time-picker-drop{font:600 1.4rem/1.8rem var(--font-family);padding:1rem 0;width:100%}[data-gene-ui-version=\"2.12.2\"] .time-picker-drop ul{width:100%}[data-gene-ui-version=\"2.12.2\"] .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.2\"] .time-picker-drop ul li:hover{background:rgba(var(--background-sc-rgb),.05)}}[data-gene-ui-version=\"2.12.2\"] .time-picker-drop ul li.active{color:var(--hero)}";
67
+ styleInject(css_248z);
68
+
69
+ function generateTimeValues(format, max) {
70
+ const numbers = [];
71
+ const formatLength = format.length;
72
+ for (let i = 0; i <= max; i++) {
73
+ if (formatLength === 1) {
74
+ numbers.push(String(i));
75
+ } else {
76
+ numbers.push(i < 10 ? "0".concat(i) : String(i));
77
+ }
78
+ }
79
+ return numbers;
80
+ }
81
+ const checkFormatValidation = (format, value) => format.length === 1 && value.length <= 2 && Number(value[0]) !== 0 || format.length === 2 && value.length === 2;
82
+ const checkHourRange = (value, format) => value.length <= 2 && (isLongHour(format) && Number(value) < 24 || isShortHour(format) && Number(value) < 12);
83
+
84
+ // seconds and minutes cant be equal or higher then 60
85
+ const checkRange = value => value.length <= 2 && Number(value) < 60;
86
+ const isLongHour = str => str === 'HH' || str === 'H';
87
+ const isShortHour = str => str === 'hh' || str === 'h';
88
+ function convertToFormat(value, format, notEmpty) {
89
+ if (!value && notEmpty) {
90
+ return format.length === 1 ? '0' : '00';
91
+ }
92
+ if (format.length === 2 && value.length === 1) {
93
+ return "0".concat(value);
94
+ }
95
+ if (format.length === 1 && value.length === 2) {
96
+ return Number(value).toString();
97
+ }
98
+ return value;
99
+ }
100
+ function TimePicker(_ref) {
101
+ let {
102
+ value,
103
+ onChange,
104
+ showSeconds,
105
+ appearance,
106
+ hourFormat,
107
+ minuteFormat,
108
+ secondFormat,
109
+ separator,
110
+ className,
111
+ disabled,
112
+ readOnly,
113
+ screenType,
114
+ onBlur,
115
+ positions,
116
+ ...restProps
117
+ } = _ref;
118
+ const {
119
+ isMobile
120
+ } = useDeviceType(screenType);
121
+ const [hour, setHour] = useState('');
122
+ const [minute, setMinute] = useState('');
123
+ const [second, setSecond] = useState('');
124
+ const [inputValue, setInputValue] = useState('');
125
+ const [minuteFieldError, setMinuteFieldError] = useState(false);
126
+ const [secondFieldError, setSecondFieldError] = useState(false);
127
+ const [hourFieldError, setHourFieldError] = useState(false);
128
+
129
+ // We save every value that selected from popup, because we need to
130
+ // close current popup when user select value from popup
131
+ const [hourPopupValue, setHourPopupValue] = useState(null);
132
+ const [minutePopupValue, setMinutePopupValue] = useState(null);
133
+ const [secondPopupValue, setSecondPopupValue] = useState(null);
134
+
135
+ // for replacing special symbols
136
+ const numberRegExp = useMemo(() => {
137
+ const numberRegExpString = "[^0-9".concat(separator, "]");
138
+ return new RegExp(numberRegExpString, 'g');
139
+ }, [separator]);
140
+ const combinedValue = useCallback(function (hour, minute, second) {
141
+ let notEmpty = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
142
+ if (hour || minute || second) {
143
+ const formated = [convertToFormat(hour, hourFormat, notEmpty), convertToFormat(minute, minuteFormat, notEmpty), convertToFormat(second, secondFormat, notEmpty)];
144
+ return showSeconds ? formated.join(separator) : "".concat(formated[0]).concat(separator).concat(formated[1]);
145
+ }
146
+ return '';
147
+ }, [showSeconds, separator, hourFormat, minuteFormat, secondFormat]);
148
+ const checkHasError = useCallback((currentValue, format) => !currentValue || !checkFormatValidation(format, currentValue) || !checkRange(currentValue), []);
149
+ const checkTimeValidation = useCallback(function (value) {
150
+ let needToSetState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
151
+ const hasError = checkHasError(value || hour, hourFormat);
152
+ needToSetState && setHourFieldError(hasError);
153
+ return hasError;
154
+ }, [checkHasError, hour, hourFormat]);
155
+ const checkMinuteValidation = useCallback(function (value) {
156
+ let needToSetState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
157
+ const hasError = checkHasError(value || minute, minuteFormat);
158
+ needToSetState && setMinuteFieldError(hasError);
159
+ return hasError;
160
+ }, [checkHasError, minute, minuteFormat]);
161
+ const checkSecondValidation = useCallback(function (value) {
162
+ let needToSetState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
163
+ const hasError = checkHasError(value || second, secondFormat);
164
+ needToSetState && showSeconds && setSecondFieldError(hasError);
165
+ return !showSeconds || hasError;
166
+ }, [checkHasError, second, secondFormat, showSeconds]);
167
+ const handleHourPopover = useCallback((e, open) => !open && checkTimeValidation(), [checkTimeValidation]);
168
+ const handleMinutePopover = useCallback((e, open) => !open && checkMinuteValidation(), [checkMinuteValidation]);
169
+ const handleSecondPopover = useCallback((e, open) => !open && checkSecondValidation(), [checkSecondValidation]);
170
+ const handlePopoverToggle = useCallback((e, open) => {
171
+ if (open) return;
172
+ const timeError = checkTimeValidation();
173
+ const minuteError = checkMinuteValidation();
174
+ const secondError = checkSecondValidation();
175
+
176
+ // need to reset all data when user click outside and any of this fields has error
177
+ if (timeError || minuteError || secondError) {
178
+ setInputValue('');
179
+ setHour('');
180
+ setMinute('');
181
+ setSecond('');
182
+ }
183
+ }, [checkTimeValidation, checkMinuteValidation, checkSecondValidation]);
184
+ const handleChange = useCallback((e, value) => {
185
+ // replacing event target's default value, because we have more then one input
186
+ // and value can be changes from popup, too
187
+ const changedEvent = {
188
+ ...e,
189
+ target: {
190
+ ...e.target,
191
+ value
192
+ }
193
+ };
194
+ onChange(changedEvent);
195
+ }, [onChange]);
196
+ const handleHourChange = useCallback(e => {
197
+ const {
198
+ value
199
+ } = e.target;
200
+ const isInRange = checkHourRange(value, hourFormat);
201
+ if (isInRange) {
202
+ if (!checkTimeValidation(value, false)) {
203
+ setHourFieldError(false);
204
+ }
205
+ setHour(value);
206
+ // second argument needs because we call onChange event immediately after setState
207
+ handleChange(e, combinedValue(value, minute, second));
208
+ }
209
+ }, [hourFormat, checkTimeValidation, handleChange, combinedValue, minute, second]);
210
+ const handleMinuteChange = useCallback(e => {
211
+ const {
212
+ value
213
+ } = e.target;
214
+ const isInRange = checkRange(value);
215
+ if (isInRange) {
216
+ if (!checkMinuteValidation(value, false)) {
217
+ setMinuteFieldError(false);
218
+ }
219
+ setMinute(value);
220
+ // second argument needs because we call onChange event immediately after setState
221
+ handleChange(e, combinedValue(hour, value, second));
222
+ }
223
+ }, [checkMinuteValidation, handleChange, combinedValue, hour, second]);
224
+ const handleSecondChange = useCallback(e => {
225
+ const {
226
+ value
227
+ } = e.target;
228
+ const isInRange = checkRange(value);
229
+ if (isInRange) {
230
+ if (!checkSecondValidation(value, false)) {
231
+ setSecondFieldError(false);
232
+ }
233
+ setSecond(value);
234
+ // second argument needs because we call onChange event immediately after setState
235
+ handleChange(e, combinedValue(hour, minute, value));
236
+ }
237
+ }, [checkSecondValidation, handleChange, combinedValue, hour, minute]);
238
+ const handleChangeFromPopup = useCallback((e, value, key) => {
239
+ let time = '';
240
+ if (key === 'second') {
241
+ time = combinedValue(hour, minute, value);
242
+ setSecondFieldError(false);
243
+ setSecondPopupValue(value);
244
+ } else if (key === 'hour') {
245
+ time = combinedValue(value, minute, second);
246
+ setHourFieldError(false);
247
+ setHourPopupValue(value);
248
+ } else {
249
+ time = combinedValue(hour, value, second);
250
+ setMinuteFieldError(false);
251
+ setMinutePopupValue(value);
252
+ }
253
+ const values = time.split(separator);
254
+ setHour(values[0]);
255
+ setMinute(values[1]);
256
+ showSeconds && setSecond(values[2]);
257
+ setInputValue(time);
258
+ handleChange(e, time);
259
+ }, [hour, minute, second, separator, showSeconds, handleChange, combinedValue]);
260
+ const handleInputChange = useCallback(e => {
261
+ const {
262
+ value
263
+ } = e.target;
264
+
265
+ // replacing special chars that not allowed
266
+ const replacedValue = value.replace(numberRegExp, '');
267
+ const timeParts = replacedValue.split(separator);
268
+ const lastChar = replacedValue[replacedValue.length - 1];
269
+ const secondLastChar = replacedValue[replacedValue.length - 2];
270
+
271
+ // Checking if last and second last chars are same and equal to separator then return
272
+ if (lastChar === separator && lastChar === secondLastChar) return;
273
+ if (value === '') {
274
+ setHour('');
275
+ setMinute('');
276
+ setSecond('');
277
+ setInputValue('');
278
+ handleChange(e, '');
279
+ return;
280
+ }
281
+ if (typeof timeParts[showSeconds ? 3 : 2] !== 'undefined') return;
282
+ if (timeParts.some(item => item.length > 2)) return;
283
+ let outOfRange = false;
284
+ timeParts[0] && setHour(timeParts[0]);
285
+ timeParts[1] && setMinute(timeParts[1]);
286
+ showSeconds && timeParts[2] && setSecond(timeParts[2]);
287
+ if (typeof timeParts[0] !== 'undefined') {
288
+ const isInRange = checkHourRange(timeParts[0], hourFormat);
289
+ if (isInRange) {
290
+ setHour(timeParts[0]);
291
+ } else {
292
+ outOfRange = true;
293
+ }
294
+ }
295
+ if (typeof timeParts[1] !== 'undefined') {
296
+ const isInRange = checkRange(timeParts[1]);
297
+ if (isInRange) {
298
+ setMinute(timeParts[1]);
299
+ } else {
300
+ outOfRange = true;
301
+ }
302
+ }
303
+ if (showSeconds && typeof timeParts[2] !== 'undefined') {
304
+ const isInRange = checkRange(timeParts[2]);
305
+ if (isInRange) {
306
+ setSecond(timeParts[2]);
307
+ } else {
308
+ outOfRange = true;
309
+ }
310
+ }
311
+
312
+ // Make field valid when after typing field pass validation
313
+ // but we must set error only when user click outside or onBlur event fires
314
+ !checkTimeValidation(timeParts[0], false) && setHourFieldError(false);
315
+ !checkMinuteValidation(timeParts[1], false) && setMinuteFieldError(false);
316
+ (!showSeconds || !checkSecondValidation(timeParts[2], false)) && setSecondFieldError(false);
317
+ if (!outOfRange) {
318
+ setInputValue(replacedValue);
319
+ onChange(e);
320
+ }
321
+ }, [numberRegExp, separator, showSeconds, checkTimeValidation, checkMinuteValidation, checkSecondValidation, handleChange, hourFormat, onChange]);
322
+ useEffect(() => {
323
+ // if hour format changes, convert value to that format
324
+ const formattedHour = convertToFormat(hour, hourFormat);
325
+ setHour(formattedHour);
326
+ setInputValue(combinedValue(formattedHour, minute, second, false));
327
+ }, [combinedValue, hour, hourFormat, minute, second]);
328
+ useEffect(() => {
329
+ // if minute format changes, convert value to that format
330
+ const formattedMinute = convertToFormat(minute, minuteFormat);
331
+ setMinute(formattedMinute);
332
+ setInputValue(combinedValue(hour, formattedMinute, second, false));
333
+ }, [combinedValue, hour, minute, minuteFormat, second]);
334
+ useEffect(() => {
335
+ // if second format changes, convert value to that format
336
+ const formattedSecond = convertToFormat(second, secondFormat);
337
+ setSecond(formattedSecond);
338
+ setInputValue(combinedValue(hour, minute, formattedSecond, false));
339
+ }, [combinedValue, hour, minute, second, secondFormat]);
340
+ useEffect(() => {
341
+ if (value) {
342
+ const timeParts = value.split(separator);
343
+ timeParts[0] && setHour(timeParts[0]);
344
+ timeParts[1] && setMinute(timeParts[1]);
345
+ showSeconds && timeParts[2] && setSecond(timeParts[2]);
346
+ setInputValue(value);
347
+ }
348
+ }, [value, separator, showSeconds]);
349
+ const timeDropDown = useMemo(() => function (numbers, active, key) {
350
+ return /*#__PURE__*/React__default.createElement("div", {
351
+ className: "time-picker-drop"
352
+ }, /*#__PURE__*/React__default.createElement(CustomScrollbar, {
353
+ autoHeight: true,
354
+ autoHeightMax: 200,
355
+ size: "small"
356
+ }, /*#__PURE__*/React__default.createElement("ul", null, numbers.map(i => /*#__PURE__*/React__default.createElement("li", {
357
+ onClick: e => handleChangeFromPopup(e, i, key),
358
+ key: i,
359
+ className: classnames({
360
+ active: i === active
361
+ })
362
+ }, /*#__PURE__*/React__default.createElement("span", null, i))))));
363
+ }, [handleChangeFromPopup]);
364
+ const hours = useMemo(() => timeDropDown(generateTimeValues(hourFormat, isLongHour(hourFormat) ? 23 : 11), hour, 'hour'), [timeDropDown, hourFormat, hour]);
365
+ const minutes = useMemo(() => timeDropDown(generateTimeValues(minuteFormat, 59), minute, 'minute'), [timeDropDown, minuteFormat, minute]);
366
+ const seconds = useMemo(() => timeDropDown(generateTimeValues(secondFormat, 59), second, 'second'), [timeDropDown, secondFormat, second]);
367
+ const handleInputBlur = useCallback(event => {
368
+ const {
369
+ currentTarget: {
370
+ value
371
+ }
372
+ } = event;
373
+ let formated = value;
374
+ if (value) {
375
+ formated = combinedValue(...value.split(separator));
376
+ setInputValue(formated);
377
+ handleChange(event, formated);
378
+ }
379
+ onBlur(formated, event);
380
+ }, [combinedValue, separator, handleChange, onBlur]);
381
+ const handleMultiInputBlur = useCallback(event => {
382
+ if (hour || minute || second) {
383
+ setHour(convertToFormat(hour, hourFormat, true));
384
+ setMinute(convertToFormat(minute, minuteFormat, true));
385
+ showSeconds && setSecond(convertToFormat(second, secondFormat, true));
386
+ }
387
+ onBlur("".concat(hour).concat(hour && minute && ':').concat(minute).concat(minute && second && ':').concat(second), event);
388
+ }, [hour, minute, second, onBlur, hourFormat, minuteFormat, showSeconds, secondFormat]);
389
+ const signleInputPopoverValue = useMemo(() => showSeconds ? convertToFormat(second, secondFormat, true) : convertToFormat(minute, minuteFormat, true), [second, secondFormat, minute, minuteFormat, showSeconds]);
390
+ return /*#__PURE__*/React__default.createElement("div", {
391
+ className: classnames('time-picker-holder', className, {
392
+ 'read-only': readOnly,
393
+ mobile: isMobile,
394
+ disabled
395
+ })
396
+ }, appearance === timePickerConfig.appearance[0] ? /*#__PURE__*/React__default.createElement("ul", null, /*#__PURE__*/React__default.createElement("li", {
397
+ className: "no-shrink icon-holder"
398
+ }, /*#__PURE__*/React__default.createElement(Icon, {
399
+ type: "bc-icon-clock"
400
+ })), /*#__PURE__*/React__default.createElement("li", {
401
+ className: "shrink-auto"
402
+ }, /*#__PURE__*/React__default.createElement(TimePickerPopover, {
403
+ value: hourPopupValue,
404
+ toggleHandler: handleHourPopover,
405
+ Content: hours,
406
+ readOnly: readOnly,
407
+ positions: positions
408
+ }, /*#__PURE__*/React__default.createElement(NumberInput, {
409
+ value: hour,
410
+ isValid: !hourFieldError,
411
+ forceAllowValidation: true,
412
+ onChange: handleHourChange,
413
+ placeholder: hourFormat,
414
+ appearance: "minimal",
415
+ showNumberIcon: false,
416
+ readOnly: readOnly,
417
+ writeProtected: isMobile,
418
+ onBlur: handleMultiInputBlur
419
+ }))), /*#__PURE__*/React__default.createElement("li", {
420
+ className: "no-shrink"
421
+ }, /*#__PURE__*/React__default.createElement("span", null, separator)), /*#__PURE__*/React__default.createElement("li", {
422
+ className: "shrink-auto"
423
+ }, /*#__PURE__*/React__default.createElement(TimePickerPopover, {
424
+ value: minutePopupValue,
425
+ toggleHandler: handleMinutePopover,
426
+ Content: minutes,
427
+ readOnly: readOnly,
428
+ positions: positions
429
+ }, /*#__PURE__*/React__default.createElement(NumberInput, {
430
+ value: minute,
431
+ isValid: !minuteFieldError,
432
+ forceAllowValidation: true,
433
+ onChange: handleMinuteChange,
434
+ placeholder: minuteFormat,
435
+ appearance: "minimal",
436
+ showNumberIcon: false,
437
+ readOnly: readOnly,
438
+ writeProtected: isMobile,
439
+ onBlur: handleMultiInputBlur
440
+ }))), showSeconds && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("li", {
441
+ className: "no-shrink"
442
+ }, /*#__PURE__*/React__default.createElement("span", null, separator)), /*#__PURE__*/React__default.createElement("li", {
443
+ className: "shrink-auto"
444
+ }, /*#__PURE__*/React__default.createElement(TimePickerPopover, {
445
+ value: secondPopupValue,
446
+ toggleHandler: handleSecondPopover,
447
+ Content: seconds,
448
+ readOnly: readOnly,
449
+ positions: positions
450
+ }, /*#__PURE__*/React__default.createElement(NumberInput, {
451
+ value: second,
452
+ forceAllowValidation: true,
453
+ isValid: !secondFieldError,
454
+ onChange: handleSecondChange,
455
+ placeholder: secondFormat,
456
+ appearance: "minimal",
457
+ showNumberIcon: false,
458
+ readOnly: readOnly,
459
+ writeProtected: isMobile,
460
+ onBlur: handleMultiInputBlur
461
+ }))))) : /*#__PURE__*/React__default.createElement(TimePickerPopover, {
462
+ toggleHandler: handlePopoverToggle,
463
+ readOnly: readOnly,
464
+ value: signleInputPopoverValue,
465
+ Content: /*#__PURE__*/React__default.createElement("ul", {
466
+ className: "time-picker-drop-holder"
467
+ }, /*#__PURE__*/React__default.createElement("li", null, hours), /*#__PURE__*/React__default.createElement("li", null, minutes), showSeconds && /*#__PURE__*/React__default.createElement("li", null, seconds)),
468
+ positions: positions
469
+ }, /*#__PURE__*/React__default.createElement(ExtendedInput, _extends({
470
+ placeholder: "".concat(hourFormat).concat(separator).concat(minuteFormat).concat(showSeconds ? "".concat(separator).concat(secondFormat) : ''),
471
+ icon: "bc-icon-clock",
472
+ onChange: handleInputChange,
473
+ value: inputValue,
474
+ isValid: !(hourFieldError || minuteFieldError || secondFieldError),
475
+ itemsDirection: "end",
476
+ readOnly: readOnly,
477
+ writeProtected: isMobile,
478
+ onBlur: handleInputBlur
479
+ }, restProps))));
480
+ }
481
+ TimePicker.propTypes = {
482
+ /**
483
+ * Define is seconds field will shown or no
484
+ */
485
+ showSeconds: PropTypes.bool,
486
+ /**
487
+ * Select view with multiple inputs or with single inputs
488
+ */
489
+ appearance: PropTypes.oneOf(timePickerConfig.appearance),
490
+ /**
491
+ * Format for hour field
492
+ */
493
+ hourFormat: PropTypes.oneOf(['HH', 'H', 'hh', 'h']),
494
+ /**
495
+ * Format for hour field
496
+ */
497
+ minuteFormat: PropTypes.oneOf(['mm', 'm']),
498
+ /**
499
+ * Format for hour field
500
+ */
501
+ secondFormat: PropTypes.oneOf(['ss', 's']),
502
+ /**
503
+ * Time field separator
504
+ */
505
+ separator: PropTypes.string,
506
+ /**
507
+ * Fires an event when field is changed((event: SyntheticEvent) => void).
508
+ */
509
+ onChange: PropTypes.func,
510
+ /**
511
+ * Fires an event when field is blurred((date: Date, event: SyntheticEvent) => void).
512
+ */
513
+ onBlur: PropTypes.func,
514
+ /**
515
+ * Additional classname
516
+ */
517
+ className: PropTypes.string,
518
+ /**
519
+ * Value for input field
520
+ */
521
+ value: PropTypes.string,
522
+ /**
523
+ * disabled for input field
524
+ */
525
+ disabled: PropTypes.bool,
526
+ /**
527
+ * Makes Time picker readonly when set to "true"
528
+ */
529
+ readOnly: PropTypes.bool,
530
+ /**
531
+ * The switch between mobile and desktop version of Dropdown will be applied automatically, when the prop is not specified.
532
+ * When the prop is present it must be changed from outside.
533
+ */
534
+ screenType: PropTypes.oneOf(screenTypes),
535
+ /**
536
+ * preferred positions by priority ['bottom','top', 'left', 'right']
537
+ * default is ['bottom','top', 'left', 'right']
538
+ * if you'd like, you can limit the positions ['top', 'left']
539
+ */
540
+ positions: PropTypes.array
541
+ };
542
+ TimePicker.defaultProps = {
543
+ appearance: timePickerConfig.appearance[0],
544
+ showSeconds: true,
545
+ hourFormat: 'HH',
546
+ minuteFormat: 'mm',
547
+ secondFormat: 'ss',
548
+ separator: ':',
549
+ onChange: noop,
550
+ onBlur: noop,
551
+ disabled: false,
552
+ readOnly: false
553
+ };
554
+
555
+ export { TimePicker as default };