@gravity-ui/date-components 1.6.0 → 2.1.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 (279) hide show
  1. package/dist/cjs/components/Calendar/Calendar.d.ts +6 -5
  2. package/dist/cjs/components/Calendar/Calendar.js +4 -4
  3. package/dist/cjs/components/Calendar/index.d.ts +6 -6
  4. package/dist/cjs/components/Calendar/index.js +5 -5
  5. package/dist/cjs/components/{CalendarBase → CalendarView}/Calendar.css +9 -6
  6. package/dist/cjs/components/{CalendarBase/CalendarBase.d.ts → CalendarView/CalendarView.d.ts} +2 -2
  7. package/dist/cjs/components/{CalendarBase/CalendarBase.js → CalendarView/CalendarView.js} +4 -3
  8. package/dist/{esm/components/CalendarBase → cjs/components/CalendarView}/hooks/types.d.ts +37 -31
  9. package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.js +1 -2
  10. package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.d.ts +2 -2
  11. package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.js +17 -0
  12. package/dist/{esm/components/CalendarBase → cjs/components/CalendarView}/hooks/useCalendarState.d.ts +1 -1
  13. package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarState.js +45 -23
  14. package/dist/cjs/components/CalendarView/hooks/useRangeCalendarState.d.ts +8 -0
  15. package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useRangeCalendarState.js +25 -14
  16. package/dist/cjs/components/CalendarView/i18n/en.json +7 -0
  17. package/dist/cjs/components/CalendarView/i18n/index.d.ts +1 -0
  18. package/dist/cjs/components/CalendarView/i18n/ru.json +7 -0
  19. package/dist/cjs/components/DateField/DateField.d.ts +1 -4
  20. package/dist/cjs/components/DateField/DateField.js +3 -1
  21. package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.d.ts +97 -0
  22. package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.js +316 -0
  23. package/dist/cjs/components/DateField/hooks/useDateFieldProps.d.ts +6 -3
  24. package/dist/cjs/components/DateField/hooks/useDateFieldProps.js +14 -12
  25. package/dist/cjs/components/DateField/hooks/useDateFieldState.d.ts +2 -65
  26. package/dist/cjs/components/DateField/hooks/useDateFieldState.js +98 -410
  27. package/dist/cjs/components/DateField/index.d.ts +1 -0
  28. package/dist/cjs/components/DateField/index.js +1 -0
  29. package/dist/cjs/components/DateField/utils.d.ts +10 -1
  30. package/dist/cjs/components/DateField/utils.js +114 -2
  31. package/dist/cjs/components/DatePicker/DatePicker.d.ts +4 -4
  32. package/dist/cjs/components/DatePicker/DatePicker.js +8 -6
  33. package/dist/cjs/components/DatePicker/MobileCalendar.css +7 -32
  34. package/dist/cjs/components/DatePicker/MobileCalendar.d.ts +0 -5
  35. package/dist/cjs/components/DatePicker/MobileCalendar.js +18 -20
  36. package/dist/cjs/components/DatePicker/StubButton.css +26 -0
  37. package/dist/cjs/components/DatePicker/StubButton.d.ts +8 -0
  38. package/dist/cjs/components/DatePicker/StubButton.js +12 -0
  39. package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.js +7 -17
  40. package/dist/cjs/components/DatePicker/hooks/useDatePickerState.d.ts +5 -4
  41. package/dist/cjs/components/DatePicker/hooks/useDatePickerState.js +71 -56
  42. package/dist/cjs/components/RangeCalendar/RangeCalendar.d.ts +3 -3
  43. package/dist/cjs/components/RangeCalendar/RangeCalendar.js +4 -4
  44. package/dist/cjs/components/RangeDateField/RangeDateField.css +4 -0
  45. package/dist/cjs/components/RangeDateField/RangeDateField.d.ts +12 -0
  46. package/dist/cjs/components/RangeDateField/RangeDateField.js +25 -0
  47. package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.d.ts +9 -0
  48. package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.js +227 -0
  49. package/dist/cjs/components/RangeDateField/index.d.ts +2 -0
  50. package/dist/cjs/components/RangeDateField/index.js +5 -0
  51. package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.d.ts +5 -0
  52. package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.js +9 -0
  53. package/dist/cjs/components/RangeDateField/utils/getRangeEditableSections.d.ts +5 -0
  54. package/dist/cjs/components/RangeDateField/utils/getRangeEditableSections.js +42 -0
  55. package/dist/cjs/components/RangeDateField/utils/index.d.ts +3 -0
  56. package/dist/cjs/components/RangeDateField/utils/index.js +6 -0
  57. package/dist/cjs/components/RangeDateField/utils/isValidRange.d.ts +3 -0
  58. package/dist/cjs/components/RangeDateField/utils/isValidRange.js +8 -0
  59. package/dist/cjs/components/RelativeDateField/RelativeDateField.d.ts +2 -2
  60. package/dist/cjs/components/RelativeDateField/RelativeDateField.js +5 -2
  61. package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +5 -11
  62. package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +3 -1
  63. package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.js +5 -4
  64. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.css +3 -0
  65. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.d.ts +2 -2
  66. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js +15 -2
  67. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +35 -27
  68. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.d.ts +2 -2
  69. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +12 -16
  70. package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.css +56 -0
  71. package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.d.ts +27 -0
  72. package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +90 -0
  73. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css +32 -0
  74. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +14 -0
  75. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +43 -0
  76. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/en.json +8 -0
  77. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.d.ts +1 -0
  78. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.js +9 -0
  79. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/ru.json +8 -0
  80. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +16 -0
  81. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +104 -0
  82. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.css +26 -0
  83. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.d.ts +18 -0
  84. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.js +67 -0
  85. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.css +14 -0
  86. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.d.ts +7 -0
  87. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.js +90 -0
  88. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/defaultPresets.d.ts +9 -0
  89. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/defaultPresets.js +186 -0
  90. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/en.json +40 -0
  91. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/index.d.ts +1 -0
  92. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/index.js +9 -0
  93. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/ru.json +40 -0
  94. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/utils.d.ts +16 -0
  95. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/utils.js +85 -0
  96. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.css +3 -0
  97. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.d.ts +9 -0
  98. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.js +62 -0
  99. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/en.json +4 -0
  100. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/index.d.ts +1 -0
  101. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/index.js +9 -0
  102. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/ru.json +4 -0
  103. package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.d.ts +26 -0
  104. package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +58 -0
  105. package/dist/cjs/components/RelativeRangeDatePicker/i18n/en.json +8 -0
  106. package/dist/cjs/components/RelativeRangeDatePicker/i18n/index.d.ts +1 -0
  107. package/dist/cjs/components/RelativeRangeDatePicker/i18n/index.js +9 -0
  108. package/dist/cjs/components/RelativeRangeDatePicker/i18n/ru.json +8 -0
  109. package/dist/cjs/components/RelativeRangeDatePicker/index.d.ts +4 -0
  110. package/dist/cjs/components/RelativeRangeDatePicker/index.js +8 -0
  111. package/dist/cjs/components/RelativeRangeDatePicker/utils.d.ts +15 -0
  112. package/dist/cjs/components/RelativeRangeDatePicker/utils.js +53 -0
  113. package/dist/cjs/components/index.d.ts +3 -0
  114. package/dist/cjs/components/index.js +2 -0
  115. package/dist/cjs/components/types/datePicker.d.ts +5 -2
  116. package/dist/cjs/components/types/events.d.ts +4 -4
  117. package/dist/cjs/components/types/inputs.d.ts +10 -9
  118. package/dist/cjs/components/utils/dates.d.ts +1 -2
  119. package/dist/cjs/components/utils/useDefaultTimeZone.d.ts +2 -0
  120. package/dist/cjs/components/utils/useDefaultTimeZone.js +15 -0
  121. package/dist/cjs/components/utils/validation/datePicker.d.ts +6 -0
  122. package/dist/cjs/components/utils/validation/datePicker.js +30 -0
  123. package/dist/cjs/components/utils/validation/i18n/en.json +6 -0
  124. package/dist/cjs/components/utils/validation/i18n/index.d.ts +1 -0
  125. package/dist/cjs/components/utils/validation/i18n/index.js +9 -0
  126. package/dist/cjs/components/utils/validation/i18n/ru.json +6 -0
  127. package/dist/esm/components/Calendar/Calendar.d.ts +6 -5
  128. package/dist/esm/components/Calendar/Calendar.js +4 -4
  129. package/dist/esm/components/Calendar/index.d.ts +6 -6
  130. package/dist/esm/components/Calendar/index.js +5 -5
  131. package/dist/esm/components/{CalendarBase → CalendarView}/Calendar.css +9 -6
  132. package/dist/esm/components/{CalendarBase/CalendarBase.d.ts → CalendarView/CalendarView.d.ts} +2 -2
  133. package/dist/esm/components/{CalendarBase/CalendarBase.js → CalendarView/CalendarView.js} +3 -2
  134. package/dist/{cjs/components/CalendarBase → esm/components/CalendarView}/hooks/types.d.ts +37 -31
  135. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.js +1 -2
  136. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.d.ts +2 -2
  137. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.js +0 -1
  138. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.js +17 -0
  139. package/dist/{cjs/components/CalendarBase → esm/components/CalendarView}/hooks/useCalendarState.d.ts +1 -1
  140. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarState.js +46 -24
  141. package/dist/esm/components/CalendarView/hooks/useRangeCalendarState.d.ts +8 -0
  142. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useRangeCalendarState.js +24 -13
  143. package/dist/esm/components/CalendarView/i18n/en.json +7 -0
  144. package/dist/esm/components/CalendarView/i18n/index.d.ts +1 -0
  145. package/dist/esm/components/CalendarView/i18n/ru.json +7 -0
  146. package/dist/esm/components/DateField/DateField.d.ts +1 -4
  147. package/dist/esm/components/DateField/DateField.js +4 -2
  148. package/dist/esm/components/DateField/hooks/useBaseDateFieldState.d.ts +97 -0
  149. package/dist/esm/components/DateField/hooks/useBaseDateFieldState.js +311 -0
  150. package/dist/esm/components/DateField/hooks/useDateFieldProps.d.ts +6 -3
  151. package/dist/esm/components/DateField/hooks/useDateFieldProps.js +14 -12
  152. package/dist/esm/components/DateField/hooks/useDateFieldState.d.ts +2 -65
  153. package/dist/esm/components/DateField/hooks/useDateFieldState.js +97 -409
  154. package/dist/esm/components/DateField/index.d.ts +1 -0
  155. package/dist/esm/components/DateField/index.js +1 -0
  156. package/dist/esm/components/DateField/utils.d.ts +10 -1
  157. package/dist/esm/components/DateField/utils.js +105 -2
  158. package/dist/esm/components/DatePicker/DatePicker.d.ts +4 -4
  159. package/dist/esm/components/DatePicker/DatePicker.js +10 -8
  160. package/dist/esm/components/DatePicker/MobileCalendar.css +7 -32
  161. package/dist/esm/components/DatePicker/MobileCalendar.d.ts +0 -5
  162. package/dist/esm/components/DatePicker/MobileCalendar.js +17 -18
  163. package/dist/esm/components/DatePicker/StubButton.css +26 -0
  164. package/dist/esm/components/DatePicker/StubButton.d.ts +8 -0
  165. package/dist/esm/components/DatePicker/StubButton.js +8 -0
  166. package/dist/esm/components/DatePicker/hooks/useDatePickerProps.js +7 -17
  167. package/dist/esm/components/DatePicker/hooks/useDatePickerState.d.ts +5 -4
  168. package/dist/esm/components/DatePicker/hooks/useDatePickerState.js +71 -56
  169. package/dist/esm/components/RangeCalendar/RangeCalendar.d.ts +3 -3
  170. package/dist/esm/components/RangeCalendar/RangeCalendar.js +4 -4
  171. package/dist/esm/components/RangeDateField/RangeDateField.css +4 -0
  172. package/dist/esm/components/RangeDateField/RangeDateField.d.ts +12 -0
  173. package/dist/esm/components/RangeDateField/RangeDateField.js +21 -0
  174. package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.d.ts +9 -0
  175. package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.js +222 -0
  176. package/dist/esm/components/RangeDateField/index.d.ts +2 -0
  177. package/dist/esm/components/RangeDateField/index.js +2 -0
  178. package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.d.ts +5 -0
  179. package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.js +5 -0
  180. package/dist/esm/components/RangeDateField/utils/getRangeEditableSections.d.ts +5 -0
  181. package/dist/esm/components/RangeDateField/utils/getRangeEditableSections.js +38 -0
  182. package/dist/esm/components/RangeDateField/utils/index.d.ts +3 -0
  183. package/dist/esm/components/RangeDateField/utils/index.js +3 -0
  184. package/dist/esm/components/RangeDateField/utils/isValidRange.d.ts +3 -0
  185. package/dist/esm/components/RangeDateField/utils/isValidRange.js +4 -0
  186. package/dist/esm/components/RelativeDateField/RelativeDateField.d.ts +2 -2
  187. package/dist/esm/components/RelativeDateField/RelativeDateField.js +5 -2
  188. package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +5 -11
  189. package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +3 -1
  190. package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.js +5 -4
  191. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.css +3 -0
  192. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.d.ts +2 -2
  193. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js +17 -4
  194. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +35 -27
  195. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.d.ts +2 -2
  196. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +12 -16
  197. package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.css +56 -0
  198. package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.d.ts +27 -0
  199. package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +85 -0
  200. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css +32 -0
  201. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +14 -0
  202. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +39 -0
  203. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/en.json +8 -0
  204. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.d.ts +1 -0
  205. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.js +5 -0
  206. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/ru.json +8 -0
  207. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +16 -0
  208. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +99 -0
  209. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.css +26 -0
  210. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.d.ts +18 -0
  211. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.js +62 -0
  212. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.css +14 -0
  213. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.d.ts +7 -0
  214. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.js +85 -0
  215. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/defaultPresets.d.ts +9 -0
  216. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/defaultPresets.js +183 -0
  217. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/en.json +40 -0
  218. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/index.d.ts +1 -0
  219. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/index.js +5 -0
  220. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/ru.json +40 -0
  221. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/utils.d.ts +16 -0
  222. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/utils.js +78 -0
  223. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.css +3 -0
  224. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.d.ts +9 -0
  225. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.js +58 -0
  226. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/en.json +4 -0
  227. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/index.d.ts +1 -0
  228. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/index.js +5 -0
  229. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/ru.json +4 -0
  230. package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.d.ts +26 -0
  231. package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +53 -0
  232. package/dist/esm/components/RelativeRangeDatePicker/i18n/en.json +8 -0
  233. package/dist/esm/components/RelativeRangeDatePicker/i18n/index.d.ts +1 -0
  234. package/dist/esm/components/RelativeRangeDatePicker/i18n/index.js +5 -0
  235. package/dist/esm/components/RelativeRangeDatePicker/i18n/ru.json +8 -0
  236. package/dist/esm/components/RelativeRangeDatePicker/index.d.ts +4 -0
  237. package/dist/esm/components/RelativeRangeDatePicker/index.js +3 -0
  238. package/dist/esm/components/RelativeRangeDatePicker/utils.d.ts +15 -0
  239. package/dist/esm/components/RelativeRangeDatePicker/utils.js +46 -0
  240. package/dist/esm/components/index.d.ts +3 -0
  241. package/dist/esm/components/index.js +2 -0
  242. package/dist/esm/components/types/datePicker.d.ts +5 -2
  243. package/dist/esm/components/types/events.d.ts +4 -4
  244. package/dist/esm/components/types/inputs.d.ts +10 -9
  245. package/dist/esm/components/utils/dates.d.ts +1 -2
  246. package/dist/esm/components/utils/useDefaultTimeZone.d.ts +2 -0
  247. package/dist/esm/components/utils/useDefaultTimeZone.js +10 -0
  248. package/dist/esm/components/utils/validation/datePicker.d.ts +6 -0
  249. package/dist/esm/components/utils/validation/datePicker.js +26 -0
  250. package/dist/esm/components/utils/validation/i18n/en.json +6 -0
  251. package/dist/esm/components/utils/validation/i18n/index.d.ts +1 -0
  252. package/dist/esm/components/utils/validation/i18n/index.js +5 -0
  253. package/dist/esm/components/utils/validation/i18n/ru.json +6 -0
  254. package/package.json +28 -28
  255. package/dist/cjs/components/CalendarBase/hooks/useRangeCalendarState.d.ts +0 -7
  256. package/dist/cjs/components/CalendarBase/i18n/en.json +0 -4
  257. package/dist/cjs/components/CalendarBase/i18n/index.d.ts +0 -1
  258. package/dist/cjs/components/CalendarBase/i18n/ru.json +0 -4
  259. package/dist/cjs/components/hooks/useControlledState.d.ts +0 -1
  260. package/dist/cjs/components/hooks/useControlledState.js +0 -28
  261. package/dist/esm/components/CalendarBase/hooks/useRangeCalendarState.d.ts +0 -7
  262. package/dist/esm/components/CalendarBase/i18n/en.json +0 -4
  263. package/dist/esm/components/CalendarBase/i18n/index.d.ts +0 -1
  264. package/dist/esm/components/CalendarBase/i18n/ru.json +0 -4
  265. package/dist/esm/components/hooks/useControlledState.d.ts +0 -1
  266. package/dist/esm/components/hooks/useControlledState.js +0 -23
  267. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/types.js +0 -0
  268. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.d.ts +0 -0
  269. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.js +0 -0
  270. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.d.ts +0 -0
  271. /package/dist/cjs/components/{CalendarBase → CalendarView}/i18n/index.js +0 -0
  272. /package/dist/cjs/components/{CalendarBase → CalendarView}/utils.d.ts +0 -0
  273. /package/dist/cjs/components/{CalendarBase → CalendarView}/utils.js +0 -0
  274. /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/types.js +0 -0
  275. /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.d.ts +0 -0
  276. /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.d.ts +0 -0
  277. /package/dist/esm/components/{CalendarBase → CalendarView}/i18n/index.js +0 -0
  278. /package/dist/esm/components/{CalendarBase → CalendarView}/utils.d.ts +0 -0
  279. /package/dist/esm/components/{CalendarBase → CalendarView}/utils.js +0 -0
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
- import type { CalendarInstance, CalendarSize } from '../CalendarBase/CalendarBase';
3
- import type { RangeCalendarStateOptions } from '../CalendarBase/hooks/useRangeCalendarState';
2
+ import type { CalendarInstance, CalendarSize } from '../CalendarView/CalendarView';
3
+ import type { RangeCalendarStateOptions } from '../CalendarView/hooks/useRangeCalendarState';
4
4
  import type { AccessibilityProps, DomProps, FocusEvents, StyleProps } from '../types';
5
- import '../CalendarBase/Calendar.css';
5
+ import '../CalendarView/Calendar.css';
6
6
  export interface RangeCalendarProps extends RangeCalendarStateOptions, DomProps, StyleProps, FocusEvents, AccessibilityProps {
7
7
  /**
8
8
  * The size of the element.
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import React from 'react';
3
- import { CalendarBase } from '../CalendarBase/CalendarBase';
4
- import { useRangeCalendarState } from '../CalendarBase/hooks/useRangeCalendarState';
5
- import '../CalendarBase/Calendar.css';
3
+ import { CalendarView } from '../CalendarView/CalendarView';
4
+ import { useRangeCalendarState } from '../CalendarView/hooks/useRangeCalendarState';
5
+ import '../CalendarView/Calendar.css';
6
6
  export const RangeCalendar = React.forwardRef(function Calendar(props, ref) {
7
7
  const state = useRangeCalendarState(props);
8
8
  const handleBlur = (e) => {
@@ -12,5 +12,5 @@ export const RangeCalendar = React.forwardRef(function Calendar(props, ref) {
12
12
  }
13
13
  (_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, e);
14
14
  };
15
- return _jsx(CalendarBase, Object.assign({ ref: ref }, props, { state: state, onBlur: handleBlur }));
15
+ return _jsx(CalendarView, Object.assign({ ref: ref }, props, { state: state, onBlur: handleBlur }));
16
16
  });
@@ -0,0 +1,4 @@
1
+ .g-date-range-date-field {
2
+ display: inline-block;
3
+ width: auto;
4
+ }
@@ -0,0 +1,12 @@
1
+ import type { DateTime } from '@gravity-ui/date-utils';
2
+ import type { DateFieldProps } from '../DateField/hooks/useDateFieldProps';
3
+ import type { RangeValue } from '../types';
4
+ import './RangeDateField.css';
5
+ export type RangeDateFieldProps = DateFieldProps<RangeValue<DateTime>> & {
6
+ /**
7
+ * Delimiter separating the start and end parts of the range.
8
+ * @default ' — '
9
+ * */
10
+ delimiter?: string;
11
+ };
12
+ export declare function RangeDateField({ className, ...props }: RangeDateFieldProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,21 @@
1
+ import { __rest } from "tslib";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import React from 'react';
4
+ import { TextInput, useFocusWithin } from '@gravity-ui/uikit';
5
+ import { block } from '../../utils/cn';
6
+ import { useDateFieldProps } from '../DateField/hooks/useDateFieldProps';
7
+ import { useRangeDateFieldState } from './hooks/useRangeDateFieldState';
8
+ import './RangeDateField.css';
9
+ const b = block('range-date-field');
10
+ export function RangeDateField(_a) {
11
+ var { className } = _a, props = __rest(_a, ["className"]);
12
+ const state = useRangeDateFieldState(props);
13
+ const { inputProps } = useDateFieldProps(state, props);
14
+ const [isActive, setActive] = React.useState(false);
15
+ const { focusWithinProps } = useFocusWithin({
16
+ onFocusWithinChange(isFocusWithin) {
17
+ setActive(isFocusWithin);
18
+ },
19
+ });
20
+ return (_jsx("div", Object.assign({ className: b(null, className), style: props.style }, focusWithinProps, { children: _jsx(TextInput, Object.assign({}, inputProps, { value: state.isEmpty && !isActive && props.placeholder ? '' : inputProps.value })) })));
21
+ }
@@ -0,0 +1,9 @@
1
+ import type { DateTime } from '@gravity-ui/date-utils';
2
+ import type { BaseDateFieldState } from '../../DateField';
3
+ import type { DateFieldBase } from '../../types/datePicker';
4
+ import type { RangeValue } from '../../types/inputs';
5
+ export interface RangeDateFieldStateOptions extends DateFieldBase<RangeValue<DateTime>> {
6
+ delimiter?: string;
7
+ }
8
+ export type RangeDateFieldState = BaseDateFieldState<RangeValue<DateTime>>;
9
+ export declare function useRangeDateFieldState(props: RangeDateFieldStateOptions): RangeDateFieldState;
@@ -0,0 +1,222 @@
1
+ /* eslint-disable complexity */
2
+ import React from 'react';
3
+ import { isValid } from '@gravity-ui/date-utils';
4
+ import { useControlledState } from '@gravity-ui/uikit';
5
+ import { useBaseDateFieldState } from '../../DateField';
6
+ import { EDITABLE_SEGMENTS, addSegment, isAllSegmentsValid, parseDateFromString, setSegment, useFormatSections, } from '../../DateField/utils';
7
+ import { isInvalid } from '../../utils/dates';
8
+ import { useDefaultTimeZone } from '../../utils/useDefaultTimeZone';
9
+ import { createPlaceholderRangeValue, getRangeEditableSections, isValidRange } from '../utils';
10
+ const RANGE_FORMAT_DELIMITER = ' — ';
11
+ export function useRangeDateFieldState(props) {
12
+ var _a, _b, _c, _d, _e;
13
+ const [value, setRange] = useControlledState(props.value, props.defaultValue || null, props.onUpdate);
14
+ const inputTimeZone = useDefaultTimeZone(((_a = props.value) === null || _a === void 0 ? void 0 : _a.start) || ((_b = props.defaultValue) === null || _b === void 0 ? void 0 : _b.start) || props.placeholderValue);
15
+ const timeZone = props.timeZone || inputTimeZone;
16
+ const handleUpdateRange = (v) => {
17
+ setRange(v ? { start: v.start.timeZone(inputTimeZone), end: v.end.timeZone(inputTimeZone) } : v);
18
+ };
19
+ const [placeholderDate, setPlaceholderDate] = React.useState(() => {
20
+ return createPlaceholderRangeValue({
21
+ placeholderValue: props.placeholderValue,
22
+ timeZone,
23
+ });
24
+ });
25
+ const format = props.format || 'L';
26
+ const delimiter = (_c = props.delimiter) !== null && _c !== void 0 ? _c : RANGE_FORMAT_DELIMITER;
27
+ const sections = useFormatSections(format);
28
+ const allSegments = React.useMemo(() => {
29
+ return sections
30
+ .filter((seg) => EDITABLE_SEGMENTS[seg.type])
31
+ .reduce((p, seg) => (Object.assign(Object.assign({}, p), { [seg.type]: true })), {});
32
+ }, [sections]);
33
+ // eslint-disable-next-line prefer-const
34
+ let [validSegments, setValidSegments] = React.useState(() => (value ? { start: Object.assign({}, allSegments), end: Object.assign({}, allSegments) } : { start: {}, end: {} }));
35
+ if (value &&
36
+ (!isAllSegmentsValid(allSegments, validSegments.start) ||
37
+ !isAllSegmentsValid(allSegments, validSegments.end))) {
38
+ setValidSegments({ start: Object.assign({}, allSegments), end: Object.assign({}, allSegments) });
39
+ }
40
+ if (!value &&
41
+ isAllSegmentsValid(allSegments, validSegments.start) &&
42
+ Object.keys(validSegments.start).length === Object.keys(allSegments).length &&
43
+ isAllSegmentsValid(allSegments, validSegments.end) &&
44
+ Object.keys(validSegments.end).length === Object.keys(allSegments).length) {
45
+ validSegments = { start: {}, end: {} };
46
+ setValidSegments(validSegments);
47
+ setPlaceholderDate(createPlaceholderRangeValue({
48
+ placeholderValue: props.placeholderValue,
49
+ timeZone,
50
+ }));
51
+ }
52
+ const displayValue = value &&
53
+ isValid(value.start) &&
54
+ isValid(value.end) &&
55
+ Object.keys(validSegments.start).length >= Object.keys(allSegments).length &&
56
+ Object.keys(validSegments.end).length >= Object.keys(allSegments).length
57
+ ? { start: value.start.timeZone(timeZone), end: value.end.timeZone(timeZone) }
58
+ : {
59
+ start: placeholderDate.start.timeZone(timeZone),
60
+ end: placeholderDate.end.timeZone(timeZone),
61
+ };
62
+ const sectionsState = useSectionsState(sections, displayValue, validSegments, delimiter);
63
+ const [selectedSections, setSelectedSections] = React.useState(-1);
64
+ const selectedSectionIndexes = React.useMemo(() => {
65
+ if (selectedSections === -1) {
66
+ return null;
67
+ }
68
+ if (selectedSections === 'all') {
69
+ return {
70
+ startIndex: 0,
71
+ endIndex: sectionsState.editableSections.length - 1,
72
+ };
73
+ }
74
+ if (typeof selectedSections === 'number') {
75
+ return { startIndex: selectedSections, endIndex: selectedSections };
76
+ }
77
+ if (typeof selectedSections === 'string') {
78
+ const selectedSectionIndex = sectionsState.editableSections.findIndex((section) => section.type === selectedSections);
79
+ return { startIndex: selectedSectionIndex, endIndex: selectedSectionIndex };
80
+ }
81
+ return selectedSections;
82
+ }, [selectedSections, sectionsState.editableSections]);
83
+ function setValue(newValue) {
84
+ if (props.disabled || props.readOnly) {
85
+ return;
86
+ }
87
+ if (isAllSegmentsValid(allSegments, validSegments.start) &&
88
+ isAllSegmentsValid(allSegments, validSegments.end)) {
89
+ if (!value || !(newValue.start.isSame(value.start) && newValue.end.isSame(value.end))) {
90
+ handleUpdateRange(newValue);
91
+ }
92
+ }
93
+ else {
94
+ if (value) {
95
+ handleUpdateRange(null);
96
+ }
97
+ setPlaceholderDate(newValue);
98
+ }
99
+ }
100
+ function markValid(portion, part) {
101
+ validSegments[portion][part] = true;
102
+ if (validSegments[portion].day &&
103
+ validSegments[portion].month &&
104
+ validSegments[portion].year &&
105
+ allSegments.weekday) {
106
+ validSegments[portion].weekday = true;
107
+ }
108
+ if (validSegments[portion].hour && allSegments.dayPeriod) {
109
+ validSegments[portion].dayPeriod = true;
110
+ }
111
+ setValidSegments(Object.assign(Object.assign({}, validSegments), { [portion]: Object.assign({}, validSegments[portion]) }));
112
+ }
113
+ function setSection(sectionIndex, amount) {
114
+ const portion = sectionIndex <= sections.length ? 'start' : 'end';
115
+ const section = sectionsState.editableSections[sectionIndex];
116
+ markValid(portion, section.type);
117
+ setValue(Object.assign(Object.assign({}, displayValue), { [portion]: setSegment(section, displayValue[portion], amount) }));
118
+ }
119
+ function adjustSection(sectionIndex, amount) {
120
+ const section = sectionsState.editableSections[sectionIndex];
121
+ const portion = sectionIndex <= sections.length ? 'start' : 'end';
122
+ if (validSegments[portion][section.type]) {
123
+ setValue(Object.assign(Object.assign({}, displayValue), { [portion]: addSegment(section, displayValue[portion], amount) }));
124
+ }
125
+ else {
126
+ markValid(portion, section.type);
127
+ if (Object.keys(validSegments[portion]).length >= Object.keys(allSegments).length) {
128
+ setValue(displayValue);
129
+ }
130
+ }
131
+ }
132
+ function flushValidSection(sectionIndex) {
133
+ const portion = sectionIndex <= sections.length ? 'start' : 'end';
134
+ delete validSegments[portion][sectionsState.editableSections[sectionIndex].type];
135
+ setValidSegments(Object.assign(Object.assign({}, validSegments), { [portion]: Object.assign({}, validSegments[portion]) }));
136
+ }
137
+ function flushAllValidSections() {
138
+ validSegments = { start: {}, end: {} };
139
+ setValidSegments({ start: {}, end: {} });
140
+ }
141
+ function getSectionValue(sectionIndex) {
142
+ const portion = sectionIndex <= sections.length ? 'start' : 'end';
143
+ return displayValue[portion];
144
+ }
145
+ function setSectionValue(sectionIndex, currentValue) {
146
+ const portion = sectionIndex <= sections.length ? 'start' : 'end';
147
+ setValue(Object.assign(Object.assign({}, displayValue), { [portion]: currentValue }));
148
+ }
149
+ function createPlaceholder() {
150
+ return createPlaceholderRangeValue({
151
+ placeholderValue: props.placeholderValue,
152
+ timeZone,
153
+ });
154
+ }
155
+ function setValueFromString(str) {
156
+ var _a, _b;
157
+ const list = str.split(delimiter);
158
+ const start = parseDateFromString((_a = list === null || list === void 0 ? void 0 : list[0]) === null || _a === void 0 ? void 0 : _a.trim(), format, timeZone);
159
+ const end = parseDateFromString((_b = list === null || list === void 0 ? void 0 : list[1]) === null || _b === void 0 ? void 0 : _b.trim(), format, timeZone);
160
+ const range = { start, end };
161
+ if (isValid(range.start) && isValid(range.end)) {
162
+ handleUpdateRange(range);
163
+ return true;
164
+ }
165
+ return false;
166
+ }
167
+ const validationState = props.validationState ||
168
+ (isInvalid(value === null || value === void 0 ? void 0 : value.start, props.minValue, props.maxValue) ? 'invalid' : undefined) ||
169
+ (isInvalid(value === null || value === void 0 ? void 0 : value.end, props.minValue, props.maxValue) ? 'invalid' : undefined) ||
170
+ (value && !isValidRange(value) ? 'invalid' : undefined) ||
171
+ (value && ((_d = props.isDateUnavailable) === null || _d === void 0 ? void 0 : _d.call(props, value.start)) ? 'invalid' : undefined) ||
172
+ (value && ((_e = props.isDateUnavailable) === null || _e === void 0 ? void 0 : _e.call(props, value.end)) ? 'invalid' : undefined);
173
+ return useBaseDateFieldState({
174
+ value,
175
+ displayValue,
176
+ placeholderValue: props.placeholderValue,
177
+ timeZone,
178
+ validationState,
179
+ editableSections: sectionsState.editableSections,
180
+ readOnly: props.readOnly,
181
+ disabled: props.disabled,
182
+ selectedSectionIndexes,
183
+ selectedSections,
184
+ isEmpty: Object.keys(validSegments.start).length === 0 &&
185
+ Object.keys(validSegments.end).length === 0,
186
+ flushAllValidSections,
187
+ flushValidSection,
188
+ setSelectedSections,
189
+ setValue,
190
+ setDate: handleUpdateRange,
191
+ adjustSection,
192
+ setSection,
193
+ getSectionValue,
194
+ setSectionValue,
195
+ createPlaceholder,
196
+ setValueFromString,
197
+ });
198
+ }
199
+ function useSectionsState(sections, value, validSegments, delimiter) {
200
+ const [state, setState] = React.useState(() => {
201
+ return {
202
+ value,
203
+ sections,
204
+ validSegments,
205
+ delimiter,
206
+ editableSections: getRangeEditableSections(sections, value, validSegments, delimiter),
207
+ };
208
+ });
209
+ if (sections !== state.sections ||
210
+ validSegments !== state.validSegments ||
211
+ !(value.start.isSame(state.value.start) && value.end.isSame(state.value.end)) ||
212
+ delimiter !== state.delimiter) {
213
+ setState({
214
+ value,
215
+ sections,
216
+ validSegments,
217
+ delimiter,
218
+ editableSections: getRangeEditableSections(sections, value, validSegments, delimiter),
219
+ });
220
+ }
221
+ return state;
222
+ }
@@ -0,0 +1,2 @@
1
+ export * from './RangeDateField';
2
+ export * from './hooks/useRangeDateFieldState';
@@ -0,0 +1,2 @@
1
+ export * from './RangeDateField';
2
+ export * from './hooks/useRangeDateFieldState';
@@ -0,0 +1,5 @@
1
+ import type { PlaceholderValueOptions } from '../../utils/dates';
2
+ export declare function createPlaceholderRangeValue({ placeholderValue, timeZone }: PlaceholderValueOptions): {
3
+ start: import("@gravity-ui/date-utils").DateTime;
4
+ end: import("@gravity-ui/date-utils").DateTime;
5
+ };
@@ -0,0 +1,5 @@
1
+ import { createPlaceholderValue } from '../../utils/dates';
2
+ export function createPlaceholderRangeValue({ placeholderValue, timeZone }) {
3
+ const date = createPlaceholderValue({ placeholderValue, timeZone });
4
+ return { start: date, end: date };
5
+ }
@@ -0,0 +1,5 @@
1
+ import type { DateTime } from '@gravity-ui/date-utils';
2
+ import type { DateFieldSectionWithoutPosition } from '../../DateField/types';
3
+ import type { EDITABLE_SEGMENTS } from '../../DateField/utils';
4
+ import type { RangeValue } from '../../types';
5
+ export declare function getRangeEditableSections(sections: DateFieldSectionWithoutPosition[], value: RangeValue<DateTime>, validSegments: RangeValue<typeof EDITABLE_SEGMENTS>, delimiter: string): import("../../DateField/types").DateFieldSection[];
@@ -0,0 +1,38 @@
1
+ import { getEditableSections, isEditableSection, toEditableSection } from '../../DateField/utils';
2
+ export function getRangeEditableSections(sections, value, validSegments, delimiter) {
3
+ const start = getEditableSections(sections, value.start, validSegments.start);
4
+ const end = getEditableSections(sections, value.end, validSegments.end);
5
+ const last = start[start.length - 1];
6
+ let position = last.end;
7
+ const previousEditableSection = last.nextEditableSection;
8
+ const sectionsCount = start.length + 1;
9
+ const delimiterSection = toEditableSection({
10
+ type: 'literal',
11
+ contentType: 'letter',
12
+ format: delimiter,
13
+ placeholder: delimiter,
14
+ hasLeadingZeros: false,
15
+ }, value.start, validSegments.start, position, previousEditableSection);
16
+ position += delimiterSection.textValue.length - 1;
17
+ let nextEditableSection;
18
+ for (let index = 0; index < end.length; index++) {
19
+ const section = end[index];
20
+ section.start += position;
21
+ section.end += position;
22
+ if (section.previousEditableSection === 0 && nextEditableSection === undefined) {
23
+ section.previousEditableSection = previousEditableSection;
24
+ }
25
+ else {
26
+ section.previousEditableSection += sectionsCount;
27
+ }
28
+ section.nextEditableSection += sectionsCount;
29
+ if (isEditableSection(section) && nextEditableSection === undefined) {
30
+ nextEditableSection = index + sectionsCount;
31
+ }
32
+ }
33
+ if (nextEditableSection !== undefined) {
34
+ delimiterSection.nextEditableSection = nextEditableSection;
35
+ start[previousEditableSection].nextEditableSection = nextEditableSection;
36
+ }
37
+ return [...start, delimiterSection, ...end];
38
+ }
@@ -0,0 +1,3 @@
1
+ export * from './getRangeEditableSections';
2
+ export * from './isValidRange';
3
+ export * from './createPlaceholderRangeValue';
@@ -0,0 +1,3 @@
1
+ export * from './getRangeEditableSections';
2
+ export * from './isValidRange';
3
+ export * from './createPlaceholderRangeValue';
@@ -0,0 +1,3 @@
1
+ import type { DateTime } from '@gravity-ui/date-utils';
2
+ import type { RangeValue } from '../../types';
3
+ export declare function isValidRange({ start, end }: RangeValue<DateTime>): boolean;
@@ -0,0 +1,4 @@
1
+ import { isValid } from '@gravity-ui/date-utils';
2
+ export function isValidRange({ start, end }) {
3
+ return isValid(start) && isValid(end) && (start.isSame(end) || start.isBefore(end));
4
+ }
@@ -1,7 +1,7 @@
1
- import type { AccessibilityProps, DomProps, FocusableProps, KeyboardEvents, StyleProps, TextInputExtendProps, TextInputProps } from '../types';
1
+ import type { AccessibilityProps, DomProps, FocusableProps, InputDOMProps, KeyboardEvents, StyleProps, TextInputExtendProps, TextInputProps } from '../types';
2
2
  import type { RelativeDateFieldOptions } from './hooks/useRelativeDateFieldState';
3
3
  import './RelativeDateField.css';
4
- export interface RelativeDateFieldProps extends RelativeDateFieldOptions, TextInputProps, TextInputExtendProps, DomProps, StyleProps, AccessibilityProps, FocusableProps, KeyboardEvents {
4
+ export interface RelativeDateFieldProps extends RelativeDateFieldOptions, TextInputProps, TextInputExtendProps, DomProps, InputDOMProps, StyleProps, AccessibilityProps, FocusableProps, KeyboardEvents {
5
5
  /**
6
6
  * Show time field in popup
7
7
  * @default false
@@ -9,9 +9,10 @@ import { useRelativeDateFieldState } from './hooks/useRelativeDateFieldState';
9
9
  import './RelativeDateField.css';
10
10
  const b = block('relative-date-field');
11
11
  export function RelativeDateField(props) {
12
+ var _a;
12
13
  const state = useRelativeDateFieldState(props);
13
14
  const { inputProps, calendarProps, timeInputProps } = useRelativeDateFieldProps(state, props);
14
- const [isMobile] = useMobile();
15
+ const isMobile = useMobile();
15
16
  const anchorRef = React.useRef(null);
16
17
  const [isOpen, setOpen] = React.useState(false);
17
18
  const { focusWithinProps } = useFocusWithin({
@@ -26,5 +27,7 @@ export function RelativeDateField(props) {
26
27
  setOpen(true);
27
28
  }
28
29
  (_a = props.onFocus) === null || _a === void 0 ? void 0 : _a.call(props, e);
29
- }, onBlur: props.onBlur })), !isMobile && (_jsx(Popup, { anchorRef: anchorRef, open: isOpen, children: _jsxs("div", { className: b('popup-content'), children: [_jsx(Calendar, Object.assign({}, calendarProps)), props.hasTime ? (_jsx("div", { className: b('time-field-wrapper'), children: _jsx(DateField, Object.assign({ className: b('time-field') }, timeInputProps)) })) : null] }) }))] })));
30
+ }, onBlur: props.onBlur })), _jsx("input", { type: "text", hidden: true, name: props.name, value: (_a = state.value) !== null && _a !== void 0 ? _a : '',
31
+ // Ignore React warning
32
+ onChange: () => { } }), !isMobile && (_jsx(Popup, { anchorRef: anchorRef, open: isOpen, children: _jsxs("div", { className: b('popup-content'), children: [_jsx(Calendar, Object.assign({}, calendarProps)), props.hasTime ? (_jsx("div", { className: b('time-field-wrapper'), children: _jsx(DateField, Object.assign({ className: b('time-field') }, timeInputProps)) })) : null] }) }))] })));
30
33
  }
@@ -6,13 +6,6 @@ export function useRelativeDateFieldProps(state, props) {
6
6
  setPrevCorrectDate(state.lastCorrectDate);
7
7
  setFocusedDate(state.lastCorrectDate);
8
8
  }
9
- let error;
10
- if (props.validationState === 'invalid') {
11
- error = props.errorMessage || true;
12
- }
13
- else {
14
- error = state.validationState === 'invalid';
15
- }
16
9
  return {
17
10
  inputProps: {
18
11
  size: props.size,
@@ -21,12 +14,13 @@ export function useRelativeDateFieldProps(state, props) {
21
14
  onUpdate: state.setText,
22
15
  disabled: state.disabled,
23
16
  hasClear: props.hasClear,
24
- //@ts-expect-error TODO: use new TextInput API
25
- error,
17
+ validationState: state.validationState,
18
+ errorMessage: props.errorMessage,
19
+ errorPlacement: props.errorPlacement,
26
20
  label: props.label,
27
21
  id: props.id,
28
- leftContent: props.leftContent,
29
- rightContent: props.rightContent,
22
+ startContent: props.startContent,
23
+ endContent: props.endContent,
30
24
  pin: props.pin,
31
25
  view: props.view,
32
26
  placeholder: props.placeholder,
@@ -24,7 +24,9 @@ export interface RelativeDateFieldState {
24
24
  */
25
25
  readOnly?: boolean;
26
26
  }
27
- export interface RelativeDateFieldOptions extends ValueBase<string, string | null>, InputBase, Validation {
27
+ export interface RelativeDateFieldOptions extends ValueBase<string | null>, InputBase, Validation {
28
28
  timeZone?: string;
29
+ /** Round up parsed date to the nearest granularity. */
30
+ roundUp?: boolean;
29
31
  }
30
32
  export declare function useRelativeDateFieldState(props: RelativeDateFieldOptions): RelativeDateFieldState;
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
2
  import { dateTimeParse, isValid } from '@gravity-ui/date-utils';
3
- import { useControlledState } from '../../hooks/useControlledState';
3
+ import { useControlledState } from '@gravity-ui/uikit';
4
4
  export function useRelativeDateFieldState(props) {
5
- const [value, setValue] = useControlledState(props.value, props.defaultValue, props.onUpdate);
5
+ var _a;
6
+ const [value, setValue] = useControlledState(props.value, (_a = props.defaultValue) !== null && _a !== void 0 ? _a : null, props.onUpdate);
6
7
  const [text, setText] = React.useState(value !== null && value !== void 0 ? value : '');
7
8
  if (value && value !== text) {
8
9
  setText(value);
@@ -30,7 +31,7 @@ export function useRelativeDateFieldState(props) {
30
31
  if (!value) {
31
32
  return null;
32
33
  }
33
- return (_a = dateTimeParse(value, { timeZone: props.timeZone })) !== null && _a !== void 0 ? _a : null;
34
+ return (_a = dateTimeParse(value, { timeZone: props.timeZone, roundUp: props.roundUp })) !== null && _a !== void 0 ? _a : null;
34
35
  }, [value, props.timeZone]);
35
36
  const [lastCorrectDate, setLastCorrectDate] = React.useState(parsedDate);
36
37
  if (parsedDate && parsedDate !== lastCorrectDate) {
@@ -38,7 +39,7 @@ export function useRelativeDateFieldState(props) {
38
39
  }
39
40
  const validationState = props.validationState || (text && !parsedDate) ? 'invalid' : undefined;
40
41
  return {
41
- value: value !== null && value !== void 0 ? value : null,
42
+ value,
42
43
  setValue(v) {
43
44
  if (props.disabled || props.readOnly) {
44
45
  return;
@@ -3,6 +3,9 @@
3
3
  display: inline-flex;
4
4
  outline: none;
5
5
  }
6
+ .g-date-relative-date-picker__input_mobile {
7
+ pointer-events: none;
8
+ }
6
9
  .g-date-relative-date-picker__field {
7
10
  width: 100%;
8
11
  }
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
2
  import type { CalendarProps } from '../Calendar';
3
- import type { AccessibilityProps, DomProps, FocusableProps, KeyboardEvents, StyleProps, TextInputProps } from '../types';
3
+ import type { AccessibilityProps, DomProps, FocusableProps, InputDOMProps, KeyboardEvents, StyleProps, TextInputProps } from '../types';
4
4
  import type { RelativeDatePickerStateOptions } from './hooks/useRelativeDatePickerState';
5
5
  import './RelativeDatePicker.css';
6
- export interface RelativeDatePickerProps extends RelativeDatePickerStateOptions, TextInputProps, FocusableProps, KeyboardEvents, DomProps, StyleProps, AccessibilityProps {
6
+ export interface RelativeDatePickerProps extends RelativeDatePickerStateOptions, TextInputProps, FocusableProps, KeyboardEvents, DomProps, InputDOMProps, StyleProps, AccessibilityProps {
7
7
  children?: (props: CalendarProps) => React.ReactNode;
8
8
  }
9
9
  export declare function RelativeDatePicker(props: RelativeDatePickerProps): import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from 'react';
3
- import { Calendar as CalendarIcon, Function as FunctionIcon } from '@gravity-ui/icons';
3
+ import { Calendar as CalendarIcon, Clock as ClockIcon, Function as FunctionIcon, } from '@gravity-ui/icons';
4
4
  import { Button, Icon, Popup, TextInput, useMobile } from '@gravity-ui/uikit';
5
5
  import { block } from '../../utils/cn';
6
6
  import { Calendar } from '../Calendar';
7
7
  import { DateField } from '../DateField';
8
- import { MobileCalendar, MobileCalendarIcon } from '../DatePicker/MobileCalendar';
8
+ import { MobileCalendar } from '../DatePicker/MobileCalendar';
9
+ import { StubButton } from '../DatePicker/StubButton';
9
10
  import { useRelativeDatePickerProps } from './hooks/useRelativeDatePickerProps';
10
11
  import { useRelativeDatePickerState } from './hooks/useRelativeDatePickerState';
11
12
  import './RelativeDatePicker.css';
@@ -14,12 +15,24 @@ export function RelativeDatePicker(props) {
14
15
  const state = useRelativeDatePickerState(props);
15
16
  const { groupProps, fieldProps, modeSwitcherProps, calendarButtonProps, popupProps, calendarProps, timeInputProps, } = useRelativeDatePickerProps(state, props);
16
17
  const anchorRef = React.useRef(null);
17
- const [isMobile] = useMobile();
18
+ const isMobile = useMobile();
19
+ const isOnlyTime = state.datePickerState.hasTime && !state.datePickerState.hasDate;
18
20
  return (_jsxs("div", Object.assign({ ref: anchorRef, className: b(null, props.className) }, groupProps, { children: [isMobile && state.mode === 'absolute' && (_jsx(MobileCalendar, { state: state.datePickerState, props: {
19
21
  id: props.id,
20
22
  disabled: props.disabled,
21
23
  readOnly: props.readOnly,
22
24
  placeholderValue: props.placeholderValue,
23
25
  timeZone: props.timeZone,
24
- } })), _jsx(TextInput, Object.assign({}, fieldProps, { leftContent: _jsx(Button, Object.assign({}, modeSwitcherProps, { children: _jsx(Icon, { data: FunctionIcon }) })), rightContent: _jsxs(React.Fragment, { children: [!isMobile && (_jsx(Button, Object.assign({}, calendarButtonProps, { children: _jsx(Icon, { data: CalendarIcon }) }))), isMobile && state.mode === 'absolute' && (_jsx(MobileCalendarIcon, { state: state.datePickerState, props: { size: props.size } }))] }) })), !isMobile && (_jsx(Popup, Object.assign({}, popupProps, { anchorRef: anchorRef, children: _jsxs("div", { className: b('popup-content'), children: [typeof props.children === 'function' ? (props.children(calendarProps)) : (_jsx(Calendar, Object.assign({}, calendarProps))), state.datePickerState.hasTime && (_jsx("div", { className: b('time-field-wrapper'), children: _jsx(DateField, Object.assign({}, timeInputProps)) }))] }) })))] })));
26
+ } })), _jsx(TextInput, Object.assign({}, fieldProps, { controlProps: Object.assign(Object.assign({}, fieldProps.controlProps), { disabled: isMobile && state.mode === 'absolute', className: b('input', { mobile: isMobile && state.mode === 'absolute' }) }), hasClear: props.hasClear && !(isMobile && state.mode === 'absolute'), startContent: _jsx(Button, Object.assign({}, modeSwitcherProps, { children: _jsx(Icon, { data: FunctionIcon }) })), endContent: _jsxs(React.Fragment, { children: [!isMobile && !isOnlyTime && (_jsx(Button, Object.assign({}, calendarButtonProps, { children: _jsx(Icon, { data: CalendarIcon }) }))), !isMobile && isOnlyTime && (_jsx(StubButton, { size: calendarButtonProps.size, icon: ClockIcon })), isMobile && state.mode === 'absolute' && (_jsx(StubButton, { size: calendarButtonProps.size, icon: isOnlyTime ? ClockIcon : CalendarIcon }))] }) })), _jsx("input", { type: "text", hidden: true, name: props.name, value: getNativeValue(state.value),
27
+ // Ignore React warning
28
+ onChange: () => { } }), !isMobile && !isOnlyTime && (_jsx(Popup, Object.assign({}, popupProps, { anchorRef: anchorRef, children: _jsxs("div", { className: b('popup-content'), children: [typeof props.children === 'function' ? (props.children(calendarProps)) : (_jsx(Calendar, Object.assign({}, calendarProps))), state.datePickerState.hasTime && (_jsx("div", { className: b('time-field-wrapper'), children: _jsx(DateField, Object.assign({}, timeInputProps)) }))] }) })))] })));
29
+ }
30
+ function getNativeValue(value) {
31
+ if (!value) {
32
+ return '';
33
+ }
34
+ if (value.type === 'relative') {
35
+ return value.value;
36
+ }
37
+ return value.value.toISOString();
25
38
  }