@gravity-ui/date-components 2.4.0 → 2.6.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/dist/cjs/components/Calendar/Calendar.js +1 -0
- package/dist/cjs/components/CalendarView/CalendarView.js +1 -0
- package/dist/cjs/components/DateField/DateField.js +5 -3
- package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.d.ts +2 -0
- package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.js +1 -0
- package/dist/cjs/components/DateField/hooks/useDateFieldState.js +1 -1
- package/dist/cjs/components/DateField/utils.d.ts +1 -2
- package/dist/cjs/components/DateField/utils.js +6 -17
- package/dist/cjs/components/DatePicker/DatePicker.d.ts +5 -2
- package/dist/cjs/components/DatePicker/DatePicker.js +5 -3
- package/dist/cjs/components/DatePicker/MobileCalendar.js +1 -0
- package/dist/cjs/components/DatePicker/hooks/datePickerStateFactory.d.ts +7 -3
- package/dist/cjs/components/DatePicker/hooks/datePickerStateFactory.js +7 -6
- package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.js +33 -6
- package/dist/cjs/components/HiddenInput/HiddenInput.d.ts +14 -0
- package/dist/cjs/components/HiddenInput/HiddenInput.js +37 -0
- package/dist/cjs/components/RangeCalendar/RangeCalendar.js +1 -0
- package/dist/cjs/components/RangeDateField/RangeDateField.js +6 -1
- package/dist/cjs/components/RangeDatePicker/RangeDatePicker.js +5 -1
- package/dist/cjs/components/RelativeDateField/RelativeDateField.js +5 -4
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.js +2 -8
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js +6 -3
- package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.d.ts +2 -2
- package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +15 -2
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +1 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.js +1 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.js +1 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.js +1 -0
- package/dist/cjs/components/types/datePicker.d.ts +8 -0
- package/dist/cjs/components/types/inputs.d.ts +5 -0
- package/dist/cjs/components/utils/mergeProps.js +3 -3
- package/dist/cjs/components/utils/validation/datePicker.js +2 -2
- package/dist/esm/components/Calendar/Calendar.js +1 -0
- package/dist/esm/components/CalendarView/CalendarView.js +1 -0
- package/dist/esm/components/DateField/DateField.js +5 -3
- package/dist/esm/components/DateField/hooks/useBaseDateFieldState.d.ts +2 -0
- package/dist/esm/components/DateField/hooks/useBaseDateFieldState.js +1 -0
- package/dist/esm/components/DateField/hooks/useDateFieldState.js +1 -1
- package/dist/esm/components/DateField/utils.d.ts +1 -2
- package/dist/esm/components/DateField/utils.js +5 -15
- package/dist/esm/components/DatePicker/DatePicker.d.ts +5 -2
- package/dist/esm/components/DatePicker/DatePicker.js +5 -3
- package/dist/esm/components/DatePicker/MobileCalendar.js +1 -0
- package/dist/esm/components/DatePicker/hooks/datePickerStateFactory.d.ts +7 -3
- package/dist/esm/components/DatePicker/hooks/datePickerStateFactory.js +7 -6
- package/dist/esm/components/DatePicker/hooks/useDatePickerProps.js +33 -6
- package/dist/esm/components/HiddenInput/HiddenInput.d.ts +14 -0
- package/dist/esm/components/HiddenInput/HiddenInput.js +31 -0
- package/dist/esm/components/RangeCalendar/RangeCalendar.js +1 -0
- package/dist/esm/components/RangeDateField/RangeDateField.js +7 -2
- package/dist/esm/components/RangeDatePicker/RangeDatePicker.js +5 -1
- package/dist/esm/components/RelativeDateField/RelativeDateField.js +5 -4
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.js +3 -11
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js +6 -3
- package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.d.ts +2 -2
- package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +15 -2
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +1 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.js +1 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.js +1 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.js +1 -0
- package/dist/esm/components/types/datePicker.d.ts +8 -0
- package/dist/esm/components/types/inputs.d.ts +5 -0
- package/dist/esm/components/utils/mergeProps.js +3 -3
- package/dist/esm/components/utils/validation/datePicker.js +2 -2
- package/package.json +26 -19
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
'use client';
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.DateField = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
@@ -6,6 +7,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
6
7
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
7
8
|
const uikit_1 = require("@gravity-ui/uikit");
|
|
8
9
|
const cn_1 = require("../../utils/cn");
|
|
10
|
+
const HiddenInput_1 = require("../HiddenInput/HiddenInput");
|
|
9
11
|
const useDateFieldProps_1 = require("./hooks/useDateFieldProps");
|
|
10
12
|
const useDateFieldState_1 = require("./hooks/useDateFieldState");
|
|
11
13
|
require("./DateField.css");
|
|
@@ -20,8 +22,8 @@ function DateField(_a) {
|
|
|
20
22
|
setActive(isFocusWithin);
|
|
21
23
|
},
|
|
22
24
|
});
|
|
23
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: b(null, className), style: props.style }, focusWithinProps, { children: [(0, jsx_runtime_1.jsx)(uikit_1.TextInput, Object.assign({}, inputProps, { value: state.isEmpty && !isActive && props.placeholder ? '' : inputProps.value })), (0, jsx_runtime_1.jsx)(
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: b(null, className), style: props.style }, focusWithinProps, { children: [(0, jsx_runtime_1.jsx)(uikit_1.TextInput, Object.assign({}, inputProps, { value: state.isEmpty && !isActive && props.placeholder ? '' : inputProps.value })), (0, jsx_runtime_1.jsx)(HiddenInput_1.HiddenInput, { name: props.name, value: state.value, toStringValue: (value) => { var _a; return (_a = value === null || value === void 0 ? void 0 : value.toISOString()) !== null && _a !== void 0 ? _a : ''; }, onReset: (value) => {
|
|
26
|
+
state.setDate(value);
|
|
27
|
+
}, disabled: state.disabled, form: props.form })] })));
|
|
26
28
|
}
|
|
27
29
|
exports.DateField = DateField;
|
|
@@ -37,6 +37,8 @@ export type DateFieldState<T = DateTime> = {
|
|
|
37
37
|
displayValue: T;
|
|
38
38
|
/** Sets the field's value. */
|
|
39
39
|
setValue: (value: T) => void;
|
|
40
|
+
/** Sets the date value. */
|
|
41
|
+
setDate: (value: T | null) => void;
|
|
40
42
|
/** Formatted value */
|
|
41
43
|
text: string;
|
|
42
44
|
/** Whether the field is read only. */
|
|
@@ -139,7 +139,7 @@ function useDateFieldState(props) {
|
|
|
139
139
|
}).timeZone(timeZone);
|
|
140
140
|
}
|
|
141
141
|
function setValueFromString(str) {
|
|
142
|
-
const date = (0, utils_1.parseDateFromString)(str,
|
|
142
|
+
const date = (0, utils_1.parseDateFromString)(str, format, timeZone);
|
|
143
143
|
if ((0, date_utils_1.isValid)(date)) {
|
|
144
144
|
handleUpdateDate(date);
|
|
145
145
|
return true;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
2
|
import type { DateFieldSection, DateFieldSectionType, DateFieldSectionWithoutPosition } from './types';
|
|
3
3
|
export declare const EDITABLE_SEGMENTS: Partial<Record<DateFieldSectionType, boolean>>;
|
|
4
|
-
export declare function expandFormat(format: string): string;
|
|
5
4
|
export declare function getSectionLimits(section: DateFieldSectionWithoutPosition, date: DateTime): {
|
|
6
5
|
minValue: number;
|
|
7
6
|
maxValue: number;
|
|
@@ -9,7 +8,7 @@ export declare function getSectionLimits(section: DateFieldSectionWithoutPositio
|
|
|
9
8
|
minValue?: undefined;
|
|
10
9
|
maxValue?: undefined;
|
|
11
10
|
};
|
|
12
|
-
export declare function getSectionValue(
|
|
11
|
+
export declare function getSectionValue(section: DateFieldSectionWithoutPosition, date: DateTime): number | undefined;
|
|
13
12
|
export declare function getDurationUnitFromSectionType(type: DateFieldSectionType): "year" | "month" | "day" | "hour" | "minute" | "second" | "date";
|
|
14
13
|
export declare function addSegment(section: DateFieldSection, date: DateTime, amount: number): DateTime;
|
|
15
14
|
export declare function setSegment(section: DateFieldSection, date: DateTime, amount: number): DateTime;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useFormatSections = exports.isAllSegmentsValid = exports.parseDateFromString = exports.formatSections = exports.getCurrentEditableSectionIndex = exports.toEditableSection = exports.isEditableSection = exports.getEditableSections = exports.cleanString = exports.splitFormatIntoSections = exports.setSegment = exports.addSegment = exports.getDurationUnitFromSectionType = exports.getSectionValue = exports.getSectionLimits = exports.
|
|
3
|
+
exports.useFormatSections = exports.isAllSegmentsValid = exports.parseDateFromString = exports.formatSections = exports.getCurrentEditableSectionIndex = exports.toEditableSection = exports.isEditableSection = exports.getEditableSections = exports.cleanString = exports.splitFormatIntoSections = exports.setSegment = exports.addSegment = exports.getDurationUnitFromSectionType = exports.getSectionValue = exports.getSectionLimits = exports.EDITABLE_SEGMENTS = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const date_utils_1 = require("@gravity-ui/date-utils");
|
|
@@ -16,17 +16,6 @@ exports.EDITABLE_SEGMENTS = {
|
|
|
16
16
|
dayPeriod: true,
|
|
17
17
|
weekday: true,
|
|
18
18
|
};
|
|
19
|
-
function expandFormat(format) {
|
|
20
|
-
const localeFormats = date_utils_1.settings.getLocaleData().formats;
|
|
21
|
-
const getShortLocalizedFormatFromLongLocalizedFormat = (formatBis) => formatBis.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (_, escapeSequence, localizedFormat) => escapeSequence || localizedFormat.slice(1));
|
|
22
|
-
return format.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, (_, escapeSequence, localizedFormat) => {
|
|
23
|
-
const LongLocalizedFormat = localizedFormat && localizedFormat.toUpperCase();
|
|
24
|
-
return (escapeSequence ||
|
|
25
|
-
localeFormats[localizedFormat] ||
|
|
26
|
-
getShortLocalizedFormatFromLongLocalizedFormat(localeFormats[LongLocalizedFormat]));
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
exports.expandFormat = expandFormat;
|
|
30
19
|
const escapedCharacters = { start: '[', end: ']' };
|
|
31
20
|
const formatTokenMap = {
|
|
32
21
|
// Year
|
|
@@ -148,13 +137,13 @@ function getSectionLimits(section, date) {
|
|
|
148
137
|
return {};
|
|
149
138
|
}
|
|
150
139
|
exports.getSectionLimits = getSectionLimits;
|
|
151
|
-
function getSectionValue(
|
|
152
|
-
const type =
|
|
140
|
+
function getSectionValue(section, date) {
|
|
141
|
+
const type = section.type;
|
|
153
142
|
switch (type) {
|
|
154
143
|
case 'year': {
|
|
155
|
-
return isFourDigitYearFormat(
|
|
144
|
+
return isFourDigitYearFormat(section.format)
|
|
156
145
|
? date.year()
|
|
157
|
-
: Number(date.format(
|
|
146
|
+
: Number(date.format(section.format));
|
|
158
147
|
}
|
|
159
148
|
case 'month':
|
|
160
149
|
case 'hour':
|
|
@@ -329,7 +318,7 @@ function getSectionPlaceholder(sectionConfig, currentTokenValue) {
|
|
|
329
318
|
}
|
|
330
319
|
function splitFormatIntoSections(format) {
|
|
331
320
|
const sections = [];
|
|
332
|
-
const expandedFormat = expandFormat(format);
|
|
321
|
+
const expandedFormat = (0, date_utils_1.expandFormat)(format);
|
|
333
322
|
let currentTokenValue = '';
|
|
334
323
|
let isSeparator = false;
|
|
335
324
|
let isInEscapeBoundary = false;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { DateTime } from '@gravity-ui/date-utils';
|
|
3
3
|
import type { CalendarProps } from '../Calendar';
|
|
4
|
-
import type { AccessibilityProps,
|
|
4
|
+
import type { AccessibilityProps, DomProps, FocusableProps, InputDOMProps, KeyboardEvents, StyleProps, TextInputProps } from '../types';
|
|
5
|
+
import type { DatePickerStateOptions } from './hooks/datePickerStateFactory';
|
|
5
6
|
import './DatePicker.css';
|
|
6
|
-
export interface DatePickerProps<T = DateTime> extends
|
|
7
|
+
export interface DatePickerProps<T = DateTime> extends DatePickerStateOptions<T>, TextInputProps, FocusableProps, KeyboardEvents, DomProps, InputDOMProps, StyleProps, AccessibilityProps {
|
|
7
8
|
children?: (props: CalendarProps<T>) => React.ReactNode;
|
|
9
|
+
disablePortal?: boolean;
|
|
10
|
+
disableFocusTrap?: boolean;
|
|
8
11
|
}
|
|
9
12
|
export declare function DatePicker({ className, ...props }: DatePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
'use client';
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.DatePicker = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
@@ -8,6 +9,7 @@ const icons_1 = require("@gravity-ui/icons");
|
|
|
8
9
|
const uikit_1 = require("@gravity-ui/uikit");
|
|
9
10
|
const Calendar_1 = require("../Calendar");
|
|
10
11
|
const DateField_1 = require("../DateField");
|
|
12
|
+
const HiddenInput_1 = require("../HiddenInput/HiddenInput");
|
|
11
13
|
const MobileCalendar_1 = require("./MobileCalendar");
|
|
12
14
|
const StubButton_1 = require("./StubButton");
|
|
13
15
|
const useDatePickerProps_1 = require("./hooks/useDatePickerProps");
|
|
@@ -21,8 +23,8 @@ function DatePicker(_a) {
|
|
|
21
23
|
const { groupProps, fieldProps, calendarButtonProps, popupProps, calendarProps, timeInputProps } = (0, useDatePickerProps_1.useDatePickerProps)(state, props);
|
|
22
24
|
const isMobile = (0, uikit_1.useMobile)();
|
|
23
25
|
const isOnlyTime = state.hasTime && !state.hasDate;
|
|
24
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, utils_1.b)(null, className) }, groupProps, { children: [isMobile ? ((0, jsx_runtime_1.jsx)(MobileCalendar_1.MobileCalendar, { props: props, state: state })) : (!isOnlyTime && ((0, jsx_runtime_1.jsx)("div", { ref: anchorRef, className: (0, utils_1.b)('popup-anchor'), children: (0, jsx_runtime_1.jsx)(uikit_1.Popup, Object.assign({ anchorRef: anchorRef }, popupProps, { children: (0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.b)('popup-content'), children: [typeof props.children === 'function' ? (props.children(calendarProps)) : ((0, jsx_runtime_1.jsx)(Calendar_1.Calendar, Object.assign({}, calendarProps))), state.hasTime && ((0, jsx_runtime_1.jsx)("div", { className: (0, utils_1.b)('time-field-wrapper'), children: (0, jsx_runtime_1.jsx)(DateField_1.DateField, Object.assign({}, timeInputProps)) }))] }) })) }))), (0, jsx_runtime_1.jsx)(uikit_1.TextInput, Object.assign({}, fieldProps, { className: (0, utils_1.b)('field', { mobile: isMobile }), hasClear: !isMobile && fieldProps.hasClear, endContent: (0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [!isMobile && !isOnlyTime && ((0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, calendarButtonProps, { children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Calendar }) }))), !isMobile && isOnlyTime && ((0, jsx_runtime_1.jsx)(StubButton_1.StubButton, { size: calendarButtonProps.size, icon: icons_1.Clock })), isMobile && ((0, jsx_runtime_1.jsx)(StubButton_1.StubButton, { size: calendarButtonProps.size, icon: isOnlyTime ? icons_1.Clock : icons_1.Calendar }))] }) })), (0, jsx_runtime_1.jsx)(
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, utils_1.b)(null, className) }, groupProps, { children: [isMobile ? ((0, jsx_runtime_1.jsx)(MobileCalendar_1.MobileCalendar, { props: props, state: state })) : (!isOnlyTime && ((0, jsx_runtime_1.jsx)("div", { ref: anchorRef, className: (0, utils_1.b)('popup-anchor'), children: (0, jsx_runtime_1.jsx)(uikit_1.Popup, Object.assign({ anchorRef: anchorRef }, popupProps, { children: (0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.b)('popup-content'), children: [typeof props.children === 'function' ? (props.children(calendarProps)) : ((0, jsx_runtime_1.jsx)(Calendar_1.Calendar, Object.assign({}, calendarProps))), state.hasTime && ((0, jsx_runtime_1.jsx)("div", { className: (0, utils_1.b)('time-field-wrapper'), children: (0, jsx_runtime_1.jsx)(DateField_1.DateField, Object.assign({}, timeInputProps)) }))] }) })) }))), (0, jsx_runtime_1.jsx)(uikit_1.TextInput, Object.assign({}, fieldProps, { className: (0, utils_1.b)('field', { mobile: isMobile }), hasClear: !isMobile && fieldProps.hasClear, endContent: (0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [!isMobile && !isOnlyTime && ((0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, calendarButtonProps, { children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Calendar }) }))), !isMobile && isOnlyTime && ((0, jsx_runtime_1.jsx)(StubButton_1.StubButton, { size: calendarButtonProps.size, icon: icons_1.Clock })), isMobile && ((0, jsx_runtime_1.jsx)(StubButton_1.StubButton, { size: calendarButtonProps.size, icon: isOnlyTime ? icons_1.Clock : icons_1.Calendar }))] }) })), (0, jsx_runtime_1.jsx)(HiddenInput_1.HiddenInput, { name: props.name, value: state.value, toStringValue: (value) => { var _a; return (_a = value === null || value === void 0 ? void 0 : value.toISOString()) !== null && _a !== void 0 ? _a : ''; }, onReset: (value) => {
|
|
27
|
+
state.setValue(value);
|
|
28
|
+
}, disabled: state.disabled, form: props.form })] })));
|
|
27
29
|
}
|
|
28
30
|
exports.DatePicker = DatePicker;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
2
|
import type { DateFieldState } from '../../DateField';
|
|
3
|
-
import type { DateFieldBase } from '../../types';
|
|
3
|
+
import type { DateFieldBase, PopupTriggerProps } from '../../types';
|
|
4
|
+
type OpenChangeReason = 'EscapeKeyDown' | 'FocusOut' | 'ClickOutside' | 'ValueSelected' | 'TriggerButtonClick' | 'ShortcutKeyDown';
|
|
4
5
|
export interface DatePickerState<T = DateTime> {
|
|
5
6
|
/** The currently selected date. */
|
|
6
7
|
value: T | null;
|
|
@@ -36,7 +37,7 @@ export interface DatePickerState<T = DateTime> {
|
|
|
36
37
|
/** Whether the calendar popover is currently open. */
|
|
37
38
|
isOpen: boolean;
|
|
38
39
|
/** Sets whether the calendar popover is open. */
|
|
39
|
-
setOpen: (isOpen: boolean) => void;
|
|
40
|
+
setOpen: (isOpen: boolean, reason: OpenChangeReason) => void;
|
|
40
41
|
dateFieldState: DateFieldState<T>;
|
|
41
42
|
}
|
|
42
43
|
export interface DatePickerStateFactoryOptions<T, O extends DateFieldBase<T>> {
|
|
@@ -46,4 +47,7 @@ export interface DatePickerStateFactoryOptions<T, O extends DateFieldBase<T>> {
|
|
|
46
47
|
getDateTime: (date: T | null | undefined) => DateTime | undefined;
|
|
47
48
|
useDateFieldState: (props: O) => DateFieldState<T>;
|
|
48
49
|
}
|
|
49
|
-
export
|
|
50
|
+
export interface DatePickerStateOptions<T> extends DateFieldBase<T>, PopupTriggerProps<[OpenChangeReason]> {
|
|
51
|
+
}
|
|
52
|
+
export declare function datePickerStateFactory<T, O extends DatePickerStateOptions<T>>({ getPlaceholderTime, mergeDateTime, setTimezone, getDateTime, useDateFieldState, }: DatePickerStateFactoryOptions<T, O>): (props: O) => DatePickerState<T>;
|
|
53
|
+
export {};
|
|
@@ -7,10 +7,11 @@ const uikit_1 = require("@gravity-ui/uikit");
|
|
|
7
7
|
const useDefaultTimeZone_1 = require("../../utils/useDefaultTimeZone");
|
|
8
8
|
function datePickerStateFactory({ getPlaceholderTime, mergeDateTime, setTimezone, getDateTime, useDateFieldState, }) {
|
|
9
9
|
return function useDatePickerState(props) {
|
|
10
|
-
var _a;
|
|
10
|
+
var _a, _b;
|
|
11
11
|
const { disabled, readOnly } = props;
|
|
12
|
-
const [isOpen,
|
|
13
|
-
const
|
|
12
|
+
const [isOpen, _setOpen] = (0, uikit_1.useControlledState)(props.open, (_a = props.defaultOpen) !== null && _a !== void 0 ? _a : false, props.onOpenChange);
|
|
13
|
+
const setOpen = _setOpen;
|
|
14
|
+
const [value, setValue] = (0, uikit_1.useControlledState)(props.value, (_b = props.defaultValue) !== null && _b !== void 0 ? _b : null, props.onUpdate);
|
|
14
15
|
const [selectedDateInner, setSelectedDate] = react_1.default.useState(null);
|
|
15
16
|
const [selectedTimeInner, setSelectedTime] = react_1.default.useState(null);
|
|
16
17
|
const inputTimeZone = (0, useDefaultTimeZone_1.useDefaultTimeZone)(getDateTime(props.value) || getDateTime(props.defaultValue) || props.placeholderValue);
|
|
@@ -65,7 +66,7 @@ function datePickerStateFactory({ getPlaceholderTime, mergeDateTime, setTimezone
|
|
|
65
66
|
commitValue(newValue, newValue);
|
|
66
67
|
}
|
|
67
68
|
if (shouldClose) {
|
|
68
|
-
setOpen(false);
|
|
69
|
+
setOpen(false, 'ValueSelected');
|
|
69
70
|
}
|
|
70
71
|
};
|
|
71
72
|
const selectTime = (newValue) => {
|
|
@@ -108,11 +109,11 @@ function datePickerStateFactory({ getPlaceholderTime, mergeDateTime, setTimezone
|
|
|
108
109
|
timeFormat,
|
|
109
110
|
timeZone,
|
|
110
111
|
isOpen,
|
|
111
|
-
setOpen(newIsOpen) {
|
|
112
|
+
setOpen(newIsOpen, reason) {
|
|
112
113
|
if (!newIsOpen && !value && selectedDate && dateFieldState.hasTime) {
|
|
113
114
|
commitValue(selectedDate, selectedTime || getPlaceholderTime(props.placeholderValue, props.timeZone));
|
|
114
115
|
}
|
|
115
|
-
setOpen(newIsOpen);
|
|
116
|
+
setOpen(newIsOpen, reason);
|
|
116
117
|
},
|
|
117
118
|
dateFieldState,
|
|
118
119
|
};
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useDatePickerProps = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const date_utils_1 = require("@gravity-ui/date-utils");
|
|
6
7
|
const uikit_1 = require("@gravity-ui/uikit");
|
|
7
8
|
const DateField_1 = require("../../DateField");
|
|
8
9
|
const getButtonSizeForInput_1 = require("../../utils/getButtonSizeForInput");
|
|
@@ -12,13 +13,31 @@ const utils_1 = require("../utils");
|
|
|
12
13
|
function useDatePickerProps(state, _a) {
|
|
13
14
|
var { onFocus, onBlur } = _a, props = tslib_1.__rest(_a, ["onFocus", "onBlur"]);
|
|
14
15
|
const [isActive, setActive] = react_1.default.useState(false);
|
|
16
|
+
const [focusedDate, setFocusedDate] = react_1.default.useState((0, date_utils_1.isDateTime)(state.dateFieldState.displayValue)
|
|
17
|
+
? state.dateFieldState.displayValue
|
|
18
|
+
: state.dateFieldState.displayValue.start);
|
|
19
|
+
const [prevDateValue, setPrevDateValue] = react_1.default.useState(state.dateFieldState.displayValue);
|
|
20
|
+
if ((0, date_utils_1.isDateTime)(state.dateFieldState.displayValue)) {
|
|
21
|
+
if (!state.dateFieldState.displayValue.isSame(prevDateValue, 'day')) {
|
|
22
|
+
setPrevDateValue(state.dateFieldState.displayValue);
|
|
23
|
+
setFocusedDate(state.dateFieldState.displayValue);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else if (!state.dateFieldState.displayValue.start.isSame(prevDateValue.start, 'day')) {
|
|
27
|
+
setPrevDateValue(state.dateFieldState.displayValue);
|
|
28
|
+
setFocusedDate(state.dateFieldState.displayValue.start);
|
|
29
|
+
}
|
|
30
|
+
else if (!state.dateFieldState.displayValue.end.isSame(prevDateValue.end, 'day')) {
|
|
31
|
+
setPrevDateValue(state.dateFieldState.displayValue);
|
|
32
|
+
setFocusedDate(state.dateFieldState.displayValue.end);
|
|
33
|
+
}
|
|
15
34
|
const { focusWithinProps } = (0, uikit_1.useFocusWithin)({
|
|
16
35
|
onFocusWithin: onFocus,
|
|
17
36
|
onBlurWithin: onBlur,
|
|
18
37
|
onFocusWithinChange(isFocusWithin) {
|
|
19
38
|
setActive(isFocusWithin);
|
|
20
39
|
if (!isFocusWithin) {
|
|
21
|
-
state.setOpen(false);
|
|
40
|
+
state.setOpen(false, 'FocusOut');
|
|
22
41
|
}
|
|
23
42
|
},
|
|
24
43
|
});
|
|
@@ -40,7 +59,7 @@ function useDatePickerProps(state, _a) {
|
|
|
40
59
|
if (!onlyTime && e.altKey && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) {
|
|
41
60
|
e.preventDefault();
|
|
42
61
|
e.stopPropagation();
|
|
43
|
-
state.setOpen(true);
|
|
62
|
+
state.setOpen(true, 'ShortcutKeyDown');
|
|
44
63
|
}
|
|
45
64
|
} }),
|
|
46
65
|
fieldProps: (0, mergeProps_1.mergeProps)(inputProps, state.dateFieldState.isEmpty && !isActive && props.placeholder
|
|
@@ -58,25 +77,31 @@ function useDatePickerProps(state, _a) {
|
|
|
58
77
|
view: 'flat-secondary',
|
|
59
78
|
onClick: () => {
|
|
60
79
|
setActive(true);
|
|
61
|
-
state.setOpen(!state.isOpen);
|
|
80
|
+
state.setOpen(!state.isOpen, 'TriggerButtonClick');
|
|
62
81
|
},
|
|
63
82
|
},
|
|
64
83
|
popupProps: {
|
|
65
84
|
open: state.isOpen,
|
|
66
85
|
onEscapeKeyDown: () => {
|
|
67
|
-
state.setOpen(false);
|
|
86
|
+
state.setOpen(false, 'EscapeKeyDown');
|
|
68
87
|
focusInput();
|
|
69
88
|
},
|
|
70
89
|
onOutsideClick: (e) => {
|
|
71
90
|
var _a;
|
|
72
91
|
if (e.target !== calendarButtonRef.current) {
|
|
73
|
-
state.setOpen(false);
|
|
92
|
+
state.setOpen(false, 'ClickOutside');
|
|
74
93
|
}
|
|
75
94
|
if (e.target && ((_a = groupRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
|
|
76
95
|
focusInput();
|
|
77
96
|
}
|
|
78
97
|
},
|
|
79
|
-
|
|
98
|
+
onTransitionExited: () => {
|
|
99
|
+
setFocusedDate((0, date_utils_1.isDateTime)(state.dateFieldState.displayValue)
|
|
100
|
+
? state.dateFieldState.displayValue
|
|
101
|
+
: state.dateFieldState.displayValue.start);
|
|
102
|
+
},
|
|
103
|
+
focusTrap: !props.disableFocusTrap,
|
|
104
|
+
disablePortal: props.disablePortal,
|
|
80
105
|
},
|
|
81
106
|
calendarProps: {
|
|
82
107
|
ref: calendarRef,
|
|
@@ -95,6 +120,8 @@ function useDatePickerProps(state, _a) {
|
|
|
95
120
|
maxValue: props.maxValue,
|
|
96
121
|
isDateUnavailable: props.isDateUnavailable,
|
|
97
122
|
timeZone: state.timeZone,
|
|
123
|
+
focusedValue: focusedDate,
|
|
124
|
+
onFocusUpdate: setFocusedDate,
|
|
98
125
|
},
|
|
99
126
|
timeInputProps: {
|
|
100
127
|
value: state.timeValue,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface HiddenInputProps<T> {
|
|
2
|
+
value: T;
|
|
3
|
+
onReset?: (value: T) => void;
|
|
4
|
+
toStringValue?: (value: T) => string;
|
|
5
|
+
name?: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
form?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function HiddenInput<T>({ name, value, onReset, form, disabled, toStringValue, }: HiddenInputProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
export declare function useFormResetHandler<T>({ initialValue, onReset, }: {
|
|
11
|
+
initialValue: T;
|
|
12
|
+
onReset?: (value: T) => void;
|
|
13
|
+
}): (node: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null) => void;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFormResetHandler = exports.HiddenInput = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
7
|
+
function HiddenInput({ name, value, onReset, form, disabled, toStringValue, }) {
|
|
8
|
+
const ref = useFormResetHandler({ initialValue: value, onReset });
|
|
9
|
+
if (!name) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const v = toStringValue ? toStringValue(value) : `${value !== null && value !== void 0 ? value : ''}`;
|
|
13
|
+
return (0, jsx_runtime_1.jsx)("input", { ref: ref, type: "hidden", name: name, value: v, disabled: disabled, form: form });
|
|
14
|
+
}
|
|
15
|
+
exports.HiddenInput = HiddenInput;
|
|
16
|
+
function useFormResetHandler({ initialValue, onReset, }) {
|
|
17
|
+
const [formElement, setFormElement] = react_1.default.useState(null);
|
|
18
|
+
const resetValue = react_1.default.useRef(initialValue);
|
|
19
|
+
react_1.default.useEffect(() => {
|
|
20
|
+
if (!formElement || !onReset) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const handleReset = () => {
|
|
24
|
+
onReset(resetValue.current);
|
|
25
|
+
};
|
|
26
|
+
formElement.addEventListener('reset', handleReset);
|
|
27
|
+
return () => {
|
|
28
|
+
formElement.removeEventListener('reset', handleReset);
|
|
29
|
+
};
|
|
30
|
+
}, [formElement, onReset]);
|
|
31
|
+
const ref = react_1.default.useCallback((node) => {
|
|
32
|
+
var _a;
|
|
33
|
+
setFormElement((_a = node === null || node === void 0 ? void 0 : node.form) !== null && _a !== void 0 ? _a : null);
|
|
34
|
+
}, []);
|
|
35
|
+
return ref;
|
|
36
|
+
}
|
|
37
|
+
exports.useFormResetHandler = useFormResetHandler;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
'use client';
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.RangeDateField = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
@@ -7,10 +8,12 @@ const react_1 = tslib_1.__importDefault(require("react"));
|
|
|
7
8
|
const uikit_1 = require("@gravity-ui/uikit");
|
|
8
9
|
const cn_1 = require("../../utils/cn");
|
|
9
10
|
const useDateFieldProps_1 = require("../DateField/hooks/useDateFieldProps");
|
|
11
|
+
const HiddenInput_1 = require("../HiddenInput/HiddenInput");
|
|
10
12
|
const useRangeDateFieldState_1 = require("./hooks/useRangeDateFieldState");
|
|
11
13
|
require("./RangeDateField.css");
|
|
12
14
|
const b = (0, cn_1.block)('range-date-field');
|
|
13
15
|
function RangeDateField(_a) {
|
|
16
|
+
var _b, _c;
|
|
14
17
|
var { className } = _a, props = tslib_1.__rest(_a, ["className"]);
|
|
15
18
|
const state = (0, useRangeDateFieldState_1.useRangeDateFieldState)(props);
|
|
16
19
|
const { inputProps } = (0, useDateFieldProps_1.useDateFieldProps)(state, props);
|
|
@@ -20,6 +23,8 @@ function RangeDateField(_a) {
|
|
|
20
23
|
setActive(isFocusWithin);
|
|
21
24
|
},
|
|
22
25
|
});
|
|
23
|
-
return ((0, jsx_runtime_1.
|
|
26
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: b(null, className), style: props.style }, focusWithinProps, { children: [(0, jsx_runtime_1.jsx)(uikit_1.TextInput, Object.assign({}, inputProps, { value: state.isEmpty && !isActive && props.placeholder ? '' : inputProps.value })), (0, jsx_runtime_1.jsx)(HiddenInput_1.HiddenInput, { name: props.name, form: props.form, onReset: (v) => {
|
|
27
|
+
state.setDate(v);
|
|
28
|
+
}, value: (_b = state.value) !== null && _b !== void 0 ? _b : null, toStringValue: (v) => (v ? v.start.toISOString() : ''), disabled: state.disabled }), (0, jsx_runtime_1.jsx)(HiddenInput_1.HiddenInput, { name: props.name, form: props.form, value: (_c = state.value) !== null && _c !== void 0 ? _c : null, toStringValue: (v) => (v ? v.end.toISOString() : ''), disabled: state.disabled })] })));
|
|
24
29
|
}
|
|
25
30
|
exports.RangeDateField = RangeDateField;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
'use client';
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.RangeDatePicker = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
@@ -10,6 +11,7 @@ const cn_1 = require("../../utils/cn");
|
|
|
10
11
|
const Calendar_1 = require("../Calendar");
|
|
11
12
|
const DatePicker_1 = require("../DatePicker");
|
|
12
13
|
const StubButton_1 = require("../DatePicker/StubButton");
|
|
14
|
+
const HiddenInput_1 = require("../HiddenInput/HiddenInput");
|
|
13
15
|
const RangeDateField_1 = require("../RangeDateField");
|
|
14
16
|
const useRangeDatePickerState_1 = require("./hooks/useRangeDatePickerState");
|
|
15
17
|
require("./RangeDatePicker.css");
|
|
@@ -20,6 +22,8 @@ function RangeDatePicker(_a) {
|
|
|
20
22
|
const state = (0, useRangeDatePickerState_1.useRangeDatePickerState)(props);
|
|
21
23
|
const { groupProps, fieldProps, calendarButtonProps, popupProps, calendarProps, timeInputProps } = (0, DatePicker_1.useDatePickerProps)(state, props);
|
|
22
24
|
const isOnlyTime = state.hasTime && !state.hasDate;
|
|
23
|
-
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: b(null, className) }, groupProps, { children: [!isOnlyTime && ((0, jsx_runtime_1.jsx)("div", { ref: anchorRef, className: b('popup-anchor'), children: (0, jsx_runtime_1.jsx)(uikit_1.Popup, Object.assign({ anchorRef: anchorRef }, popupProps, { children: (0, jsx_runtime_1.jsxs)("div", { className: b('popup-content'), children: [typeof props.children === 'function' ? (props.children(Object.assign(Object.assign({}, calendarProps), { value: state.value }))) : ((0, jsx_runtime_1.jsx)(Calendar_1.RangeCalendar, Object.assign({}, calendarProps, { value: state.value }))), state.hasTime && ((0, jsx_runtime_1.jsx)("div", { className: b('time-field-wrapper'), children: (0, jsx_runtime_1.jsx)(RangeDateField_1.RangeDateField, Object.assign({}, timeInputProps)) }))] }) })) })), (0, jsx_runtime_1.jsx)(uikit_1.TextInput, Object.assign({}, fieldProps, { className: b('field'), hasClear: fieldProps.hasClear, endContent: (0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [!isOnlyTime && ((0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, calendarButtonProps, { children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Calendar }) }))), isOnlyTime && ((0, jsx_runtime_1.jsx)(StubButton_1.StubButton, { size: calendarButtonProps.size, icon: icons_1.Clock }))] }) }))
|
|
25
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: b(null, className) }, groupProps, { children: [!isOnlyTime && ((0, jsx_runtime_1.jsx)("div", { ref: anchorRef, className: b('popup-anchor'), children: (0, jsx_runtime_1.jsx)(uikit_1.Popup, Object.assign({ anchorRef: anchorRef }, popupProps, { children: (0, jsx_runtime_1.jsxs)("div", { className: b('popup-content'), children: [typeof props.children === 'function' ? (props.children(Object.assign(Object.assign({}, calendarProps), { value: state.value }))) : ((0, jsx_runtime_1.jsx)(Calendar_1.RangeCalendar, Object.assign({}, calendarProps, { value: state.value }))), state.hasTime && ((0, jsx_runtime_1.jsx)("div", { className: b('time-field-wrapper'), children: (0, jsx_runtime_1.jsx)(RangeDateField_1.RangeDateField, Object.assign({}, timeInputProps)) }))] }) })) })), (0, jsx_runtime_1.jsx)(uikit_1.TextInput, Object.assign({}, fieldProps, { className: b('field'), hasClear: fieldProps.hasClear, endContent: (0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [!isOnlyTime && ((0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, calendarButtonProps, { children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Calendar }) }))), isOnlyTime && ((0, jsx_runtime_1.jsx)(StubButton_1.StubButton, { size: calendarButtonProps.size, icon: icons_1.Clock }))] }) })), (0, jsx_runtime_1.jsx)(HiddenInput_1.HiddenInput, { name: props.name, form: props.form, onReset: (v) => {
|
|
26
|
+
state.dateFieldState.setDate(v);
|
|
27
|
+
}, value: state.value, toStringValue: (v) => (v ? v.start.toISOString() : ''), disabled: state.disabled }), (0, jsx_runtime_1.jsx)(HiddenInput_1.HiddenInput, { name: props.name, form: props.form, value: state.value, toStringValue: (v) => (v ? v.end.toISOString() : ''), disabled: state.disabled })] })));
|
|
24
28
|
}
|
|
25
29
|
exports.RangeDatePicker = RangeDatePicker;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
'use client';
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.RelativeDateField = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
@@ -8,12 +9,12 @@ const uikit_1 = require("@gravity-ui/uikit");
|
|
|
8
9
|
const cn_1 = require("../../utils/cn");
|
|
9
10
|
const Calendar_1 = require("../Calendar");
|
|
10
11
|
const DateField_1 = require("../DateField");
|
|
12
|
+
const HiddenInput_1 = require("../HiddenInput/HiddenInput");
|
|
11
13
|
const useRelativeDateFieldProps_1 = require("./hooks/useRelativeDateFieldProps");
|
|
12
14
|
const useRelativeDateFieldState_1 = require("./hooks/useRelativeDateFieldState");
|
|
13
15
|
require("./RelativeDateField.css");
|
|
14
16
|
const b = (0, cn_1.block)('relative-date-field');
|
|
15
17
|
function RelativeDateField(props) {
|
|
16
|
-
var _a;
|
|
17
18
|
const state = (0, useRelativeDateFieldState_1.useRelativeDateFieldState)(props);
|
|
18
19
|
const { inputProps, calendarProps, timeInputProps } = (0, useRelativeDateFieldProps_1.useRelativeDateFieldProps)(state, props);
|
|
19
20
|
const isMobile = (0, uikit_1.useMobile)();
|
|
@@ -31,8 +32,8 @@ function RelativeDateField(props) {
|
|
|
31
32
|
setOpen(true);
|
|
32
33
|
}
|
|
33
34
|
(_a = props.onFocus) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
34
|
-
}, onBlur: props.onBlur })), (0, jsx_runtime_1.jsx)(
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
}, onBlur: props.onBlur })), (0, jsx_runtime_1.jsx)(HiddenInput_1.HiddenInput, { name: props.name, value: state.value, onReset: (value) => {
|
|
36
|
+
state.setValue(value);
|
|
37
|
+
}, disabled: state.disabled, form: props.form }), !isMobile && ((0, jsx_runtime_1.jsx)(uikit_1.Popup, { anchorRef: anchorRef, open: isOpen, children: (0, jsx_runtime_1.jsxs)("div", { className: b('popup-content'), children: [(0, jsx_runtime_1.jsx)(Calendar_1.Calendar, Object.assign({}, calendarProps)), props.hasTime ? ((0, jsx_runtime_1.jsx)("div", { className: b('time-field-wrapper'), children: (0, jsx_runtime_1.jsx)(DateField_1.DateField, Object.assign({ className: b('time-field') }, timeInputProps)) })) : null] }) }))] })));
|
|
37
38
|
}
|
|
38
39
|
exports.RelativeDateField = RelativeDateField;
|
|
@@ -17,7 +17,7 @@ function useRelativeDateFieldState(props) {
|
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
setText(t);
|
|
20
|
-
if (
|
|
20
|
+
if ((0, date_utils_1.isLikeRelative)(t)) {
|
|
21
21
|
const date = (0, date_utils_1.dateTimeParse)(t);
|
|
22
22
|
if (date && (0, date_utils_1.isValid)(date)) {
|
|
23
23
|
setValue(t);
|
|
@@ -36,7 +36,7 @@ function useRelativeDateFieldState(props) {
|
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
38
|
return (_a = (0, date_utils_1.dateTimeParse)(value, { timeZone: props.timeZone, roundUp: props.roundUp })) !== null && _a !== void 0 ? _a : null;
|
|
39
|
-
}, [value, props.timeZone]);
|
|
39
|
+
}, [value, props.timeZone, props.roundUp]);
|
|
40
40
|
const [lastCorrectDate, setLastCorrectDate] = react_1.default.useState(parsedDate);
|
|
41
41
|
if (parsedDate && parsedDate !== lastCorrectDate) {
|
|
42
42
|
setLastCorrectDate(parsedDate);
|
|
@@ -60,9 +60,3 @@ function useRelativeDateFieldState(props) {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
exports.useRelativeDateFieldState = useRelativeDateFieldState;
|
|
63
|
-
function isLikeRelativeDate(text) {
|
|
64
|
-
if (typeof date_utils_1.isLikeRelative === 'function') {
|
|
65
|
-
return (0, date_utils_1.isLikeRelative)(text);
|
|
66
|
-
}
|
|
67
|
-
return /^now/i.test(text);
|
|
68
|
-
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
'use client';
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.RelativeDatePicker = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
@@ -11,11 +12,13 @@ const Calendar_1 = require("../Calendar");
|
|
|
11
12
|
const DateField_1 = require("../DateField");
|
|
12
13
|
const MobileCalendar_1 = require("../DatePicker/MobileCalendar");
|
|
13
14
|
const StubButton_1 = require("../DatePicker/StubButton");
|
|
15
|
+
const HiddenInput_1 = require("../HiddenInput/HiddenInput");
|
|
14
16
|
const useRelativeDatePickerProps_1 = require("./hooks/useRelativeDatePickerProps");
|
|
15
17
|
const useRelativeDatePickerState_1 = require("./hooks/useRelativeDatePickerState");
|
|
16
18
|
require("./RelativeDatePicker.css");
|
|
17
19
|
const b = (0, cn_1.block)('relative-date-picker');
|
|
18
20
|
function RelativeDatePicker(props) {
|
|
21
|
+
var _a;
|
|
19
22
|
const state = (0, useRelativeDatePickerState_1.useRelativeDatePickerState)(props);
|
|
20
23
|
const { groupProps, fieldProps, modeSwitcherProps, calendarButtonProps, popupProps, calendarProps, timeInputProps, } = (0, useRelativeDatePickerProps_1.useRelativeDatePickerProps)(state, props);
|
|
21
24
|
const anchorRef = react_1.default.useRef(null);
|
|
@@ -27,9 +30,9 @@ function RelativeDatePicker(props) {
|
|
|
27
30
|
readOnly: props.readOnly,
|
|
28
31
|
placeholderValue: props.placeholderValue,
|
|
29
32
|
timeZone: props.timeZone,
|
|
30
|
-
} })), (0, jsx_runtime_1.jsx)(uikit_1.TextInput, Object.assign({}, fieldProps, { controlProps: Object.assign(Object.assign({}, fieldProps.controlProps), { disabled: isMobile && state.mode === 'absolute', className: b('input', { mobile: isMobile && state.mode === 'absolute' }) }), hasClear: props.hasClear && !(isMobile && state.mode === 'absolute'), startContent: (0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, modeSwitcherProps, { children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Function }) })), endContent: (0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [!isMobile && !isOnlyTime && ((0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, calendarButtonProps, { children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Calendar }) }))), !isMobile && isOnlyTime && ((0, jsx_runtime_1.jsx)(StubButton_1.StubButton, { size: calendarButtonProps.size, icon: icons_1.Clock })), isMobile && state.mode === 'absolute' && ((0, jsx_runtime_1.jsx)(StubButton_1.StubButton, { size: calendarButtonProps.size, icon: isOnlyTime ? icons_1.Clock : icons_1.Calendar }))] }) })), (0, jsx_runtime_1.jsx)(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
} })), (0, jsx_runtime_1.jsx)(uikit_1.TextInput, Object.assign({}, fieldProps, { controlProps: Object.assign(Object.assign({}, fieldProps.controlProps), { disabled: isMobile && state.mode === 'absolute', className: b('input', { mobile: isMobile && state.mode === 'absolute' }) }), hasClear: props.hasClear && !(isMobile && state.mode === 'absolute'), startContent: (0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, modeSwitcherProps, { children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Function }) })), endContent: (0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [!isMobile && !isOnlyTime && ((0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, calendarButtonProps, { children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Calendar }) }))), !isMobile && isOnlyTime && ((0, jsx_runtime_1.jsx)(StubButton_1.StubButton, { size: calendarButtonProps.size, icon: icons_1.Clock })), isMobile && state.mode === 'absolute' && ((0, jsx_runtime_1.jsx)(StubButton_1.StubButton, { size: calendarButtonProps.size, icon: isOnlyTime ? icons_1.Clock : icons_1.Calendar }))] }) })), (0, jsx_runtime_1.jsx)(HiddenInput_1.HiddenInput, { name: props.name, value: (_a = state.value) === null || _a === void 0 ? void 0 : _a.type, disabled: state.disabled, form: props.form }), (0, jsx_runtime_1.jsx)(HiddenInput_1.HiddenInput, { name: props.name, value: state.value, toStringValue: (value) => getNativeValue(value), onReset: (value) => {
|
|
34
|
+
state.setValue(value);
|
|
35
|
+
}, disabled: state.disabled, form: props.form }), !isMobile && !isOnlyTime && ((0, jsx_runtime_1.jsx)(uikit_1.Popup, Object.assign({}, popupProps, { anchorRef: anchorRef, children: (0, jsx_runtime_1.jsxs)("div", { className: b('popup-content'), children: [typeof props.children === 'function' ? (props.children(calendarProps)) : ((0, jsx_runtime_1.jsx)(Calendar_1.Calendar, Object.assign({}, calendarProps))), state.datePickerState.hasTime && ((0, jsx_runtime_1.jsx)("div", { className: b('time-field-wrapper'), children: (0, jsx_runtime_1.jsx)(DateField_1.DateField, Object.assign({}, timeInputProps)) }))] }) })))] })));
|
|
33
36
|
}
|
|
34
37
|
exports.RelativeDatePicker = RelativeDatePicker;
|
|
35
38
|
function getNativeValue(value) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
2
|
import type { Value } from '../RelativeDatePicker';
|
|
3
|
-
import type { DomProps, FocusableProps, InputBase, RangeValue, StyleProps, TextInputProps, Validation } from '../types';
|
|
3
|
+
import type { DomProps, FocusableProps, InputBase, InputDOMProps, RangeValue, StyleProps, TextInputProps, Validation } from '../types';
|
|
4
4
|
import type { Preset } from './components/Presets/defaultPresets';
|
|
5
5
|
import type { PresetTab } from './components/Presets/utils';
|
|
6
6
|
import type { RelativeRangeDatePickerStateOptions } from './hooks/useRelativeRangeDatePickerState';
|
|
7
7
|
import './RelativeRangeDatePicker.css';
|
|
8
|
-
export interface RelativeRangeDatePickerProps extends RelativeRangeDatePickerStateOptions, DomProps, InputBase, TextInputProps, Validation, FocusableProps, StyleProps {
|
|
8
|
+
export interface RelativeRangeDatePickerProps extends RelativeRangeDatePickerStateOptions, DomProps, InputBase, InputDOMProps, TextInputProps, Validation, FocusableProps, StyleProps {
|
|
9
9
|
/** Format of the date when rendered in the input. [Available formats](https://day.js.org/docs/en/display/format) */
|
|
10
10
|
format?: string;
|
|
11
11
|
/** A placeholder date that controls the default values of each segment when the user first interacts with them. Defaults to today's date at midnight. */
|