@gravity-ui/date-components 2.0.1 → 2.2.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/CalendarView/hooks/useCalendarProps.js +17 -0
- package/dist/cjs/components/CalendarView/i18n/en.json +4 -1
- package/dist/cjs/components/CalendarView/i18n/index.d.ts +1 -1
- package/dist/cjs/components/CalendarView/i18n/ru.json +4 -1
- package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.d.ts +2 -2
- package/dist/cjs/components/DateField/hooks/useDateFieldProps.d.ts +2 -2
- package/dist/cjs/components/DateField/hooks/useDateFieldState.d.ts +1 -2
- package/dist/cjs/components/DateField/utils.js +2 -1
- package/dist/cjs/components/DatePicker/DatePicker.d.ts +3 -2
- package/dist/cjs/components/DatePicker/DatePicker.js +3 -1
- package/dist/cjs/components/DatePicker/MobileCalendar.css +1 -26
- package/dist/cjs/components/DatePicker/MobileCalendar.d.ts +0 -5
- package/dist/cjs/components/DatePicker/MobileCalendar.js +2 -9
- package/dist/cjs/components/DatePicker/StubButton.css +26 -0
- package/dist/cjs/components/DatePicker/StubButton.d.ts +8 -0
- package/dist/cjs/components/DatePicker/StubButton.js +12 -0
- package/dist/cjs/components/DatePicker/hooks/datePickerStateFactory.d.ts +49 -0
- package/dist/cjs/components/DatePicker/hooks/datePickerStateFactory.js +121 -0
- package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.d.ts +9 -5
- package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.js +4 -2
- package/dist/cjs/components/DatePicker/hooks/useDatePickerState.d.ts +2 -41
- package/dist/cjs/components/DatePicker/hooks/useDatePickerState.js +11 -131
- package/dist/cjs/components/DatePicker/{utils.js → utils/cn.js} +1 -1
- package/dist/cjs/components/DatePicker/utils/getDateTimeValue.d.ts +3 -0
- package/dist/cjs/components/DatePicker/utils/getDateTimeValue.js +10 -0
- package/dist/cjs/components/DatePicker/utils/index.d.ts +2 -0
- package/dist/cjs/components/DatePicker/utils/index.js +5 -0
- package/dist/cjs/components/RangeCalendar/RangeCalendar.d.ts +5 -10
- package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.d.ts +2 -2
- package/dist/cjs/components/RangeDatePicker/RangeDatePicker.css +22 -0
- package/dist/cjs/components/RangeDatePicker/RangeDatePicker.d.ts +6 -0
- package/dist/cjs/components/RangeDatePicker/RangeDatePicker.js +25 -0
- package/dist/cjs/components/RangeDatePicker/hooks/useRangeDatePickerState.d.ts +7 -0
- package/dist/cjs/components/RangeDatePicker/hooks/useRangeDatePickerState.js +28 -0
- package/dist/cjs/components/RangeDatePicker/index.d.ts +2 -0
- package/dist/cjs/components/RangeDatePicker/index.js +5 -0
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js +4 -2
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.js +3 -3
- package/dist/esm/components/CalendarView/hooks/useCalendarProps.js +17 -0
- package/dist/esm/components/CalendarView/i18n/en.json +4 -1
- package/dist/esm/components/CalendarView/i18n/index.d.ts +1 -1
- package/dist/esm/components/CalendarView/i18n/ru.json +4 -1
- package/dist/esm/components/DateField/hooks/useBaseDateFieldState.d.ts +2 -2
- package/dist/esm/components/DateField/hooks/useDateFieldProps.d.ts +2 -2
- package/dist/esm/components/DateField/hooks/useDateFieldState.d.ts +1 -2
- package/dist/esm/components/DateField/utils.js +2 -1
- package/dist/esm/components/DatePicker/DatePicker.d.ts +3 -2
- package/dist/esm/components/DatePicker/DatePicker.js +5 -3
- package/dist/esm/components/DatePicker/MobileCalendar.css +1 -26
- package/dist/esm/components/DatePicker/MobileCalendar.d.ts +0 -5
- package/dist/esm/components/DatePicker/MobileCalendar.js +1 -7
- package/dist/esm/components/DatePicker/StubButton.css +26 -0
- package/dist/esm/components/DatePicker/StubButton.d.ts +8 -0
- package/dist/esm/components/DatePicker/StubButton.js +8 -0
- package/dist/esm/components/DatePicker/hooks/datePickerStateFactory.d.ts +49 -0
- package/dist/esm/components/DatePicker/hooks/datePickerStateFactory.js +116 -0
- package/dist/esm/components/DatePicker/hooks/useDatePickerProps.d.ts +9 -5
- package/dist/esm/components/DatePicker/hooks/useDatePickerProps.js +4 -2
- package/dist/esm/components/DatePicker/hooks/useDatePickerState.d.ts +2 -41
- package/dist/esm/components/DatePicker/hooks/useDatePickerState.js +11 -129
- package/dist/esm/components/DatePicker/utils/cn.js +2 -0
- package/dist/esm/components/DatePicker/utils/getDateTimeValue.d.ts +3 -0
- package/dist/esm/components/DatePicker/utils/getDateTimeValue.js +6 -0
- package/dist/esm/components/DatePicker/utils/index.d.ts +2 -0
- package/dist/esm/components/DatePicker/utils/index.js +2 -0
- package/dist/esm/components/RangeCalendar/RangeCalendar.d.ts +5 -10
- package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.d.ts +2 -2
- package/dist/esm/components/RangeDatePicker/RangeDatePicker.css +22 -0
- package/dist/esm/components/RangeDatePicker/RangeDatePicker.d.ts +6 -0
- package/dist/esm/components/RangeDatePicker/RangeDatePicker.js +21 -0
- package/dist/esm/components/RangeDatePicker/hooks/useRangeDatePickerState.d.ts +7 -0
- package/dist/esm/components/RangeDatePicker/hooks/useRangeDatePickerState.js +25 -0
- package/dist/esm/components/RangeDatePicker/index.d.ts +2 -0
- package/dist/esm/components/RangeDatePicker/index.js +2 -0
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js +6 -4
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.js +3 -3
- package/package.json +2 -2
- package/dist/esm/components/DatePicker/utils.js +0 -2
- /package/dist/cjs/components/DatePicker/{utils.d.ts → utils/cn.d.ts} +0 -0
- /package/dist/esm/components/DatePicker/{utils.d.ts → utils/cn.d.ts} +0 -0
|
@@ -1,137 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useDatePickerState = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
-
const uikit_1 = require("@gravity-ui/uikit");
|
|
7
4
|
const DateField_1 = require("../../DateField");
|
|
8
5
|
const dates_1 = require("../../utils/dates");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let selectedTime = selectedTimeInner;
|
|
21
|
-
const format = props.format || 'L';
|
|
22
|
-
const commitValue = (date, time) => {
|
|
23
|
-
if (disabled || readOnly) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
setValue((0, dates_1.mergeDateTime)(date, time).timeZone(inputTimeZone));
|
|
27
|
-
setSelectedDate(null);
|
|
28
|
-
setSelectedTime(null);
|
|
29
|
-
};
|
|
30
|
-
const dateFieldState = (0, DateField_1.useDateFieldState)({
|
|
31
|
-
value,
|
|
32
|
-
onUpdate(date) {
|
|
33
|
-
if (date) {
|
|
34
|
-
commitValue(date, date);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
setValue(null);
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
disabled,
|
|
41
|
-
readOnly,
|
|
42
|
-
validationState: props.validationState,
|
|
43
|
-
minValue: props.minValue,
|
|
44
|
-
maxValue: props.maxValue,
|
|
45
|
-
isDateUnavailable: props.isDateUnavailable,
|
|
46
|
-
format,
|
|
47
|
-
placeholderValue: props.placeholderValue,
|
|
48
|
-
timeZone,
|
|
49
|
-
});
|
|
50
|
-
const timeFormat = react_1.default.useMemo(() => {
|
|
51
|
-
const hasSeconds = dateFieldState.sections.some((s) => s.type === 'second');
|
|
52
|
-
return hasSeconds ? 'LTS' : 'LT';
|
|
53
|
-
}, [dateFieldState.sections]);
|
|
54
|
-
if (value) {
|
|
55
|
-
selectedDate = value.timeZone(timeZone);
|
|
56
|
-
if (dateFieldState.hasTime) {
|
|
57
|
-
selectedTime = value.timeZone(timeZone);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
61
|
-
const selectDate = (newValue) => {
|
|
62
|
-
if (disabled || readOnly) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const shouldClose = !dateFieldState.hasTime;
|
|
66
|
-
if (dateFieldState.hasTime) {
|
|
67
|
-
if (selectedTime || shouldClose) {
|
|
68
|
-
commitValue(newValue, selectedTime || newValue);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
setSelectedDate(newValue);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
commitValue(newValue, newValue);
|
|
76
|
-
}
|
|
77
|
-
if (shouldClose) {
|
|
78
|
-
setOpen(false);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
const selectTime = (newValue) => {
|
|
82
|
-
if (disabled || readOnly) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const newTime = newValue !== null && newValue !== void 0 ? newValue : (0, dates_1.createPlaceholderValue)({
|
|
86
|
-
placeholderValue: props.placeholderValue,
|
|
87
|
-
timeZone,
|
|
88
|
-
});
|
|
89
|
-
if (selectedDate) {
|
|
90
|
-
commitValue(selectedDate, newTime);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
setSelectedTime(newTime);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
if (dateFieldState.hasTime && !selectedTime) {
|
|
97
|
-
selectedTime = dateFieldState.displayValue;
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
value,
|
|
101
|
-
setValue(newDate) {
|
|
102
|
-
if (props.readOnly || props.disabled) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
if (newDate) {
|
|
106
|
-
setValue(newDate.timeZone(inputTimeZone));
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
setValue(null);
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
dateValue: selectedDate,
|
|
113
|
-
timeValue: selectedTime,
|
|
114
|
-
setDateValue: selectDate,
|
|
115
|
-
setTimeValue: selectTime,
|
|
116
|
-
disabled,
|
|
117
|
-
readOnly,
|
|
118
|
-
format,
|
|
119
|
-
hasDate: dateFieldState.hasDate,
|
|
120
|
-
hasTime: dateFieldState.hasTime,
|
|
121
|
-
timeFormat,
|
|
122
|
-
timeZone,
|
|
123
|
-
isOpen,
|
|
124
|
-
setOpen(newIsOpen) {
|
|
125
|
-
if (!newIsOpen && !value && selectedDate && dateFieldState.hasTime) {
|
|
126
|
-
commitValue(selectedDate, selectedTime ||
|
|
127
|
-
(0, dates_1.createPlaceholderValue)({
|
|
128
|
-
placeholderValue: props.placeholderValue,
|
|
129
|
-
timeZone: inputTimeZone,
|
|
130
|
-
}));
|
|
131
|
-
}
|
|
132
|
-
setOpen(newIsOpen);
|
|
133
|
-
},
|
|
134
|
-
dateFieldState,
|
|
135
|
-
};
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const datePickerStateFactory_1 = require("./datePickerStateFactory");
|
|
8
|
+
exports.useDatePickerState = (0, datePickerStateFactory_1.datePickerStateFactory)({
|
|
9
|
+
getPlaceholderTime,
|
|
10
|
+
mergeDateTime: dates_1.mergeDateTime,
|
|
11
|
+
setTimezone: (date, timeZone) => date.timeZone(timeZone),
|
|
12
|
+
getDateTime: utils_1.getDateTimeValue,
|
|
13
|
+
useDateFieldState: DateField_1.useDateFieldState,
|
|
14
|
+
});
|
|
15
|
+
function getPlaceholderTime(placeholderValue, timeZone) {
|
|
16
|
+
return (0, dates_1.createPlaceholderValue)({ placeholderValue, timeZone });
|
|
136
17
|
}
|
|
137
|
-
exports.useDatePickerState = useDatePickerState;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDateTimeValue = void 0;
|
|
4
|
+
function getDateTimeValue(value) {
|
|
5
|
+
if (!value) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
return 'start' in value && 'end' in value ? value.start : value;
|
|
9
|
+
}
|
|
10
|
+
exports.getDateTimeValue = getDateTimeValue;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
2
|
+
import type { DateTime } from '@gravity-ui/date-utils';
|
|
3
|
+
import type { CalendarProps } from '../Calendar/Calendar';
|
|
4
|
+
import type { CalendarInstance } from '../CalendarView/CalendarView';
|
|
5
|
+
import type { RangeValue } from '../types';
|
|
5
6
|
import '../CalendarView/Calendar.css';
|
|
6
|
-
export
|
|
7
|
-
/**
|
|
8
|
-
* The size of the element.
|
|
9
|
-
* @default m
|
|
10
|
-
*/
|
|
11
|
-
size?: CalendarSize;
|
|
12
|
-
}
|
|
7
|
+
export type RangeCalendarProps = CalendarProps<RangeValue<DateTime>>;
|
|
13
8
|
export declare const RangeCalendar: React.ForwardRefExoticComponent<RangeCalendarProps & React.RefAttributes<CalendarInstance>>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
|
-
import type {
|
|
2
|
+
import type { DateFieldState } from '../../DateField';
|
|
3
3
|
import type { DateFieldBase } from '../../types/datePicker';
|
|
4
4
|
import type { RangeValue } from '../../types/inputs';
|
|
5
5
|
export interface RangeDateFieldStateOptions extends DateFieldBase<RangeValue<DateTime>> {
|
|
6
6
|
delimiter?: string;
|
|
7
7
|
}
|
|
8
|
-
export type RangeDateFieldState =
|
|
8
|
+
export type RangeDateFieldState = DateFieldState<RangeValue<DateTime>>;
|
|
9
9
|
export declare function useRangeDateFieldState(props: RangeDateFieldStateOptions): RangeDateFieldState;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
.g-date-range-date-picker {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: inline-block;
|
|
4
|
+
outline: none;
|
|
5
|
+
}
|
|
6
|
+
.g-date-range-date-picker__field {
|
|
7
|
+
width: 100%;
|
|
8
|
+
}
|
|
9
|
+
.g-date-range-date-picker__popup-anchor {
|
|
10
|
+
position: absolute;
|
|
11
|
+
z-index: -1;
|
|
12
|
+
inset: 0;
|
|
13
|
+
}
|
|
14
|
+
.g-date-range-date-picker__popup-content {
|
|
15
|
+
outline: none;
|
|
16
|
+
}
|
|
17
|
+
.g-date-range-date-picker__time-field {
|
|
18
|
+
width: 100%;
|
|
19
|
+
}
|
|
20
|
+
.g-date-range-date-picker__time-field-wrapper {
|
|
21
|
+
padding: 10px;
|
|
22
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
|
+
import type { DatePickerProps } from '../DatePicker';
|
|
3
|
+
import type { RangeValue } from '../types';
|
|
4
|
+
import './RangeDatePicker.css';
|
|
5
|
+
export type RangeDatePickerProps = DatePickerProps<RangeValue<DateTime>>;
|
|
6
|
+
export declare function RangeDatePicker({ className, ...props }: RangeDatePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RangeDatePicker = 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
|
+
const icons_1 = require("@gravity-ui/icons");
|
|
8
|
+
const uikit_1 = require("@gravity-ui/uikit");
|
|
9
|
+
const cn_1 = require("../../utils/cn");
|
|
10
|
+
const Calendar_1 = require("../Calendar");
|
|
11
|
+
const DatePicker_1 = require("../DatePicker");
|
|
12
|
+
const StubButton_1 = require("../DatePicker/StubButton");
|
|
13
|
+
const RangeDateField_1 = require("../RangeDateField");
|
|
14
|
+
const useRangeDatePickerState_1 = require("./hooks/useRangeDatePickerState");
|
|
15
|
+
require("./RangeDatePicker.css");
|
|
16
|
+
const b = (0, cn_1.block)('range-date-picker');
|
|
17
|
+
function RangeDatePicker(_a) {
|
|
18
|
+
var { className } = _a, props = tslib_1.__rest(_a, ["className"]);
|
|
19
|
+
const anchorRef = react_1.default.useRef(null);
|
|
20
|
+
const state = (0, useRangeDatePickerState_1.useRangeDatePickerState)(props);
|
|
21
|
+
const { groupProps, fieldProps, calendarButtonProps, popupProps, calendarProps, timeInputProps } = (0, DatePicker_1.useDatePickerProps)(state, props);
|
|
22
|
+
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 }))] }) }))] })));
|
|
24
|
+
}
|
|
25
|
+
exports.RangeDatePicker = RangeDatePicker;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
|
+
import type { DatePickerState } from '../../DatePicker';
|
|
3
|
+
import type { RangeDateFieldStateOptions } from '../../RangeDateField';
|
|
4
|
+
import type { RangeValue } from '../../types';
|
|
5
|
+
export type RangeDatePickerState = DatePickerState<RangeValue<DateTime>>;
|
|
6
|
+
export type RangeDatePickerStateOptions = RangeDateFieldStateOptions;
|
|
7
|
+
export declare const useRangeDatePickerState: (props: RangeDateFieldStateOptions) => DatePickerState<RangeValue<DateTime>>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRangeDatePickerState = void 0;
|
|
4
|
+
const datePickerStateFactory_1 = require("../../DatePicker/hooks/datePickerStateFactory");
|
|
5
|
+
const utils_1 = require("../../DatePicker/utils");
|
|
6
|
+
const RangeDateField_1 = require("../../RangeDateField");
|
|
7
|
+
const dates_1 = require("../../utils/dates");
|
|
8
|
+
exports.useRangeDatePickerState = (0, datePickerStateFactory_1.datePickerStateFactory)({
|
|
9
|
+
getPlaceholderTime,
|
|
10
|
+
mergeDateTime: mergeRangeDateTime,
|
|
11
|
+
setTimezone,
|
|
12
|
+
getDateTime: utils_1.getDateTimeValue,
|
|
13
|
+
useDateFieldState: RangeDateField_1.useRangeDateFieldState,
|
|
14
|
+
});
|
|
15
|
+
function getPlaceholderTime(placeholderValue, timeZone) {
|
|
16
|
+
const date = (0, dates_1.createPlaceholderValue)({ placeholderValue, timeZone });
|
|
17
|
+
return { start: date, end: date };
|
|
18
|
+
}
|
|
19
|
+
function mergeRangeDateTime(date, time) {
|
|
20
|
+
const start = (0, dates_1.mergeDateTime)(date.start, time.start);
|
|
21
|
+
const end = (0, dates_1.mergeDateTime)(date.end, time.end);
|
|
22
|
+
return { start, end };
|
|
23
|
+
}
|
|
24
|
+
function setTimezone(date, timeZone) {
|
|
25
|
+
const start = date.start.timeZone(timeZone);
|
|
26
|
+
const end = date.end.timeZone(timeZone);
|
|
27
|
+
return { start, end };
|
|
28
|
+
}
|
|
@@ -10,6 +10,7 @@ const cn_1 = require("../../utils/cn");
|
|
|
10
10
|
const Calendar_1 = require("../Calendar");
|
|
11
11
|
const DateField_1 = require("../DateField");
|
|
12
12
|
const MobileCalendar_1 = require("../DatePicker/MobileCalendar");
|
|
13
|
+
const StubButton_1 = require("../DatePicker/StubButton");
|
|
13
14
|
const useRelativeDatePickerProps_1 = require("./hooks/useRelativeDatePickerProps");
|
|
14
15
|
const useRelativeDatePickerState_1 = require("./hooks/useRelativeDatePickerState");
|
|
15
16
|
require("./RelativeDatePicker.css");
|
|
@@ -19,15 +20,16 @@ function RelativeDatePicker(props) {
|
|
|
19
20
|
const { groupProps, fieldProps, modeSwitcherProps, calendarButtonProps, popupProps, calendarProps, timeInputProps, } = (0, useRelativeDatePickerProps_1.useRelativeDatePickerProps)(state, props);
|
|
20
21
|
const anchorRef = react_1.default.useRef(null);
|
|
21
22
|
const isMobile = (0, uikit_1.useMobile)();
|
|
23
|
+
const isOnlyTime = state.datePickerState.hasTime && !state.datePickerState.hasDate;
|
|
22
24
|
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ ref: anchorRef, className: b(null, props.className) }, groupProps, { children: [isMobile && state.mode === 'absolute' && ((0, jsx_runtime_1.jsx)(MobileCalendar_1.MobileCalendar, { state: state.datePickerState, props: {
|
|
23
25
|
id: props.id,
|
|
24
26
|
disabled: props.disabled,
|
|
25
27
|
readOnly: props.readOnly,
|
|
26
28
|
placeholderValue: props.placeholderValue,
|
|
27
29
|
timeZone: props.timeZone,
|
|
28
|
-
} })), (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 && ((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 && state.mode === 'absolute' && ((0, jsx_runtime_1.jsx)(
|
|
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)("input", { type: "text", hidden: true, name: props.name, value: getNativeValue(state.value),
|
|
29
31
|
// Ignore React warning
|
|
30
|
-
onChange: () => { } }), !isMobile && ((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)) }))] }) })))] })));
|
|
32
|
+
onChange: () => { } }), !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)) }))] }) })))] })));
|
|
31
33
|
}
|
|
32
34
|
exports.RelativeDatePicker = RelativeDatePicker;
|
|
33
35
|
function getNativeValue(value) {
|
|
@@ -36,7 +36,7 @@ const data = [
|
|
|
36
36
|
get title() {
|
|
37
37
|
return (0, i18n_1.i18n)('Last 5 minutes');
|
|
38
38
|
},
|
|
39
|
-
from: 'now
|
|
39
|
+
from: 'now - 5m',
|
|
40
40
|
to: 'now',
|
|
41
41
|
},
|
|
42
42
|
{
|
|
@@ -64,8 +64,8 @@ const data = [
|
|
|
64
64
|
get title() {
|
|
65
65
|
return (0, i18n_1.i18n)('Previous month');
|
|
66
66
|
},
|
|
67
|
-
from: 'now
|
|
68
|
-
to: 'now
|
|
67
|
+
from: 'now - 1M/M',
|
|
68
|
+
to: 'now - 1M/M',
|
|
69
69
|
},
|
|
70
70
|
];
|
|
71
71
|
function PresetsExamples({ size }) {
|
|
@@ -30,6 +30,8 @@ export function useCalendarProps(props, state) {
|
|
|
30
30
|
},
|
|
31
31
|
extraProps: {
|
|
32
32
|
'aria-disabled': modeDisabled ? 'true' : undefined,
|
|
33
|
+
'aria-description': getAriaDescriptionForModeButton(state.mode, state.availableModes),
|
|
34
|
+
'aria-live': 'polite',
|
|
33
35
|
},
|
|
34
36
|
children: title,
|
|
35
37
|
};
|
|
@@ -104,3 +106,18 @@ export function useCalendarProps(props, state) {
|
|
|
104
106
|
previousButtonProps,
|
|
105
107
|
};
|
|
106
108
|
}
|
|
109
|
+
function getAriaDescriptionForModeButton(mode, availableModes) {
|
|
110
|
+
const nextModeIndex = availableModes.indexOf(mode) + 1;
|
|
111
|
+
const isModeLast = nextModeIndex === availableModes.length;
|
|
112
|
+
if (isModeLast) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
const ariaLabelMap = {
|
|
116
|
+
days: '',
|
|
117
|
+
months: i18n('Switch to months view'),
|
|
118
|
+
quarters: i18n('Switch to quarters view'),
|
|
119
|
+
years: i18n('Switch to years view'),
|
|
120
|
+
};
|
|
121
|
+
const nextMode = availableModes[nextModeIndex];
|
|
122
|
+
return ariaLabelMap[nextMode];
|
|
123
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const i18n: (key: "Previous" | "Next", params?: import("@gravity-ui/i18n").Params | undefined) => string;
|
|
1
|
+
export declare const i18n: (key: "Previous" | "Next" | "Switch to months view" | "Switch to quarters view" | "Switch to years view", params?: import("@gravity-ui/i18n").Params | undefined) => string;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"Previous": "Назад",
|
|
3
|
-
"Next": "Вперёд"
|
|
3
|
+
"Next": "Вперёд",
|
|
4
|
+
"Switch to months view": "Переключиться на просмотр по месяцам",
|
|
5
|
+
"Switch to quarters view": "Переключиться на просмотр по кварталам",
|
|
6
|
+
"Switch to years view": "Переключиться на просмотр по годам"
|
|
4
7
|
}
|
|
@@ -28,7 +28,7 @@ export type BaseDateFieldStateOptions<T = DateTime> = {
|
|
|
28
28
|
createPlaceholder: () => T;
|
|
29
29
|
setValueFromString: (str: string) => boolean;
|
|
30
30
|
};
|
|
31
|
-
export type
|
|
31
|
+
export type DateFieldState<T = DateTime> = {
|
|
32
32
|
/** The current field value. */
|
|
33
33
|
value: T | null;
|
|
34
34
|
/** Is no part of value is filled. */
|
|
@@ -94,4 +94,4 @@ export type BaseDateFieldState<T = DateTime> = {
|
|
|
94
94
|
onInput: (key: string) => void;
|
|
95
95
|
setValueFromString: (str: string) => boolean;
|
|
96
96
|
};
|
|
97
|
-
export declare function useBaseDateFieldState<T = DateTime>(props: BaseDateFieldStateOptions<T>):
|
|
97
|
+
export declare function useBaseDateFieldState<T = DateTime>(props: BaseDateFieldStateOptions<T>): DateFieldState<T>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
2
|
import type { TextInputProps } from '@gravity-ui/uikit';
|
|
3
3
|
import type { AccessibilityProps, DateFieldBase, TextInputProps as DateFieldTextInputProps, DomProps, FocusableProps, InputDOMProps, KeyboardEvents, StyleProps, TextInputExtendProps } from '../../types';
|
|
4
|
-
import type {
|
|
4
|
+
import type { DateFieldState } from './useBaseDateFieldState';
|
|
5
5
|
export interface DateFieldProps<T = DateTime> extends DateFieldBase<T>, DateFieldTextInputProps, TextInputExtendProps, DomProps, InputDOMProps, FocusableProps, KeyboardEvents, StyleProps, AccessibilityProps {
|
|
6
6
|
}
|
|
7
|
-
export declare function useDateFieldProps<T = DateTime>(state:
|
|
7
|
+
export declare function useDateFieldProps<T = DateTime>(state: DateFieldState<T>, props: DateFieldProps<T>): {
|
|
8
8
|
inputProps: TextInputProps;
|
|
9
9
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { DateFieldBase } from '../../types/datePicker';
|
|
2
|
-
import type {
|
|
2
|
+
import type { DateFieldState } from './useBaseDateFieldState';
|
|
3
3
|
export interface DateFieldStateOptions extends DateFieldBase {
|
|
4
4
|
}
|
|
5
|
-
export type DateFieldState = BaseDateFieldState;
|
|
6
5
|
export declare function useDateFieldState(props: DateFieldStateOptions): DateFieldState;
|
|
@@ -64,6 +64,7 @@ const formatTokenMap = {
|
|
|
64
64
|
function getDateSectionConfigFromFormatToken(formatToken) {
|
|
65
65
|
const config = formatTokenMap[formatToken];
|
|
66
66
|
if (!config) {
|
|
67
|
+
// eslint-disable-next-line no-console
|
|
67
68
|
console.error([
|
|
68
69
|
`The token "${formatToken}" is not supported by the Date field.`,
|
|
69
70
|
'Please try using another token.',
|
|
@@ -185,7 +186,7 @@ export function addSegment(section, date, amount) {
|
|
|
185
186
|
var _a;
|
|
186
187
|
let val = (_a = section.value) !== null && _a !== void 0 ? _a : 0;
|
|
187
188
|
if (section.type === 'dayPeriod') {
|
|
188
|
-
val = date.hour() + (date.hour()
|
|
189
|
+
val = date.hour() + (date.hour() >= 12 ? -12 : 12);
|
|
189
190
|
}
|
|
190
191
|
else {
|
|
191
192
|
val = val + amount;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
3
|
import type { CalendarProps } from '../Calendar';
|
|
3
4
|
import type { AccessibilityProps, DateFieldBase, DomProps, FocusableProps, InputDOMProps, KeyboardEvents, StyleProps, TextInputProps } from '../types';
|
|
4
5
|
import './DatePicker.css';
|
|
5
|
-
export interface DatePickerProps extends DateFieldBase
|
|
6
|
-
children?: (props: CalendarProps) => React.ReactNode;
|
|
6
|
+
export interface DatePickerProps<T = DateTime> extends DateFieldBase<T>, TextInputProps, FocusableProps, KeyboardEvents, DomProps, InputDOMProps, StyleProps, AccessibilityProps {
|
|
7
|
+
children?: (props: CalendarProps<T>) => React.ReactNode;
|
|
7
8
|
}
|
|
8
9
|
export declare function DatePicker({ className, ...props }: DatePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import { Calendar as CalendarIcon } from '@gravity-ui/icons';
|
|
4
|
+
import { Calendar as CalendarIcon, Clock as ClockIcon } from '@gravity-ui/icons';
|
|
5
5
|
import { Button, Icon, Popup, TextInput, useMobile } from '@gravity-ui/uikit';
|
|
6
6
|
import { Calendar } from '../Calendar';
|
|
7
7
|
import { DateField } from '../DateField';
|
|
8
|
-
import { MobileCalendar
|
|
8
|
+
import { MobileCalendar } from './MobileCalendar';
|
|
9
|
+
import { StubButton } from './StubButton';
|
|
9
10
|
import { useDatePickerProps } from './hooks/useDatePickerProps';
|
|
10
11
|
import { useDatePickerState } from './hooks/useDatePickerState';
|
|
11
12
|
import { b } from './utils';
|
|
@@ -16,7 +17,8 @@ export function DatePicker(_a) {
|
|
|
16
17
|
const state = useDatePickerState(props);
|
|
17
18
|
const { groupProps, fieldProps, calendarButtonProps, popupProps, calendarProps, timeInputProps } = useDatePickerProps(state, props);
|
|
18
19
|
const isMobile = useMobile();
|
|
19
|
-
|
|
20
|
+
const isOnlyTime = state.hasTime && !state.hasDate;
|
|
21
|
+
return (_jsxs("div", Object.assign({ className: b(null, className) }, groupProps, { children: [isMobile ? (_jsx(MobileCalendar, { props: props, state: state })) : (!isOnlyTime && (_jsx("div", { ref: anchorRef, className: b('popup-anchor'), children: _jsx(Popup, Object.assign({ anchorRef: anchorRef }, popupProps, { children: _jsxs("div", { className: b('popup-content'), children: [typeof props.children === 'function' ? (props.children(calendarProps)) : (_jsx(Calendar, Object.assign({}, calendarProps))), state.hasTime && (_jsx("div", { className: b('time-field-wrapper'), children: _jsx(DateField, Object.assign({}, timeInputProps)) }))] }) })) }))), _jsx(TextInput, Object.assign({}, fieldProps, { className: b('field', { mobile: isMobile }), hasClear: !isMobile && fieldProps.hasClear, endContent: _jsxs(React.Fragment, { children: [!isMobile && !isOnlyTime && (_jsx(Button, Object.assign({}, calendarButtonProps, { children: _jsx(Icon, { data: CalendarIcon }) }))), !isMobile && isOnlyTime && (_jsx(StubButton, { size: calendarButtonProps.size, icon: ClockIcon })), isMobile && (_jsx(StubButton, { size: calendarButtonProps.size, icon: isOnlyTime ? ClockIcon : CalendarIcon }))] }) })), _jsx("input", { type: "text", hidden: true, name: props.name, value: state.value ? state.value.toISOString() : '',
|
|
20
22
|
// Ignore React warning
|
|
21
23
|
onChange: () => { } })] })));
|
|
22
24
|
}
|
|
@@ -1,29 +1,4 @@
|
|
|
1
1
|
.g-date-mobile-calendar {
|
|
2
|
-
position: relative;
|
|
3
|
-
display: inline-block;
|
|
4
|
-
width: 24px;
|
|
5
|
-
height: 24px;
|
|
6
|
-
}
|
|
7
|
-
.g-date-mobile-calendar_size_xs {
|
|
8
|
-
width: 20px;
|
|
9
|
-
height: 20px;
|
|
10
|
-
}
|
|
11
|
-
.g-date-mobile-calendar_size_m {
|
|
12
|
-
width: 28px;
|
|
13
|
-
height: 28px;
|
|
14
|
-
}
|
|
15
|
-
.g-date-mobile-calendar_size_l {
|
|
16
|
-
width: 36px;
|
|
17
|
-
height: 36px;
|
|
18
|
-
}
|
|
19
|
-
.g-date-mobile-calendar__button {
|
|
20
|
-
position: absolute;
|
|
21
|
-
inset: 0;
|
|
22
|
-
display: flex;
|
|
23
|
-
justify-content: center;
|
|
24
|
-
align-items: center;
|
|
25
|
-
}
|
|
26
|
-
.g-date-mobile-calendar__input {
|
|
27
2
|
position: absolute;
|
|
28
3
|
z-index: 1;
|
|
29
4
|
inset-block-start: 0;
|
|
@@ -37,7 +12,7 @@
|
|
|
37
12
|
opacity: 0;
|
|
38
13
|
border: none;
|
|
39
14
|
}
|
|
40
|
-
.g-date-mobile-
|
|
15
|
+
.g-date-mobile-calendar::-webkit-calendar-picker-indicator {
|
|
41
16
|
position: absolute;
|
|
42
17
|
inset-block-start: 0;
|
|
43
18
|
inset-inline-start: 0;
|
|
@@ -6,9 +6,4 @@ interface MobileCalendarProps {
|
|
|
6
6
|
state: DatePickerState;
|
|
7
7
|
}
|
|
8
8
|
export declare function MobileCalendar({ props, state }: MobileCalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
-
interface MobileCalendarIconProps {
|
|
10
|
-
props: DatePickerProps;
|
|
11
|
-
state: DatePickerState;
|
|
12
|
-
}
|
|
13
|
-
export declare function MobileCalendarIcon({ props }: MobileCalendarIconProps): import("react/jsx-runtime").JSX.Element;
|
|
14
9
|
export {};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { dateTime } from '@gravity-ui/date-utils';
|
|
3
|
-
import { Calendar as CalendarIcon } from '@gravity-ui/icons';
|
|
4
|
-
import { Icon } from '@gravity-ui/uikit';
|
|
5
3
|
import { block } from '../../utils/cn';
|
|
6
4
|
import { createPlaceholderValue, mergeDateTime } from '../utils/dates';
|
|
7
|
-
import { getButtonSizeForInput } from '../utils/getButtonSizeForInput';
|
|
8
5
|
import './MobileCalendar.css';
|
|
9
6
|
const b = block('mobile-calendar');
|
|
10
7
|
export function MobileCalendar({ props, state }) {
|
|
@@ -16,7 +13,7 @@ export function MobileCalendar({ props, state }) {
|
|
|
16
13
|
else if (state.hasTime) {
|
|
17
14
|
type = 'time';
|
|
18
15
|
}
|
|
19
|
-
return (_jsx("input", { className: b(
|
|
16
|
+
return (_jsx("input", { className: b(), disabled: props.disabled, type: type, value: formatNative(state.dateFieldState.displayValue, type), id: props.id, min: formatNative((_a = props.minValue) === null || _a === void 0 ? void 0 : _a.timeZone(state.timeZone), type), max: formatNative((_b = props.maxValue) === null || _b === void 0 ? void 0 : _b.timeZone(state.timeZone), type), tabIndex: -1, onChange: (e) => {
|
|
20
17
|
var _a, _b;
|
|
21
18
|
if (props.readOnly) {
|
|
22
19
|
return;
|
|
@@ -53,9 +50,6 @@ export function MobileCalendar({ props, state }) {
|
|
|
53
50
|
}
|
|
54
51
|
} }));
|
|
55
52
|
}
|
|
56
|
-
export function MobileCalendarIcon({ props }) {
|
|
57
|
-
return (_jsx("span", { className: b({ size: getButtonSizeForInput(props.size) }), children: _jsx("span", { className: b('button'), children: _jsx(Icon, { data: CalendarIcon }) }) }));
|
|
58
|
-
}
|
|
59
53
|
function getDateFormat(type) {
|
|
60
54
|
switch (type) {
|
|
61
55
|
case 'time': {
|