@snack-uikit/calendar 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +20 -5
- package/dist/cjs/components/Calendar/Calendar.d.ts +22 -8
- package/dist/cjs/components/Calendar/Calendar.js +3 -3
- package/dist/cjs/components/Calendar/utils.d.ts +1 -2
- package/dist/cjs/components/Calendar/utils.js +15 -20
- package/dist/cjs/components/TimePicker/TimePicker.d.ts +34 -0
- package/dist/cjs/components/TimePicker/TimePicker.js +149 -0
- package/dist/cjs/components/TimePicker/index.d.ts +1 -0
- package/dist/cjs/components/TimePicker/index.js +25 -0
- package/dist/cjs/components/TimePicker/styles.module.css +12 -0
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/components/index.js +2 -1
- package/dist/cjs/constants.d.ts +5 -0
- package/dist/cjs/constants.js +7 -2
- package/dist/cjs/helperComponents/Button/Button.js +7 -6
- package/dist/cjs/helperComponents/Button/styles.module.css +13 -13
- package/dist/cjs/helperComponents/CalendarBase/CalendarBase.d.ts +6 -3
- package/dist/cjs/helperComponents/CalendarBase/CalendarBase.js +86 -38
- package/dist/cjs/helperComponents/CalendarBase/hooks.d.ts +10 -1
- package/dist/cjs/helperComponents/CalendarBase/hooks.js +30 -0
- package/dist/cjs/helperComponents/CalendarBase/styles.module.css +36 -12
- package/dist/cjs/helperComponents/CalendarContext/CalendarContext.d.ts +23 -6
- package/dist/cjs/helperComponents/CalendarContext/CalendarContext.js +18 -2
- package/dist/cjs/helperComponents/ColumnLabels/styles.module.css +3 -3
- package/dist/cjs/helperComponents/Footer/Footer.d.ts +1 -0
- package/dist/cjs/helperComponents/Footer/Footer.js +126 -0
- package/dist/cjs/helperComponents/Footer/index.d.ts +1 -0
- package/dist/cjs/helperComponents/Footer/index.js +25 -0
- package/dist/cjs/helperComponents/Footer/styles.module.css +49 -0
- package/dist/cjs/helperComponents/Item/Item.js +3 -2
- package/dist/cjs/helperComponents/Item/hooks.d.ts +2 -2
- package/dist/cjs/helperComponents/Item/hooks.js +6 -4
- package/dist/cjs/helperComponents/MonthView/MonthView.js +38 -3
- package/dist/cjs/helperComponents/TimeList/TimeList.d.ts +15 -0
- package/dist/cjs/helperComponents/TimeList/TimeList.js +65 -0
- package/dist/cjs/helperComponents/TimeList/index.d.ts +1 -0
- package/dist/cjs/helperComponents/TimeList/index.js +25 -0
- package/dist/cjs/helperComponents/TimePickerBase/TimePickerBase.d.ts +3 -0
- package/dist/cjs/helperComponents/TimePickerBase/TimePickerBase.js +190 -0
- package/dist/cjs/helperComponents/TimePickerBase/index.d.ts +1 -0
- package/dist/cjs/helperComponents/TimePickerBase/index.js +25 -0
- package/dist/cjs/helperComponents/TimePickerBase/styles.module.css +103 -0
- package/dist/cjs/hooks.d.ts +17 -2
- package/dist/cjs/hooks.js +119 -9
- package/dist/cjs/types.d.ts +12 -0
- package/dist/cjs/utils.d.ts +1 -1
- package/dist/cjs/utils.js +6 -4
- package/dist/esm/components/Calendar/Calendar.d.ts +22 -8
- package/dist/esm/components/Calendar/Calendar.js +3 -3
- package/dist/esm/components/Calendar/utils.d.ts +1 -2
- package/dist/esm/components/Calendar/utils.js +11 -11
- package/dist/esm/components/TimePicker/TimePicker.d.ts +34 -0
- package/dist/esm/components/TimePicker/TimePicker.js +86 -0
- package/dist/esm/components/TimePicker/index.d.ts +1 -0
- package/dist/esm/components/TimePicker/index.js +1 -0
- package/dist/esm/components/TimePicker/styles.module.css +12 -0
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/constants.d.ts +5 -0
- package/dist/esm/constants.js +5 -0
- package/dist/esm/helperComponents/Button/Button.js +8 -7
- package/dist/esm/helperComponents/Button/styles.module.css +13 -13
- package/dist/esm/helperComponents/CalendarBase/CalendarBase.d.ts +6 -3
- package/dist/esm/helperComponents/CalendarBase/CalendarBase.js +37 -22
- package/dist/esm/helperComponents/CalendarBase/hooks.d.ts +10 -1
- package/dist/esm/helperComponents/CalendarBase/hooks.js +20 -0
- package/dist/esm/helperComponents/CalendarBase/styles.module.css +36 -12
- package/dist/esm/helperComponents/CalendarContext/CalendarContext.d.ts +23 -6
- package/dist/esm/helperComponents/CalendarContext/CalendarContext.js +15 -1
- package/dist/esm/helperComponents/ColumnLabels/styles.module.css +3 -3
- package/dist/esm/helperComponents/Footer/Footer.d.ts +1 -0
- package/dist/esm/helperComponents/Footer/Footer.js +63 -0
- package/dist/esm/helperComponents/Footer/index.d.ts +1 -0
- package/dist/esm/helperComponents/Footer/index.js +1 -0
- package/dist/esm/helperComponents/Footer/styles.module.css +49 -0
- package/dist/esm/helperComponents/Item/Item.js +2 -2
- package/dist/esm/helperComponents/Item/hooks.d.ts +2 -2
- package/dist/esm/helperComponents/Item/hooks.js +6 -5
- package/dist/esm/helperComponents/MonthView/MonthView.js +31 -3
- package/dist/esm/helperComponents/TimeList/TimeList.d.ts +15 -0
- package/dist/esm/helperComponents/TimeList/TimeList.js +37 -0
- package/dist/esm/helperComponents/TimeList/index.d.ts +1 -0
- package/dist/esm/helperComponents/TimeList/index.js +1 -0
- package/dist/esm/helperComponents/TimePickerBase/TimePickerBase.d.ts +3 -0
- package/dist/esm/helperComponents/TimePickerBase/TimePickerBase.js +113 -0
- package/dist/esm/helperComponents/TimePickerBase/index.d.ts +1 -0
- package/dist/esm/helperComponents/TimePickerBase/index.js +1 -0
- package/dist/esm/helperComponents/TimePickerBase/styles.module.css +103 -0
- package/dist/esm/hooks.d.ts +17 -2
- package/dist/esm/hooks.js +109 -8
- package/dist/esm/types.d.ts +12 -0
- package/dist/esm/utils.d.ts +1 -1
- package/dist/esm/utils.js +4 -2
- package/package.json +6 -3
- package/src/components/Calendar/Calendar.tsx +27 -12
- package/src/components/Calendar/utils.ts +17 -10
- package/src/components/TimePicker/TimePicker.tsx +166 -0
- package/src/components/TimePicker/index.ts +1 -0
- package/src/components/TimePicker/styles.module.scss +13 -0
- package/src/components/index.ts +1 -0
- package/src/constants.ts +7 -0
- package/src/helperComponents/Button/Button.tsx +8 -7
- package/src/helperComponents/Button/styles.module.scss +12 -12
- package/src/helperComponents/CalendarBase/CalendarBase.tsx +78 -43
- package/src/helperComponents/CalendarBase/hooks.ts +31 -1
- package/src/helperComponents/CalendarBase/styles.module.scss +37 -14
- package/src/helperComponents/CalendarContext/CalendarContext.tsx +47 -7
- package/src/helperComponents/ColumnLabel/styles.module.scss +6 -6
- package/src/helperComponents/ColumnLabels/styles.module.scss +2 -2
- package/src/helperComponents/Footer/Footer.tsx +129 -0
- package/src/helperComponents/Footer/index.ts +1 -0
- package/src/helperComponents/Footer/styles.module.scss +31 -0
- package/src/helperComponents/Item/Item.tsx +2 -1
- package/src/helperComponents/Item/hooks.ts +8 -6
- package/src/helperComponents/Item/styles.module.scss +29 -29
- package/src/helperComponents/MonthView/MonthView.tsx +43 -2
- package/src/helperComponents/TimeList/TimeList.tsx +69 -0
- package/src/helperComponents/TimeList/index.ts +1 -0
- package/src/helperComponents/TimePickerBase/TimePickerBase.tsx +202 -0
- package/src/helperComponents/TimePickerBase/index.ts +1 -0
- package/src/helperComponents/TimePickerBase/styles.module.scss +76 -0
- package/src/hooks.ts +139 -6
- package/src/types.ts +15 -0
- package/src/utils.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 0.11.0 (2024-10-31)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **PDS-438:** add timepicker ([f4d2536](https://github.com/cloud-ru-tech/snack-uikit/commit/f4d253672750e1fcafa435fc1cace4ea22f79e13))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### BREAKING CHANGES
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
* **PDS-438:** add mode date-time to calendar, change type of navigationStartRef to RefObject ([4b4b7aa](https://github.com/cloud-ru-tech/snack-uikit/commit/4b4b7aadc6f1ab81b6b730a01c7dfed6d978ffcf))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# 0.10.0 (2024-10-28)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* **FF-5782:** sass use/forward approach ([3e53869](https://github.com/cloud-ru-tech/snack-uikit/commit/3e53869ace864a7718e434b7f410c15dbd911cd5))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
6
33
|
# 0.9.0 (2024-10-28)
|
|
7
34
|
|
|
8
35
|
|
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ import { Calendar } from '@snack-uikit/calendar';
|
|
|
31
31
|
### Props
|
|
32
32
|
| name | type | default value | description |
|
|
33
33
|
|------|------|---------------|-------------|
|
|
34
|
-
| mode* | "date" \| "range" \| "month" | - | Режим работы календаря: <br> - `date` - режим выбора даты <br> - `range` - режим выбора периода
|
|
34
|
+
| mode* | "date" \| "date-time" \| "range" \| "month" | - | Режим работы календаря: <br> - `date` - режим выбора даты <br> - `range` - режим выбора периода <br> - `month` - режим выбора месяца <br> - `date-time` - режим выбора даты и времени |
|
|
35
35
|
| size | enum Size: `"s"`, `"m"`, `"l"` | m | Размер |
|
|
36
36
|
| today | `number \| Date` | - | Дата сегодняшнего дня |
|
|
37
37
|
| showHolidays | `boolean` | - | Раскрашивает субботу и воскресенье |
|
|
@@ -42,10 +42,25 @@ import { Calendar } from '@snack-uikit/calendar';
|
|
|
42
42
|
| autofocus | `boolean` | - | Автофокус |
|
|
43
43
|
| locale | `Intl.Locale` | Проставляется в соответствие с языком в настройках браузера | Локаль, в соответствие с которой выставляется язык названий и первый день недели |
|
|
44
44
|
| onFocusLeave | `(direction: FocusDirection) => void` | - | Колбек потери фокуса. Вызывается со значением `next`, когда фокус покидает компонент, передвигаясь вперед, по клавише `tab`. Со значением `prev` - по клавише стрелки вверх или `shift + tab`. |
|
|
45
|
-
| navigationStartRef | `
|
|
46
|
-
| value | `Date \| Range` | - | Выбранное значение.<br> - в режиме date тип `Date` <br> - в режиме range тип `Range` (`[Date, Date]`)
|
|
47
|
-
| defaultValue | `Date \| Range` | - | Значение по-умолчанию для uncontrolled.<br> - в режиме date тип `Date` <br> - в режиме range тип `Range` (`[Date, Date]`)
|
|
48
|
-
| onChangeValue | `((value: Date) => void) \| ((value: Range) => void) \| ((value: Date) => void)` | - | Колбек выбора значения.<br> - в режиме date принимает тип `Date` <br> - в режиме range принимает тип `Range`
|
|
45
|
+
| navigationStartRef | `RefObject<{ focus(): void; }>` | - | Ссылка на управление первым элементом навигации |
|
|
46
|
+
| value | `Date \| Range` | - | Выбранное значение.<br> - в режиме date тип `Date` <br> - в режиме range тип `Range` (`[Date, Date]`) <br> - в режиме month тип `Date` <br> - в режиме date-time тип `Date` |
|
|
47
|
+
| defaultValue | `Date \| Range` | - | Значение по-умолчанию для uncontrolled.<br> - в режиме date тип `Date` <br> - в режиме range тип `Range` (`[Date, Date]`) <br> - в режиме month тип `Date` <br> - в режиме date-time тип `Date` |
|
|
48
|
+
| onChangeValue | `((value: Date) => void) \| ((value: Range) => void) \| ((value: Date) => void) \| ((value: Date) => void)` | - | Колбек выбора значения.<br> - в режиме date принимает тип `Date` <br> - в режиме range принимает тип `Range` <br> - в режиме month принимает тип `Date` <br> - в режиме date-time принимает тип `Date` |
|
|
49
|
+
| showSeconds | `boolean` | - | Показывать ли секунды (только в режиме date-time) |
|
|
50
|
+
## TimePicker
|
|
51
|
+
### Props
|
|
52
|
+
| name | type | default value | description |
|
|
53
|
+
|------|------|---------------|-------------|
|
|
54
|
+
| value | `TimeValue` | - | Выбранное значение. |
|
|
55
|
+
| today | `number \| Date` | - | Дата сегодняшнего дня |
|
|
56
|
+
| defaultValue | `TimeValue` | - | Значение по-умолчанию для uncontrolled. |
|
|
57
|
+
| onChangeValue | `(value?: TimeValue) => void` | - | Колбек выбора значения |
|
|
58
|
+
| showSeconds | `boolean` | true | Показывать ли секунды |
|
|
59
|
+
| size | enum Size: `"s"`, `"m"`, `"l"` | m | Размер |
|
|
60
|
+
| className | `string` | - | CSS-класс контейнера |
|
|
61
|
+
| fitToContainer | `boolean` | true | Отключает предустановленный размер, заставляя компонент подстраиваться к размеру контейнра: (width: 100%, height: 100%). |
|
|
62
|
+
| onFocusLeave | `(direction: FocusDirection) => void` | - | Колбек потери фокуса. Вызывается со значением `next`, когда фокус покидает компонент, передвигаясь вперед, по клавише `tab`. Со значением `prev` - по клавише стрелки вверх или `shift + tab`. |
|
|
63
|
+
| navigationStartRef | `RefObject<{ focus(): void; }>` | - | Ссылка на управление первым элементом навигации |
|
|
49
64
|
|
|
50
65
|
|
|
51
66
|
[//]: DOCUMENTATION_SECTION_END
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CSSProperties,
|
|
1
|
+
import { CSSProperties, RefObject } from 'react';
|
|
2
2
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
3
|
import { CALENDAR_MODE } from '../../constants';
|
|
4
4
|
import { BuildCellPropsFunction, FocusDirection, Range, Size } from '../../types';
|
|
@@ -42,8 +42,10 @@ type CommonCalendarProps = {
|
|
|
42
42
|
locale?: Intl.Locale;
|
|
43
43
|
/** Колбек потери фокуса. Вызывается со значением `next`, когда фокус покидает компонент, передвигаясь вперед, по клавише `tab`. Со значением `prev` - по клавише стрелки вверх или `shift + tab`. */
|
|
44
44
|
onFocusLeave?(direction: FocusDirection): void;
|
|
45
|
-
/**
|
|
46
|
-
navigationStartRef?:
|
|
45
|
+
/** Ссылка на управление первым элементом навигации */
|
|
46
|
+
navigationStartRef?: RefObject<{
|
|
47
|
+
focus(): void;
|
|
48
|
+
}>;
|
|
47
49
|
};
|
|
48
50
|
type DateCalendarProps = CommonCalendarProps & {
|
|
49
51
|
/** Режим работы календаря: <br> - `date` - режим выбора даты */
|
|
@@ -56,15 +58,27 @@ type DateCalendarProps = CommonCalendarProps & {
|
|
|
56
58
|
onChangeValue?(value: Date): void;
|
|
57
59
|
};
|
|
58
60
|
type MonthCalendarProps = CommonCalendarProps & {
|
|
59
|
-
/**
|
|
61
|
+
/** <br> - `month` - режим выбора месяца */
|
|
60
62
|
mode: typeof CALENDAR_MODE.Month;
|
|
61
|
-
/**
|
|
63
|
+
/** <br> - в режиме month тип `Date` */
|
|
62
64
|
value?: Date;
|
|
63
|
-
/**
|
|
65
|
+
/** <br> - в режиме month тип `Date` */
|
|
64
66
|
defaultValue?: Date;
|
|
65
|
-
/**
|
|
67
|
+
/** <br> - в режиме month принимает тип `Date` */
|
|
66
68
|
onChangeValue?(value: Date): void;
|
|
67
69
|
};
|
|
70
|
+
type DateTimeCalendarProps = CommonCalendarProps & {
|
|
71
|
+
/** <br> - `date-time` - режим выбора даты и времени */
|
|
72
|
+
mode: typeof CALENDAR_MODE.DateTime;
|
|
73
|
+
/** <br> - в режиме date-time тип `Date` */
|
|
74
|
+
value?: Date;
|
|
75
|
+
/** <br> - в режиме date-time тип `Date` */
|
|
76
|
+
defaultValue?: Date;
|
|
77
|
+
/** <br> - в режиме date-time принимает тип `Date` */
|
|
78
|
+
onChangeValue?(value: Date): void;
|
|
79
|
+
/** Показывать ли секунды (только в режиме date-time) */
|
|
80
|
+
showSeconds?: boolean;
|
|
81
|
+
};
|
|
68
82
|
type RangeCalendarProps = CommonCalendarProps & {
|
|
69
83
|
/** <br> - `range` - режим выбора периода */
|
|
70
84
|
mode: typeof CALENDAR_MODE.Range;
|
|
@@ -75,6 +89,6 @@ type RangeCalendarProps = CommonCalendarProps & {
|
|
|
75
89
|
/** <br> - в режиме range принимает тип `Range` */
|
|
76
90
|
onChangeValue?(value: Range): void;
|
|
77
91
|
};
|
|
78
|
-
export type CalendarProps = WithSupportProps<DateCalendarProps | RangeCalendarProps | MonthCalendarProps>;
|
|
92
|
+
export type CalendarProps = WithSupportProps<DateCalendarProps | RangeCalendarProps | MonthCalendarProps | DateTimeCalendarProps>;
|
|
79
93
|
export declare function Calendar(props: CalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
80
94
|
export {};
|
|
@@ -26,7 +26,7 @@ function Calendar(props) {
|
|
|
26
26
|
} = props,
|
|
27
27
|
rest = __rest(props, ["className", "onChangeValue", "buildCellProps", "mode"]);
|
|
28
28
|
const changeValueHandler = (0, react_1.useCallback)(value => {
|
|
29
|
-
if (mode === constants_1.CALENDAR_MODE.Date || mode === constants_1.CALENDAR_MODE.Month) {
|
|
29
|
+
if (mode === constants_1.CALENDAR_MODE.Date || mode === constants_1.CALENDAR_MODE.Month || mode === constants_1.CALENDAR_MODE.DateTime) {
|
|
30
30
|
const [date] = value;
|
|
31
31
|
onChangeValue === null || onChangeValue === void 0 ? void 0 : onChangeValue(date);
|
|
32
32
|
return;
|
|
@@ -36,8 +36,8 @@ function Calendar(props) {
|
|
|
36
36
|
return (0, jsx_runtime_1.jsx)(CalendarBase_1.CalendarBase, Object.assign({}, rest, {
|
|
37
37
|
mode: mode,
|
|
38
38
|
className: className,
|
|
39
|
-
value: (0, utils_1.getNormalizedValue)(props),
|
|
40
|
-
defaultValue: (0, utils_1.
|
|
39
|
+
value: (0, utils_1.getNormalizedValue)(props.value),
|
|
40
|
+
defaultValue: (0, utils_1.getNormalizedValue)(props.defaultValue),
|
|
41
41
|
onChangeValue: changeValueHandler,
|
|
42
42
|
buildCellProps: buildCellProps
|
|
43
43
|
}));
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { Range } from '../../types';
|
|
2
2
|
import { CalendarProps } from './Calendar';
|
|
3
|
-
export declare const getNormalizedValue: (
|
|
4
|
-
export declare const getNormalizedDefaultValue: ({ defaultValue, mode }: CalendarProps) => Range | undefined;
|
|
3
|
+
export declare const getNormalizedValue: (value: CalendarProps["value"]) => Range | undefined;
|
|
@@ -3,25 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (
|
|
6
|
+
exports.getNormalizedValue = void 0;
|
|
7
|
+
function isRangeValue(value) {
|
|
8
|
+
return Array.isArray(value) && value.length === 2 && value[0] instanceof Date && value[1] instanceof Date;
|
|
9
|
+
}
|
|
10
|
+
function isDateValue(value) {
|
|
11
|
+
return value instanceof Date;
|
|
12
|
+
}
|
|
13
|
+
const getNormalizedValue = value => {
|
|
14
|
+
if (isRangeValue(value)) {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
if (isDateValue(value)) {
|
|
18
|
+
return [value, value];
|
|
19
|
+
}
|
|
15
20
|
return value;
|
|
16
21
|
};
|
|
17
|
-
exports.getNormalizedValue = getNormalizedValue;
|
|
18
|
-
const getNormalizedDefaultValue = _ref2 => {
|
|
19
|
-
let {
|
|
20
|
-
defaultValue,
|
|
21
|
-
mode
|
|
22
|
-
} = _ref2;
|
|
23
|
-
if (!defaultValue) return defaultValue;
|
|
24
|
-
if (mode === constants_1.CALENDAR_MODE.Date || mode === constants_1.CALENDAR_MODE.Month) return [defaultValue, defaultValue];
|
|
25
|
-
return defaultValue;
|
|
26
|
-
};
|
|
27
|
-
exports.getNormalizedDefaultValue = getNormalizedDefaultValue;
|
|
22
|
+
exports.getNormalizedValue = getNormalizedValue;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
+
import { FocusDirection, Size, TimeValue } from '../../types';
|
|
4
|
+
export type TimePickerProps = WithSupportProps<{
|
|
5
|
+
/** Выбранное значение.*/
|
|
6
|
+
value?: TimeValue;
|
|
7
|
+
/** Дата сегодняшнего дня */
|
|
8
|
+
today?: Date | number;
|
|
9
|
+
/** Значение по-умолчанию для uncontrolled. */
|
|
10
|
+
defaultValue?: TimeValue;
|
|
11
|
+
/** Колбек выбора значения */
|
|
12
|
+
onChangeValue?(value?: TimeValue): void;
|
|
13
|
+
/** Показывать ли секунды */
|
|
14
|
+
showSeconds?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Размер
|
|
17
|
+
* @default m
|
|
18
|
+
*/
|
|
19
|
+
size?: Size;
|
|
20
|
+
/** CSS-класс контейнера */
|
|
21
|
+
className?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Отключает предустановленный размер, заставляя компонент подстраиваться к размеру контейнра: (width: 100%, height: 100%).
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
fitToContainer?: boolean;
|
|
27
|
+
/** Колбек потери фокуса. Вызывается со значением `next`, когда фокус покидает компонент, передвигаясь вперед, по клавише `tab`. Со значением `prev` - по клавише стрелки вверх или `shift + tab`. */
|
|
28
|
+
onFocusLeave?(direction: FocusDirection): void;
|
|
29
|
+
/** Ссылка на управление первым элементом навигации */
|
|
30
|
+
navigationStartRef?: RefObject<{
|
|
31
|
+
focus(): void;
|
|
32
|
+
}>;
|
|
33
|
+
}>;
|
|
34
|
+
export declare function TimePicker({ className, size, fitToContainer, value: valueProp, defaultValue, onChangeValue, onFocusLeave, 'data-test-id': testId, navigationStartRef, showSeconds, today: todayProp, }: TimePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
+
return mod && mod.__esModule ? mod : {
|
|
5
|
+
"default": mod
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
exports.TimePicker = TimePicker;
|
|
12
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
13
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
14
|
+
const react_1 = require("react");
|
|
15
|
+
const uncontrollable_1 = require("uncontrollable");
|
|
16
|
+
const locale_1 = require("@snack-uikit/locale");
|
|
17
|
+
const utils_1 = require("@snack-uikit/utils");
|
|
18
|
+
const constants_1 = require("../../constants");
|
|
19
|
+
const CalendarContext_1 = require("../../helperComponents/CalendarContext");
|
|
20
|
+
const Footer_1 = require("../../helperComponents/Footer");
|
|
21
|
+
const TimePickerBase_1 = require("../../helperComponents/TimePickerBase");
|
|
22
|
+
const hooks_1 = require("../../hooks");
|
|
23
|
+
const utils_2 = require("../../utils");
|
|
24
|
+
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
25
|
+
const stubDate = new Date();
|
|
26
|
+
const stubFunc = () => {};
|
|
27
|
+
function TimePicker(_ref) {
|
|
28
|
+
let {
|
|
29
|
+
className,
|
|
30
|
+
size = constants_1.SIZE.M,
|
|
31
|
+
fitToContainer = true,
|
|
32
|
+
value: valueProp,
|
|
33
|
+
defaultValue,
|
|
34
|
+
onChangeValue,
|
|
35
|
+
onFocusLeave,
|
|
36
|
+
'data-test-id': testId,
|
|
37
|
+
navigationStartRef,
|
|
38
|
+
showSeconds = true,
|
|
39
|
+
today: todayProp
|
|
40
|
+
} = _ref;
|
|
41
|
+
const [value, setValueState] = (0, uncontrollable_1.useUncontrolledProp)(valueProp, defaultValue, onChangeValue);
|
|
42
|
+
const setValueEventHandler = (0, utils_1.useEventHandler)(setValueState);
|
|
43
|
+
const [internalValue, setInternalValue] = (0, react_1.useState)();
|
|
44
|
+
const [focus, setFocus] = (0, react_1.useState)(undefined);
|
|
45
|
+
const today = typeof todayProp === 'number' ? new Date(todayProp) : todayProp;
|
|
46
|
+
(0, react_1.useEffect)(() => {
|
|
47
|
+
var _a, _b, _c;
|
|
48
|
+
if (!(internalValue === null || internalValue === void 0 ? void 0 : internalValue[0])) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const hours = (_a = internalValue[0].getHours()) !== null && _a !== void 0 ? _a : 0;
|
|
52
|
+
const minutes = (_b = internalValue[0].getMinutes()) !== null && _b !== void 0 ? _b : 0;
|
|
53
|
+
const seconds = (_c = internalValue[0].getSeconds()) !== null && _c !== void 0 ? _c : 0;
|
|
54
|
+
setValueEventHandler({
|
|
55
|
+
hours,
|
|
56
|
+
minutes,
|
|
57
|
+
seconds
|
|
58
|
+
});
|
|
59
|
+
}, [internalValue, setValueEventHandler]);
|
|
60
|
+
const setValue = (0, react_1.useCallback)(dates => {
|
|
61
|
+
const newDate = dates[0];
|
|
62
|
+
setInternalValue([newDate, newDate]);
|
|
63
|
+
}, []);
|
|
64
|
+
const {
|
|
65
|
+
dateAndTime,
|
|
66
|
+
onTimeChange,
|
|
67
|
+
onDateChange,
|
|
68
|
+
onDateAndTimeChange,
|
|
69
|
+
isDateFilled,
|
|
70
|
+
isTimeFilled,
|
|
71
|
+
isDateAndTimeFilled
|
|
72
|
+
} = (0, hooks_1.useDateAndTime)({
|
|
73
|
+
showSeconds,
|
|
74
|
+
value
|
|
75
|
+
});
|
|
76
|
+
const applyButtonRef = (0, react_1.useRef)(null);
|
|
77
|
+
const currentButtonRef = (0, react_1.useRef)(null);
|
|
78
|
+
const hoursKeyboardNavigationRef = (0, react_1.useRef)({
|
|
79
|
+
focusItem: () => {}
|
|
80
|
+
});
|
|
81
|
+
const minutesKeyboardNavigationRef = (0, react_1.useRef)({
|
|
82
|
+
focusItem: () => {}
|
|
83
|
+
});
|
|
84
|
+
const secondsKeyboardNavigationRef = (0, react_1.useRef)({
|
|
85
|
+
focusItem: () => {}
|
|
86
|
+
});
|
|
87
|
+
const getTestId = (0, react_1.useMemo)(() => (0, utils_2.getTestIdBuilder)(testId), [testId]);
|
|
88
|
+
const {
|
|
89
|
+
lang: ctxLang
|
|
90
|
+
} = (0, locale_1.useLocale)();
|
|
91
|
+
const locale = (0, react_1.useMemo)(() => (0, utils_2.getLocale)({
|
|
92
|
+
localeProp: constants_1.DEFAULT_LOCALE,
|
|
93
|
+
ctxLang
|
|
94
|
+
}), [ctxLang]);
|
|
95
|
+
return (0, jsx_runtime_1.jsx)("div", {
|
|
96
|
+
className: (0, classnames_1.default)(styles_module_scss_1.default.timePickerWrapper, className),
|
|
97
|
+
"data-fit-to-container": fitToContainer || undefined,
|
|
98
|
+
"data-test-id": testId,
|
|
99
|
+
children: (0, jsx_runtime_1.jsxs)(CalendarContext_1.CalendarContext.Provider, {
|
|
100
|
+
value: {
|
|
101
|
+
mode: 'time',
|
|
102
|
+
locale,
|
|
103
|
+
size,
|
|
104
|
+
value: internalValue,
|
|
105
|
+
fitToContainer,
|
|
106
|
+
focus,
|
|
107
|
+
setValue,
|
|
108
|
+
setFocus,
|
|
109
|
+
getTestId,
|
|
110
|
+
onFocusLeave,
|
|
111
|
+
navigationStartRef,
|
|
112
|
+
showSeconds,
|
|
113
|
+
dateAndTime,
|
|
114
|
+
onTimeChange,
|
|
115
|
+
onDateAndTimeChange,
|
|
116
|
+
isTimeFilled,
|
|
117
|
+
applyButtonRef,
|
|
118
|
+
currentButtonRef,
|
|
119
|
+
hoursKeyboardNavigationRef,
|
|
120
|
+
minutesKeyboardNavigationRef,
|
|
121
|
+
secondsKeyboardNavigationRef,
|
|
122
|
+
today,
|
|
123
|
+
// Stub props
|
|
124
|
+
viewMode: 'month',
|
|
125
|
+
showHolidays: false,
|
|
126
|
+
viewDate: stubDate,
|
|
127
|
+
referenceDate: stubDate,
|
|
128
|
+
preselectedRange: undefined,
|
|
129
|
+
viewShift: 0,
|
|
130
|
+
setViewMode: stubFunc,
|
|
131
|
+
setViewShift: stubFunc,
|
|
132
|
+
startPreselect: stubFunc,
|
|
133
|
+
continuePreselect: stubFunc,
|
|
134
|
+
completePreselect: stubFunc,
|
|
135
|
+
restartPreselect: stubFunc,
|
|
136
|
+
buildCellProps: () => ({
|
|
137
|
+
isDisabled: false,
|
|
138
|
+
isHoliday: false
|
|
139
|
+
}),
|
|
140
|
+
onDateChange,
|
|
141
|
+
isDateAndTimeFilled,
|
|
142
|
+
isDateFilled
|
|
143
|
+
},
|
|
144
|
+
children: [(0, jsx_runtime_1.jsx)(TimePickerBase_1.TimePickerBase, {
|
|
145
|
+
showDivider: false
|
|
146
|
+
}), (0, jsx_runtime_1.jsx)(Footer_1.Footer, {})]
|
|
147
|
+
})
|
|
148
|
+
});
|
|
149
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TimePicker';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./TimePicker"), exports);
|
|
@@ -22,4 +22,5 @@ var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
|
22
22
|
Object.defineProperty(exports, "__esModule", {
|
|
23
23
|
value: true
|
|
24
24
|
});
|
|
25
|
-
__exportStar(require("./Calendar"), exports);
|
|
25
|
+
__exportStar(require("./Calendar"), exports);
|
|
26
|
+
__exportStar(require("./TimePicker"), exports);
|
package/dist/cjs/constants.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const VIEW_MODE: {
|
|
|
5
5
|
};
|
|
6
6
|
export declare const CALENDAR_MODE: {
|
|
7
7
|
readonly Date: "date";
|
|
8
|
+
readonly DateTime: "date-time";
|
|
8
9
|
readonly Range: "range";
|
|
9
10
|
readonly Month: "month";
|
|
10
11
|
};
|
|
@@ -35,3 +36,7 @@ export declare const GRID_SIZE: {
|
|
|
35
36
|
};
|
|
36
37
|
};
|
|
37
38
|
export declare const AUTOFOCUS = "autofocus";
|
|
39
|
+
export declare const HOURS = 24;
|
|
40
|
+
export declare const MINUTES = 60;
|
|
41
|
+
export declare const SECONDS = 60;
|
|
42
|
+
export declare const DEFAULT_LOCALE: Intl.Locale;
|
package/dist/cjs/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.AUTOFOCUS = exports.GRID_SIZE = exports.SIZE = exports.IN_RANGE_POSITION = exports.CALENDAR_MODE = exports.VIEW_MODE = void 0;
|
|
6
|
+
exports.DEFAULT_LOCALE = exports.SECONDS = exports.MINUTES = exports.HOURS = exports.AUTOFOCUS = exports.GRID_SIZE = exports.SIZE = exports.IN_RANGE_POSITION = exports.CALENDAR_MODE = exports.VIEW_MODE = void 0;
|
|
7
7
|
exports.VIEW_MODE = {
|
|
8
8
|
Month: 'month',
|
|
9
9
|
Year: 'year',
|
|
@@ -11,6 +11,7 @@ exports.VIEW_MODE = {
|
|
|
11
11
|
};
|
|
12
12
|
exports.CALENDAR_MODE = {
|
|
13
13
|
Date: 'date',
|
|
14
|
+
DateTime: 'date-time',
|
|
14
15
|
Range: 'range',
|
|
15
16
|
Month: 'month'
|
|
16
17
|
};
|
|
@@ -40,4 +41,8 @@ exports.GRID_SIZE = {
|
|
|
40
41
|
columns: 3
|
|
41
42
|
}
|
|
42
43
|
};
|
|
43
|
-
exports.AUTOFOCUS = 'autofocus';
|
|
44
|
+
exports.AUTOFOCUS = 'autofocus';
|
|
45
|
+
exports.HOURS = 24;
|
|
46
|
+
exports.MINUTES = 60;
|
|
47
|
+
exports.SECONDS = 60;
|
|
48
|
+
exports.DEFAULT_LOCALE = new Intl.Locale('ru-RU');
|
|
@@ -73,18 +73,19 @@ function Button(_a) {
|
|
|
73
73
|
// do nothing
|
|
74
74
|
}
|
|
75
75
|
}, [onDownArrowKeyDown, onFocusLeave, onLeftArrowKeyDown, onRightArrowKeyDown]);
|
|
76
|
+
(0, react_1.useImperativeHandle)(useNavigationStartRef ? navigationStartRef : undefined, () => ({
|
|
77
|
+
focus: () => {
|
|
78
|
+
var _a;
|
|
79
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
76
82
|
return (0, jsx_runtime_1.jsxs)("button", Object.assign({
|
|
77
83
|
type: 'button',
|
|
78
84
|
tabIndex: tabIndex,
|
|
79
85
|
className: styles_module_scss_1.default.button,
|
|
80
86
|
onClick: onClick,
|
|
81
87
|
"data-size": size,
|
|
82
|
-
ref:
|
|
83
|
-
if (buttonRef) {
|
|
84
|
-
useNavigationStartRef && (navigationStartRef === null || navigationStartRef === void 0 ? void 0 : navigationStartRef(buttonRef));
|
|
85
|
-
ref.current = buttonRef;
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
+
ref: ref,
|
|
88
89
|
onKeyDown: onKeyDownHandler,
|
|
89
90
|
onFocus: () => setFocus(focusName),
|
|
90
91
|
onBlur: () => setFocus(undefined),
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
cursor:pointer;
|
|
12
12
|
}
|
|
13
13
|
.button:not(:disabled):hover, .button:not(:disabled):focus-visible{
|
|
14
|
-
background-color:color-
|
|
14
|
+
background-color:color-mix(in srgb, var(--sys-neutral-accent-default, #787b8a), var(--sys-neutral-background1-level, #fdfdfd) calc((1 - var(--opacity-a008, 0.08)) * 100%));
|
|
15
15
|
}
|
|
16
16
|
.button:not(:disabled):focus-visible{
|
|
17
17
|
outline-width:var(--border-state-focus-s-border-width, 2px);
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
padding-right:var(--space-calendar-button-s-horizontal-padding, 8px);
|
|
27
27
|
gap:var(--space-calendar-button-s-gap, 4px);
|
|
28
28
|
border-radius:var(--radius-calendar-button-s, 12px);
|
|
29
|
-
font-family:var(--sans-label-
|
|
30
|
-
font-weight:var(--sans-label-
|
|
31
|
-
line-height:var(--sans-label-
|
|
32
|
-
font-size:var(--sans-label-
|
|
33
|
-
letter-spacing:var(--sans-label-
|
|
34
|
-
paragraph-spacing:var(--sans-label-
|
|
29
|
+
font-family:var(--sans-label-m-font-family, SB Sans Interface);
|
|
30
|
+
font-weight:var(--sans-label-m-font-weight, Semibold);
|
|
31
|
+
line-height:var(--sans-label-m-line-height, 16px);
|
|
32
|
+
font-size:var(--sans-label-m-font-size, 12px);
|
|
33
|
+
letter-spacing:var(--sans-label-m-letter-spacing, 0px);
|
|
34
|
+
paragraph-spacing:var(--sans-label-m-paragraph-spacing, 6.6px);
|
|
35
35
|
}
|
|
36
36
|
.button[data-size=m]{
|
|
37
37
|
height:var(--size-calendar-button-m, 40px);
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
padding-right:var(--space-calendar-button-m-horizontal-padding, 8px);
|
|
40
40
|
gap:var(--space-calendar-button-m-gap, 4px);
|
|
41
41
|
border-radius:var(--radius-calendar-button-m, 14px);
|
|
42
|
-
font-family:var(--sans-label-
|
|
43
|
-
font-weight:var(--sans-label-
|
|
44
|
-
line-height:var(--sans-label-
|
|
45
|
-
font-size:var(--sans-label-
|
|
46
|
-
letter-spacing:var(--sans-label-
|
|
47
|
-
paragraph-spacing:var(--sans-label-
|
|
42
|
+
font-family:var(--sans-label-l-font-family, SB Sans Interface);
|
|
43
|
+
font-weight:var(--sans-label-l-font-weight, Semibold);
|
|
44
|
+
line-height:var(--sans-label-l-line-height, 20px);
|
|
45
|
+
font-size:var(--sans-label-l-font-size, 14px);
|
|
46
|
+
letter-spacing:var(--sans-label-l-letter-spacing, 0px);
|
|
47
|
+
paragraph-spacing:var(--sans-label-l-paragraph-spacing, 7.7px);
|
|
48
48
|
}
|
|
49
49
|
.button[data-size=l]{
|
|
50
50
|
height:var(--size-calendar-button-l, 48px);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CSSProperties,
|
|
1
|
+
import { CSSProperties, RefObject } from 'react';
|
|
2
2
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
3
|
import { BuildCellPropsFunction, CalendarMode, FocusDirection, Range, Size } from '../../types';
|
|
4
4
|
export type CalendarBaseProps = WithSupportProps<{
|
|
@@ -10,12 +10,15 @@ export type CalendarBaseProps = WithSupportProps<{
|
|
|
10
10
|
today?: Date | number;
|
|
11
11
|
buildCellProps?: BuildCellPropsFunction;
|
|
12
12
|
showHolidays?: boolean;
|
|
13
|
+
showSeconds?: boolean;
|
|
13
14
|
style?: CSSProperties;
|
|
14
15
|
className?: string;
|
|
15
16
|
defaultValue?: Range;
|
|
16
17
|
fitToContainer?: boolean;
|
|
17
18
|
autofocus?: boolean;
|
|
18
19
|
locale?: Intl.Locale;
|
|
19
|
-
navigationStartRef?:
|
|
20
|
+
navigationStartRef?: RefObject<{
|
|
21
|
+
focus(): void;
|
|
22
|
+
}>;
|
|
20
23
|
}>;
|
|
21
|
-
export declare function CalendarBase({ className, mode, size, autofocus, fitToContainer, value: valueProp, defaultValue, onChangeValue, today: todayProp, showHolidays, style, locale: localeProp, onFocusLeave, buildCellProps, 'data-test-id': testId, navigationStartRef, ...rest }: CalendarBaseProps): import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
export declare function CalendarBase({ className, mode, size, autofocus, fitToContainer, value: valueProp, defaultValue, onChangeValue, today: todayProp, showHolidays, showSeconds, style, locale: localeProp, onFocusLeave, buildCellProps, 'data-test-id': testId, navigationStartRef, ...rest }: CalendarBaseProps): import("react/jsx-runtime").JSX.Element;
|