@gravity-ui/date-components 1.0.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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/cjs/components/Calendar/Calendar.css +220 -0
- package/dist/cjs/components/Calendar/Calendar.d.ts +13 -0
- package/dist/cjs/components/Calendar/Calendar.js +15 -0
- package/dist/cjs/components/Calendar/CalendarBase.d.ts +18 -0
- package/dist/cjs/components/Calendar/CalendarBase.js +89 -0
- package/dist/cjs/components/Calendar/RangeCalendar.d.ts +13 -0
- package/dist/cjs/components/Calendar/RangeCalendar.js +22 -0
- package/dist/cjs/components/Calendar/hooks/types.d.ts +124 -0
- package/dist/cjs/components/Calendar/hooks/types.js +2 -0
- package/dist/cjs/components/Calendar/hooks/useCalendarCellProps.d.ts +19 -0
- package/dist/cjs/components/Calendar/hooks/useCalendarCellProps.js +98 -0
- package/dist/cjs/components/Calendar/hooks/useCalendarGridProps.d.ts +5 -0
- package/dist/cjs/components/Calendar/hooks/useCalendarGridProps.js +57 -0
- package/dist/cjs/components/Calendar/hooks/useCalendarProps.d.ts +10 -0
- package/dist/cjs/components/Calendar/hooks/useCalendarProps.js +110 -0
- package/dist/cjs/components/Calendar/hooks/useCalendarState.d.ts +7 -0
- package/dist/cjs/components/Calendar/hooks/useCalendarState.js +178 -0
- package/dist/cjs/components/Calendar/hooks/useRangeCalendarState.d.ts +7 -0
- package/dist/cjs/components/Calendar/hooks/useRangeCalendarState.js +82 -0
- package/dist/cjs/components/Calendar/i18n/en.json +4 -0
- package/dist/cjs/components/Calendar/i18n/index.d.ts +1 -0
- package/dist/cjs/components/Calendar/i18n/index.js +11 -0
- package/dist/cjs/components/Calendar/i18n/ru.json +4 -0
- package/dist/cjs/components/Calendar/index.d.ts +8 -0
- package/dist/cjs/components/Calendar/index.js +23 -0
- package/dist/cjs/components/Calendar/utils.d.ts +4 -0
- package/dist/cjs/components/Calendar/utils.js +40 -0
- package/dist/cjs/components/DateField/DateField.css +4 -0
- package/dist/cjs/components/DateField/DateField.d.ts +6 -0
- package/dist/cjs/components/DateField/DateField.js +38 -0
- package/dist/cjs/components/DateField/hooks/useDateFieldProps.d.ts +6 -0
- package/dist/cjs/components/DateField/hooks/useDateFieldProps.js +203 -0
- package/dist/cjs/components/DateField/hooks/useDateFieldState.d.ts +67 -0
- package/dist/cjs/components/DateField/hooks/useDateFieldState.js +628 -0
- package/dist/cjs/components/DateField/i18n/en.json +10 -0
- package/dist/cjs/components/DateField/i18n/index.d.ts +1 -0
- package/dist/cjs/components/DateField/i18n/index.js +11 -0
- package/dist/cjs/components/DateField/i18n/ru.json +10 -0
- package/dist/cjs/components/DateField/index.d.ts +3 -0
- package/dist/cjs/components/DateField/index.js +19 -0
- package/dist/cjs/components/DateField/types.d.ts +67 -0
- package/dist/cjs/components/DateField/types.js +2 -0
- package/dist/cjs/components/DateField/utils.d.ts +14 -0
- package/dist/cjs/components/DateField/utils.js +276 -0
- package/dist/cjs/components/DatePicker/DatePicker.css +19 -0
- package/dist/cjs/components/DatePicker/DatePicker.d.ts +5 -0
- package/dist/cjs/components/DatePicker/DatePicker.js +66 -0
- package/dist/cjs/components/DatePicker/DesktopCalendar.d.ts +15 -0
- package/dist/cjs/components/DatePicker/DesktopCalendar.js +56 -0
- package/dist/cjs/components/DatePicker/MobileCalendar.css +49 -0
- package/dist/cjs/components/DatePicker/MobileCalendar.d.ts +14 -0
- package/dist/cjs/components/DatePicker/MobileCalendar.js +78 -0
- package/dist/cjs/components/DatePicker/hooks/useDatePickerState.d.ts +45 -0
- package/dist/cjs/components/DatePicker/hooks/useDatePickerState.js +114 -0
- package/dist/cjs/components/DatePicker/i18n/en.json +3 -0
- package/dist/cjs/components/DatePicker/i18n/index.d.ts +1 -0
- package/dist/cjs/components/DatePicker/i18n/index.js +11 -0
- package/dist/cjs/components/DatePicker/i18n/ru.json +3 -0
- package/dist/cjs/components/DatePicker/index.d.ts +2 -0
- package/dist/cjs/components/DatePicker/index.js +18 -0
- package/dist/cjs/components/DatePicker/utils.d.ts +1 -0
- package/dist/cjs/components/DatePicker/utils.js +5 -0
- package/dist/cjs/components/RelativeDateField/RelativeDateField.css +16 -0
- package/dist/cjs/components/RelativeDateField/RelativeDateField.d.ts +11 -0
- package/dist/cjs/components/RelativeDateField/RelativeDateField.js +37 -0
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldProps.d.ts +12 -0
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +66 -0
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +30 -0
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.js +66 -0
- package/dist/cjs/components/RelativeDateField/index.d.ts +3 -0
- package/dist/cjs/components/RelativeDateField/index.js +19 -0
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.css +16 -0
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.d.ts +6 -0
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js +32 -0
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.d.ts +17 -0
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +175 -0
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.d.ts +36 -0
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +109 -0
- package/dist/cjs/components/RelativeDatePicker/i18n/en.json +4 -0
- package/dist/cjs/components/RelativeDatePicker/i18n/index.d.ts +1 -0
- package/dist/cjs/components/RelativeDatePicker/i18n/index.js +11 -0
- package/dist/cjs/components/RelativeDatePicker/i18n/ru.json +4 -0
- package/dist/cjs/components/RelativeDatePicker/index.d.ts +3 -0
- package/dist/cjs/components/RelativeDatePicker/index.js +19 -0
- package/dist/cjs/components/hooks/useControlledState.d.ts +1 -0
- package/dist/cjs/components/hooks/useControlledState.js +30 -0
- package/dist/cjs/components/index.d.ts +5 -0
- package/dist/cjs/components/index.js +21 -0
- package/dist/cjs/components/types/datePicker.d.ts +16 -0
- package/dist/cjs/components/types/datePicker.js +2 -0
- package/dist/cjs/components/types/events.d.ts +17 -0
- package/dist/cjs/components/types/events.js +2 -0
- package/dist/cjs/components/types/index.d.ts +4 -0
- package/dist/cjs/components/types/index.js +2 -0
- package/dist/cjs/components/types/inputs.d.ts +79 -0
- package/dist/cjs/components/types/inputs.js +2 -0
- package/dist/cjs/components/types/style.d.ts +7 -0
- package/dist/cjs/components/types/style.js +2 -0
- package/dist/cjs/components/utils/getButtonSizeForInput.d.ts +2 -0
- package/dist/cjs/components/utils/getButtonSizeForInput.js +20 -0
- package/dist/cjs/components/utils/mergeProps.d.ts +13 -0
- package/dist/cjs/components/utils/mergeProps.js +47 -0
- package/dist/cjs/components/variables.css +0 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +17 -0
- package/dist/cjs/utils/cn.d.ts +2 -0
- package/dist/cjs/utils/cn.js +6 -0
- package/dist/esm/components/Calendar/Calendar.css +220 -0
- package/dist/esm/components/Calendar/Calendar.d.ts +13 -0
- package/dist/esm/components/Calendar/Calendar.js +9 -0
- package/dist/esm/components/Calendar/CalendarBase.d.ts +18 -0
- package/dist/esm/components/Calendar/CalendarBase.js +83 -0
- package/dist/esm/components/Calendar/RangeCalendar.d.ts +13 -0
- package/dist/esm/components/Calendar/RangeCalendar.js +16 -0
- package/dist/esm/components/Calendar/hooks/types.d.ts +124 -0
- package/dist/esm/components/Calendar/hooks/types.js +1 -0
- package/dist/esm/components/Calendar/hooks/useCalendarCellProps.d.ts +19 -0
- package/dist/esm/components/Calendar/hooks/useCalendarCellProps.js +91 -0
- package/dist/esm/components/Calendar/hooks/useCalendarGridProps.d.ts +5 -0
- package/dist/esm/components/Calendar/hooks/useCalendarGridProps.js +54 -0
- package/dist/esm/components/Calendar/hooks/useCalendarProps.d.ts +10 -0
- package/dist/esm/components/Calendar/hooks/useCalendarProps.js +103 -0
- package/dist/esm/components/Calendar/hooks/useCalendarState.d.ts +7 -0
- package/dist/esm/components/Calendar/hooks/useCalendarState.js +171 -0
- package/dist/esm/components/Calendar/hooks/useRangeCalendarState.d.ts +7 -0
- package/dist/esm/components/Calendar/hooks/useRangeCalendarState.js +75 -0
- package/dist/esm/components/Calendar/i18n/en.json +4 -0
- package/dist/esm/components/Calendar/i18n/index.d.ts +1 -0
- package/dist/esm/components/Calendar/i18n/index.js +5 -0
- package/dist/esm/components/Calendar/i18n/ru.json +4 -0
- package/dist/esm/components/Calendar/index.d.ts +8 -0
- package/dist/esm/components/Calendar/index.js +7 -0
- package/dist/esm/components/Calendar/utils.d.ts +4 -0
- package/dist/esm/components/Calendar/utils.js +34 -0
- package/dist/esm/components/DateField/DateField.css +4 -0
- package/dist/esm/components/DateField/DateField.d.ts +6 -0
- package/dist/esm/components/DateField/DateField.js +31 -0
- package/dist/esm/components/DateField/hooks/useDateFieldProps.d.ts +6 -0
- package/dist/esm/components/DateField/hooks/useDateFieldProps.js +196 -0
- package/dist/esm/components/DateField/hooks/useDateFieldState.d.ts +67 -0
- package/dist/esm/components/DateField/hooks/useDateFieldState.js +621 -0
- package/dist/esm/components/DateField/i18n/en.json +10 -0
- package/dist/esm/components/DateField/i18n/index.d.ts +1 -0
- package/dist/esm/components/DateField/i18n/index.js +5 -0
- package/dist/esm/components/DateField/i18n/ru.json +10 -0
- package/dist/esm/components/DateField/index.d.ts +3 -0
- package/dist/esm/components/DateField/index.js +3 -0
- package/dist/esm/components/DateField/types.d.ts +67 -0
- package/dist/esm/components/DateField/types.js +1 -0
- package/dist/esm/components/DateField/utils.d.ts +14 -0
- package/dist/esm/components/DateField/utils.js +268 -0
- package/dist/esm/components/DatePicker/DatePicker.css +19 -0
- package/dist/esm/components/DatePicker/DatePicker.d.ts +5 -0
- package/dist/esm/components/DatePicker/DatePicker.js +59 -0
- package/dist/esm/components/DatePicker/DesktopCalendar.d.ts +15 -0
- package/dist/esm/components/DatePicker/DesktopCalendar.js +48 -0
- package/dist/esm/components/DatePicker/MobileCalendar.css +49 -0
- package/dist/esm/components/DatePicker/MobileCalendar.d.ts +14 -0
- package/dist/esm/components/DatePicker/MobileCalendar.js +73 -0
- package/dist/esm/components/DatePicker/hooks/useDatePickerState.d.ts +45 -0
- package/dist/esm/components/DatePicker/hooks/useDatePickerState.js +107 -0
- package/dist/esm/components/DatePicker/i18n/en.json +3 -0
- package/dist/esm/components/DatePicker/i18n/index.d.ts +1 -0
- package/dist/esm/components/DatePicker/i18n/index.js +5 -0
- package/dist/esm/components/DatePicker/i18n/ru.json +3 -0
- package/dist/esm/components/DatePicker/index.d.ts +2 -0
- package/dist/esm/components/DatePicker/index.js +2 -0
- package/dist/esm/components/DatePicker/utils.d.ts +1 -0
- package/dist/esm/components/DatePicker/utils.js +2 -0
- package/dist/esm/components/RelativeDateField/RelativeDateField.css +16 -0
- package/dist/esm/components/RelativeDateField/RelativeDateField.d.ts +11 -0
- package/dist/esm/components/RelativeDateField/RelativeDateField.js +30 -0
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldProps.d.ts +12 -0
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +59 -0
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +30 -0
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.js +59 -0
- package/dist/esm/components/RelativeDateField/index.d.ts +3 -0
- package/dist/esm/components/RelativeDateField/index.js +3 -0
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.css +16 -0
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.d.ts +6 -0
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js +25 -0
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.d.ts +17 -0
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +168 -0
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.d.ts +36 -0
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +102 -0
- package/dist/esm/components/RelativeDatePicker/i18n/en.json +4 -0
- package/dist/esm/components/RelativeDatePicker/i18n/index.d.ts +1 -0
- package/dist/esm/components/RelativeDatePicker/i18n/index.js +5 -0
- package/dist/esm/components/RelativeDatePicker/i18n/ru.json +4 -0
- package/dist/esm/components/RelativeDatePicker/index.d.ts +3 -0
- package/dist/esm/components/RelativeDatePicker/index.js +3 -0
- package/dist/esm/components/hooks/useControlledState.d.ts +1 -0
- package/dist/esm/components/hooks/useControlledState.js +23 -0
- package/dist/esm/components/index.d.ts +5 -0
- package/dist/esm/components/index.js +5 -0
- package/dist/esm/components/types/datePicker.d.ts +16 -0
- package/dist/esm/components/types/datePicker.js +1 -0
- package/dist/esm/components/types/events.d.ts +17 -0
- package/dist/esm/components/types/events.js +1 -0
- package/dist/esm/components/types/index.d.ts +4 -0
- package/dist/esm/components/types/index.js +1 -0
- package/dist/esm/components/types/inputs.d.ts +79 -0
- package/dist/esm/components/types/inputs.js +1 -0
- package/dist/esm/components/types/style.d.ts +7 -0
- package/dist/esm/components/types/style.js +1 -0
- package/dist/esm/components/utils/getButtonSizeForInput.d.ts +2 -0
- package/dist/esm/components/utils/getButtonSizeForInput.js +16 -0
- package/dist/esm/components/utils/mergeProps.d.ts +13 -0
- package/dist/esm/components/utils/mergeProps.js +43 -0
- package/dist/esm/components/variables.css +0 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/utils/cn.d.ts +2 -0
- package/dist/esm/utils/cn.js +3 -0
- package/package.json +119 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export type DateFieldSectionType = Exclude<Intl.DateTimeFormatPartTypes, 'era'>;
|
|
2
|
+
export type DateFormatTokenMap = {
|
|
3
|
+
[formatToken: string]: DateFieldSectionType | {
|
|
4
|
+
sectionType: DateFieldSectionType;
|
|
5
|
+
contentType: 'digit' | 'letter';
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export interface DateFieldSection {
|
|
9
|
+
value: number | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Value of the section, as rendered inside the input.
|
|
12
|
+
* For example, in the date `May 25, 1995`, the value of the month section is "May".
|
|
13
|
+
*/
|
|
14
|
+
textValue: string;
|
|
15
|
+
/**
|
|
16
|
+
* Format token used to parse the value of this section from the date object.
|
|
17
|
+
* For example, in the format `MMMM D, YYYY`, the format of the month section is "MMMM".
|
|
18
|
+
*/
|
|
19
|
+
format: string;
|
|
20
|
+
/**
|
|
21
|
+
* Placeholder rendered when the value of this section is empty.
|
|
22
|
+
*/
|
|
23
|
+
placeholder: string;
|
|
24
|
+
/**
|
|
25
|
+
* Type of the section.
|
|
26
|
+
*/
|
|
27
|
+
type: DateFieldSectionType;
|
|
28
|
+
/**
|
|
29
|
+
* Type of content of the section.
|
|
30
|
+
* Will determine if we should apply a digit-based editing or a letter-based editing.
|
|
31
|
+
*/
|
|
32
|
+
contentType: 'digit' | 'letter';
|
|
33
|
+
/**
|
|
34
|
+
* Available values
|
|
35
|
+
*/
|
|
36
|
+
options?: string[];
|
|
37
|
+
/** The minimum numeric value for the segment, if applicable. */
|
|
38
|
+
minValue?: number;
|
|
39
|
+
/** The maximum numeric value for the segment, if applicable. */
|
|
40
|
+
maxValue?: number;
|
|
41
|
+
/**
|
|
42
|
+
* If `true`, the value of this section is supposed to have leading zeroes.
|
|
43
|
+
* For example, the value `1` should be rendered as "01" instead of "1".
|
|
44
|
+
*/
|
|
45
|
+
hasLeadingZeros: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* If `true`, the section value has been modified since the last time the sections were generated from a valid date.
|
|
48
|
+
* When we can generate a valid date from the section, we don't directly pass it to `onChange`,
|
|
49
|
+
* Otherwise, we would lose all the information contained in the original date, things like:
|
|
50
|
+
* - time if the format does not contain it
|
|
51
|
+
* - timezone / UTC
|
|
52
|
+
*
|
|
53
|
+
* To avoid losing that information, we transfer the values of the modified sections from the newly generated date to the original date.
|
|
54
|
+
*/
|
|
55
|
+
modified: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Start index of the section in the format
|
|
58
|
+
*/
|
|
59
|
+
start: number;
|
|
60
|
+
/**
|
|
61
|
+
* End index of the section in the format
|
|
62
|
+
*/
|
|
63
|
+
end: number;
|
|
64
|
+
previousEditableSection: number;
|
|
65
|
+
nextEditableSection: number;
|
|
66
|
+
}
|
|
67
|
+
export type DateFieldSectionWithoutPosition<TSection extends DateFieldSection = DateFieldSection> = Omit<TSection, 'start' | 'end' | 'value' | 'textValue' | 'modified' | 'previousEditableSection' | 'nextEditableSection'>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
|
+
import type { DateFieldSectionWithoutPosition } from './types';
|
|
3
|
+
export declare const isMac: boolean;
|
|
4
|
+
export declare const CtrlCmd: string;
|
|
5
|
+
export declare function expandFormat(format: string): string;
|
|
6
|
+
export declare function splitFormatIntoSections(format: string): DateFieldSectionWithoutPosition[];
|
|
7
|
+
interface PlaceholderValueOptions {
|
|
8
|
+
placeholderValue?: DateTime;
|
|
9
|
+
timeZone?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function createPlaceholderValue({ placeholderValue, timeZone }: PlaceholderValueOptions): DateTime;
|
|
12
|
+
export declare function isInvalid(value: DateTime | null | undefined, minValue: DateTime | undefined, maxValue: DateTime | undefined): boolean;
|
|
13
|
+
export declare function mergeDateTime(date: DateTime, time: DateTime): DateTime;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeDateTime = exports.isInvalid = exports.createPlaceholderValue = exports.splitFormatIntoSections = exports.expandFormat = exports.CtrlCmd = exports.isMac = void 0;
|
|
4
|
+
const date_utils_1 = require("@gravity-ui/date-utils");
|
|
5
|
+
const i18n_1 = require("./i18n");
|
|
6
|
+
exports.isMac = window.navigator.userAgent.indexOf('Macintosh') >= 0;
|
|
7
|
+
exports.CtrlCmd = exports.isMac ? 'metaKey' : 'ctrlKey';
|
|
8
|
+
function expandFormat(format) {
|
|
9
|
+
const localeFormats = date_utils_1.settings.getLocaleData().formats;
|
|
10
|
+
const getShortLocalizedFormatFromLongLocalizedFormat = (formatBis) => formatBis.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (_, escapeSequence, localizedFormat) => escapeSequence || localizedFormat.slice(1));
|
|
11
|
+
return format.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, (_, escapeSequence, localizedFormat) => {
|
|
12
|
+
const LongLocalizedFormat = localizedFormat && localizedFormat.toUpperCase();
|
|
13
|
+
return (escapeSequence ||
|
|
14
|
+
localeFormats[localizedFormat] ||
|
|
15
|
+
getShortLocalizedFormatFromLongLocalizedFormat(localeFormats[LongLocalizedFormat]));
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.expandFormat = expandFormat;
|
|
19
|
+
const escapedCharacters = { start: '[', end: ']' };
|
|
20
|
+
const formatTokenMap = {
|
|
21
|
+
// Year
|
|
22
|
+
YY: 'year',
|
|
23
|
+
YYYY: 'year',
|
|
24
|
+
// Month
|
|
25
|
+
M: 'month',
|
|
26
|
+
MM: 'month',
|
|
27
|
+
MMM: { sectionType: 'month', contentType: 'letter' },
|
|
28
|
+
MMMM: { sectionType: 'month', contentType: 'letter' },
|
|
29
|
+
// Day of the month
|
|
30
|
+
D: 'day',
|
|
31
|
+
DD: 'day',
|
|
32
|
+
Do: 'day',
|
|
33
|
+
// Day of the week
|
|
34
|
+
d: 'weekday',
|
|
35
|
+
dd: { sectionType: 'weekday', contentType: 'letter' },
|
|
36
|
+
ddd: { sectionType: 'weekday', contentType: 'letter' },
|
|
37
|
+
dddd: { sectionType: 'weekday', contentType: 'letter' },
|
|
38
|
+
// Day period AM, PM
|
|
39
|
+
A: { sectionType: 'dayPeriod', contentType: 'letter' },
|
|
40
|
+
a: { sectionType: 'dayPeriod', contentType: 'letter' },
|
|
41
|
+
// Hours
|
|
42
|
+
H: 'hour',
|
|
43
|
+
HH: 'hour',
|
|
44
|
+
h: 'hour',
|
|
45
|
+
hh: 'hour',
|
|
46
|
+
// Minutes
|
|
47
|
+
m: 'minute',
|
|
48
|
+
mm: 'minute',
|
|
49
|
+
// Seconds
|
|
50
|
+
s: 'second',
|
|
51
|
+
ss: 'second',
|
|
52
|
+
// Timezone
|
|
53
|
+
z: { sectionType: 'timeZoneName', contentType: 'letter' },
|
|
54
|
+
zzz: { sectionType: 'timeZoneName', contentType: 'letter' },
|
|
55
|
+
Z: { sectionType: 'timeZoneName', contentType: 'letter' },
|
|
56
|
+
ZZ: { sectionType: 'timeZoneName', contentType: 'letter' },
|
|
57
|
+
};
|
|
58
|
+
function getDateSectionConfigFromFormatToken(formatToken) {
|
|
59
|
+
const config = formatTokenMap[formatToken];
|
|
60
|
+
if (!config) {
|
|
61
|
+
console.error([
|
|
62
|
+
`The token "${formatToken}" is not supported by the Date field.`,
|
|
63
|
+
'Please try using another token.',
|
|
64
|
+
].join('\n'));
|
|
65
|
+
return {
|
|
66
|
+
type: 'literal',
|
|
67
|
+
contentType: 'letter',
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (typeof config === 'string') {
|
|
71
|
+
return {
|
|
72
|
+
type: config,
|
|
73
|
+
contentType: 'digit',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
type: config.sectionType,
|
|
78
|
+
contentType: config.contentType,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function isFourDigitYearFormat(format) {
|
|
82
|
+
return (0, date_utils_1.dateTime)().format(format).length === 4;
|
|
83
|
+
}
|
|
84
|
+
function doesSectionHaveLeadingZeros(contentType, sectionType, format) {
|
|
85
|
+
if (contentType !== 'digit') {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
switch (sectionType) {
|
|
89
|
+
case 'year': {
|
|
90
|
+
if (isFourDigitYearFormat(format)) {
|
|
91
|
+
const formatted0001 = (0, date_utils_1.dateTime)().set('year', 1).format(format);
|
|
92
|
+
return formatted0001 === '0001';
|
|
93
|
+
}
|
|
94
|
+
const formatted2001 = (0, date_utils_1.dateTime)().set('year', 2001).format(format);
|
|
95
|
+
return formatted2001 === '01';
|
|
96
|
+
}
|
|
97
|
+
case 'month': {
|
|
98
|
+
return (0, date_utils_1.dateTime)().startOf('year').format(format).length > 1;
|
|
99
|
+
}
|
|
100
|
+
case 'day': {
|
|
101
|
+
return (0, date_utils_1.dateTime)().startOf('month').format(format).length > 1;
|
|
102
|
+
}
|
|
103
|
+
case 'weekday': {
|
|
104
|
+
return (0, date_utils_1.dateTime)().startOf('week').format(format).length > 1;
|
|
105
|
+
}
|
|
106
|
+
case 'hour': {
|
|
107
|
+
return (0, date_utils_1.dateTime)().set('hour', 1).format(format).length > 1;
|
|
108
|
+
}
|
|
109
|
+
case 'minute': {
|
|
110
|
+
return (0, date_utils_1.dateTime)().set('minute', 1).format(format).length > 1;
|
|
111
|
+
}
|
|
112
|
+
case 'second': {
|
|
113
|
+
return (0, date_utils_1.dateTime)().set('second', 1).format(format).length > 1;
|
|
114
|
+
}
|
|
115
|
+
default: {
|
|
116
|
+
throw new Error('Invalid section type');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function getSectionPlaceholder(sectionConfig, currentTokenValue) {
|
|
121
|
+
switch (sectionConfig.type) {
|
|
122
|
+
case 'year': {
|
|
123
|
+
return (0, i18n_1.i18n)('year_placeholder').repeat((0, date_utils_1.dateTime)().format(currentTokenValue).length);
|
|
124
|
+
}
|
|
125
|
+
case 'month': {
|
|
126
|
+
return (0, i18n_1.i18n)('month_placeholder').repeat(sectionConfig.contentType === 'letter' ? 4 : 2);
|
|
127
|
+
}
|
|
128
|
+
case 'day': {
|
|
129
|
+
return (0, i18n_1.i18n)('day_placeholder').repeat(2);
|
|
130
|
+
}
|
|
131
|
+
case 'weekday': {
|
|
132
|
+
return (0, i18n_1.i18n)('weekday_placeholder').repeat(sectionConfig.contentType === 'letter' ? 4 : 2);
|
|
133
|
+
}
|
|
134
|
+
case 'hour': {
|
|
135
|
+
return (0, i18n_1.i18n)('hour_placeholder').repeat(2);
|
|
136
|
+
}
|
|
137
|
+
case 'minute': {
|
|
138
|
+
return (0, i18n_1.i18n)('minute_placeholder').repeat(2);
|
|
139
|
+
}
|
|
140
|
+
case 'second': {
|
|
141
|
+
return (0, i18n_1.i18n)('second_placeholder').repeat(2);
|
|
142
|
+
}
|
|
143
|
+
case 'dayPeriod': {
|
|
144
|
+
return (0, i18n_1.i18n)('dayPeriod_placeholder');
|
|
145
|
+
}
|
|
146
|
+
default: {
|
|
147
|
+
return currentTokenValue;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function splitFormatIntoSections(format) {
|
|
152
|
+
const sections = [];
|
|
153
|
+
const expandedFormat = expandFormat(format);
|
|
154
|
+
let currentTokenValue = '';
|
|
155
|
+
let isSeparator = false;
|
|
156
|
+
let isInEscapeBoundary = false;
|
|
157
|
+
for (let i = 0; i < expandedFormat.length; i++) {
|
|
158
|
+
const char = expandedFormat[i];
|
|
159
|
+
if (isInEscapeBoundary) {
|
|
160
|
+
if (char === escapedCharacters.end) {
|
|
161
|
+
isInEscapeBoundary = false;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
currentTokenValue += char;
|
|
165
|
+
}
|
|
166
|
+
else if (char.match(/[a-zA-Z]/)) {
|
|
167
|
+
if (isSeparator) {
|
|
168
|
+
addLiteralSection(sections, currentTokenValue);
|
|
169
|
+
currentTokenValue = '';
|
|
170
|
+
}
|
|
171
|
+
isSeparator = false;
|
|
172
|
+
currentTokenValue += char;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
if (!isSeparator) {
|
|
176
|
+
addFormatSection(sections, currentTokenValue);
|
|
177
|
+
currentTokenValue = '';
|
|
178
|
+
}
|
|
179
|
+
isSeparator = true;
|
|
180
|
+
if (char === escapedCharacters.start) {
|
|
181
|
+
isInEscapeBoundary = true;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
currentTokenValue += char;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (currentTokenValue) {
|
|
189
|
+
if (isSeparator) {
|
|
190
|
+
addLiteralSection(sections, currentTokenValue);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
addFormatSection(sections, currentTokenValue);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return sections;
|
|
197
|
+
}
|
|
198
|
+
exports.splitFormatIntoSections = splitFormatIntoSections;
|
|
199
|
+
function addFormatSection(sections, token) {
|
|
200
|
+
if (!token) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const sectionConfig = getDateSectionConfigFromFormatToken(token);
|
|
204
|
+
const hasLeadingZeros = doesSectionHaveLeadingZeros(sectionConfig.contentType, sectionConfig.type, token);
|
|
205
|
+
sections.push(Object.assign(Object.assign({}, sectionConfig), { format: token, placeholder: getSectionPlaceholder(sectionConfig, token), options: getSectionOptions(sectionConfig, token), hasLeadingZeros }));
|
|
206
|
+
}
|
|
207
|
+
function addLiteralSection(sections, token) {
|
|
208
|
+
if (!token) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
sections.push({
|
|
212
|
+
type: 'literal',
|
|
213
|
+
contentType: 'letter',
|
|
214
|
+
format: token,
|
|
215
|
+
placeholder: token,
|
|
216
|
+
hasLeadingZeros: false,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function getSectionOptions(section, token) {
|
|
220
|
+
switch (section.type) {
|
|
221
|
+
case 'month': {
|
|
222
|
+
const format = section.contentType === 'letter' ? token : 'MMMM';
|
|
223
|
+
let date = (0, date_utils_1.dateTime)().startOf('year');
|
|
224
|
+
const options = [];
|
|
225
|
+
for (let i = 0; i < 12; i++) {
|
|
226
|
+
options.push(date.format(format).toLocaleUpperCase());
|
|
227
|
+
date = date.add(1, 'months');
|
|
228
|
+
}
|
|
229
|
+
return options;
|
|
230
|
+
}
|
|
231
|
+
case 'dayPeriod': {
|
|
232
|
+
const amDayPeriod = (0, date_utils_1.dateTime)().hour(0);
|
|
233
|
+
const pmDayPeriod = amDayPeriod.hour(12);
|
|
234
|
+
const options = [
|
|
235
|
+
amDayPeriod.format(token).toLocaleUpperCase(),
|
|
236
|
+
pmDayPeriod.format(token).toLocaleUpperCase(),
|
|
237
|
+
];
|
|
238
|
+
return options;
|
|
239
|
+
}
|
|
240
|
+
case 'weekday': {
|
|
241
|
+
const format = section.contentType === 'letter' ? token : 'dddd';
|
|
242
|
+
let date = (0, date_utils_1.dateTime)().day(0);
|
|
243
|
+
const options = [];
|
|
244
|
+
for (let i = 0; i < 7; i++) {
|
|
245
|
+
options.push(date.format(format).toLocaleUpperCase());
|
|
246
|
+
date = date.add(1, 'day');
|
|
247
|
+
}
|
|
248
|
+
return options;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
function createPlaceholderValue({ placeholderValue, timeZone }) {
|
|
254
|
+
return (placeholderValue !== null && placeholderValue !== void 0 ? placeholderValue : (0, date_utils_1.dateTime)({ timeZone }).set('hour', 0).set('minute', 0).set('second', 0));
|
|
255
|
+
}
|
|
256
|
+
exports.createPlaceholderValue = createPlaceholderValue;
|
|
257
|
+
function isInvalid(value, minValue, maxValue) {
|
|
258
|
+
if (!value) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
if (minValue && value.isBefore(minValue)) {
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
if (maxValue && maxValue.isBefore(value)) {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
exports.isInvalid = isInvalid;
|
|
270
|
+
function mergeDateTime(date, time) {
|
|
271
|
+
return date
|
|
272
|
+
.set('hours', time.hour())
|
|
273
|
+
.set('minutes', time.minute())
|
|
274
|
+
.set('seconds', time.second());
|
|
275
|
+
}
|
|
276
|
+
exports.mergeDateTime = mergeDateTime;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
.g-date-date-picker {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: inline-block;
|
|
4
|
+
}
|
|
5
|
+
.g-date-date-picker__field {
|
|
6
|
+
width: 100%;
|
|
7
|
+
}
|
|
8
|
+
.g-date-date-picker__field_mobile {
|
|
9
|
+
pointer-events: none;
|
|
10
|
+
}
|
|
11
|
+
.g-date-date-picker__popup-content {
|
|
12
|
+
outline: none;
|
|
13
|
+
}
|
|
14
|
+
.g-date-date-picker__time-field {
|
|
15
|
+
width: 100%;
|
|
16
|
+
}
|
|
17
|
+
.g-date-date-picker__time-field-wrapper {
|
|
18
|
+
padding: 10px;
|
|
19
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AccessibilityProps, DateFieldBase, DomProps, FocusableProps, KeyboardEvents, StyleProps, TextInputProps } from '../types';
|
|
2
|
+
import './DatePicker.css';
|
|
3
|
+
export interface DatePickerProps extends DateFieldBase, TextInputProps, FocusableProps, KeyboardEvents, DomProps, StyleProps, AccessibilityProps {
|
|
4
|
+
}
|
|
5
|
+
export declare function DatePicker({ value, defaultValue, onUpdate, className, onFocus, onBlur, ...props }: DatePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DatePicker = void 0;
|
|
18
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
+
const react_1 = __importDefault(require("react"));
|
|
20
|
+
const uikit_1 = require("@gravity-ui/uikit");
|
|
21
|
+
const DateField_1 = require("../DateField");
|
|
22
|
+
const DesktopCalendar_1 = require("./DesktopCalendar");
|
|
23
|
+
const MobileCalendar_1 = require("./MobileCalendar");
|
|
24
|
+
const useDatePickerState_1 = require("./hooks/useDatePickerState");
|
|
25
|
+
const utils_1 = require("./utils");
|
|
26
|
+
require("./DatePicker.css");
|
|
27
|
+
function DatePicker(_a) {
|
|
28
|
+
var { value, defaultValue, onUpdate, className, onFocus, onBlur } = _a, props = __rest(_a, ["value", "defaultValue", "onUpdate", "className", "onFocus", "onBlur"]);
|
|
29
|
+
const anchorRef = react_1.default.useRef(null);
|
|
30
|
+
const state = (0, useDatePickerState_1.useDatePickerState)(Object.assign(Object.assign({}, props), { value,
|
|
31
|
+
defaultValue,
|
|
32
|
+
onUpdate }));
|
|
33
|
+
const [isMobile] = (0, uikit_1.useMobile)();
|
|
34
|
+
const [isActive, setActive] = react_1.default.useState(false);
|
|
35
|
+
const { focusWithinProps } = (0, uikit_1.useFocusWithin)({
|
|
36
|
+
onFocusWithin: onFocus,
|
|
37
|
+
onBlurWithin: onBlur,
|
|
38
|
+
onFocusWithinChange(isFocusWithin) {
|
|
39
|
+
setActive(isFocusWithin);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const fieldState = (0, DateField_1.useDateFieldState)({
|
|
43
|
+
value: state.value,
|
|
44
|
+
onUpdate: state.setValue,
|
|
45
|
+
disabled: state.disabled,
|
|
46
|
+
readOnly: state.readOnly,
|
|
47
|
+
validationState: props.validationState,
|
|
48
|
+
minValue: props.minValue,
|
|
49
|
+
maxValue: props.maxValue,
|
|
50
|
+
isDateUnavailable: props.isDateUnavailable,
|
|
51
|
+
format: state.format,
|
|
52
|
+
placeholderValue: props.placeholderValue,
|
|
53
|
+
timeZone: props.timeZone,
|
|
54
|
+
});
|
|
55
|
+
const { inputProps } = (0, DateField_1.useDateFieldProps)(fieldState, props);
|
|
56
|
+
return (
|
|
57
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
58
|
+
(0, jsx_runtime_1.jsxs)("div", Object.assign({ ref: anchorRef, className: (0, utils_1.b)(null, className), style: props.style }, focusWithinProps, { role: "group", "aria-disabled": state.disabled || undefined, onKeyDown: (e) => {
|
|
59
|
+
if (e.altKey && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
e.stopPropagation();
|
|
62
|
+
state.setOpen(true);
|
|
63
|
+
}
|
|
64
|
+
}, children: [isMobile ? ((0, jsx_runtime_1.jsx)(MobileCalendar_1.MobileCalendar, { props: props, state: state })) : ((0, jsx_runtime_1.jsx)(DesktopCalendar_1.DesktopCalendar, { anchorRef: anchorRef, props: props, state: state })), (0, jsx_runtime_1.jsx)(uikit_1.TextInput, Object.assign({}, inputProps, { value: fieldState.isEmpty && !isActive && props.placeholder ? '' : inputProps.value, className: (0, utils_1.b)('field', { mobile: isMobile }), hasClear: !isMobile && inputProps.hasClear, rightContent: isMobile ? ((0, jsx_runtime_1.jsx)(MobileCalendar_1.MobileCalendarIcon, { props: props, state: state })) : ((0, jsx_runtime_1.jsx)(DesktopCalendar_1.DesktopCalendarButton, { props: props, state: state })) }))] })));
|
|
65
|
+
}
|
|
66
|
+
exports.DatePicker = DatePicker;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { DatePickerProps } from './DatePicker';
|
|
3
|
+
import type { DatePickerState } from './hooks/useDatePickerState';
|
|
4
|
+
interface DesktopCalendarProps {
|
|
5
|
+
anchorRef: React.RefObject<HTMLElement>;
|
|
6
|
+
props: DatePickerProps;
|
|
7
|
+
state: DatePickerState;
|
|
8
|
+
}
|
|
9
|
+
export declare function DesktopCalendar({ anchorRef, props, state }: DesktopCalendarProps): import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
interface DesktopCalendarButtonProps {
|
|
11
|
+
props: DatePickerProps;
|
|
12
|
+
state: DatePickerState;
|
|
13
|
+
}
|
|
14
|
+
export declare function DesktopCalendarButton({ props, state }: DesktopCalendarButtonProps): import("react/jsx-runtime").JSX.Element | null;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DesktopCalendarButton = exports.DesktopCalendar = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const icons_1 = require("@gravity-ui/icons");
|
|
10
|
+
const uikit_1 = require("@gravity-ui/uikit");
|
|
11
|
+
const Calendar_1 = require("../Calendar");
|
|
12
|
+
const DateField_1 = require("../DateField");
|
|
13
|
+
const getButtonSizeForInput_1 = require("../utils/getButtonSizeForInput");
|
|
14
|
+
const i18n_1 = require("./i18n");
|
|
15
|
+
const utils_1 = require("./utils");
|
|
16
|
+
function DesktopCalendar({ anchorRef, props, state }) {
|
|
17
|
+
var _a;
|
|
18
|
+
const { focusWithinProps } = (0, uikit_1.useFocusWithin)({
|
|
19
|
+
isDisabled: !state.isOpen,
|
|
20
|
+
onBlurWithin: () => {
|
|
21
|
+
state.setOpen(false);
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
if (!state.hasDate) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return ((0, jsx_runtime_1.jsx)(uikit_1.Popup, { open: state.isOpen, anchorRef: anchorRef, onClose: () => {
|
|
28
|
+
state.setOpen(false);
|
|
29
|
+
}, restoreFocus: true, children: (0, jsx_runtime_1.jsxs)("div", Object.assign({}, focusWithinProps, { className: (0, utils_1.b)('popup-content'), children: [(0, jsx_runtime_1.jsx)(Calendar_1.Calendar
|
|
30
|
+
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
31
|
+
, {
|
|
32
|
+
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
33
|
+
autoFocus: true, size: props.size === 's' ? 'm' : props.size, disabled: props.disabled, readOnly: props.readOnly, onUpdate: (d) => {
|
|
34
|
+
state.setDateValue(d);
|
|
35
|
+
}, defaultFocusedValue: (_a = state.dateValue) !== null && _a !== void 0 ? _a : undefined, value: state.dateValue, minValue: props.minValue, maxValue: props.maxValue, isDateUnavailable: props.isDateUnavailable, timeZone: props.timeZone }), 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, { className: (0, utils_1.b)('time-field'), size: props.size, readOnly: props.readOnly, value: state.timeValue, onUpdate: state.setTimeValue, placeholderValue: props.placeholderValue, minValue: props.minValue, maxValue: props.maxValue, timeZone: props.timeZone, format: state.timeFormat }) }))] })) }));
|
|
36
|
+
}
|
|
37
|
+
exports.DesktopCalendar = DesktopCalendar;
|
|
38
|
+
function DesktopCalendarButton({ props, state }) {
|
|
39
|
+
const wasOpenBeforeClickRef = react_1.default.useRef(false);
|
|
40
|
+
if (!state.hasDate) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(uikit_1.Button, { view: "flat", size: (0, getButtonSizeForInput_1.getButtonSizeForInput)(props.size), disabled: props.disabled, extraProps: {
|
|
44
|
+
'aria-label': (0, i18n_1.i18n)('Calendar'),
|
|
45
|
+
'aria-haspopup': 'dialog',
|
|
46
|
+
'aria-expanded': state.isOpen,
|
|
47
|
+
}, onFocus: () => {
|
|
48
|
+
wasOpenBeforeClickRef.current = state.isOpen;
|
|
49
|
+
}, onClick: () => {
|
|
50
|
+
if (!wasOpenBeforeClickRef.current) {
|
|
51
|
+
state.setOpen(true);
|
|
52
|
+
}
|
|
53
|
+
wasOpenBeforeClickRef.current = false;
|
|
54
|
+
}, children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Calendar }) }));
|
|
55
|
+
}
|
|
56
|
+
exports.DesktopCalendarButton = DesktopCalendarButton;
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
position: absolute;
|
|
28
|
+
z-index: 1;
|
|
29
|
+
top: 0;
|
|
30
|
+
left: 0;
|
|
31
|
+
box-sizing: border-box;
|
|
32
|
+
width: 100%;
|
|
33
|
+
height: 100%;
|
|
34
|
+
margin: 0;
|
|
35
|
+
padding: 0;
|
|
36
|
+
cursor: pointer;
|
|
37
|
+
opacity: 0;
|
|
38
|
+
border: none;
|
|
39
|
+
}
|
|
40
|
+
.g-date-mobile-calendar__input::-webkit-calendar-picker-indicator {
|
|
41
|
+
position: absolute;
|
|
42
|
+
top: 0;
|
|
43
|
+
left: 0;
|
|
44
|
+
width: 100%;
|
|
45
|
+
height: 100%;
|
|
46
|
+
margin: 0;
|
|
47
|
+
padding: 0;
|
|
48
|
+
cursor: pointer;
|
|
49
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DatePickerProps } from './DatePicker';
|
|
2
|
+
import type { DatePickerState } from './hooks/useDatePickerState';
|
|
3
|
+
import './MobileCalendar.css';
|
|
4
|
+
interface MobileCalendarProps {
|
|
5
|
+
props: DatePickerProps;
|
|
6
|
+
state: DatePickerState;
|
|
7
|
+
}
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MobileCalendarIcon = exports.MobileCalendar = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const date_utils_1 = require("@gravity-ui/date-utils");
|
|
6
|
+
const icons_1 = require("@gravity-ui/icons");
|
|
7
|
+
const uikit_1 = require("@gravity-ui/uikit");
|
|
8
|
+
const cn_1 = require("../../utils/cn");
|
|
9
|
+
const utils_1 = require("../DateField/utils");
|
|
10
|
+
const getButtonSizeForInput_1 = require("../utils/getButtonSizeForInput");
|
|
11
|
+
require("./MobileCalendar.css");
|
|
12
|
+
const b = (0, cn_1.block)('mobile-calendar');
|
|
13
|
+
function MobileCalendar({ props, state }) {
|
|
14
|
+
let type = 'date';
|
|
15
|
+
if (state.hasTime && state.hasDate) {
|
|
16
|
+
type = 'datetime-local';
|
|
17
|
+
}
|
|
18
|
+
else if (state.hasTime) {
|
|
19
|
+
type = 'time';
|
|
20
|
+
}
|
|
21
|
+
return ((0, jsx_runtime_1.jsx)("input", { className: b('input'), disabled: props.disabled, type: type, value: formatNative(state.value || props.placeholderValue, type), id: props.id, min: formatNative(props.minValue, type), max: formatNative(props.maxValue, type), tabIndex: -1, onChange: (e) => {
|
|
22
|
+
if (props.readOnly) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const newValue = e.target.value;
|
|
26
|
+
if (newValue) {
|
|
27
|
+
const localDate = (0, date_utils_1.dateTime)({ input: newValue, format: getDateFormat(type) });
|
|
28
|
+
let newDate = state.hasDate
|
|
29
|
+
? (0, date_utils_1.dateTime)({
|
|
30
|
+
input: newValue,
|
|
31
|
+
format: getDateFormat(type),
|
|
32
|
+
timeZone: props.timeZone,
|
|
33
|
+
})
|
|
34
|
+
: (0, utils_1.createPlaceholderValue)({
|
|
35
|
+
placeholderValue: props.placeholderValue,
|
|
36
|
+
timeZone: props.timeZone,
|
|
37
|
+
});
|
|
38
|
+
if (state.hasTime) {
|
|
39
|
+
newDate = (0, utils_1.mergeDateTime)(newDate, localDate);
|
|
40
|
+
}
|
|
41
|
+
else if (state.dateValue) {
|
|
42
|
+
newDate = (0, utils_1.mergeDateTime)(newDate, state.dateValue);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
newDate = newDate.set('hours', 0).set('minutes', 0).set('seconds', 0);
|
|
46
|
+
}
|
|
47
|
+
state.setValue(newDate);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
state.setValue(null);
|
|
51
|
+
}
|
|
52
|
+
} }));
|
|
53
|
+
}
|
|
54
|
+
exports.MobileCalendar = MobileCalendar;
|
|
55
|
+
function MobileCalendarIcon({ props }) {
|
|
56
|
+
return ((0, jsx_runtime_1.jsx)("span", { className: b({ size: (0, getButtonSizeForInput_1.getButtonSizeForInput)(props.size) }), children: (0, jsx_runtime_1.jsx)("span", { className: b('button'), children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Calendar }) }) }));
|
|
57
|
+
}
|
|
58
|
+
exports.MobileCalendarIcon = MobileCalendarIcon;
|
|
59
|
+
function getDateFormat(type) {
|
|
60
|
+
switch (type) {
|
|
61
|
+
case 'time': {
|
|
62
|
+
return 'HH:mm';
|
|
63
|
+
}
|
|
64
|
+
case 'datetime-local': {
|
|
65
|
+
return 'YYYY-MM-DDTHH:mm';
|
|
66
|
+
}
|
|
67
|
+
default: {
|
|
68
|
+
return 'YYYY-MM-DD';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function formatNative(date, type) {
|
|
73
|
+
if (!date) {
|
|
74
|
+
return '';
|
|
75
|
+
}
|
|
76
|
+
const format = getDateFormat(type);
|
|
77
|
+
return date.format(format);
|
|
78
|
+
}
|