@skbkontur/react-ui 6.1.3 → 6.1.4-eef21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Group/Group.js +3 -2
- package/components/Group/Group.js.map +1 -1
- package/components/Input/Input.d.ts +1 -1
- package/components/Input/Input.js.map +1 -1
- package/components/TimePicker/TimeClockIcon.d.ts +3 -0
- package/components/TimePicker/TimeClockIcon.js +11 -0
- package/components/TimePicker/TimeClockIcon.js.map +1 -0
- package/components/TimePicker/TimeFragmentsView.d.ts +15 -0
- package/components/TimePicker/TimeFragmentsView.js +72 -0
- package/components/TimePicker/TimeFragmentsView.js.map +1 -0
- package/components/TimePicker/TimeFragmentsView.styles.d.ts +12 -0
- package/components/TimePicker/TimeFragmentsView.styles.js +43 -0
- package/components/TimePicker/TimeFragmentsView.styles.js.map +1 -0
- package/components/TimePicker/TimeInput.d.ts +22 -0
- package/components/TimePicker/TimeInput.js +103 -0
- package/components/TimePicker/TimeInput.js.map +1 -0
- package/components/TimePicker/TimePicker.d.ts +77 -0
- package/components/TimePicker/TimePicker.js +508 -0
- package/components/TimePicker/TimePicker.js.map +1 -0
- package/components/TimePicker/TimePicker.styles.d.ts +14 -0
- package/components/TimePicker/TimePicker.styles.js +45 -0
- package/components/TimePicker/TimePicker.styles.js.map +1 -0
- package/components/TimePicker/TimePickerItems.d.ts +17 -0
- package/components/TimePicker/TimePickerItems.js +80 -0
- package/components/TimePicker/TimePickerItems.js.map +1 -0
- package/components/TimePicker/TimePickerMobilePopup.d.ts +38 -0
- package/components/TimePicker/TimePickerMobilePopup.js +21 -0
- package/components/TimePicker/TimePickerMobilePopup.js.map +1 -0
- package/components/TimePicker/TimePickerPopup.d.ts +20 -0
- package/components/TimePicker/TimePickerPopup.js +18 -0
- package/components/TimePicker/TimePickerPopup.js.map +1 -0
- package/components/TimePicker/helpers/TimePicker.constants.d.ts +22 -0
- package/components/TimePicker/helpers/TimePicker.constants.js +31 -0
- package/components/TimePicker/helpers/TimePicker.constants.js.map +1 -0
- package/components/TimePicker/helpers/TimePicker.editing.d.ts +23 -0
- package/components/TimePicker/helpers/TimePicker.editing.js +101 -0
- package/components/TimePicker/helpers/TimePicker.editing.js.map +1 -0
- package/components/TimePicker/helpers/TimePicker.layout.d.ts +6 -0
- package/components/TimePicker/helpers/TimePicker.layout.js +49 -0
- package/components/TimePicker/helpers/TimePicker.layout.js.map +1 -0
- package/components/TimePicker/helpers/TimePicker.selection.d.ts +5 -0
- package/components/TimePicker/helpers/TimePicker.selection.js +23 -0
- package/components/TimePicker/helpers/TimePicker.selection.js.map +1 -0
- package/components/TimePicker/helpers/TimePicker.shared.d.ts +47 -0
- package/components/TimePicker/helpers/TimePicker.shared.js +70 -0
- package/components/TimePicker/helpers/TimePicker.shared.js.map +1 -0
- package/components/TimePicker/helpers/TimePicker.value.d.ts +30 -0
- package/components/TimePicker/helpers/TimePicker.value.js +96 -0
- package/components/TimePicker/helpers/TimePicker.value.js.map +1 -0
- package/components/TimePicker/helpers/scrollSelectedItemIntoView.d.ts +4 -0
- package/components/TimePicker/helpers/scrollSelectedItemIntoView.js +24 -0
- package/components/TimePicker/helpers/scrollSelectedItemIntoView.js.map +1 -0
- package/components/TimePicker/helpers/validateTimePicker.d.ts +8 -0
- package/components/TimePicker/helpers/validateTimePicker.js +16 -0
- package/components/TimePicker/helpers/validateTimePicker.js.map +1 -0
- package/components/TimePicker/hooks/useTimePickerDropdown.d.ts +17 -0
- package/components/TimePicker/hooks/useTimePickerDropdown.js +62 -0
- package/components/TimePicker/hooks/useTimePickerDropdown.js.map +1 -0
- package/components/TimePicker/hooks/useTimePickerSelection.d.ts +18 -0
- package/components/TimePicker/hooks/useTimePickerSelection.js +66 -0
- package/components/TimePicker/hooks/useTimePickerSelection.js.map +1 -0
- package/components/TimePicker/hooks/useTimePickerValue.d.ts +18 -0
- package/components/TimePicker/hooks/useTimePickerValue.js +59 -0
- package/components/TimePicker/hooks/useTimePickerValue.js.map +1 -0
- package/components/TimePicker/index.d.ts +2 -0
- package/components/TimePicker/index.js +2 -0
- package/components/TimePicker/index.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/internal/NativeTimeInput/NativeTimeInput.d.ts +16 -0
- package/internal/NativeTimeInput/NativeTimeInput.js +25 -0
- package/internal/NativeTimeInput/NativeTimeInput.js.map +1 -0
- package/internal/NativeTimeInput/NativeTimeInput.styles.d.ts +3 -0
- package/internal/NativeTimeInput/NativeTimeInput.styles.js +15 -0
- package/internal/NativeTimeInput/NativeTimeInput.styles.js.map +1 -0
- package/internal/NativeTimeInput/NativeTimeInput.utils.d.ts +7 -0
- package/internal/NativeTimeInput/NativeTimeInput.utils.js +28 -0
- package/internal/NativeTimeInput/NativeTimeInput.utils.js.map +1 -0
- package/internal/NativeTimeInput/index.d.ts +1 -0
- package/internal/NativeTimeInput/index.js +2 -0
- package/internal/NativeTimeInput/index.js.map +1 -0
- package/internal/icons2022/TimeClockIcon/TimeClockIcon16Light.d.ts +2 -0
- package/internal/icons2022/TimeClockIcon/TimeClockIcon16Light.js +20 -0
- package/internal/icons2022/TimeClockIcon/TimeClockIcon16Light.js.map +1 -0
- package/internal/icons2022/TimeClockIcon/TimeClockIcon20Light.d.ts +2 -0
- package/internal/icons2022/TimeClockIcon/TimeClockIcon20Light.js +20 -0
- package/internal/icons2022/TimeClockIcon/TimeClockIcon20Light.js.map +1 -0
- package/internal/icons2022/TimeClockIcon/TimeClockIcon24Regular.d.ts +2 -0
- package/internal/icons2022/TimeClockIcon/TimeClockIcon24Regular.js +20 -0
- package/internal/icons2022/TimeClockIcon/TimeClockIcon24Regular.js.map +1 -0
- package/internal/themes/BasicTheme.d.ts +34 -0
- package/internal/themes/BasicTheme.js +96 -0
- package/internal/themes/BasicTheme.js.map +1 -1
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +1 -0
- package/lib/utils.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1 @@
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EACtB,MAAM,EAAE,MAAM,IAAI,8BAAM,KAAK,EAAE,EAAE,UAAU,EAAE,gBAAgB,EAAE,IAAG,MAAM,CAAQ,EAChF,KAAK,iCAAO,KAAK,KAAE,QAAQ,EAAE,aAAa,KAAK,OAAO,GACtD,SAAS,EAAE,iBAAiB,EAC5B,KAAK,EAAE,KAAK;QAEZ,oBAAC,iBAAiB,IAChB,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,EACZ,eAAe,EAAE,eAAe,GAChC,CACY,CACjB,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import React, { useContext, useEffect, useImperativeHandle, useRef } from 'react';\n\nimport { InputLikeText } from '../../internal/InputLikeText/index.js';\nimport { forwardRefAndName } from '../../lib/forwardRefAndName.js';\nimport { useEmotion, useStyles } from '../../lib/renderEnvironment/index.js';\nimport { ThemeContext } from '../../lib/theming/ThemeContext.js';\nimport type { InputProps } from '../Input/index.js';\nimport { getTimePickerInputMinWidth, getTimePickerSuffixMargin } from './helpers/TimePicker.layout.js';\nimport { getTimeSegments, type TimeFormat, type TimeSegment } from './helpers/TimePicker.shared.js';\nimport { TimeClockIcon } from './TimeClockIcon.js';\nimport type { TimeFragmentsViewRef } from './TimeFragmentsView.js';\nimport { TimeFragmentsView } from './TimeFragmentsView.js';\nimport { getStyles } from './TimePicker.styles.js';\n\nexport interface TimeInputRef {\n focus(): void;\n\n blur(): void;\n\n blink(): void;\n\n isFragment(el: HTMLElement | EventTarget | null): boolean;\n\n isAllSelected(): boolean;\n\n getSegment(el: HTMLElement | EventTarget | null): TimeSegment | null;\n\n selectSegment(segment: TimeSegment): void;\n\n selectAll(): void;\n\n getNode(): HTMLElement | null;\n}\n\nexport interface TimeInputProps extends Omit<InputProps, 'type' | 'value' | 'onValueChange' | 'inputMode'> {\n hasDropdown?: boolean;\n format: TimeFormat;\n value: string;\n 'aria-placeholder'?: string;\n onSelectSegment?(segment: TimeSegment, event: React.MouseEvent<HTMLSpanElement>): void;\n}\n\nexport const TimeInput = forwardRefAndName<TimeInputRef, TimeInputProps>('TimeInput', (props, ref) => {\n const {\n hasDropdown = false,\n size = 'small',\n disabled,\n autoFocus,\n suffix,\n style,\n width,\n corners,\n rightIcon,\n format,\n value,\n onSelectSegment,\n ...rest\n } = props;\n\n const theme = useContext(ThemeContext);\n\n const { cx } = useEmotion();\n\n const styles = useStyles(getStyles);\n\n const inputLikeTextRef = useRef<InputLikeText>(null);\n const fragmentsViewRef = useRef<TimeFragmentsViewRef>(null);\n\n useImperativeHandle(\n ref,\n () => ({\n focus: () => inputLikeTextRef.current?.focus(),\n blur: () => inputLikeTextRef.current?.blur(),\n blink: () => inputLikeTextRef.current?.blink(),\n getNode: () => inputLikeTextRef.current?.getNode() ?? null,\n isFragment: (el) => fragmentsViewRef.current?.isFragment(el) ?? false,\n getSegment: (el) => fragmentsViewRef.current?.getSegment(el) ?? null,\n selectAll: () => {\n const rootNode = fragmentsViewRef.current?.getRootNode() ?? null;\n\n if (!rootNode) {\n return;\n }\n\n inputLikeTextRef.current?.selectInnerNode(rootNode, 0, rootNode.childNodes.length);\n },\n\n isAllSelected: () => {\n const rootNode = fragmentsViewRef.current?.getRootNode() ?? null;\n\n if (!rootNode) {\n return false;\n }\n\n const selection = rootNode.ownerDocument.defaultView?.getSelection() ?? null;\n\n if (!selection || selection.rangeCount === 0 || selection.isCollapsed) {\n return false;\n }\n\n const range = selection.getRangeAt(0);\n const text = rootNode.textContent ?? '';\n\n return (\n range.toString() === text && rootNode.contains(range.startContainer) && rootNode.contains(range.endContainer)\n );\n },\n\n selectSegment: (segment) => {\n const rootNode = fragmentsViewRef.current?.getRootNode() ?? null;\n\n if (!rootNode) {\n return;\n }\n\n const segmentIndex = getTimeSegments(format).indexOf(segment);\n const start = segmentIndex < 0 ? 0 : segmentIndex * 2;\n const end = start + 1;\n\n inputLikeTextRef.current?.selectInnerNode(rootNode, start, end);\n },\n }),\n [format],\n );\n\n useEffect(() => {\n if (!autoFocus || disabled) {\n return;\n }\n\n const timer = setTimeout(() => {\n inputLikeTextRef.current?.focus();\n }, 0);\n\n return () => {\n clearTimeout(timer);\n };\n }, []);\n\n const resolvedRightIcon =\n rightIcon === undefined ? (\n <span\n className={cx(styles.rightIcon(), styles.rightIconDefault(theme), {\n [styles.rightIconInteractive()]: hasDropdown && !disabled,\n })}\n >\n <TimeClockIcon size={size} />\n </span>\n ) : (\n rightIcon\n );\n const suffixMarginLeft = getTimePickerSuffixMargin(size, theme);\n const inputMinWidth = getTimePickerInputMinWidth(size, format, resolvedRightIcon !== null, theme);\n\n return (\n <InputLikeText\n ref={inputLikeTextRef}\n {...rest}\n takeContentWidth\n disabled={disabled}\n size={size}\n inputMode={'numeric'}\n width={width ?? 'auto'}\n suffix={suffix && <span style={{ marginLeft: suffixMarginLeft }}>{suffix}</span>}\n style={{ ...style, minWidth: inputMinWidth, ...corners }}\n rightIcon={resolvedRightIcon}\n value={value}\n >\n <TimeFragmentsView\n ref={fragmentsViewRef}\n format={format}\n size={size}\n value={value}\n onSelectSegment={onSelectSegment}\n />\n </InputLikeText>\n );\n});\n"]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { AriaAttributes, HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { CommonProps } from '../../internal/CommonWrapper/index.js';
|
|
4
|
+
import type { SizeProp } from '../../lib/types/props.js';
|
|
5
|
+
import type { TimeFormat, TimeItem } from './helpers/TimePicker.shared.js';
|
|
6
|
+
export interface TimePickerProps extends CommonProps, Pick<AriaAttributes, 'aria-describedby' | 'aria-label'>, Pick<HTMLAttributes<HTMLElement>, 'id'> {
|
|
7
|
+
/** Устанавливает формат времени @default HH:mm */
|
|
8
|
+
format?: TimeFormat;
|
|
9
|
+
/** Определяет массив объектов с элементами в формате TimeItem. */
|
|
10
|
+
items?: TimeItem[];
|
|
11
|
+
/** Задает нижнюю границу времени. Элементы за границей становятся заблокированными. */
|
|
12
|
+
minTime?: string;
|
|
13
|
+
/** Задает верхнюю границу времени. Элементы за границей становятся заблокированными. */
|
|
14
|
+
maxTime?: string;
|
|
15
|
+
/** Значение поля @param value. */
|
|
16
|
+
value?: string;
|
|
17
|
+
/** Устанавливает фокус на поле ввода после окончания загрузки страницы @default false */
|
|
18
|
+
autoFocus?: boolean;
|
|
19
|
+
/** Делает компонент заблокированным. */
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
/** Переводит контрол в состояние валидации ошибки. */
|
|
22
|
+
error?: boolean;
|
|
23
|
+
/** Переводит контрол в состояние валидации предупреждения. */
|
|
24
|
+
warning?: boolean;
|
|
25
|
+
/** Включает нативный системный выбор времени на мобильных устройствах. */
|
|
26
|
+
useMobileNativeTimePicker?: boolean;
|
|
27
|
+
/** Расположение выпадающего меню. */
|
|
28
|
+
menuPos?: 'top' | 'bottom';
|
|
29
|
+
/** Выравнивание выпадающего меню. */
|
|
30
|
+
menuAlign?: 'left' | 'right';
|
|
31
|
+
/** Ширина выпадающего меню. По умолчанию — минимальная ширина поля ввода, расширяется по контенту. */
|
|
32
|
+
menuWidth?: string | number;
|
|
33
|
+
/** Задает ширину поля. */
|
|
34
|
+
width?: string | number;
|
|
35
|
+
/** Переопределяет иконку или скрывает, если передать `null`. */
|
|
36
|
+
rightIcon?: React.ReactNode | (() => React.ReactNode);
|
|
37
|
+
/** Устанавливает суффикс после значения и перед иконкой. */
|
|
38
|
+
suffix?: ReactNode;
|
|
39
|
+
/** Размер поля ввода и выпадающего меню. */
|
|
40
|
+
size?: SizeProp;
|
|
41
|
+
/** Устанавливает радиус скруглений углов.
|
|
42
|
+
* @ignore */
|
|
43
|
+
corners?: Partial<Pick<React.CSSProperties, 'borderTopRightRadius' | 'borderBottomRightRadius' | 'borderBottomLeftRadius' | 'borderTopLeftRadius'>>;
|
|
44
|
+
/** Задает функцию, которая вызывается при нажатии на контрол. */
|
|
45
|
+
onClick?(event: React.MouseEvent<HTMLElement>): void;
|
|
46
|
+
/**
|
|
47
|
+
* Событие изменения значения `value` в поле.
|
|
48
|
+
* Во процессе ввода значение частично нормализуется по сегментам, например `1` => `01`.
|
|
49
|
+
* При потере фокуса возвращает полностью нормализованное значение в формате `HH:mm[:ss]`.
|
|
50
|
+
*/
|
|
51
|
+
onValueChange?(value: string): void;
|
|
52
|
+
/** Событие потери фокуса. */
|
|
53
|
+
onBlur?(event: React.FocusEvent<HTMLElement>): void;
|
|
54
|
+
/** Событие получения фокуса. */
|
|
55
|
+
onFocus?(event: React.FocusEvent<HTMLElement>): void;
|
|
56
|
+
/** Событие нажатия клавиши. */
|
|
57
|
+
onKeyDown?(event: React.KeyboardEvent<HTMLElement>): void;
|
|
58
|
+
/** Событие вставки из буфера. */
|
|
59
|
+
onPaste?(event: React.ClipboardEvent<HTMLElement>): void;
|
|
60
|
+
}
|
|
61
|
+
export interface TimePickerRef {
|
|
62
|
+
/** Устанавливает фокус на поле ввода. */
|
|
63
|
+
focus(): void;
|
|
64
|
+
/** Снимает фокус с поля ввода. */
|
|
65
|
+
blur(): void;
|
|
66
|
+
/** Закрывает выпадающее меню. */
|
|
67
|
+
close(): void;
|
|
68
|
+
/** Запускает анимацию blink у поля ввода времени. */
|
|
69
|
+
blink(): void;
|
|
70
|
+
/** Возвращает корневой DOM-узел компонента. */
|
|
71
|
+
getRootNode(): HTMLElement | null;
|
|
72
|
+
}
|
|
73
|
+
export type TimePicker = TimePickerRef;
|
|
74
|
+
/** Поле с временем помогает вводить время с клавиатуры или выбирать его с помощью мыши. */
|
|
75
|
+
export declare const TimePicker: import("../../lib/forwardRefAndName.js").ReactUIComponentWithRef<TimePickerRef, TimePickerProps> & Record<never, never> & {
|
|
76
|
+
validate: (value: import("../../typings/utility-types.js").Nullable<string>, options?: import("./helpers/validateTimePicker.js").TimePickerValidationOptions) => boolean;
|
|
77
|
+
};
|
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import React, { useCallback, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
24
|
+
import { CommonWrapper } from '../../internal/CommonWrapper/index.js';
|
|
25
|
+
import { NativeTimeInput } from '../../internal/NativeTimeInput/index.js';
|
|
26
|
+
import { isIOS, isMobile } from '../../lib/client.js';
|
|
27
|
+
import { isKeyArrowDown, isKeyArrowLeft, isKeyArrowRight, isKeyArrowUp, isKeyBackspace, isKeyChar, isKeyDelete, isKeyEnter, isKeyEscape, isKeySpace, isKeyTab, isModShift, isShortcutSelectAll, } from '../../lib/events/keyboard/identifiers.js';
|
|
28
|
+
import { forwardRefAndName } from '../../lib/forwardRefAndName.js';
|
|
29
|
+
import { useStyles } from '../../lib/renderEnvironment/index.js';
|
|
30
|
+
import { ThemeContext } from '../../lib/theming/ThemeContext.js';
|
|
31
|
+
import { getRandomID } from '../../lib/utils.js';
|
|
32
|
+
import { scrollSelectedItemIntoView } from './helpers/scrollSelectedItemIntoView.js';
|
|
33
|
+
import { DIGIT_REGEXP, EMPTY_SEGMENT, EMPTY_VALUE, TimePickerDataTids } from './helpers/TimePicker.constants.js';
|
|
34
|
+
import { commitTimeSegmentOnLeave, deleteTimeSegmentDigit, formatDigitToTimeSegment, shiftTimeSegmentValue, } from './helpers/TimePicker.editing.js';
|
|
35
|
+
import { getTimePickerPopupMaxHeight } from './helpers/TimePicker.layout.js';
|
|
36
|
+
import { getNextTimeSegment, getPreviousTimeSegment } from './helpers/TimePicker.selection.js';
|
|
37
|
+
import { getEmptyDisplayValue, isTimeDisplayEmpty, isTimeValueOutOfRange, normalizeTimeValue, parsePastedTimeValue, replaceTimeSegment, } from './helpers/TimePicker.value.js';
|
|
38
|
+
import { validateTimePicker } from './helpers/validateTimePicker.js';
|
|
39
|
+
import { useTimePickerDropdown } from './hooks/useTimePickerDropdown.js';
|
|
40
|
+
import { useTimePickerSelection } from './hooks/useTimePickerSelection.js';
|
|
41
|
+
import { useTimePickerValue } from './hooks/useTimePickerValue.js';
|
|
42
|
+
import { TimeInput } from './TimeInput.js';
|
|
43
|
+
import { getStyles } from './TimePicker.styles.js';
|
|
44
|
+
import { TimePickerMobilePopup } from './TimePickerMobilePopup.js';
|
|
45
|
+
import { TimePickerPopup } from './TimePickerPopup.js';
|
|
46
|
+
/** Поле с временем помогает вводить время с клавиатуры или выбирать его с помощью мыши. */
|
|
47
|
+
export var TimePicker = Object.assign(forwardRefAndName('TimePicker', function (props, ref) {
|
|
48
|
+
var _a;
|
|
49
|
+
var disabled = props.disabled, _b = props.useMobileNativeTimePicker, useMobileNativeTimePicker = _b === void 0 ? false : _b, _c = props.format, format = _c === void 0 ? 'HH:mm' : _c, _d = props.size, size = _d === void 0 ? 'small' : _d, items = props.items, menuPos = props.menuPos, menuAlign = props.menuAlign, menuWidth = props.menuWidth, minTime = props.minTime, maxTime = props.maxTime, rightIcon = props.rightIcon, suffix = props.suffix, corners = props.corners, value = props.value, onValueChange = props.onValueChange, onFocus = props.onFocus, onBlur = props.onBlur, onClick = props.onClick, onKeyDown = props.onKeyDown, onPaste = props.onPaste, inputProps = __rest(props, ["disabled", "useMobileNativeTimePicker", "format", "size", "items", "menuPos", "menuAlign", "menuWidth", "minTime", "maxTime", "rightIcon", "suffix", "corners", "value", "onValueChange", "onFocus", "onBlur", "onClick", "onKeyDown", "onPaste"]);
|
|
50
|
+
var theme = useContext(ThemeContext);
|
|
51
|
+
var styles = useStyles(getStyles);
|
|
52
|
+
var _e = useState(false), isInputFocused = _e[0], setIsInputFocused = _e[1];
|
|
53
|
+
var inputRef = useRef(null);
|
|
54
|
+
var mobileInputRef = useRef(null);
|
|
55
|
+
var nativeInputRef = useRef(null);
|
|
56
|
+
var rootRef = useRef(null);
|
|
57
|
+
var itemRefs = useRef(new Map());
|
|
58
|
+
var isMouseFocusRef = useRef(false);
|
|
59
|
+
var isMouseDownOnFragmentRef = useRef(false);
|
|
60
|
+
var mouseDownSegmentRef = useRef(null);
|
|
61
|
+
var popupIdRef = useRef(TimePickerDataTids.popup + getRandomID());
|
|
62
|
+
var _f = useState(false), isMobileDevice = _f[0], setIsMobileDevice = _f[1];
|
|
63
|
+
var _g = useState(false), canUseMobileNativeTimePicker = _g[0], setCanUseMobileNativeTimePicker = _g[1];
|
|
64
|
+
var _h = useTimePickerValue({ isInputFocused: isInputFocused, format: format, value: value, onValueChange: onValueChange }), editingValue = _h.editingValue, editingValueRef = _h.editingValueRef, setEditingValue = _h.setEditingValue, updateEditingValue = _h.updateEditingValue, commitEditingValue = _h.commitEditingValue, clearEditingValue = _h.clearEditingValue;
|
|
65
|
+
var hasDropdown = ((_a = items === null || items === void 0 ? void 0 : items.length) !== null && _a !== void 0 ? _a : 0) > 0;
|
|
66
|
+
var resolvedItems = useMemo(function () {
|
|
67
|
+
return (items !== null && items !== void 0 ? items : []).map(function (item) { return (__assign(__assign({}, item), { disabled: Boolean(item.disabled) || isTimeValueOutOfRange(item.value, format, minTime, maxTime) })); });
|
|
68
|
+
}, [maxTime, minTime, format, items]);
|
|
69
|
+
var popupMaxHeight = getTimePickerPopupMaxHeight(size, theme);
|
|
70
|
+
var ariaPlaceholder = format === 'HH:mm' ? 'чч:мм' : 'чч:мм:сс';
|
|
71
|
+
var normalizedValue = normalizeTimeValue(editingValue, format);
|
|
72
|
+
var selectedItemIndex = resolvedItems.findIndex(function (item) { return normalizeTimeValue(item.value, format) === normalizedValue; });
|
|
73
|
+
var canUseMobileDropdownTimePicker = hasDropdown && isMobileDevice && !canUseMobileNativeTimePicker;
|
|
74
|
+
var displayValue = editingValue;
|
|
75
|
+
if (isInputFocused) {
|
|
76
|
+
displayValue = editingValue === EMPTY_VALUE ? getEmptyDisplayValue(format) : editingValue;
|
|
77
|
+
}
|
|
78
|
+
else if (isTimeDisplayEmpty(editingValue)) {
|
|
79
|
+
displayValue = EMPTY_VALUE;
|
|
80
|
+
}
|
|
81
|
+
var resetMouseInteractionState = useCallback(function () {
|
|
82
|
+
isMouseFocusRef.current = false;
|
|
83
|
+
isMouseDownOnFragmentRef.current = false;
|
|
84
|
+
mouseDownSegmentRef.current = null;
|
|
85
|
+
}, []);
|
|
86
|
+
var normalizeCurrentSegmentIfNeeded = useCallback(function (segment) {
|
|
87
|
+
var nextDisplayValue = commitTimeSegmentOnLeave(editingValue === EMPTY_VALUE ? getEmptyDisplayValue(format) : editingValue, segment, format);
|
|
88
|
+
updateEditingValue(nextDisplayValue);
|
|
89
|
+
}, [editingValue, format, updateEditingValue]);
|
|
90
|
+
var openNativeTimePicker = useCallback(function () {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
if (!canUseMobileNativeTimePicker || disabled) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (isIOS) {
|
|
96
|
+
(_a = nativeInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
(_b = nativeInputRef.current) === null || _b === void 0 ? void 0 : _b.click();
|
|
100
|
+
}
|
|
101
|
+
}, [canUseMobileNativeTimePicker, disabled]);
|
|
102
|
+
var _j = useTimePickerDropdown({
|
|
103
|
+
disabled: disabled,
|
|
104
|
+
hasDropdown: hasDropdown,
|
|
105
|
+
items: resolvedItems,
|
|
106
|
+
selectedItemIndex: selectedItemIndex >= 0 ? selectedItemIndex : null,
|
|
107
|
+
}), isDropdownOpened = _j.isDropdownOpened, highlightedItemIndex = _j.highlightedItemIndex, openDropdown = _j.openDropdown, closeDropdown = _j.closeDropdown, resetHighlightedItem = _j.resetHighlightedItem, tryNavigateItems = _j.tryNavigateItems;
|
|
108
|
+
var popupId = popupIdRef.current;
|
|
109
|
+
var activeDescendantId = hasDropdown && highlightedItemIndex !== null ? "".concat(popupId, "-item-").concat(highlightedItemIndex) : undefined;
|
|
110
|
+
var getActiveInput = useCallback(function () { return (canUseMobileDropdownTimePicker && isDropdownOpened ? mobileInputRef.current : inputRef.current); }, [canUseMobileDropdownTimePicker, isDropdownOpened]);
|
|
111
|
+
var _k = useTimePickerSelection({
|
|
112
|
+
isInputFocused: isInputFocused,
|
|
113
|
+
format: format,
|
|
114
|
+
displayValue: displayValue,
|
|
115
|
+
getInput: getActiveInput,
|
|
116
|
+
}), selection = _k.selection, selectedSegment = _k.selectedSegment, selectSegment = _k.selectSegment, selectAll = _k.selectAll, syncSelectionWithDOM = _k.syncSelectionWithDOM;
|
|
117
|
+
var closeOpenedDropdown = useCallback(function () {
|
|
118
|
+
if (canUseMobileDropdownTimePicker && isDropdownOpened) {
|
|
119
|
+
setIsInputFocused(false);
|
|
120
|
+
resetMouseInteractionState();
|
|
121
|
+
if (isTimeDisplayEmpty(editingValueRef.current)) {
|
|
122
|
+
clearEditingValue();
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
commitEditingValue();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
closeDropdown();
|
|
129
|
+
}, [
|
|
130
|
+
canUseMobileDropdownTimePicker,
|
|
131
|
+
clearEditingValue,
|
|
132
|
+
closeDropdown,
|
|
133
|
+
commitEditingValue,
|
|
134
|
+
editingValueRef,
|
|
135
|
+
isDropdownOpened,
|
|
136
|
+
resetMouseInteractionState,
|
|
137
|
+
]);
|
|
138
|
+
var selectItem = useCallback(function (item) {
|
|
139
|
+
if (item.disabled) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (canUseMobileDropdownTimePicker) {
|
|
143
|
+
setIsInputFocused(false);
|
|
144
|
+
resetMouseInteractionState();
|
|
145
|
+
}
|
|
146
|
+
updateEditingValue(item.value);
|
|
147
|
+
closeDropdown();
|
|
148
|
+
}, [canUseMobileDropdownTimePicker, closeDropdown, resetMouseInteractionState, updateEditingValue]);
|
|
149
|
+
var isSelectHighlightedItem = useCallback(function () {
|
|
150
|
+
if (highlightedItemIndex === null) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
var item = resolvedItems[highlightedItemIndex];
|
|
154
|
+
if (!item || item.disabled) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
selectItem(item);
|
|
158
|
+
return true;
|
|
159
|
+
}, [highlightedItemIndex, resolvedItems, selectItem]);
|
|
160
|
+
var focusInput = useCallback(function () {
|
|
161
|
+
var _a;
|
|
162
|
+
(_a = getActiveInput()) === null || _a === void 0 ? void 0 : _a.focus();
|
|
163
|
+
}, [getActiveInput]);
|
|
164
|
+
var blurInput = useCallback(function () {
|
|
165
|
+
var _a;
|
|
166
|
+
(_a = getActiveInput()) === null || _a === void 0 ? void 0 : _a.blur();
|
|
167
|
+
}, [getActiveInput]);
|
|
168
|
+
var closeInputDropdown = useCallback(function () {
|
|
169
|
+
closeOpenedDropdown();
|
|
170
|
+
}, [closeOpenedDropdown]);
|
|
171
|
+
var blinkInput = useCallback(function () {
|
|
172
|
+
var _a;
|
|
173
|
+
(_a = getActiveInput()) === null || _a === void 0 ? void 0 : _a.blink();
|
|
174
|
+
}, [getActiveInput]);
|
|
175
|
+
useImperativeHandle(ref, function () { return ({
|
|
176
|
+
focus: focusInput,
|
|
177
|
+
blur: blurInput,
|
|
178
|
+
blink: blinkInput,
|
|
179
|
+
close: closeInputDropdown,
|
|
180
|
+
getRootNode: function () { return rootRef.current; },
|
|
181
|
+
}); }, [blinkInput, blurInput, closeInputDropdown, focusInput, getActiveInput]);
|
|
182
|
+
useLayoutEffect(function () {
|
|
183
|
+
if (!isDropdownOpened) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
var selectedIndex = highlightedItemIndex !== null && highlightedItemIndex !== void 0 ? highlightedItemIndex : selectedItemIndex;
|
|
187
|
+
if (selectedIndex < 0) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
var targetNode = itemRefs.current.get(selectedIndex);
|
|
191
|
+
if (targetNode) {
|
|
192
|
+
scrollSelectedItemIntoView(targetNode);
|
|
193
|
+
}
|
|
194
|
+
}, [highlightedItemIndex, isDropdownOpened, selectedItemIndex]);
|
|
195
|
+
useEffect(function () {
|
|
196
|
+
if (disabled && isDropdownOpened) {
|
|
197
|
+
closeOpenedDropdown();
|
|
198
|
+
}
|
|
199
|
+
}, [closeOpenedDropdown, disabled, isDropdownOpened]);
|
|
200
|
+
useEffect(function () {
|
|
201
|
+
setIsMobileDevice(Boolean(isMobile));
|
|
202
|
+
setCanUseMobileNativeTimePicker(useMobileNativeTimePicker && Boolean(isMobile));
|
|
203
|
+
}, [useMobileNativeTimePicker]);
|
|
204
|
+
var handleCloseMobileDropdown = useCallback(function () {
|
|
205
|
+
closeOpenedDropdown();
|
|
206
|
+
}, [closeOpenedDropdown]);
|
|
207
|
+
var handleFocusBySource = function (event, isMobilePopupInput) {
|
|
208
|
+
if (canUseMobileNativeTimePicker) {
|
|
209
|
+
openNativeTimePicker();
|
|
210
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (canUseMobileDropdownTimePicker && !isMobilePopupInput) {
|
|
214
|
+
openDropdown();
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
setIsInputFocused(true);
|
|
218
|
+
openDropdown();
|
|
219
|
+
if (isMouseDownOnFragmentRef.current && !isInputFocused) {
|
|
220
|
+
if (isTimeDisplayEmpty(editingValueRef.current)) {
|
|
221
|
+
selectSegment('hours');
|
|
222
|
+
}
|
|
223
|
+
else if (mouseDownSegmentRef.current) {
|
|
224
|
+
selectSegment(mouseDownSegmentRef.current);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
selectSegment('hours');
|
|
229
|
+
}
|
|
230
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
231
|
+
};
|
|
232
|
+
var handleFocus = function (event) { return handleFocusBySource(event, false); };
|
|
233
|
+
var handleMobileFocus = function (event) { return handleFocusBySource(event, true); };
|
|
234
|
+
var handleBlurBySource = function (event, isMobilePopupInput) {
|
|
235
|
+
if (canUseMobileNativeTimePicker) {
|
|
236
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (canUseMobileDropdownTimePicker && !isMobilePopupInput) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
setIsInputFocused(false);
|
|
243
|
+
resetMouseInteractionState();
|
|
244
|
+
if (isMobilePopupInput) {
|
|
245
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
closeDropdown();
|
|
249
|
+
if (isTimeDisplayEmpty(editingValueRef.current)) {
|
|
250
|
+
clearEditingValue();
|
|
251
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
commitEditingValue();
|
|
255
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
256
|
+
};
|
|
257
|
+
var handleBlur = function (event) { return handleBlurBySource(event, false); };
|
|
258
|
+
var handleMobileBlur = function (event) { return handleBlurBySource(event, true); };
|
|
259
|
+
var handleClickBySource = function (event, isMobilePopupInput) {
|
|
260
|
+
if (canUseMobileNativeTimePicker) {
|
|
261
|
+
openNativeTimePicker();
|
|
262
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (canUseMobileDropdownTimePicker && !isMobilePopupInput) {
|
|
266
|
+
openDropdown();
|
|
267
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
openDropdown();
|
|
271
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
272
|
+
};
|
|
273
|
+
var handleClick = function (event) { return handleClickBySource(event, false); };
|
|
274
|
+
var handleMobileClick = function (event) { return handleClickBySource(event, true); };
|
|
275
|
+
var handleMouseDownCaptureBySource = function (event, isMobilePopupInput) {
|
|
276
|
+
var _a, _b;
|
|
277
|
+
if (canUseMobileNativeTimePicker || (canUseMobileDropdownTimePicker && !isMobilePopupInput)) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
var currentInputRef = isMobilePopupInput ? mobileInputRef : inputRef;
|
|
281
|
+
var segment = (_b = (_a = currentInputRef.current) === null || _a === void 0 ? void 0 : _a.getSegment(event.target)) !== null && _b !== void 0 ? _b : null;
|
|
282
|
+
var isFragment = segment !== null;
|
|
283
|
+
if (isInputFocused && !isFragment) {
|
|
284
|
+
event.preventDefault();
|
|
285
|
+
}
|
|
286
|
+
isMouseFocusRef.current = !isInputFocused;
|
|
287
|
+
isMouseDownOnFragmentRef.current = isFragment;
|
|
288
|
+
mouseDownSegmentRef.current = segment;
|
|
289
|
+
};
|
|
290
|
+
var handleMouseDownCapture = function (event) {
|
|
291
|
+
return handleMouseDownCaptureBySource(event, false);
|
|
292
|
+
};
|
|
293
|
+
var handleMobileMouseDownCapture = function (event) {
|
|
294
|
+
return handleMouseDownCaptureBySource(event, true);
|
|
295
|
+
};
|
|
296
|
+
var handleMouseUpBySource = function (_event, isMobilePopupInput) {
|
|
297
|
+
if (disabled || canUseMobileNativeTimePicker || (canUseMobileDropdownTimePicker && !isMobilePopupInput)) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
syncSelectionWithDOM();
|
|
301
|
+
};
|
|
302
|
+
var handleMouseUp = function (event) { return handleMouseUpBySource(event, false); };
|
|
303
|
+
var handleMobileMouseUp = function (event) { return handleMouseUpBySource(event, true); };
|
|
304
|
+
var handleSelectSegmentByMouseBySource = function (segment, isMobilePopupInput) {
|
|
305
|
+
if (canUseMobileNativeTimePicker) {
|
|
306
|
+
openNativeTimePicker();
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (canUseMobileDropdownTimePicker && !isMobilePopupInput) {
|
|
310
|
+
openDropdown();
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
openDropdown();
|
|
314
|
+
if (disabled) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (!(isMouseFocusRef.current && isTimeDisplayEmpty(editingValueRef.current)) && selectedSegment !== segment) {
|
|
318
|
+
normalizeCurrentSegmentIfNeeded(selectedSegment);
|
|
319
|
+
selectSegment(segment);
|
|
320
|
+
}
|
|
321
|
+
resetMouseInteractionState();
|
|
322
|
+
};
|
|
323
|
+
var handleSelectSegmentByMouse = function (segment) { return handleSelectSegmentByMouseBySource(segment, false); };
|
|
324
|
+
var handleMobileSelectSegmentByMouse = function (segment) {
|
|
325
|
+
return handleSelectSegmentByMouseBySource(segment, true);
|
|
326
|
+
};
|
|
327
|
+
var handleKeyDownBySource = function (event, isMobilePopupInput) {
|
|
328
|
+
var _a, _b, _c, _d, _e, _f;
|
|
329
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
|
|
330
|
+
if (event.defaultPrevented || disabled) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (canUseMobileNativeTimePicker) {
|
|
334
|
+
openNativeTimePicker();
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (canUseMobileDropdownTimePicker && !isMobilePopupInput) {
|
|
338
|
+
openDropdown();
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (isShortcutSelectAll(event)) {
|
|
342
|
+
event.preventDefault();
|
|
343
|
+
selectAll();
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
if (event.altKey || event.ctrlKey || event.metaKey) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
var currentDisplayValue = displayValue;
|
|
350
|
+
var currentSegment = selectedSegment;
|
|
351
|
+
var hasAllSelectionInState = selection === 'all';
|
|
352
|
+
var hasAllSelectionInDOM = (_b = (_a = getActiveInput()) === null || _a === void 0 ? void 0 : _a.isAllSelected()) !== null && _b !== void 0 ? _b : false;
|
|
353
|
+
var shouldHandleAsAllSelection = hasAllSelectionInState || hasAllSelectionInDOM;
|
|
354
|
+
if (hasAllSelectionInDOM && !hasAllSelectionInState) {
|
|
355
|
+
syncSelectionWithDOM();
|
|
356
|
+
}
|
|
357
|
+
if (shouldHandleAsAllSelection && (isKeyBackspace(event) || isKeyDelete(event))) {
|
|
358
|
+
event.preventDefault();
|
|
359
|
+
updateEditingValue(getEmptyDisplayValue(format));
|
|
360
|
+
selectSegment('hours');
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (DIGIT_REGEXP.test(event.key)) {
|
|
364
|
+
event.preventDefault();
|
|
365
|
+
resetHighlightedItem();
|
|
366
|
+
var nextDigitInputValue = shouldHandleAsAllSelection ? getEmptyDisplayValue(format) : currentDisplayValue;
|
|
367
|
+
var nextDigitInputSegment = shouldHandleAsAllSelection ? 'hours' : currentSegment;
|
|
368
|
+
var result = formatDigitToTimeSegment(nextDigitInputValue, nextDigitInputSegment, event.key, format);
|
|
369
|
+
if (result.shouldBlink) {
|
|
370
|
+
(_c = getActiveInput()) === null || _c === void 0 ? void 0 : _c.blink();
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
updateEditingValue(result.nextValue);
|
|
374
|
+
selectSegment(result.selectedSegment);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
if (isKeyArrowLeft(event)) {
|
|
378
|
+
event.preventDefault();
|
|
379
|
+
normalizeCurrentSegmentIfNeeded(currentSegment);
|
|
380
|
+
selectSegment((_d = getPreviousTimeSegment(currentSegment)) !== null && _d !== void 0 ? _d : currentSegment);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (isModShift(isKeyTab)(event)) {
|
|
384
|
+
var previousSegment = getPreviousTimeSegment(currentSegment);
|
|
385
|
+
if (previousSegment) {
|
|
386
|
+
event.preventDefault();
|
|
387
|
+
normalizeCurrentSegmentIfNeeded(currentSegment);
|
|
388
|
+
selectSegment(previousSegment);
|
|
389
|
+
}
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (isKeyArrowRight(event)) {
|
|
393
|
+
event.preventDefault();
|
|
394
|
+
normalizeCurrentSegmentIfNeeded(currentSegment);
|
|
395
|
+
selectSegment((_e = getNextTimeSegment(currentSegment, format)) !== null && _e !== void 0 ? _e : currentSegment);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (isKeyTab(event)) {
|
|
399
|
+
var nextSegment = getNextTimeSegment(currentSegment, format);
|
|
400
|
+
if (nextSegment) {
|
|
401
|
+
event.preventDefault();
|
|
402
|
+
normalizeCurrentSegmentIfNeeded(currentSegment);
|
|
403
|
+
selectSegment(nextSegment);
|
|
404
|
+
}
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
if (isKeyArrowUp(event) || isKeyArrowDown(event)) {
|
|
408
|
+
event.preventDefault();
|
|
409
|
+
var itemStep = isKeyArrowUp(event) ? -1 : 1;
|
|
410
|
+
if (tryNavigateItems(itemStep)) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
var step = isKeyArrowUp(event) ? 1 : -1;
|
|
414
|
+
updateEditingValue(shiftTimeSegmentValue(currentDisplayValue, currentSegment, step, format));
|
|
415
|
+
selectSegment(currentSegment);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (isKeyBackspace(event)) {
|
|
419
|
+
event.preventDefault();
|
|
420
|
+
var nextDisplayValue = deleteTimeSegmentDigit(currentDisplayValue, currentSegment, format);
|
|
421
|
+
var nextSegment = currentSegment;
|
|
422
|
+
if (nextDisplayValue === currentDisplayValue) {
|
|
423
|
+
var previousSegment = getPreviousTimeSegment(currentSegment);
|
|
424
|
+
if (previousSegment) {
|
|
425
|
+
nextSegment = previousSegment;
|
|
426
|
+
nextDisplayValue = deleteTimeSegmentDigit(currentDisplayValue, previousSegment, format);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
updateEditingValue(nextDisplayValue);
|
|
430
|
+
selectSegment(nextSegment);
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if (isKeyDelete(event)) {
|
|
434
|
+
event.preventDefault();
|
|
435
|
+
updateEditingValue(replaceTimeSegment(currentDisplayValue, currentSegment, EMPTY_SEGMENT, format));
|
|
436
|
+
selectSegment(currentSegment);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
if (isKeyEscape(event)) {
|
|
440
|
+
if (isDropdownOpened) {
|
|
441
|
+
event.preventDefault();
|
|
442
|
+
closeDropdown();
|
|
443
|
+
}
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
if (isKeyEnter(event)) {
|
|
447
|
+
if (isSelectHighlightedItem()) {
|
|
448
|
+
event.preventDefault();
|
|
449
|
+
}
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
if (isKeySpace(event)) {
|
|
453
|
+
event.preventDefault();
|
|
454
|
+
var nextSegment = getNextTimeSegment(currentSegment, format);
|
|
455
|
+
var nextDisplayValue = commitTimeSegmentOnLeave(currentDisplayValue, currentSegment, format);
|
|
456
|
+
updateEditingValue(nextDisplayValue);
|
|
457
|
+
if (nextSegment) {
|
|
458
|
+
selectSegment(nextSegment);
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
selectSegment(currentSegment);
|
|
462
|
+
}
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
if (isKeyChar(event)) {
|
|
466
|
+
event.preventDefault();
|
|
467
|
+
(_f = getActiveInput()) === null || _f === void 0 ? void 0 : _f.blink();
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
var handleKeyDown = function (event) { return handleKeyDownBySource(event, false); };
|
|
471
|
+
var handleMobileKeyDown = function (event) { return handleKeyDownBySource(event, true); };
|
|
472
|
+
var handlePasteBySource = function (event, isMobilePopupInput) {
|
|
473
|
+
var _a, _b;
|
|
474
|
+
onPaste === null || onPaste === void 0 ? void 0 : onPaste(event);
|
|
475
|
+
if (event.defaultPrevented || disabled) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
if (canUseMobileNativeTimePicker || (canUseMobileDropdownTimePicker && !isMobilePopupInput)) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
var pastedValue = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text');
|
|
482
|
+
var nextDisplayValue = parsePastedTimeValue(pastedValue, format);
|
|
483
|
+
event.preventDefault();
|
|
484
|
+
if (isTimeDisplayEmpty(nextDisplayValue)) {
|
|
485
|
+
(_b = getActiveInput()) === null || _b === void 0 ? void 0 : _b.blink();
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
updateEditingValue(nextDisplayValue);
|
|
489
|
+
selectSegment('hours');
|
|
490
|
+
};
|
|
491
|
+
var handlePaste = function (event) { return handlePasteBySource(event, false); };
|
|
492
|
+
var handleMobilePaste = function (event) { return handlePasteBySource(event, true); };
|
|
493
|
+
var handleNativeValueChange = useCallback(function (nextValue) {
|
|
494
|
+
setEditingValue(nextValue);
|
|
495
|
+
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(nextValue);
|
|
496
|
+
}, [onValueChange, setEditingValue]);
|
|
497
|
+
return (React.createElement(CommonWrapper, __assign({}, props),
|
|
498
|
+
React.createElement("span", { ref: rootRef, className: styles.root(), "data-tid": TimePickerDataTids.root },
|
|
499
|
+
React.createElement(TimeInput, __assign({}, inputProps, { "data-tid": TimePickerDataTids.input, ref: inputRef, disabled: disabled, hasDropdown: hasDropdown, size: size, format: format, corners: corners, rightIcon: rightIcon, suffix: suffix, value: displayValue, "aria-haspopup": hasDropdown ? 'listbox' : undefined, "aria-expanded": hasDropdown && isDropdownOpened ? true : undefined, "aria-controls": hasDropdown && isDropdownOpened ? popupId : undefined, "aria-activedescendant": activeDescendantId, "aria-placeholder": ariaPlaceholder, onClick: handleClick, onBlur: handleBlur, onFocus: handleFocus, onMouseDownCapture: handleMouseDownCapture, onMouseUp: handleMouseUp, onKeyDown: handleKeyDown, onSelectSegment: handleSelectSegmentByMouse, onPaste: handlePaste })),
|
|
500
|
+
canUseMobileNativeTimePicker && (React.createElement(NativeTimeInput, { "data-tid": TimePickerDataTids.nativeInput, disabled: disabled, ref: nativeInputRef, format: format, minTime: minTime, maxTime: maxTime, value: editingValue, onValueChange: handleNativeValueChange })),
|
|
501
|
+
canUseMobileDropdownTimePicker && isDropdownOpened && (React.createElement(TimePickerMobilePopup, { id: popupId, opened: isDropdownOpened, value: displayValue, inputRef: mobileInputRef, disabled: disabled, format: format, size: size, rightIcon: rightIcon, suffix: suffix, resolvedItems: resolvedItems, highlightedItemIndex: highlightedItemIndex, normalizedValue: normalizedValue, itemRefs: itemRefs, error: props.error, warning: props.warning, "aria-describedby": props['aria-describedby'], "aria-label": props['aria-label'], "aria-placeholder": ariaPlaceholder, onFocus: handleMobileFocus, onBlur: handleMobileBlur, onClick: handleMobileClick, onKeyDown: handleMobileKeyDown, onMouseDownCapture: handleMobileMouseDownCapture, onMouseUp: handleMobileMouseUp, onPaste: handleMobilePaste, onSelectSegment: handleMobileSelectSegmentByMouse, onSelectItem: selectItem, onCloseRequest: handleCloseMobileDropdown })),
|
|
502
|
+
hasDropdown &&
|
|
503
|
+
!canUseMobileNativeTimePicker &&
|
|
504
|
+
!canUseMobileDropdownTimePicker &&
|
|
505
|
+
isDropdownOpened &&
|
|
506
|
+
rootRef.current && (React.createElement(TimePickerPopup, { id: popupId, anchorElement: rootRef.current, menuPos: menuPos, menuAlign: menuAlign, menuWidth: menuWidth, popupMaxHeight: popupMaxHeight, format: format, size: size, resolvedItems: resolvedItems, highlightedItemIndex: highlightedItemIndex, normalizedValue: normalizedValue, itemRefs: itemRefs, onSelectItem: selectItem })))));
|
|
507
|
+
}), { validate: validateTimePicker });
|
|
508
|
+
//# sourceMappingURL=TimePicker.js.map
|