@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.
Files changed (217) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/cjs/components/Calendar/Calendar.css +220 -0
  4. package/dist/cjs/components/Calendar/Calendar.d.ts +13 -0
  5. package/dist/cjs/components/Calendar/Calendar.js +15 -0
  6. package/dist/cjs/components/Calendar/CalendarBase.d.ts +18 -0
  7. package/dist/cjs/components/Calendar/CalendarBase.js +89 -0
  8. package/dist/cjs/components/Calendar/RangeCalendar.d.ts +13 -0
  9. package/dist/cjs/components/Calendar/RangeCalendar.js +22 -0
  10. package/dist/cjs/components/Calendar/hooks/types.d.ts +124 -0
  11. package/dist/cjs/components/Calendar/hooks/types.js +2 -0
  12. package/dist/cjs/components/Calendar/hooks/useCalendarCellProps.d.ts +19 -0
  13. package/dist/cjs/components/Calendar/hooks/useCalendarCellProps.js +98 -0
  14. package/dist/cjs/components/Calendar/hooks/useCalendarGridProps.d.ts +5 -0
  15. package/dist/cjs/components/Calendar/hooks/useCalendarGridProps.js +57 -0
  16. package/dist/cjs/components/Calendar/hooks/useCalendarProps.d.ts +10 -0
  17. package/dist/cjs/components/Calendar/hooks/useCalendarProps.js +110 -0
  18. package/dist/cjs/components/Calendar/hooks/useCalendarState.d.ts +7 -0
  19. package/dist/cjs/components/Calendar/hooks/useCalendarState.js +178 -0
  20. package/dist/cjs/components/Calendar/hooks/useRangeCalendarState.d.ts +7 -0
  21. package/dist/cjs/components/Calendar/hooks/useRangeCalendarState.js +82 -0
  22. package/dist/cjs/components/Calendar/i18n/en.json +4 -0
  23. package/dist/cjs/components/Calendar/i18n/index.d.ts +1 -0
  24. package/dist/cjs/components/Calendar/i18n/index.js +11 -0
  25. package/dist/cjs/components/Calendar/i18n/ru.json +4 -0
  26. package/dist/cjs/components/Calendar/index.d.ts +8 -0
  27. package/dist/cjs/components/Calendar/index.js +23 -0
  28. package/dist/cjs/components/Calendar/utils.d.ts +4 -0
  29. package/dist/cjs/components/Calendar/utils.js +40 -0
  30. package/dist/cjs/components/DateField/DateField.css +4 -0
  31. package/dist/cjs/components/DateField/DateField.d.ts +6 -0
  32. package/dist/cjs/components/DateField/DateField.js +38 -0
  33. package/dist/cjs/components/DateField/hooks/useDateFieldProps.d.ts +6 -0
  34. package/dist/cjs/components/DateField/hooks/useDateFieldProps.js +203 -0
  35. package/dist/cjs/components/DateField/hooks/useDateFieldState.d.ts +67 -0
  36. package/dist/cjs/components/DateField/hooks/useDateFieldState.js +628 -0
  37. package/dist/cjs/components/DateField/i18n/en.json +10 -0
  38. package/dist/cjs/components/DateField/i18n/index.d.ts +1 -0
  39. package/dist/cjs/components/DateField/i18n/index.js +11 -0
  40. package/dist/cjs/components/DateField/i18n/ru.json +10 -0
  41. package/dist/cjs/components/DateField/index.d.ts +3 -0
  42. package/dist/cjs/components/DateField/index.js +19 -0
  43. package/dist/cjs/components/DateField/types.d.ts +67 -0
  44. package/dist/cjs/components/DateField/types.js +2 -0
  45. package/dist/cjs/components/DateField/utils.d.ts +14 -0
  46. package/dist/cjs/components/DateField/utils.js +276 -0
  47. package/dist/cjs/components/DatePicker/DatePicker.css +19 -0
  48. package/dist/cjs/components/DatePicker/DatePicker.d.ts +5 -0
  49. package/dist/cjs/components/DatePicker/DatePicker.js +66 -0
  50. package/dist/cjs/components/DatePicker/DesktopCalendar.d.ts +15 -0
  51. package/dist/cjs/components/DatePicker/DesktopCalendar.js +56 -0
  52. package/dist/cjs/components/DatePicker/MobileCalendar.css +49 -0
  53. package/dist/cjs/components/DatePicker/MobileCalendar.d.ts +14 -0
  54. package/dist/cjs/components/DatePicker/MobileCalendar.js +78 -0
  55. package/dist/cjs/components/DatePicker/hooks/useDatePickerState.d.ts +45 -0
  56. package/dist/cjs/components/DatePicker/hooks/useDatePickerState.js +114 -0
  57. package/dist/cjs/components/DatePicker/i18n/en.json +3 -0
  58. package/dist/cjs/components/DatePicker/i18n/index.d.ts +1 -0
  59. package/dist/cjs/components/DatePicker/i18n/index.js +11 -0
  60. package/dist/cjs/components/DatePicker/i18n/ru.json +3 -0
  61. package/dist/cjs/components/DatePicker/index.d.ts +2 -0
  62. package/dist/cjs/components/DatePicker/index.js +18 -0
  63. package/dist/cjs/components/DatePicker/utils.d.ts +1 -0
  64. package/dist/cjs/components/DatePicker/utils.js +5 -0
  65. package/dist/cjs/components/RelativeDateField/RelativeDateField.css +16 -0
  66. package/dist/cjs/components/RelativeDateField/RelativeDateField.d.ts +11 -0
  67. package/dist/cjs/components/RelativeDateField/RelativeDateField.js +37 -0
  68. package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldProps.d.ts +12 -0
  69. package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +66 -0
  70. package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +30 -0
  71. package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.js +66 -0
  72. package/dist/cjs/components/RelativeDateField/index.d.ts +3 -0
  73. package/dist/cjs/components/RelativeDateField/index.js +19 -0
  74. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.css +16 -0
  75. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.d.ts +6 -0
  76. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js +32 -0
  77. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.d.ts +17 -0
  78. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +175 -0
  79. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.d.ts +36 -0
  80. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +109 -0
  81. package/dist/cjs/components/RelativeDatePicker/i18n/en.json +4 -0
  82. package/dist/cjs/components/RelativeDatePicker/i18n/index.d.ts +1 -0
  83. package/dist/cjs/components/RelativeDatePicker/i18n/index.js +11 -0
  84. package/dist/cjs/components/RelativeDatePicker/i18n/ru.json +4 -0
  85. package/dist/cjs/components/RelativeDatePicker/index.d.ts +3 -0
  86. package/dist/cjs/components/RelativeDatePicker/index.js +19 -0
  87. package/dist/cjs/components/hooks/useControlledState.d.ts +1 -0
  88. package/dist/cjs/components/hooks/useControlledState.js +30 -0
  89. package/dist/cjs/components/index.d.ts +5 -0
  90. package/dist/cjs/components/index.js +21 -0
  91. package/dist/cjs/components/types/datePicker.d.ts +16 -0
  92. package/dist/cjs/components/types/datePicker.js +2 -0
  93. package/dist/cjs/components/types/events.d.ts +17 -0
  94. package/dist/cjs/components/types/events.js +2 -0
  95. package/dist/cjs/components/types/index.d.ts +4 -0
  96. package/dist/cjs/components/types/index.js +2 -0
  97. package/dist/cjs/components/types/inputs.d.ts +79 -0
  98. package/dist/cjs/components/types/inputs.js +2 -0
  99. package/dist/cjs/components/types/style.d.ts +7 -0
  100. package/dist/cjs/components/types/style.js +2 -0
  101. package/dist/cjs/components/utils/getButtonSizeForInput.d.ts +2 -0
  102. package/dist/cjs/components/utils/getButtonSizeForInput.js +20 -0
  103. package/dist/cjs/components/utils/mergeProps.d.ts +13 -0
  104. package/dist/cjs/components/utils/mergeProps.js +47 -0
  105. package/dist/cjs/components/variables.css +0 -0
  106. package/dist/cjs/index.d.ts +1 -0
  107. package/dist/cjs/index.js +17 -0
  108. package/dist/cjs/utils/cn.d.ts +2 -0
  109. package/dist/cjs/utils/cn.js +6 -0
  110. package/dist/esm/components/Calendar/Calendar.css +220 -0
  111. package/dist/esm/components/Calendar/Calendar.d.ts +13 -0
  112. package/dist/esm/components/Calendar/Calendar.js +9 -0
  113. package/dist/esm/components/Calendar/CalendarBase.d.ts +18 -0
  114. package/dist/esm/components/Calendar/CalendarBase.js +83 -0
  115. package/dist/esm/components/Calendar/RangeCalendar.d.ts +13 -0
  116. package/dist/esm/components/Calendar/RangeCalendar.js +16 -0
  117. package/dist/esm/components/Calendar/hooks/types.d.ts +124 -0
  118. package/dist/esm/components/Calendar/hooks/types.js +1 -0
  119. package/dist/esm/components/Calendar/hooks/useCalendarCellProps.d.ts +19 -0
  120. package/dist/esm/components/Calendar/hooks/useCalendarCellProps.js +91 -0
  121. package/dist/esm/components/Calendar/hooks/useCalendarGridProps.d.ts +5 -0
  122. package/dist/esm/components/Calendar/hooks/useCalendarGridProps.js +54 -0
  123. package/dist/esm/components/Calendar/hooks/useCalendarProps.d.ts +10 -0
  124. package/dist/esm/components/Calendar/hooks/useCalendarProps.js +103 -0
  125. package/dist/esm/components/Calendar/hooks/useCalendarState.d.ts +7 -0
  126. package/dist/esm/components/Calendar/hooks/useCalendarState.js +171 -0
  127. package/dist/esm/components/Calendar/hooks/useRangeCalendarState.d.ts +7 -0
  128. package/dist/esm/components/Calendar/hooks/useRangeCalendarState.js +75 -0
  129. package/dist/esm/components/Calendar/i18n/en.json +4 -0
  130. package/dist/esm/components/Calendar/i18n/index.d.ts +1 -0
  131. package/dist/esm/components/Calendar/i18n/index.js +5 -0
  132. package/dist/esm/components/Calendar/i18n/ru.json +4 -0
  133. package/dist/esm/components/Calendar/index.d.ts +8 -0
  134. package/dist/esm/components/Calendar/index.js +7 -0
  135. package/dist/esm/components/Calendar/utils.d.ts +4 -0
  136. package/dist/esm/components/Calendar/utils.js +34 -0
  137. package/dist/esm/components/DateField/DateField.css +4 -0
  138. package/dist/esm/components/DateField/DateField.d.ts +6 -0
  139. package/dist/esm/components/DateField/DateField.js +31 -0
  140. package/dist/esm/components/DateField/hooks/useDateFieldProps.d.ts +6 -0
  141. package/dist/esm/components/DateField/hooks/useDateFieldProps.js +196 -0
  142. package/dist/esm/components/DateField/hooks/useDateFieldState.d.ts +67 -0
  143. package/dist/esm/components/DateField/hooks/useDateFieldState.js +621 -0
  144. package/dist/esm/components/DateField/i18n/en.json +10 -0
  145. package/dist/esm/components/DateField/i18n/index.d.ts +1 -0
  146. package/dist/esm/components/DateField/i18n/index.js +5 -0
  147. package/dist/esm/components/DateField/i18n/ru.json +10 -0
  148. package/dist/esm/components/DateField/index.d.ts +3 -0
  149. package/dist/esm/components/DateField/index.js +3 -0
  150. package/dist/esm/components/DateField/types.d.ts +67 -0
  151. package/dist/esm/components/DateField/types.js +1 -0
  152. package/dist/esm/components/DateField/utils.d.ts +14 -0
  153. package/dist/esm/components/DateField/utils.js +268 -0
  154. package/dist/esm/components/DatePicker/DatePicker.css +19 -0
  155. package/dist/esm/components/DatePicker/DatePicker.d.ts +5 -0
  156. package/dist/esm/components/DatePicker/DatePicker.js +59 -0
  157. package/dist/esm/components/DatePicker/DesktopCalendar.d.ts +15 -0
  158. package/dist/esm/components/DatePicker/DesktopCalendar.js +48 -0
  159. package/dist/esm/components/DatePicker/MobileCalendar.css +49 -0
  160. package/dist/esm/components/DatePicker/MobileCalendar.d.ts +14 -0
  161. package/dist/esm/components/DatePicker/MobileCalendar.js +73 -0
  162. package/dist/esm/components/DatePicker/hooks/useDatePickerState.d.ts +45 -0
  163. package/dist/esm/components/DatePicker/hooks/useDatePickerState.js +107 -0
  164. package/dist/esm/components/DatePicker/i18n/en.json +3 -0
  165. package/dist/esm/components/DatePicker/i18n/index.d.ts +1 -0
  166. package/dist/esm/components/DatePicker/i18n/index.js +5 -0
  167. package/dist/esm/components/DatePicker/i18n/ru.json +3 -0
  168. package/dist/esm/components/DatePicker/index.d.ts +2 -0
  169. package/dist/esm/components/DatePicker/index.js +2 -0
  170. package/dist/esm/components/DatePicker/utils.d.ts +1 -0
  171. package/dist/esm/components/DatePicker/utils.js +2 -0
  172. package/dist/esm/components/RelativeDateField/RelativeDateField.css +16 -0
  173. package/dist/esm/components/RelativeDateField/RelativeDateField.d.ts +11 -0
  174. package/dist/esm/components/RelativeDateField/RelativeDateField.js +30 -0
  175. package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldProps.d.ts +12 -0
  176. package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +59 -0
  177. package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +30 -0
  178. package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.js +59 -0
  179. package/dist/esm/components/RelativeDateField/index.d.ts +3 -0
  180. package/dist/esm/components/RelativeDateField/index.js +3 -0
  181. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.css +16 -0
  182. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.d.ts +6 -0
  183. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js +25 -0
  184. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.d.ts +17 -0
  185. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +168 -0
  186. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.d.ts +36 -0
  187. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +102 -0
  188. package/dist/esm/components/RelativeDatePicker/i18n/en.json +4 -0
  189. package/dist/esm/components/RelativeDatePicker/i18n/index.d.ts +1 -0
  190. package/dist/esm/components/RelativeDatePicker/i18n/index.js +5 -0
  191. package/dist/esm/components/RelativeDatePicker/i18n/ru.json +4 -0
  192. package/dist/esm/components/RelativeDatePicker/index.d.ts +3 -0
  193. package/dist/esm/components/RelativeDatePicker/index.js +3 -0
  194. package/dist/esm/components/hooks/useControlledState.d.ts +1 -0
  195. package/dist/esm/components/hooks/useControlledState.js +23 -0
  196. package/dist/esm/components/index.d.ts +5 -0
  197. package/dist/esm/components/index.js +5 -0
  198. package/dist/esm/components/types/datePicker.d.ts +16 -0
  199. package/dist/esm/components/types/datePicker.js +1 -0
  200. package/dist/esm/components/types/events.d.ts +17 -0
  201. package/dist/esm/components/types/events.js +1 -0
  202. package/dist/esm/components/types/index.d.ts +4 -0
  203. package/dist/esm/components/types/index.js +1 -0
  204. package/dist/esm/components/types/inputs.d.ts +79 -0
  205. package/dist/esm/components/types/inputs.js +1 -0
  206. package/dist/esm/components/types/style.d.ts +7 -0
  207. package/dist/esm/components/types/style.js +1 -0
  208. package/dist/esm/components/utils/getButtonSizeForInput.d.ts +2 -0
  209. package/dist/esm/components/utils/getButtonSizeForInput.js +16 -0
  210. package/dist/esm/components/utils/mergeProps.d.ts +13 -0
  211. package/dist/esm/components/utils/mergeProps.js +43 -0
  212. package/dist/esm/components/variables.css +0 -0
  213. package/dist/esm/index.d.ts +1 -0
  214. package/dist/esm/index.js +1 -0
  215. package/dist/esm/utils/cn.d.ts +2 -0
  216. package/dist/esm/utils/cn.js +3 -0
  217. package/package.json +119 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 YANDEX LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @gravity-ui/date-components · [![npm package](https://img.shields.io/npm/v/@gravity-ui/date-components)](https://www.npmjs.com/package/@gravity-ui/date-components) [![CI](https://img.shields.io/github/actions/workflow/status/gravity-ui/date-components/.github/workflows/ci.yml?label=CI&logo=github)](https://github.com/gravity-ui/date-components/actions/workflows/ci.yml?query=branch:main) [![storybook](https://img.shields.io/badge/Storybook-deployed-ff4685)](https://preview.gravity-ui.com/date-components/)
2
+
3
+ ## Install
4
+
5
+ ```shell
6
+ npm install --save-dev @gravity-ui/uikit @gravity-ui/date-components
7
+ ```
8
+
9
+ ## Development
10
+
11
+ To start the development server with storybook run the following:
12
+
13
+ ```shell
14
+ npm start
15
+ ```
@@ -0,0 +1,220 @@
1
+ .g-date-calendar {
2
+ --_--calendar-padding: var(--g-date-calendar-padding, 8px);
3
+ --_--calendar-day-size: var(--g-date-calendar-day-size, 28px);
4
+ --_--calendar-days-gap: var(--g-date-calendar-days-gap, 2px);
5
+ --_--calendar-width: calc(
6
+ 7 * var(--_--calendar-day-size) + 6 * var(--_--calendar-days-gap) + 2 *
7
+ var(--_--calendar-padding)
8
+ );
9
+ --_--calendar-grid-height: calc(
10
+ 7 * var(--_--calendar-day-size) + 5 * var(--_--calendar-days-gap) +
11
+ var(--_--calendar-padding)
12
+ );
13
+ display: inline-block;
14
+ width: var(--_--calendar-width);
15
+ }
16
+ .g-date-calendar_size_l {
17
+ --g-date-calendar-day-size: 36px;
18
+ }
19
+ .g-date-calendar_size_xl {
20
+ --g-date-calendar-day-size: 42px;
21
+ font-size: var(--g-text-body-2-font-size);
22
+ line-height: var(--g-text-body-2-line-height);
23
+ font-weight: var(--g-text-body-font-weight);
24
+ }
25
+ .g-date-calendar__header {
26
+ display: flex;
27
+ padding: var(--_--calendar-padding) var(--_--calendar-padding) 0;
28
+ }
29
+ .g-date-calendar__years-label {
30
+ color: var(--g-color-text-secondary);
31
+ }
32
+ .g-date-calendar__controls {
33
+ margin-left: auto;
34
+ }
35
+ .g-date-calendar__grid {
36
+ position: relative;
37
+ overflow: hidden;
38
+ width: 100%;
39
+ height: var(--_--calendar-grid-height);
40
+ user-select: none;
41
+ }
42
+ .g-date-calendar__content {
43
+ position: absolute;
44
+ top: 0;
45
+ left: 0;
46
+ display: grid;
47
+ grid-template-rows: var(--_--calendar-day-size) 1fr;
48
+ box-sizing: border-box;
49
+ width: 100%;
50
+ height: 100%;
51
+ padding: 0 var(--_--calendar-padding) var(--_--calendar-padding);
52
+ }
53
+ .g-date-calendar__content_animation_forward {
54
+ transform: translateX(-100%);
55
+ animation: calendar-forward 0.25s ease forwards;
56
+ }
57
+ .g-date-calendar__content_animation_forward.g-date-calendar__current-state {
58
+ left: -100%;
59
+ }
60
+ .g-date-calendar__content_animation_backward {
61
+ transform: translateX(0);
62
+ animation: calendar-backward 0.25s ease forwards;
63
+ }
64
+ .g-date-calendar__content_animation_backward.g-date-calendar__current-state {
65
+ left: 100%;
66
+ }
67
+ .g-date-calendar__content_animation_zoom-in {
68
+ transform: scale();
69
+ }
70
+ .g-date-calendar__content_animation_zoom-in.g-date-calendar__previous-state {
71
+ animation: calendar-zoom-in-hiding 0.25s ease forwards;
72
+ }
73
+ .g-date-calendar__content_animation_zoom-in.g-date-calendar__current-state {
74
+ animation: calendar-zoom-in-showing 0.25s ease forwards;
75
+ }
76
+ .g-date-calendar__content_animation_zoom-out {
77
+ transform: scale();
78
+ }
79
+ .g-date-calendar__content_animation_zoom-out.g-date-calendar__current-state {
80
+ animation: calendar-zoom-out-showing 0.25s ease forwards;
81
+ }
82
+ .g-date-calendar__content_animation_zoom-out.g-date-calendar__previous-state {
83
+ animation: calendar-zoom-out-hiding 0.25s ease forwards;
84
+ }
85
+ @keyframes calendar-forward {
86
+ from {
87
+ transform: translateX(0);
88
+ }
89
+ to {
90
+ transform: translateX(100%);
91
+ }
92
+ }
93
+ @keyframes calendar-backward {
94
+ from {
95
+ transform: translateX(0);
96
+ }
97
+ to {
98
+ transform: translateX(-100%);
99
+ }
100
+ }
101
+ @keyframes calendar-zoom-in-showing {
102
+ from {
103
+ opacity: 0;
104
+ transform: scale(2);
105
+ }
106
+ to {
107
+ opacity: 1;
108
+ transform: scale(1);
109
+ }
110
+ }
111
+ @keyframes calendar-zoom-in-hiding {
112
+ from {
113
+ opacity: 1;
114
+ transform: scale(1);
115
+ }
116
+ to {
117
+ opacity: 0;
118
+ transform: scale(0);
119
+ }
120
+ }
121
+ @keyframes calendar-zoom-out-showing {
122
+ from {
123
+ opacity: 0;
124
+ transform: scale(0);
125
+ }
126
+ to {
127
+ opacity: 1;
128
+ transform: scale(1);
129
+ }
130
+ }
131
+ @keyframes calendar-zoom-out-hiding {
132
+ from {
133
+ opacity: 1;
134
+ transform: scale(1);
135
+ }
136
+ to {
137
+ opacity: 0;
138
+ transform: scale(2);
139
+ }
140
+ }
141
+ .g-date-calendar__grid-rowgroup {
142
+ display: grid;
143
+ gap: var(--_--calendar-days-gap);
144
+ }
145
+ .g-date-calendar__grid-rowgroup_mode_months, .g-date-calendar__grid-rowgroup_mode_years {
146
+ grid-row: 1/-1;
147
+ padding: 12px 0 0;
148
+ }
149
+ .g-date-calendar__grid-row {
150
+ display: grid;
151
+ grid-auto-columns: 1fr;
152
+ grid-auto-flow: column;
153
+ gap: var(--_--calendar-days-gap);
154
+ }
155
+ .g-date-calendar__weekday {
156
+ display: flex;
157
+ justify-content: center;
158
+ align-items: center;
159
+ width: 100%;
160
+ height: 100%;
161
+ }
162
+ .g-date-calendar__weekday_weekend {
163
+ color: var(--g-color-text-danger);
164
+ }
165
+ .g-date-calendar__button {
166
+ position: relative;
167
+ display: flex;
168
+ justify-content: center;
169
+ align-items: center;
170
+ width: 100%;
171
+ height: 100%;
172
+ font-weight: var(--g-text-subheader-font-weight);
173
+ cursor: pointer;
174
+ border-radius: 4px;
175
+ outline: none;
176
+ }
177
+ .g-date-calendar__button:focus {
178
+ box-shadow: 0 0 0 2px var(--g-color-line-misc);
179
+ }
180
+ .g-date-calendar__button:focus:not(:focus-visible) {
181
+ box-shadow: none;
182
+ }
183
+ .g-date-calendar__button:hover {
184
+ background-color: var(--g-color-base-generic);
185
+ }
186
+ .g-date-calendar__button_selected[class] {
187
+ background-color: var(--g-color-base-selection);
188
+ }
189
+ .g-date-calendar__button_selected.g-date-calendar__button_selection-start, .g-date-calendar__button_selected.g-date-calendar__button_selection-end {
190
+ background-color: var(--g-color-base-brand);
191
+ }
192
+ .g-date-calendar__button_weekend {
193
+ color: var(--g-color-text-danger);
194
+ }
195
+ .g-date-calendar__button_out-of-boundary {
196
+ font-weight: var(--g-text-body-font-weight);
197
+ opacity: 0.6;
198
+ }
199
+ .g-date-calendar__button_current::before {
200
+ position: absolute;
201
+ top: 50%;
202
+ display: block;
203
+ width: 4px;
204
+ height: 4px;
205
+ content: "";
206
+ border-radius: 50%;
207
+ background-color: var(--g-color-text-primary);
208
+ transform: translateY(8px);
209
+ }
210
+ .g-date-calendar__button_disabled {
211
+ font-weight: var(--g-text-body-font-weight);
212
+ pointer-events: none;
213
+ opacity: 0.6;
214
+ }
215
+ .g-date-calendar__button_unavailable:not(.g-date-calendar__button_disabled) {
216
+ font-weight: var(--g-text-body-font-weight);
217
+ cursor: default;
218
+ opacity: 0.5;
219
+ background-color: var(--g-color-base-generic);
220
+ }
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import type { AccessibilityProps, DomProps, FocusEvents, StyleProps } from '../types';
3
+ import type { CalendarInstance, CalendarSize } from './CalendarBase';
4
+ import type { CalendarStateOptions } from './hooks/useCalendarState';
5
+ import './Calendar.css';
6
+ export interface CalendarProps extends CalendarStateOptions, DomProps, StyleProps, FocusEvents, AccessibilityProps {
7
+ /**
8
+ * The size of the element.
9
+ * @default m
10
+ */
11
+ size?: CalendarSize;
12
+ }
13
+ export declare const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttributes<CalendarInstance>>;
@@ -0,0 +1,15 @@
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.Calendar = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = __importDefault(require("react"));
9
+ const CalendarBase_1 = require("./CalendarBase");
10
+ const useCalendarState_1 = require("./hooks/useCalendarState");
11
+ require("./Calendar.css");
12
+ exports.Calendar = react_1.default.forwardRef(function Calendar(props, ref) {
13
+ const state = (0, useCalendarState_1.useCalendarState)(props);
14
+ return (0, jsx_runtime_1.jsx)(CalendarBase_1.CalendarBase, Object.assign({ ref: ref }, props, { state: state }));
15
+ });
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import type { AccessibilityProps, DomProps, FocusEvents, StyleProps } from '../types';
3
+ import type { RangeCalendarState } from './hooks/types';
4
+ import type { CalendarState } from './hooks/useCalendarState';
5
+ import './Calendar.css';
6
+ export type CalendarSize = 'm' | 'l' | 'xl';
7
+ export interface CalendarInstance {
8
+ focus: () => void;
9
+ }
10
+ export interface CalendarBaseProps extends DomProps, StyleProps, FocusEvents, AccessibilityProps {
11
+ state: CalendarState | RangeCalendarState;
12
+ /**
13
+ * The size of the element.
14
+ * @default m
15
+ */
16
+ size?: CalendarSize;
17
+ }
18
+ export declare const CalendarBase: React.ForwardRefExoticComponent<CalendarBaseProps & React.RefAttributes<CalendarInstance>>;
@@ -0,0 +1,89 @@
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.CalendarBase = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = __importDefault(require("react"));
9
+ const uikit_1 = require("@gravity-ui/uikit");
10
+ const cn_1 = require("../../utils/cn");
11
+ const useCalendarCellProps_1 = require("./hooks/useCalendarCellProps");
12
+ const useCalendarGridProps_1 = require("./hooks/useCalendarGridProps");
13
+ const useCalendarProps_1 = require("./hooks/useCalendarProps");
14
+ const utils_1 = require("./utils");
15
+ require("./Calendar.css");
16
+ const b = (0, cn_1.block)('calendar');
17
+ exports.CalendarBase = react_1.default.forwardRef(function Calendar(props, ref) {
18
+ const { state } = props;
19
+ const { calendarProps, modeButtonProps, nextButtonProps, previousButtonProps } = (0, useCalendarProps_1.useCalendarProps)(props, state);
20
+ react_1.default.useImperativeHandle(ref, () => ({
21
+ focus() {
22
+ state.setFocused(true);
23
+ },
24
+ }));
25
+ return ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, calendarProps, { className: b({ size: props.size }), children: [(0, jsx_runtime_1.jsxs)("div", { className: b('header'), children: [(0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, modeButtonProps, { view: "flat", size: props.size, children: state.mode === 'years' ? ((0, jsx_runtime_1.jsx)("span", { className: b('mode-label', b(`years-label`)), children: modeButtonProps.children }, "label")) : ([
26
+ (0, jsx_runtime_1.jsx)("span", { className: b('mode-label'), children: modeButtonProps.children }, "label"),
27
+ (0, jsx_runtime_1.jsx)(uikit_1.Button.Icon, { children: (0, jsx_runtime_1.jsx)(uikit_1.ArrowToggle, { direction: "bottom" }) }, "icon"),
28
+ ]) })), (0, jsx_runtime_1.jsxs)("div", { className: b('controls'), children: [(0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, previousButtonProps, { view: "flat", size: props.size, children: (0, jsx_runtime_1.jsx)(uikit_1.Button.Icon, { children: (0, jsx_runtime_1.jsx)(uikit_1.ArrowToggle, { direction: "left" }) }) })), (0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, nextButtonProps, { view: "flat", size: props.size, children: (0, jsx_runtime_1.jsx)(uikit_1.Button.Icon, { children: (0, jsx_runtime_1.jsx)(uikit_1.ArrowToggle, { direction: "right" }) }) }))] })] }), (0, jsx_runtime_1.jsx)(CalendarGrid, { state: state })] })));
29
+ });
30
+ function CalendarGrid({ state }) {
31
+ const [prevState, setPrevState] = react_1.default.useState(() => (Object.assign(Object.assign({}, state), { isFocused: false })));
32
+ const modeChanged = state.mode !== prevState.mode;
33
+ const startDateChanged = !state.startDate.isSame(prevState.startDate, 'days');
34
+ let animation;
35
+ if (modeChanged) {
36
+ if ((state.mode === 'days' && prevState.mode === 'months') ||
37
+ (state.mode === 'months' && prevState.mode === 'years')) {
38
+ animation = 'zoom-out';
39
+ }
40
+ else {
41
+ animation = 'zoom-in';
42
+ }
43
+ }
44
+ else if (startDateChanged) {
45
+ if (state.startDate.isBefore(prevState.startDate)) {
46
+ animation = 'forward';
47
+ }
48
+ else {
49
+ animation = 'backward';
50
+ }
51
+ }
52
+ const { gridProps } = (0, useCalendarGridProps_1.useCalendarGridProps)(state);
53
+ return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: b('grid') }, gridProps, { children: [animation && ((0, jsx_runtime_1.jsx)(Content, { className: b('previous-state'), state: prevState, animation: animation })), (0, jsx_runtime_1.jsx)(Content, { className: b('current-state'), state: state, animation: animation, onAnimationEnd: () => {
54
+ setPrevState(Object.assign(Object.assign({}, state), { isFocused: false }));
55
+ } }, "current")] })));
56
+ }
57
+ function Content({ className, state, animation, onAnimationEnd }) {
58
+ return ((0, jsx_runtime_1.jsxs)("div", { className: b('content', { animation }, className), onAnimationEnd: onAnimationEnd, role: "presentation", children: [state.mode === 'days' && (0, jsx_runtime_1.jsx)(Weekdays, { state: state }), (0, jsx_runtime_1.jsx)(CalendarGridCells, { state: state })] }));
59
+ }
60
+ function Weekdays({ state }) {
61
+ const weekdays = (0, utils_1.getWeekDays)();
62
+ return ((0, jsx_runtime_1.jsx)("div", { className: b('grid-row'), role: "row", children: weekdays.map((date) => {
63
+ return ((0, jsx_runtime_1.jsx)("div", { className: b('weekday', { weekend: state.isWeekend(date) }), role: "columnheader", "aria-label": date.format('dddd'), children: date.format('dd') }, date.day()));
64
+ }) }));
65
+ }
66
+ function CalendarGridCells({ state }) {
67
+ const rowsInPeriod = state.mode === 'days' ? 6 : 4;
68
+ const columnsInRow = state.mode === 'days' ? 7 : 3;
69
+ const days = (0, utils_1.getDaysInPeriod)(state.startDate, state.endDate, state.mode);
70
+ return ((0, jsx_runtime_1.jsx)("div", { className: b('grid-rowgroup', { mode: state.mode }), role: "rowgroup", children: [...new Array(rowsInPeriod).keys()].map((rowIndex) => ((0, jsx_runtime_1.jsx)("div", { className: b('grid-row'), role: "row", children: days
71
+ .slice(rowIndex * columnsInRow, (rowIndex + 1) * columnsInRow)
72
+ .map((date) => {
73
+ return (0, jsx_runtime_1.jsx)(CalendarCell, { date: date, state: state }, date.unix());
74
+ }) }, rowIndex))) }));
75
+ }
76
+ function CalendarCell({ date, state }) {
77
+ const { cellProps, buttonProps, formattedDate, isDisabled, isSelected, isRangeSelection, isSelectionStart, isSelectionEnd, isOutsideCurrentRange, isUnavailable, isCurrent, isWeekend, } = (0, useCalendarCellProps_1.useCalendarCellProps)(date, state);
78
+ return ((0, jsx_runtime_1.jsx)("div", Object.assign({}, cellProps, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({}, buttonProps, { className: b('button', {
79
+ disabled: isDisabled,
80
+ selected: isSelected,
81
+ 'range-selection': isRangeSelection,
82
+ 'selection-start': isSelectionStart,
83
+ 'selection-end': isSelectionEnd,
84
+ 'out-of-boundary': isOutsideCurrentRange,
85
+ unavailable: isUnavailable,
86
+ current: isCurrent,
87
+ weekend: isWeekend,
88
+ }), children: formattedDate })) })));
89
+ }
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import type { AccessibilityProps, DomProps, FocusEvents, StyleProps } from '../types';
3
+ import type { CalendarInstance, CalendarSize } from './CalendarBase';
4
+ import type { RangeCalendarStateOptions } from './hooks/useRangeCalendarState';
5
+ import './Calendar.css';
6
+ export interface RangeCalendarProps extends RangeCalendarStateOptions, DomProps, StyleProps, FocusEvents, AccessibilityProps {
7
+ /**
8
+ * The size of the element.
9
+ * @default m
10
+ */
11
+ size?: CalendarSize;
12
+ }
13
+ export declare const RangeCalendar: React.ForwardRefExoticComponent<RangeCalendarProps & React.RefAttributes<CalendarInstance>>;
@@ -0,0 +1,22 @@
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.RangeCalendar = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = __importDefault(require("react"));
9
+ const CalendarBase_1 = require("./CalendarBase");
10
+ const useRangeCalendarState_1 = require("./hooks/useRangeCalendarState");
11
+ require("./Calendar.css");
12
+ exports.RangeCalendar = react_1.default.forwardRef(function Calendar(props, ref) {
13
+ const state = (0, useRangeCalendarState_1.useRangeCalendarState)(props);
14
+ const handleBlur = (e) => {
15
+ var _a;
16
+ if (state.anchorDate) {
17
+ state.selectFocusedDate();
18
+ }
19
+ (_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, e);
20
+ };
21
+ return (0, jsx_runtime_1.jsx)(CalendarBase_1.CalendarBase, Object.assign({ ref: ref }, props, { state: state, onBlur: handleBlur }));
22
+ });
@@ -0,0 +1,124 @@
1
+ import type { DateTime } from '@gravity-ui/date-utils';
2
+ import type { InputBase, RangeValue } from '../../types';
3
+ export type CalendarLayout = 'days' | 'months' | 'years';
4
+ export interface CalendarStateOptionsBase extends InputBase {
5
+ /** The minimum allowed date that a user may select. */
6
+ minValue?: DateTime;
7
+ /** The maximum allowed date that a user may select. */
8
+ maxValue?: DateTime;
9
+ /** Callback that is called for each date of the calendar. If it returns true, then the date is unavailable. */
10
+ isDateUnavailable?: (date: DateTime) => boolean;
11
+ /** */
12
+ timeZone?: string;
13
+ /**
14
+ * Whether to automatically focus the calendar when it mounts.
15
+ * @default false
16
+ */
17
+ autoFocus?: boolean;
18
+ /** Controls the currently focused date within the calendar. */
19
+ focusedValue?: DateTime | null;
20
+ /** The date that is focused when the calendar first mounts (uncontrolled). */
21
+ defaultFocusedValue?: DateTime;
22
+ /** Handler that is called when the focused date changes. */
23
+ onFocusUpdate?: (date: DateTime) => void;
24
+ /** Controls what to show in calendar (days, months or years) */
25
+ mode?: CalendarLayout;
26
+ /** Initial mode to show in calendar (days, months or years) */
27
+ defaultMode?: CalendarLayout;
28
+ /** Handler that is called when the mode changes */
29
+ onUpdateMode?: (mode: CalendarLayout) => void;
30
+ }
31
+ interface CalendarStateBase {
32
+ /** Whether the calendar is disabled. */
33
+ readonly disabled?: boolean;
34
+ /** Whether the calendar is in a read only state. */
35
+ readonly readOnly?: boolean;
36
+ readonly timeZone?: string;
37
+ /** The minimum allowed date that a user may select. */
38
+ readonly minValue?: DateTime;
39
+ /** The maximum allowed date that a user may select. */
40
+ readonly maxValue?: DateTime;
41
+ /** The currently focused date. */
42
+ readonly focusedDate: DateTime;
43
+ /** Sets the focused date. */
44
+ setFocusedDate(date: DateTime): void;
45
+ /** Selects the currently focused date. */
46
+ selectFocusedDate(): void;
47
+ /** Selects the given date. */
48
+ selectDate(date: DateTime): void;
49
+ /** Moves focus to the next calendar date. */
50
+ focusNextCell(): void;
51
+ /** Moves focus to the previous calendar date. */
52
+ focusPreviousCell(): void;
53
+ /** Moves focus to the next row of dates, e.g. the next week. */
54
+ focusNextRow(): void;
55
+ /** Moves focus to the previous row of dates, e.g. the previous work. */
56
+ focusPreviousRow(): void;
57
+ /**
58
+ * Moves focus to the next page of dates, e.g. the next month.
59
+ * If the `larger` option is `true`, the focus is moved by the next larger unit.
60
+ * For example, if days are displayed, then focus moves to the next year.
61
+ */
62
+ focusNextPage(larger?: boolean): void;
63
+ /**
64
+ * Moves focus to the previous page of dates, e.g. the previous month.
65
+ * If the `larger` option is `true`, the focus is moved by the next larger unit.
66
+ * For example, if days are displayed, then focus moves to the previous year.
67
+ */
68
+ focusPreviousPage(larger?: boolean): void;
69
+ /** Moves focus to the start of the current section of dates, e.g. the start of the current month. */
70
+ focusSectionStart(): void;
71
+ /** Moves focus to the end of the current section of dates, e.g. the end of the current month month. */
72
+ focusSectionEnd(): void;
73
+ /** Switches to more detailed layout. */
74
+ zoomIn(): void;
75
+ /** Switches to less detailed layout. */
76
+ zoomOut(): void;
77
+ /** Whether focus is currently within the calendar. */
78
+ readonly isFocused: boolean;
79
+ /** Sets whether focus is currently within the calendar. */
80
+ setFocused(isFocused: boolean): void;
81
+ /** Returns whether the given date is invalid according to the `minValue` and `maxValue` props. */
82
+ isInvalid(date: DateTime): boolean;
83
+ /** Returns whether the previous page is allowed to be selected according to the `minValue` prop. */
84
+ isPreviousPageInvalid(): boolean;
85
+ /** Returns whether the next page is allowed to be selected according to the `maxValue` prop. */
86
+ isNextPageInvalid(): boolean;
87
+ /** Returns whether the given date is currently selected. */
88
+ isSelected(date: DateTime): boolean;
89
+ /** Returns whether the given date is unavailable according to the `isDateUnavailable` prop. */
90
+ isCellUnavailable(date: DateTime): boolean;
91
+ /** Returns whether the given date is currently focused. */
92
+ isCellFocused(date: DateTime): boolean;
93
+ /** Returns whether the given date is disabled according to the `minValue, `maxValue`, and `isDisabled` props. */
94
+ isCellDisabled(date: DateTime): boolean;
95
+ /** Returns whether the given date is weekend */
96
+ isWeekend(date: DateTime): boolean;
97
+ /** Current calendar layout */
98
+ readonly mode: CalendarLayout;
99
+ /** Sets calendar layout */
100
+ setMode(mode: CalendarLayout): void;
101
+ readonly startDate: DateTime;
102
+ readonly endDate: DateTime;
103
+ }
104
+ export interface CalendarState extends CalendarStateBase {
105
+ /** The currently selected date. */
106
+ readonly value?: DateTime | null;
107
+ /** Sets the currently selected date. */
108
+ setValue(value: DateTime): void;
109
+ }
110
+ export interface RangeCalendarState extends CalendarStateBase {
111
+ /** The currently selected range. */
112
+ readonly value?: RangeValue<DateTime> | null;
113
+ /** Sets the currently selected range. */
114
+ setValue(value: RangeValue<DateTime>): void;
115
+ /** The current anchor date that the user clicked on to begin range selection. */
116
+ readonly anchorDate: DateTime | undefined;
117
+ /** Sets the anchor date that the user clicked on to begin range selection. */
118
+ setAnchorDate(date: DateTime | undefined): void;
119
+ /** The currently highlighted date range. */
120
+ readonly highlightedRange: RangeValue<DateTime> | undefined;
121
+ /** Highlights the given date during selection, e.g. by hovering. */
122
+ highlightDate(date: DateTime): void;
123
+ }
124
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import type { DateTime } from '@gravity-ui/date-utils';
3
+ import type { CalendarState, RangeCalendarState } from './types';
4
+ export declare function useCalendarCellProps(date: DateTime, state: CalendarState | RangeCalendarState): {
5
+ cellProps: React.HTMLAttributes<unknown>;
6
+ buttonProps: React.HTMLAttributes<unknown> & {
7
+ ref: React.Ref<HTMLDivElement>;
8
+ };
9
+ formattedDate: string;
10
+ isDisabled: boolean;
11
+ isSelected: boolean;
12
+ isRangeSelection: boolean;
13
+ isSelectionStart: boolean | undefined;
14
+ isSelectionEnd: boolean | undefined;
15
+ isOutsideCurrentRange: boolean;
16
+ isUnavailable: boolean;
17
+ isCurrent: boolean;
18
+ isWeekend: boolean;
19
+ };