@snack-uikit/fields 0.31.0 → 0.32.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/CHANGELOG.md +22 -0
- package/README.md +179 -147
- package/dist/cjs/components/FieldDate/FieldDate.d.ts +15 -24
- package/dist/cjs/components/FieldDate/FieldDate.js +53 -41
- package/dist/cjs/components/FieldDate/index.d.ts +0 -1
- package/dist/cjs/components/FieldDate/index.js +1 -9
- package/dist/cjs/components/FieldSecure/FieldSecure.d.ts +1 -1
- package/dist/cjs/components/FieldSelect/hooks.d.ts +2 -2
- package/dist/cjs/components/FieldSelect/hooks.js +7 -3
- package/dist/cjs/components/FieldSlider/FieldSlider.d.ts +1 -1
- package/dist/cjs/components/FieldText/FieldText.d.ts +1 -1
- package/dist/cjs/components/FieldTextArea/FieldTextArea.d.ts +1 -1
- package/dist/cjs/components/FieldTime/FieldTime.d.ts +30 -0
- package/dist/cjs/components/FieldTime/FieldTime.js +298 -0
- package/dist/cjs/components/FieldTime/index.d.ts +1 -0
- package/dist/cjs/components/{FieldDate/hooks → FieldTime}/index.js +1 -1
- package/dist/cjs/components/FieldTime/styles.module.css +27 -0
- package/dist/cjs/components/index.d.ts +6 -5
- package/dist/cjs/components/index.js +6 -5
- package/dist/cjs/constants/dateFields.d.ts +24 -0
- package/dist/cjs/constants/dateFields.js +152 -0
- package/dist/cjs/constants/index.d.ts +2 -0
- package/dist/cjs/constants/index.js +26 -0
- package/dist/cjs/hooks/dateHandlers/index.d.ts +3 -0
- package/dist/cjs/hooks/dateHandlers/index.js +27 -0
- package/dist/cjs/{components/FieldDate/hooks → hooks/dateHandlers}/useDateField.d.ts +13 -5
- package/dist/cjs/{components/FieldDate/hooks → hooks/dateHandlers}/useDateField.js +49 -34
- package/dist/cjs/hooks/dateHandlers/useDateFieldHelpersForMode.d.ts +18 -0
- package/dist/cjs/hooks/dateHandlers/useDateFieldHelpersForMode.js +113 -0
- package/dist/cjs/hooks/index.d.ts +1 -0
- package/dist/cjs/hooks/index.js +1 -0
- package/dist/cjs/hooks/useCopyButton.js +1 -1
- package/dist/cjs/{types.d.ts → types/allFields.d.ts} +1 -1
- package/dist/cjs/types/dateFields.d.ts +11 -0
- package/dist/cjs/types/index.d.ts +2 -0
- package/dist/cjs/types/index.js +26 -0
- package/dist/cjs/utils/dateFields.d.ts +10 -0
- package/dist/cjs/utils/dateFields.js +71 -0
- package/dist/esm/components/FieldDate/FieldDate.d.ts +15 -24
- package/dist/esm/components/FieldDate/FieldDate.js +39 -31
- package/dist/esm/components/FieldDate/index.d.ts +0 -1
- package/dist/esm/components/FieldDate/index.js +0 -1
- package/dist/esm/components/FieldSecure/FieldSecure.d.ts +1 -1
- package/dist/esm/components/FieldSelect/hooks.d.ts +2 -2
- package/dist/esm/components/FieldSelect/hooks.js +9 -3
- package/dist/esm/components/FieldSlider/FieldSlider.d.ts +1 -1
- package/dist/esm/components/FieldText/FieldText.d.ts +1 -1
- package/dist/esm/components/FieldTextArea/FieldTextArea.d.ts +1 -1
- package/dist/esm/components/FieldTime/FieldTime.d.ts +30 -0
- package/dist/esm/components/FieldTime/FieldTime.js +161 -0
- package/dist/esm/components/FieldTime/index.d.ts +1 -0
- package/dist/esm/components/FieldTime/index.js +1 -0
- package/dist/esm/components/FieldTime/styles.module.css +27 -0
- package/dist/esm/components/index.d.ts +6 -5
- package/dist/esm/components/index.js +6 -5
- package/dist/esm/constants/dateFields.d.ts +24 -0
- package/dist/esm/constants/dateFields.js +103 -0
- package/dist/esm/constants/index.d.ts +2 -0
- package/dist/esm/constants/index.js +2 -0
- package/dist/esm/hooks/dateHandlers/index.d.ts +3 -0
- package/dist/esm/hooks/dateHandlers/index.js +3 -0
- package/dist/esm/{components/FieldDate/hooks → hooks/dateHandlers}/useDateField.d.ts +13 -5
- package/dist/esm/{components/FieldDate/hooks → hooks/dateHandlers}/useDateField.js +48 -35
- package/dist/esm/hooks/dateHandlers/useDateFieldHelpersForMode.d.ts +18 -0
- package/dist/esm/hooks/dateHandlers/useDateFieldHelpersForMode.js +95 -0
- package/dist/esm/hooks/index.d.ts +1 -0
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/useCopyButton.js +1 -1
- package/dist/esm/{types.d.ts → types/allFields.d.ts} +1 -1
- package/dist/esm/types/dateFields.d.ts +11 -0
- package/dist/esm/types/index.d.ts +2 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/utils/dateFields.d.ts +10 -0
- package/dist/esm/utils/dateFields.js +59 -0
- package/package.json +10 -10
- package/src/components/FieldDate/FieldDate.tsx +72 -52
- package/src/components/FieldDate/index.ts +0 -1
- package/src/components/FieldSelect/hooks.ts +15 -3
- package/src/components/FieldTime/FieldTime.tsx +350 -0
- package/src/components/FieldTime/index.ts +1 -0
- package/src/components/FieldTime/styles.module.scss +41 -0
- package/src/components/index.ts +6 -5
- package/src/constants/dateFields.ts +127 -0
- package/src/constants/index.ts +2 -0
- package/src/hooks/dateHandlers/index.ts +3 -0
- package/src/{components/FieldDate/hooks → hooks/dateHandlers}/useDateField.ts +93 -47
- package/src/hooks/dateHandlers/useDateFieldHelpersForMode.ts +145 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useCopyButton.tsx +1 -1
- package/src/{types.ts → types/allFields.ts} +1 -1
- package/src/types/dateFields.ts +14 -0
- package/src/types/index.ts +2 -0
- package/src/utils/dateFields.ts +75 -0
- package/dist/cjs/components/FieldDate/constants.d.ts +0 -10
- package/dist/cjs/components/FieldDate/constants.js +0 -49
- package/dist/cjs/components/FieldDate/hooks/index.d.ts +0 -1
- package/dist/cjs/components/FieldDate/hooks/useDateFieldHelpers.d.ts +0 -10
- package/dist/cjs/components/FieldDate/hooks/useDateFieldHelpers.js +0 -82
- package/dist/cjs/components/FieldDate/types.d.ts +0 -6
- package/dist/cjs/components/FieldDate/utils.d.ts +0 -9
- package/dist/cjs/components/FieldDate/utils.js +0 -56
- package/dist/esm/components/FieldDate/constants.d.ts +0 -10
- package/dist/esm/components/FieldDate/constants.js +0 -28
- package/dist/esm/components/FieldDate/hooks/index.d.ts +0 -1
- package/dist/esm/components/FieldDate/hooks/index.js +0 -1
- package/dist/esm/components/FieldDate/hooks/useDateFieldHelpers.d.ts +0 -10
- package/dist/esm/components/FieldDate/hooks/useDateFieldHelpers.js +0 -66
- package/dist/esm/components/FieldDate/types.d.ts +0 -6
- package/dist/esm/components/FieldDate/utils.d.ts +0 -9
- package/dist/esm/components/FieldDate/utils.js +0 -43
- package/src/components/FieldDate/constants.ts +0 -33
- package/src/components/FieldDate/hooks/index.ts +0 -1
- package/src/components/FieldDate/hooks/useDateFieldHelpers.ts +0 -96
- package/src/components/FieldDate/types.ts +0 -6
- package/src/components/FieldDate/utils.ts +0 -49
- /package/dist/cjs/{constants.d.ts → constants/allFields.d.ts} +0 -0
- /package/dist/cjs/{constants.js → constants/allFields.js} +0 -0
- /package/dist/cjs/{components/FieldDate/hooks → hooks/dateHandlers}/useFocusHandlers.d.ts +0 -0
- /package/dist/cjs/{components/FieldDate/hooks → hooks/dateHandlers}/useFocusHandlers.js +0 -0
- /package/dist/cjs/{components/FieldDate/hooks → hooks/dateHandlers}/useHandlers.d.ts +0 -0
- /package/dist/cjs/{components/FieldDate/hooks → hooks/dateHandlers}/useHandlers.js +0 -0
- /package/dist/cjs/{components/FieldDate/types.js → types/allFields.js} +0 -0
- /package/dist/cjs/{types.js → types/dateFields.js} +0 -0
- /package/dist/esm/{constants.d.ts → constants/allFields.d.ts} +0 -0
- /package/dist/esm/{constants.js → constants/allFields.js} +0 -0
- /package/dist/esm/{components/FieldDate/hooks → hooks/dateHandlers}/useFocusHandlers.d.ts +0 -0
- /package/dist/esm/{components/FieldDate/hooks → hooks/dateHandlers}/useFocusHandlers.js +0 -0
- /package/dist/esm/{components/FieldDate/hooks → hooks/dateHandlers}/useHandlers.d.ts +0 -0
- /package/dist/esm/{components/FieldDate/hooks → hooks/dateHandlers}/useHandlers.js +0 -0
- /package/dist/esm/{components/FieldDate/types.js → types/allFields.js} +0 -0
- /package/dist/esm/{types.js → types/dateFields.js} +0 -0
- /package/src/{constants.ts → constants/allFields.ts} +0 -0
- /package/src/{components/FieldDate/hooks → hooks/dateHandlers}/useFocusHandlers.ts +0 -0
- /package/src/{components/FieldDate/hooks → hooks/dateHandlers}/useHandlers.ts +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ValueOf } from '@snack-uikit/utils';
|
|
2
|
+
import { MODES, NO_SECONDS_MODE, TIME_MODES } from '../constants';
|
|
3
|
+
export type Slot = {
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
max: number;
|
|
7
|
+
min: number;
|
|
8
|
+
};
|
|
9
|
+
export type Mode = ValueOf<typeof MODES>;
|
|
10
|
+
export type TimeMode = ValueOf<typeof TIME_MODES>;
|
|
11
|
+
export type NoSecondsMode = typeof NO_SECONDS_MODE;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./allFields"), exports);
|
|
26
|
+
__exportStar(require("./dateFields"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SlotKey } from '../constants';
|
|
2
|
+
import { Mode, NoSecondsMode, TimeMode } from '../types';
|
|
3
|
+
export declare function getSlotKeyFromIndexHandler(mode: Mode | TimeMode | NoSecondsMode): (index: number | null) => SlotKey | undefined;
|
|
4
|
+
export declare function getNextSlotKeyHandler(mode: Mode | TimeMode | NoSecondsMode): (slotKey: SlotKey | undefined) => SlotKey;
|
|
5
|
+
export declare function getPrevSlotKeyHandler(mode: Mode | TimeMode | NoSecondsMode): (slotKey: SlotKey | undefined) => SlotKey;
|
|
6
|
+
/**
|
|
7
|
+
* Преобразует строковое значение поля FieldDate в тип Date
|
|
8
|
+
* @function helper
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseDate(value: string): Date | undefined;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSlotKeyFromIndexHandler = getSlotKeyFromIndexHandler;
|
|
7
|
+
exports.getNextSlotKeyHandler = getNextSlotKeyHandler;
|
|
8
|
+
exports.getPrevSlotKeyHandler = getPrevSlotKeyHandler;
|
|
9
|
+
exports.parseDate = parseDate;
|
|
10
|
+
const constants_1 = require("../constants");
|
|
11
|
+
function getSlotKeyFromIndexHandler(mode) {
|
|
12
|
+
return index => {
|
|
13
|
+
if (index !== null) {
|
|
14
|
+
for (const key in constants_1.SLOTS[mode]) {
|
|
15
|
+
if (index >= constants_1.SLOTS[mode][key].start && index <= constants_1.SLOTS[mode][key].end) {
|
|
16
|
+
return key;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function getNextSlotKeyHandler(mode) {
|
|
24
|
+
const order = constants_1.SLOT_ORDER[mode];
|
|
25
|
+
return slotKey => {
|
|
26
|
+
const defaultIndex = order.length - 1;
|
|
27
|
+
const defaultSLot = order[defaultIndex];
|
|
28
|
+
const currentIndex = order.indexOf(slotKey);
|
|
29
|
+
return currentIndex === -1 || currentIndex === defaultIndex ? defaultSLot : order[currentIndex + 1];
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function getPrevSlotKeyHandler(mode) {
|
|
33
|
+
const order = constants_1.SLOT_ORDER[mode];
|
|
34
|
+
return slotKey => {
|
|
35
|
+
const defaultIndex = 0;
|
|
36
|
+
const defaultSLot = order[defaultIndex];
|
|
37
|
+
const currentIndex = order.indexOf(slotKey);
|
|
38
|
+
return currentIndex === -1 || currentIndex === defaultIndex ? defaultSLot : order[currentIndex - 1];
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const DATE_STUB = new Date();
|
|
42
|
+
/**
|
|
43
|
+
* Преобразует строковое значение поля FieldDate в тип Date
|
|
44
|
+
* @function helper
|
|
45
|
+
*/
|
|
46
|
+
function parseDate(value) {
|
|
47
|
+
if (!value) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const splittedValue = value.split(', ');
|
|
51
|
+
const date = splittedValue[0];
|
|
52
|
+
let time = splittedValue[1];
|
|
53
|
+
let [day, month, year] = date.split('.').map(Number);
|
|
54
|
+
month -= 1;
|
|
55
|
+
if (date.includes(':')) {
|
|
56
|
+
time = date;
|
|
57
|
+
}
|
|
58
|
+
if (time) {
|
|
59
|
+
if (isNaN(year) || isNaN(month) || isNaN(day)) {
|
|
60
|
+
year = DATE_STUB.getFullYear();
|
|
61
|
+
month = DATE_STUB.getMonth();
|
|
62
|
+
day = DATE_STUB.getDay();
|
|
63
|
+
}
|
|
64
|
+
const [hours = 0, minutes = 0, seconds = 0] = time.split(':').map(str => {
|
|
65
|
+
var _a;
|
|
66
|
+
return (_a = Number(str)) !== null && _a !== void 0 ? _a : 0;
|
|
67
|
+
});
|
|
68
|
+
return new Date(year, month, day, hours, minutes, seconds);
|
|
69
|
+
}
|
|
70
|
+
return new Date(year, month, day);
|
|
71
|
+
}
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { CalendarProps } from '@snack-uikit/calendar';
|
|
2
2
|
import { InputPrivateProps } from '@snack-uikit/input-private';
|
|
3
3
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
4
|
+
import { MODES } from '../../constants';
|
|
5
|
+
import { Mode } from '../../types';
|
|
4
6
|
import { FieldDecoratorProps } from '../FieldDecorator';
|
|
5
|
-
type InputProps = Pick<InputPrivateProps, 'id' | 'name' | '
|
|
7
|
+
type InputProps = Pick<InputPrivateProps, 'id' | 'name' | 'disabled' | 'readonly' | 'onFocus' | 'onBlur'>;
|
|
6
8
|
type WrapperProps = Pick<FieldDecoratorProps, 'className' | 'label' | 'labelTooltip' | 'required' | 'caption' | 'hint' | 'showHintIcon' | 'size' | 'validationState' | 'labelTooltipPlacement' | 'error'>;
|
|
9
|
+
type FieldDateWithSeconds = {
|
|
10
|
+
mode: typeof MODES.DateTime;
|
|
11
|
+
showSeconds?: boolean;
|
|
12
|
+
};
|
|
7
13
|
type FieldDateOwnProps = {
|
|
8
14
|
/** Открыт date-picker */
|
|
9
15
|
open?: boolean;
|
|
10
16
|
/** Колбек открытия пикера */
|
|
11
17
|
onOpenChange?(value: boolean): void;
|
|
18
|
+
/** Значение поля */
|
|
19
|
+
value?: Date;
|
|
12
20
|
/** Колбек смены значения */
|
|
13
|
-
onChange?(value:
|
|
21
|
+
onChange?(value: Date | undefined): void;
|
|
14
22
|
/** Отображение кнопки копирования */
|
|
15
23
|
showCopyButton?: boolean;
|
|
16
24
|
/**
|
|
@@ -18,27 +26,10 @@ type FieldDateOwnProps = {
|
|
|
18
26
|
* @default true
|
|
19
27
|
*/
|
|
20
28
|
showClearButton?: boolean;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
mode: Mode;
|
|
30
|
+
} & Pick<CalendarProps, 'buildCellProps'> & ({
|
|
31
|
+
mode: typeof MODES.Date;
|
|
32
|
+
} | FieldDateWithSeconds);
|
|
24
33
|
export type FieldDateProps = WithSupportProps<FieldDateOwnProps & InputProps & WrapperProps>;
|
|
25
|
-
export declare const FieldDate: import("react").ForwardRefExoticComponent<
|
|
26
|
-
'data-test-id'?: string;
|
|
27
|
-
} & import("react").AriaAttributes & {
|
|
28
|
-
/** Открыт date-picker */
|
|
29
|
-
open?: boolean;
|
|
30
|
-
/** Колбек открытия пикера */
|
|
31
|
-
onOpenChange?(value: boolean): void;
|
|
32
|
-
/** Колбек смены значения */
|
|
33
|
-
onChange?(value: string): void;
|
|
34
|
-
/** Отображение кнопки копирования */
|
|
35
|
-
showCopyButton?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Отображение кнопки Очистки поля
|
|
38
|
-
* @default true
|
|
39
|
-
*/
|
|
40
|
-
showClearButton?: boolean;
|
|
41
|
-
/** Текущая локаль календаря */
|
|
42
|
-
locale?: Intl.Locale;
|
|
43
|
-
} & Pick<CalendarProps, "buildCellProps"> & InputProps & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
34
|
+
export declare const FieldDate: import("react").ForwardRefExoticComponent<FieldDateProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
44
35
|
export {};
|
|
@@ -11,33 +11,23 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import mergeRefs from 'merge-refs';
|
|
14
|
-
import { forwardRef, useCallback, useEffect, useMemo, useRef
|
|
14
|
+
import { forwardRef, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
15
15
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
16
16
|
import { Calendar } from '@snack-uikit/calendar';
|
|
17
17
|
import { Dropdown } from '@snack-uikit/dropdown';
|
|
18
18
|
import { CalendarSVG } from '@snack-uikit/icons';
|
|
19
19
|
import { ICON_SIZE, InputPrivate, runAfterRerender, SIZE, useButtonNavigation, useClearButton, } from '@snack-uikit/input-private';
|
|
20
20
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
21
|
-
import { CONTAINER_VARIANT, VALIDATION_STATE } from '../../constants';
|
|
21
|
+
import { CONTAINER_VARIANT, DEFAULT_LOCALE, SlotKey, VALIDATION_STATE } from '../../constants';
|
|
22
22
|
import { FieldContainerPrivate } from '../../helperComponents';
|
|
23
|
-
import { useCopyButton } from '../../hooks';
|
|
23
|
+
import { useCopyButton, useDateField, useFocusHandlers, useHandlers } from '../../hooks';
|
|
24
24
|
import { getValidationState } from '../../utils/getValidationState';
|
|
25
25
|
import { FieldDecorator } from '../FieldDecorator';
|
|
26
|
-
import { DEFAULT_LOCALE, SlotKey } from './constants';
|
|
27
|
-
import { useDateField } from './hooks';
|
|
28
|
-
import { useFocusHandlers } from './hooks/useFocusHandlers';
|
|
29
|
-
import { useHandlers } from './hooks/useHandlers';
|
|
30
26
|
import styles from './styles.module.css';
|
|
31
|
-
import { parseDate } from './utils';
|
|
32
|
-
const CALENDAR_SIZE_MAP = {
|
|
33
|
-
[SIZE.S]: 's',
|
|
34
|
-
[SIZE.M]: 'm',
|
|
35
|
-
[SIZE.L]: 'm',
|
|
36
|
-
};
|
|
37
27
|
export const FieldDate = forwardRef((_a, ref) => {
|
|
38
|
-
var
|
|
28
|
+
var _b;
|
|
29
|
+
var { id, name, value: valueProp, disabled = false, readonly = false, showCopyButton: showCopyButtonProp = true, showClearButton: showClearButtonProp = true, open, onOpenChange, onChange, onFocus, onBlur: onBlurProp, className, label, labelTooltip, labelTooltipPlacement, required = false, caption, hint, showHintIcon, size = SIZE.S, validationState = VALIDATION_STATE.Default, buildCellProps, error, mode } = _a, rest = __rest(_a, ["id", "name", "value", "disabled", "readonly", "showCopyButton", "showClearButton", "open", "onOpenChange", "onChange", "onFocus", "onBlur", "className", "label", "labelTooltip", "labelTooltipPlacement", "required", "caption", "hint", "showHintIcon", "size", "validationState", "buildCellProps", "error", "mode"]);
|
|
39
30
|
const [isOpen, setIsOpen] = useUncontrolledProp(open, false, onOpenChange);
|
|
40
|
-
const [pickerAutofocus, setPickerAutofocus] = useState(false);
|
|
41
31
|
const localRef = useRef(null);
|
|
42
32
|
const clearButtonRef = useRef(null);
|
|
43
33
|
const copyButtonRef = useRef(null);
|
|
@@ -46,16 +36,18 @@ export const FieldDate = forwardRef((_a, ref) => {
|
|
|
46
36
|
const showAdditionalButton = Boolean(valueProp && !disabled);
|
|
47
37
|
const showClearButton = showClearButtonProp && showAdditionalButton && !readonly;
|
|
48
38
|
const showCopyButton = showCopyButtonProp && showAdditionalButton && readonly;
|
|
39
|
+
const showSeconds = mode === 'date-time' ? ((_b = rest.showSeconds) !== null && _b !== void 0 ? _b : true) : undefined;
|
|
49
40
|
const fieldValidationState = getValidationState({ validationState, error });
|
|
41
|
+
const navigationStartRef = useRef(null);
|
|
50
42
|
const checkForLeavingFocus = useCallback((event) => {
|
|
51
43
|
if (event.key === 'ArrowDown') {
|
|
52
|
-
setPickerAutofocus(true);
|
|
53
44
|
setIsOpen(true);
|
|
45
|
+
setTimeout(() => { var _a; return (_a = navigationStartRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, 0);
|
|
54
46
|
}
|
|
55
47
|
}, [setIsOpen]);
|
|
56
48
|
const handleClear = useCallback(() => {
|
|
57
49
|
var _a, _b, _c;
|
|
58
|
-
onChange && onChange(
|
|
50
|
+
onChange && onChange(undefined);
|
|
59
51
|
if ((_a = localRef.current) === null || _a === void 0 ? void 0 : _a.value) {
|
|
60
52
|
localRef.current.value = '';
|
|
61
53
|
}
|
|
@@ -68,8 +60,24 @@ export const FieldDate = forwardRef((_a, ref) => {
|
|
|
68
60
|
setIsOpen(false);
|
|
69
61
|
}
|
|
70
62
|
}, [onChange, required, setIsOpen]);
|
|
63
|
+
const getStringDateValue = useCallback((date) => {
|
|
64
|
+
if (!date)
|
|
65
|
+
return '';
|
|
66
|
+
if (mode === 'date') {
|
|
67
|
+
return date.toLocaleDateString(DEFAULT_LOCALE);
|
|
68
|
+
}
|
|
69
|
+
return date.toLocaleString(DEFAULT_LOCALE, {
|
|
70
|
+
year: 'numeric',
|
|
71
|
+
month: 'numeric',
|
|
72
|
+
day: 'numeric',
|
|
73
|
+
hour: '2-digit',
|
|
74
|
+
minute: '2-digit',
|
|
75
|
+
second: showSeconds ? '2-digit' : undefined,
|
|
76
|
+
});
|
|
77
|
+
}, [mode, showSeconds]);
|
|
78
|
+
const valueToCopy = getStringDateValue(valueProp);
|
|
71
79
|
const clearButtonSettings = useClearButton({ clearButtonRef, showClearButton, size, onClear: handleClear });
|
|
72
|
-
const copyButtonSettings = useCopyButton({ copyButtonRef, showCopyButton, size, valueToCopy
|
|
80
|
+
const copyButtonSettings = useCopyButton({ copyButtonRef, showCopyButton, size, valueToCopy });
|
|
73
81
|
const calendarIcon = useMemo(() => ({
|
|
74
82
|
active: false,
|
|
75
83
|
show: true,
|
|
@@ -81,10 +89,12 @@ export const FieldDate = forwardRef((_a, ref) => {
|
|
|
81
89
|
inputRef: localRef,
|
|
82
90
|
onChange,
|
|
83
91
|
readonly,
|
|
84
|
-
locale,
|
|
92
|
+
locale: DEFAULT_LOCALE,
|
|
85
93
|
setIsOpen,
|
|
94
|
+
mode,
|
|
95
|
+
showSeconds,
|
|
86
96
|
});
|
|
87
|
-
const setInputFocusFromButtons = useCallback(() => setInputFocus(SlotKey.Year), [setInputFocus]);
|
|
97
|
+
const setInputFocusFromButtons = useCallback(() => setInputFocus(mode === 'date' ? SlotKey.Year : SlotKey.Seconds), [mode, setInputFocus]);
|
|
88
98
|
const { postfixButtons, inputTabIndex, onInputKeyDown: navigationInputKeyDownHandler, setInitialTabIndices, } = useButtonNavigation({
|
|
89
99
|
setInputFocus: setInputFocusFromButtons,
|
|
90
100
|
inputRef: localRef,
|
|
@@ -93,12 +103,14 @@ export const FieldDate = forwardRef((_a, ref) => {
|
|
|
93
103
|
readonly,
|
|
94
104
|
submitKeys: ['Enter', 'Space', 'Tab'],
|
|
95
105
|
});
|
|
96
|
-
// TODO: do not hardcode locale here
|
|
97
106
|
const handleSelectDate = (date) => {
|
|
98
107
|
var _a;
|
|
99
|
-
onChange && onChange(date
|
|
108
|
+
onChange && onChange(date);
|
|
100
109
|
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
101
110
|
setIsOpen(false);
|
|
111
|
+
if (localRef.current) {
|
|
112
|
+
localRef.current.value = getStringDateValue(date);
|
|
113
|
+
}
|
|
102
114
|
};
|
|
103
115
|
const handleCalendarFocusLeave = () => {
|
|
104
116
|
setInitialTabIndices();
|
|
@@ -120,11 +132,12 @@ export const FieldDate = forwardRef((_a, ref) => {
|
|
|
120
132
|
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
121
133
|
}
|
|
122
134
|
}, [open]);
|
|
135
|
+
// TODO input ref - determine whether to update ref based on input/non-input state
|
|
123
136
|
useEffect(() => {
|
|
124
|
-
if (localRef.current) {
|
|
125
|
-
localRef.current.value = valueProp;
|
|
137
|
+
if (localRef.current && document.activeElement !== localRef.current) {
|
|
138
|
+
localRef.current.value = getStringDateValue(valueProp);
|
|
126
139
|
}
|
|
127
|
-
}, [valueProp]);
|
|
140
|
+
}, [getStringDateValue, valueProp]);
|
|
128
141
|
const onFocusByKeyboard = useCallback((e) => {
|
|
129
142
|
setInputFocus();
|
|
130
143
|
onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
|
|
@@ -146,10 +159,5 @@ export const FieldDate = forwardRef((_a, ref) => {
|
|
|
146
159
|
: {
|
|
147
160
|
open: showDropList,
|
|
148
161
|
onOpenChange: setIsOpen,
|
|
149
|
-
}), { content: _jsx("div", { className: styles.calendarWrapper, "data-size": size, children: _jsx(Calendar, { mode:
|
|
150
|
-
if (pickerAutofocus) {
|
|
151
|
-
element === null || element === void 0 ? void 0 : element.focus();
|
|
152
|
-
setPickerAutofocus(false);
|
|
153
|
-
}
|
|
154
|
-
}, onFocusLeave: handleCalendarFocusLeave, locale: locale, "data-test-id": 'field-date__calendar' }) }), children: _jsx(FieldContainerPrivate, { className: styles.container, size: size, validationState: fieldValidationState, disabled: disabled, readonly: readonly, variant: CONTAINER_VARIANT.SingleLine, focused: showDropList, inputRef: localRef, postfix: postfixButtons, children: _jsx(InputPrivate, { ref: mergeRefs(ref, localRef), "data-size": size, value: value || '', placeholder: mask, onChange: handleChange, onFocus: inputHandlers.onFocus, onMouseDown: inputHandlers.onMouseDown, onBlur: onBlur, onKeyDown: handleInputKeyDown, onClick: onClick, disabled: disabled, readonly: readonly, tabIndex: inputTabIndex, type: 'text', id: id, name: name, "data-test-id": 'field-date__input' }) }) })) })));
|
|
162
|
+
}), { content: _jsx("div", { className: styles.calendarWrapper, "data-size": size, children: _jsx(Calendar, { mode: mode, size: size, value: valueProp, showSeconds: showSeconds, onChangeValue: handleSelectDate, buildCellProps: buildCellProps, navigationStartRef: navigationStartRef, onFocusLeave: handleCalendarFocusLeave, locale: DEFAULT_LOCALE, "data-test-id": 'field-date__calendar', fitToContainer: false }) }), children: _jsx(FieldContainerPrivate, { className: styles.container, size: size, validationState: fieldValidationState, disabled: disabled, readonly: readonly, variant: CONTAINER_VARIANT.SingleLine, focused: showDropList, inputRef: localRef, postfix: postfixButtons, children: _jsx(InputPrivate, { ref: mergeRefs(ref, localRef), "data-size": size, value: value || '', placeholder: mask, onChange: handleChange, onFocus: inputHandlers.onFocus, onMouseDown: inputHandlers.onMouseDown, onBlur: onBlur, onKeyDown: handleInputKeyDown, onClick: onClick, disabled: disabled, readonly: readonly, tabIndex: inputTabIndex, type: 'text', id: id, name: name, "data-test-id": 'field-date__input' }) }) })) })));
|
|
155
163
|
});
|
|
@@ -21,5 +21,5 @@ type FieldSecureOwnProps = {
|
|
|
21
21
|
export type FieldSecureProps = WithSupportProps<FieldSecureOwnProps & InputProps & WrapperProps>;
|
|
22
22
|
export declare const FieldSecure: import("react").ForwardRefExoticComponent<{
|
|
23
23
|
'data-test-id'?: string;
|
|
24
|
-
} & import("react").AriaAttributes & FieldSecureOwnProps & Pick<Partial<InputPrivateProps>, "value" | "onChange"> & Pick<InputPrivateProps, "onFocus" | "onBlur" | "id" | "disabled" | "
|
|
24
|
+
} & import("react").AriaAttributes & FieldSecureOwnProps & Pick<Partial<InputPrivateProps>, "value" | "onChange"> & Pick<InputPrivateProps, "onFocus" | "onBlur" | "id" | "disabled" | "name" | "readonly" | "placeholder" | "autoComplete" | "maxLength"> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
25
25
|
export {};
|
|
@@ -27,9 +27,9 @@ export declare function useSearchInput({ value, onChange, defaultValue, selected
|
|
|
27
27
|
resetSearchOnOptionSelection?: boolean;
|
|
28
28
|
}): {
|
|
29
29
|
inputValue: string;
|
|
30
|
-
setInputValue: (value:
|
|
30
|
+
setInputValue: (value: string) => void;
|
|
31
31
|
prevInputValue: import("react").MutableRefObject<string>;
|
|
32
|
-
onInputValueChange: (value:
|
|
32
|
+
onInputValueChange: (value: string) => void;
|
|
33
33
|
updateInputValue: (selectedItem?: ItemWithId) => void;
|
|
34
34
|
};
|
|
35
35
|
export declare function useHandleDeleteItem(setValue: Handler): (item?: ItemWithId) => (e?: MouseEvent<HTMLButtonElement>) => void;
|
|
@@ -52,15 +52,21 @@ export function useButtons({ readonly, showClearButton, showCopyButton, size, on
|
|
|
52
52
|
return { postfixButtons, inputKeyDownNavigationHandler, buttonsRefs };
|
|
53
53
|
}
|
|
54
54
|
export function useSearchInput({ value, onChange, defaultValue, selectedOptionFormatter, resetSearchOnOptionSelection = true, }) {
|
|
55
|
-
const [inputValue = '',
|
|
55
|
+
const [inputValue = '', setInputValueState] = useValueControl({ value, onChange, defaultValue });
|
|
56
56
|
const prevInputValue = useRef(inputValue);
|
|
57
57
|
const updateInputValue = useCallback((selectedItem) => {
|
|
58
58
|
const newInputValue = selectedOptionFormatter(selectedItem);
|
|
59
59
|
if (resetSearchOnOptionSelection && (inputValue !== newInputValue || prevInputValue.current !== newInputValue)) {
|
|
60
|
-
|
|
60
|
+
setInputValueState(newInputValue);
|
|
61
61
|
prevInputValue.current = newInputValue;
|
|
62
62
|
}
|
|
63
|
-
}, [inputValue, resetSearchOnOptionSelection, selectedOptionFormatter,
|
|
63
|
+
}, [inputValue, resetSearchOnOptionSelection, selectedOptionFormatter, setInputValueState]);
|
|
64
|
+
const setInputValue = useCallback((value) => {
|
|
65
|
+
const updatedValue = prevInputValue.current && value.includes(prevInputValue.current)
|
|
66
|
+
? value.replace(prevInputValue.current, '')
|
|
67
|
+
: value;
|
|
68
|
+
setInputValueState(updatedValue);
|
|
69
|
+
}, [setInputValueState]);
|
|
64
70
|
return { inputValue, setInputValue, prevInputValue, onInputValueChange: setInputValue, updateInputValue };
|
|
65
71
|
}
|
|
66
72
|
export function useHandleDeleteItem(setValue) {
|
|
@@ -23,5 +23,5 @@ type FieldSliderOwnProps = {
|
|
|
23
23
|
export type FieldSliderProps = WithSupportProps<FieldSliderOwnProps & SliderProps & WrapperProps>;
|
|
24
24
|
export declare const FieldSlider: import("react").ForwardRefExoticComponent<{
|
|
25
25
|
'data-test-id'?: string;
|
|
26
|
-
} & import("react").AriaAttributes & FieldSliderOwnProps & Pick<InputPrivateProps, "onFocus" | "onBlur" | "id" | "disabled" | "
|
|
26
|
+
} & import("react").AriaAttributes & FieldSliderOwnProps & Pick<InputPrivateProps, "onFocus" | "onBlur" | "id" | "disabled" | "name" | "readonly"> & Pick<SliderComponentProps, "value" | "onChange" | "range" | "tipFormatter"> & Required<Pick<SliderComponentProps, "max" | "min" | "step" | "marks">> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
27
27
|
export {};
|
|
@@ -27,5 +27,5 @@ type FieldTextOwnProps = {
|
|
|
27
27
|
export type FieldTextProps = WithSupportProps<FieldTextOwnProps & InputProps & WrapperProps>;
|
|
28
28
|
export declare const FieldText: import("react").ForwardRefExoticComponent<{
|
|
29
29
|
'data-test-id'?: string;
|
|
30
|
-
} & import("react").AriaAttributes & FieldTextOwnProps & Pick<Partial<InputPrivateProps>, "value" | "onChange"> & Pick<InputPrivateProps, "onFocus" | "onBlur" | "id" | "disabled" | "
|
|
30
|
+
} & import("react").AriaAttributes & FieldTextOwnProps & Pick<Partial<InputPrivateProps>, "value" | "onChange"> & Pick<InputPrivateProps, "onFocus" | "onBlur" | "id" | "disabled" | "name" | "readonly" | "placeholder" | "autoComplete" | "maxLength"> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
31
31
|
export {};
|
|
@@ -26,5 +26,5 @@ type FieldTextAreaOwnProps = {
|
|
|
26
26
|
export type FieldTextAreaProps = WithSupportProps<FieldTextAreaOwnProps & InputProps & WrapperProps>;
|
|
27
27
|
export declare const FieldTextArea: import("react").ForwardRefExoticComponent<{
|
|
28
28
|
'data-test-id'?: string;
|
|
29
|
-
} & import("react").AriaAttributes & FieldTextAreaOwnProps & Pick<Partial<TextAreaProps>, "value"> & Pick<TextAreaProps, "onFocus" | "onBlur" | "id" | "disabled" | "
|
|
29
|
+
} & import("react").AriaAttributes & FieldTextAreaOwnProps & Pick<Partial<TextAreaProps>, "value"> & Pick<TextAreaProps, "onFocus" | "onBlur" | "id" | "disabled" | "name" | "readonly" | "placeholder" | "maxLength"> & WrapperProps & import("react").RefAttributes<HTMLTextAreaElement>>;
|
|
30
30
|
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TimePickerProps } from '@snack-uikit/calendar';
|
|
2
|
+
import { InputPrivateProps } from '@snack-uikit/input-private';
|
|
3
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
4
|
+
import { FieldDecoratorProps } from '../FieldDecorator';
|
|
5
|
+
type InputProps = Pick<InputPrivateProps, 'id' | 'name' | 'disabled' | 'readonly' | 'onFocus' | 'onBlur'>;
|
|
6
|
+
type WrapperProps = Pick<FieldDecoratorProps, 'className' | 'label' | 'labelTooltip' | 'required' | 'caption' | 'hint' | 'showHintIcon' | 'size' | 'validationState' | 'labelTooltipPlacement' | 'error'>;
|
|
7
|
+
type FieldTimeOwnProps = {
|
|
8
|
+
/** Открыт time-picker */
|
|
9
|
+
open?: boolean;
|
|
10
|
+
/** Колбек открытия пикера */
|
|
11
|
+
onOpenChange?(value: boolean): void;
|
|
12
|
+
/** Значение поля */
|
|
13
|
+
value?: TimePickerProps['value'];
|
|
14
|
+
/** Колбек смены значения */
|
|
15
|
+
onChange?: TimePickerProps['onChangeValue'];
|
|
16
|
+
/** Отображение кнопки копирования */
|
|
17
|
+
showCopyButton?: boolean;
|
|
18
|
+
/** Показывать ли секунды */
|
|
19
|
+
showSeconds?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Отображение кнопки Очистки поля
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
showClearButton?: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type FieldTimeProps = WithSupportProps<FieldTimeOwnProps & InputProps & WrapperProps>;
|
|
27
|
+
export declare const FieldTime: import("react").ForwardRefExoticComponent<{
|
|
28
|
+
'data-test-id'?: string;
|
|
29
|
+
} & import("react").AriaAttributes & FieldTimeOwnProps & InputProps & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import mergeRefs from 'merge-refs';
|
|
14
|
+
import { forwardRef, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
15
|
+
import { useUncontrolledProp } from 'uncontrollable';
|
|
16
|
+
import { TimePicker } from '@snack-uikit/calendar';
|
|
17
|
+
import { Dropdown } from '@snack-uikit/dropdown';
|
|
18
|
+
import { WatchSVG } from '@snack-uikit/icons';
|
|
19
|
+
import { ICON_SIZE, InputPrivate, runAfterRerender, SIZE, useButtonNavigation, useClearButton, } from '@snack-uikit/input-private';
|
|
20
|
+
import { extractSupportProps } from '@snack-uikit/utils';
|
|
21
|
+
import { CONTAINER_VARIANT, DEFAULT_LOCALE, SlotKey, TIME_MODES, VALIDATION_STATE } from '../../constants';
|
|
22
|
+
import { FieldContainerPrivate } from '../../helperComponents';
|
|
23
|
+
import { useCopyButton, useDateField, useFocusHandlers, useHandlers } from '../../hooks';
|
|
24
|
+
import { getValidationState } from '../../utils/getValidationState';
|
|
25
|
+
import { FieldDecorator } from '../FieldDecorator';
|
|
26
|
+
import styles from './styles.module.css';
|
|
27
|
+
const getStringTimeValue = (time, { showSeconds, locale }) => {
|
|
28
|
+
var _a, _b, _c;
|
|
29
|
+
if (!time) {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
const date = new Date();
|
|
33
|
+
date.setHours((_a = time.hours) !== null && _a !== void 0 ? _a : 0);
|
|
34
|
+
date.setMinutes((_b = time.minutes) !== null && _b !== void 0 ? _b : 0);
|
|
35
|
+
date.setSeconds((_c = time.seconds) !== null && _c !== void 0 ? _c : 0);
|
|
36
|
+
return date.toLocaleTimeString(locale, {
|
|
37
|
+
hour: 'numeric',
|
|
38
|
+
minute: 'numeric',
|
|
39
|
+
second: showSeconds ? 'numeric' : undefined,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
export const FieldTime = forwardRef((_a, ref) => {
|
|
43
|
+
var { id, name, value: valueProp, disabled = false, readonly = false, showCopyButton: showCopyButtonProp = true, showClearButton: showClearButtonProp = true, open, onOpenChange, onChange, onFocus, onBlur: onBlurProp, className, label, labelTooltip, labelTooltipPlacement, required = false, caption, hint, showHintIcon, showSeconds = true, size = SIZE.S, validationState = VALIDATION_STATE.Default, error } = _a, rest = __rest(_a, ["id", "name", "value", "disabled", "readonly", "showCopyButton", "showClearButton", "open", "onOpenChange", "onChange", "onFocus", "onBlur", "className", "label", "labelTooltip", "labelTooltipPlacement", "required", "caption", "hint", "showHintIcon", "showSeconds", "size", "validationState", "error"]);
|
|
44
|
+
const [isOpen, setIsOpen] = useUncontrolledProp(open, false, onOpenChange);
|
|
45
|
+
const localRef = useRef(null);
|
|
46
|
+
const clearButtonRef = useRef(null);
|
|
47
|
+
const copyButtonRef = useRef(null);
|
|
48
|
+
const calendarIconSize = size === SIZE.S ? ICON_SIZE.Xs : ICON_SIZE.S;
|
|
49
|
+
const showDropList = isOpen && !readonly && !disabled;
|
|
50
|
+
const showAdditionalButton = Boolean(valueProp && !disabled);
|
|
51
|
+
const showClearButton = showClearButtonProp && showAdditionalButton && !readonly;
|
|
52
|
+
const showCopyButton = showCopyButtonProp && showAdditionalButton && readonly;
|
|
53
|
+
const fieldValidationState = getValidationState({ validationState, error });
|
|
54
|
+
const navigationStartRef = useRef(null);
|
|
55
|
+
const checkForLeavingFocus = useCallback((event) => {
|
|
56
|
+
if (event.key === 'ArrowDown') {
|
|
57
|
+
setIsOpen(true);
|
|
58
|
+
setTimeout(() => { var _a; return (_a = navigationStartRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, 0);
|
|
59
|
+
}
|
|
60
|
+
}, [setIsOpen]);
|
|
61
|
+
const handleClear = useCallback(() => {
|
|
62
|
+
var _a, _b, _c;
|
|
63
|
+
onChange && onChange(undefined);
|
|
64
|
+
if ((_a = localRef.current) === null || _a === void 0 ? void 0 : _a.value) {
|
|
65
|
+
localRef.current.value = '';
|
|
66
|
+
}
|
|
67
|
+
if (required) {
|
|
68
|
+
(_b = localRef.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
69
|
+
setIsOpen(true);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
(_c = localRef.current) === null || _c === void 0 ? void 0 : _c.blur();
|
|
73
|
+
setIsOpen(false);
|
|
74
|
+
}
|
|
75
|
+
}, [onChange, required, setIsOpen]);
|
|
76
|
+
const valueToCopy = getStringTimeValue(valueProp, { showSeconds, locale: DEFAULT_LOCALE });
|
|
77
|
+
const clearButtonSettings = useClearButton({ clearButtonRef, showClearButton, size, onClear: handleClear });
|
|
78
|
+
const copyButtonSettings = useCopyButton({ copyButtonRef, showCopyButton, size, valueToCopy });
|
|
79
|
+
const calendarIcon = useMemo(() => ({
|
|
80
|
+
active: false,
|
|
81
|
+
show: true,
|
|
82
|
+
id: 'watchIcon',
|
|
83
|
+
render: props => (_jsx(WatchSVG, Object.assign({}, props, { size: calendarIconSize, className: styles.calendarIcon, "data-size": size }))),
|
|
84
|
+
}), [calendarIconSize, size]);
|
|
85
|
+
const memorizedButtons = useMemo(() => [clearButtonSettings, copyButtonSettings, calendarIcon], [clearButtonSettings, copyButtonSettings, calendarIcon]);
|
|
86
|
+
const { value, handleChange, handleClick: timeInputClickHandler, handleKeyDown: timeInputKeyDownHandler, handleBlur: timeInputBlurHandler, mask, setInputFocus, } = useDateField({
|
|
87
|
+
inputRef: localRef,
|
|
88
|
+
onChange,
|
|
89
|
+
readonly,
|
|
90
|
+
locale: DEFAULT_LOCALE,
|
|
91
|
+
setIsOpen,
|
|
92
|
+
mode: showSeconds ? TIME_MODES.FullTime : TIME_MODES.NoSeconds,
|
|
93
|
+
showSeconds,
|
|
94
|
+
});
|
|
95
|
+
const setInputFocusFromButtons = useCallback(() => setInputFocus(SlotKey.Seconds), [setInputFocus]);
|
|
96
|
+
const { postfixButtons, inputTabIndex, onInputKeyDown: navigationInputKeyDownHandler, setInitialTabIndices, } = useButtonNavigation({
|
|
97
|
+
setInputFocus: setInputFocusFromButtons,
|
|
98
|
+
inputRef: localRef,
|
|
99
|
+
postfixButtons: memorizedButtons,
|
|
100
|
+
onButtonKeyDown: checkForLeavingFocus,
|
|
101
|
+
readonly,
|
|
102
|
+
submitKeys: ['Enter', 'Space', 'Tab'],
|
|
103
|
+
});
|
|
104
|
+
const handleSelectTime = (time) => {
|
|
105
|
+
var _a;
|
|
106
|
+
onChange && onChange(time);
|
|
107
|
+
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
108
|
+
setIsOpen(false);
|
|
109
|
+
if (localRef.current) {
|
|
110
|
+
localRef.current.value = getStringTimeValue(time, { showSeconds, locale: DEFAULT_LOCALE });
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const handleCalendarFocusLeave = () => {
|
|
114
|
+
setInitialTabIndices();
|
|
115
|
+
// TODO: find out why it works not as expected (focus is moved to the next element instead of the focused one)
|
|
116
|
+
// maybe floating-ui causes the problem
|
|
117
|
+
runAfterRerender(() => {
|
|
118
|
+
setInputFocus(SlotKey.Hours);
|
|
119
|
+
setIsOpen(false);
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
const handleInputKeyDown = useHandlers([
|
|
123
|
+
checkForLeavingFocus,
|
|
124
|
+
timeInputKeyDownHandler,
|
|
125
|
+
navigationInputKeyDownHandler,
|
|
126
|
+
]);
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
var _a;
|
|
129
|
+
if (open) {
|
|
130
|
+
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
131
|
+
}
|
|
132
|
+
}, [open]);
|
|
133
|
+
// TODO input ref - determine whether to update ref based on input/non-input state
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (localRef.current && document.activeElement !== localRef.current) {
|
|
136
|
+
localRef.current.value = getStringTimeValue(valueProp, { showSeconds, locale: DEFAULT_LOCALE });
|
|
137
|
+
}
|
|
138
|
+
}, [showSeconds, valueProp]);
|
|
139
|
+
const onFocusByKeyboard = useCallback((e) => {
|
|
140
|
+
setInputFocus();
|
|
141
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
|
|
142
|
+
}, [onFocus, setInputFocus]);
|
|
143
|
+
const inputHandlers = useFocusHandlers({
|
|
144
|
+
onFocusByClick: onFocus,
|
|
145
|
+
onFocusByKeyboard,
|
|
146
|
+
});
|
|
147
|
+
const onBlur = useHandlers([timeInputBlurHandler, inputHandlers.onBlur, onBlurProp]);
|
|
148
|
+
const onClick = useCallback((e) => {
|
|
149
|
+
timeInputClickHandler();
|
|
150
|
+
if (isOpen) {
|
|
151
|
+
// stop the event because want picker to stay opened
|
|
152
|
+
e.stopPropagation();
|
|
153
|
+
}
|
|
154
|
+
}, [timeInputClickHandler, isOpen]);
|
|
155
|
+
return (_jsx(FieldDecorator, Object.assign({ className: className, label: label, labelTooltip: labelTooltip, labelTooltipPlacement: labelTooltipPlacement, labelFor: id, required: required, caption: caption, hint: hint, disabled: disabled, readonly: readonly, showHintIcon: showHintIcon, size: size, error: error, validationState: fieldValidationState }, extractSupportProps(rest), { children: _jsx(Dropdown, Object.assign({ trigger: 'click', triggerClassName: styles.triggerClassName, widthStrategy: 'auto' }, (readonly || disabled
|
|
156
|
+
? { open: false }
|
|
157
|
+
: {
|
|
158
|
+
open: showDropList,
|
|
159
|
+
onOpenChange: setIsOpen,
|
|
160
|
+
}), { content: _jsx(TimePicker, { size: size, value: valueProp, onChangeValue: handleSelectTime, navigationStartRef: navigationStartRef, onFocusLeave: handleCalendarFocusLeave, "data-test-id": 'field-time__timepicker', fitToContainer: false, showSeconds: showSeconds }), children: _jsx(FieldContainerPrivate, { className: styles.container, size: size, validationState: fieldValidationState, disabled: disabled, readonly: readonly, variant: CONTAINER_VARIANT.SingleLine, focused: showDropList, inputRef: localRef, postfix: postfixButtons, children: _jsx(InputPrivate, { ref: mergeRefs(ref, localRef), "data-size": size, value: value || '', placeholder: mask, onChange: handleChange, onFocus: inputHandlers.onFocus, onMouseDown: inputHandlers.onMouseDown, onBlur: onBlur, onKeyDown: handleInputKeyDown, onClick: onClick, disabled: disabled, readonly: readonly, tabIndex: inputTabIndex, type: 'text', id: id, name: name, "data-test-id": 'field-time__input' }) }) })) })));
|
|
161
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FieldTime';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FieldTime';
|