@gravity-ui/date-components 1.5.0 → 2.0.1

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 (265) 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/{esm/components/CalendarBase → cjs/components/CalendarView}/hooks/useCalendarState.d.ts +1 -1
  12. package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarState.js +45 -23
  13. package/dist/cjs/components/CalendarView/hooks/useRangeCalendarState.d.ts +8 -0
  14. package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useRangeCalendarState.js +25 -14
  15. package/dist/cjs/components/DateField/DateField.d.ts +1 -4
  16. package/dist/cjs/components/DateField/DateField.js +3 -1
  17. package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.d.ts +97 -0
  18. package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.js +316 -0
  19. package/dist/cjs/components/DateField/hooks/useDateFieldProps.d.ts +6 -3
  20. package/dist/cjs/components/DateField/hooks/useDateFieldProps.js +14 -12
  21. package/dist/cjs/components/DateField/hooks/useDateFieldState.d.ts +2 -65
  22. package/dist/cjs/components/DateField/hooks/useDateFieldState.js +98 -410
  23. package/dist/cjs/components/DateField/index.d.ts +1 -0
  24. package/dist/cjs/components/DateField/index.js +1 -0
  25. package/dist/cjs/components/DateField/utils.d.ts +10 -1
  26. package/dist/cjs/components/DateField/utils.js +114 -2
  27. package/dist/cjs/components/DatePicker/DatePicker.d.ts +4 -4
  28. package/dist/cjs/components/DatePicker/DatePicker.js +6 -6
  29. package/dist/cjs/components/DatePicker/MobileCalendar.css +6 -6
  30. package/dist/cjs/components/DatePicker/MobileCalendar.js +17 -12
  31. package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.js +5 -16
  32. package/dist/cjs/components/DatePicker/hooks/useDatePickerState.d.ts +5 -4
  33. package/dist/cjs/components/DatePicker/hooks/useDatePickerState.js +71 -56
  34. package/dist/cjs/components/RangeCalendar/RangeCalendar.d.ts +3 -3
  35. package/dist/cjs/components/RangeCalendar/RangeCalendar.js +4 -4
  36. package/dist/cjs/components/RangeDateField/RangeDateField.css +4 -0
  37. package/dist/cjs/components/RangeDateField/RangeDateField.d.ts +12 -0
  38. package/dist/cjs/components/RangeDateField/RangeDateField.js +25 -0
  39. package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.d.ts +9 -0
  40. package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.js +227 -0
  41. package/dist/cjs/components/RangeDateField/index.d.ts +2 -0
  42. package/dist/cjs/components/RangeDateField/index.js +5 -0
  43. package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.d.ts +5 -0
  44. package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.js +9 -0
  45. package/dist/cjs/components/RangeDateField/utils/getRangeEditableSections.d.ts +5 -0
  46. package/dist/cjs/components/RangeDateField/utils/getRangeEditableSections.js +42 -0
  47. package/dist/cjs/components/RangeDateField/utils/index.d.ts +3 -0
  48. package/dist/cjs/components/RangeDateField/utils/index.js +6 -0
  49. package/dist/cjs/components/RangeDateField/utils/isValidRange.d.ts +3 -0
  50. package/dist/cjs/components/RangeDateField/utils/isValidRange.js +8 -0
  51. package/dist/cjs/components/RelativeDateField/RelativeDateField.d.ts +2 -2
  52. package/dist/cjs/components/RelativeDateField/RelativeDateField.js +5 -2
  53. package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +5 -11
  54. package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +3 -1
  55. package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.js +5 -4
  56. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.css +3 -0
  57. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.d.ts +2 -2
  58. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js +13 -2
  59. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +35 -27
  60. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.d.ts +2 -2
  61. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +12 -16
  62. package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.css +56 -0
  63. package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.d.ts +27 -0
  64. package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +90 -0
  65. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css +32 -0
  66. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +14 -0
  67. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +43 -0
  68. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/en.json +8 -0
  69. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.d.ts +1 -0
  70. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.js +9 -0
  71. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/ru.json +8 -0
  72. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +16 -0
  73. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +104 -0
  74. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.css +26 -0
  75. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.d.ts +18 -0
  76. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.js +67 -0
  77. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.css +14 -0
  78. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.d.ts +7 -0
  79. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.js +90 -0
  80. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/defaultPresets.d.ts +9 -0
  81. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/defaultPresets.js +186 -0
  82. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/en.json +40 -0
  83. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/index.d.ts +1 -0
  84. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/index.js +9 -0
  85. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/ru.json +40 -0
  86. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/utils.d.ts +16 -0
  87. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/utils.js +85 -0
  88. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.css +3 -0
  89. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.d.ts +9 -0
  90. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.js +62 -0
  91. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/en.json +4 -0
  92. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/index.d.ts +1 -0
  93. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/index.js +9 -0
  94. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/ru.json +4 -0
  95. package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.d.ts +26 -0
  96. package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +58 -0
  97. package/dist/cjs/components/RelativeRangeDatePicker/i18n/en.json +8 -0
  98. package/dist/cjs/components/RelativeRangeDatePicker/i18n/index.d.ts +1 -0
  99. package/dist/cjs/components/RelativeRangeDatePicker/i18n/index.js +9 -0
  100. package/dist/cjs/components/RelativeRangeDatePicker/i18n/ru.json +8 -0
  101. package/dist/cjs/components/RelativeRangeDatePicker/index.d.ts +4 -0
  102. package/dist/cjs/components/RelativeRangeDatePicker/index.js +8 -0
  103. package/dist/cjs/components/RelativeRangeDatePicker/utils.d.ts +15 -0
  104. package/dist/cjs/components/RelativeRangeDatePicker/utils.js +53 -0
  105. package/dist/cjs/components/index.d.ts +3 -0
  106. package/dist/cjs/components/index.js +2 -0
  107. package/dist/cjs/components/types/datePicker.d.ts +5 -2
  108. package/dist/cjs/components/types/events.d.ts +4 -4
  109. package/dist/cjs/components/types/inputs.d.ts +10 -9
  110. package/dist/cjs/components/utils/dates.d.ts +1 -2
  111. package/dist/cjs/components/utils/useDefaultTimeZone.d.ts +2 -0
  112. package/dist/cjs/components/utils/useDefaultTimeZone.js +15 -0
  113. package/dist/cjs/components/utils/validation/datePicker.d.ts +6 -0
  114. package/dist/cjs/components/utils/validation/datePicker.js +30 -0
  115. package/dist/cjs/components/utils/validation/i18n/en.json +6 -0
  116. package/dist/cjs/components/utils/validation/i18n/index.d.ts +1 -0
  117. package/dist/cjs/components/utils/validation/i18n/index.js +9 -0
  118. package/dist/cjs/components/utils/validation/i18n/ru.json +6 -0
  119. package/dist/esm/components/Calendar/Calendar.d.ts +6 -5
  120. package/dist/esm/components/Calendar/Calendar.js +4 -4
  121. package/dist/esm/components/Calendar/index.d.ts +6 -6
  122. package/dist/esm/components/Calendar/index.js +5 -5
  123. package/dist/esm/components/{CalendarBase → CalendarView}/Calendar.css +9 -6
  124. package/dist/esm/components/{CalendarBase/CalendarBase.d.ts → CalendarView/CalendarView.d.ts} +2 -2
  125. package/dist/esm/components/{CalendarBase/CalendarBase.js → CalendarView/CalendarView.js} +3 -2
  126. package/dist/{cjs/components/CalendarBase → esm/components/CalendarView}/hooks/types.d.ts +37 -31
  127. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.js +1 -2
  128. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.d.ts +2 -2
  129. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.js +0 -1
  130. package/dist/{cjs/components/CalendarBase → esm/components/CalendarView}/hooks/useCalendarState.d.ts +1 -1
  131. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarState.js +46 -24
  132. package/dist/esm/components/CalendarView/hooks/useRangeCalendarState.d.ts +8 -0
  133. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useRangeCalendarState.js +24 -13
  134. package/dist/esm/components/DateField/DateField.d.ts +1 -4
  135. package/dist/esm/components/DateField/DateField.js +4 -2
  136. package/dist/esm/components/DateField/hooks/useBaseDateFieldState.d.ts +97 -0
  137. package/dist/esm/components/DateField/hooks/useBaseDateFieldState.js +311 -0
  138. package/dist/esm/components/DateField/hooks/useDateFieldProps.d.ts +6 -3
  139. package/dist/esm/components/DateField/hooks/useDateFieldProps.js +14 -12
  140. package/dist/esm/components/DateField/hooks/useDateFieldState.d.ts +2 -65
  141. package/dist/esm/components/DateField/hooks/useDateFieldState.js +97 -409
  142. package/dist/esm/components/DateField/index.d.ts +1 -0
  143. package/dist/esm/components/DateField/index.js +1 -0
  144. package/dist/esm/components/DateField/utils.d.ts +10 -1
  145. package/dist/esm/components/DateField/utils.js +105 -2
  146. package/dist/esm/components/DatePicker/DatePicker.d.ts +4 -4
  147. package/dist/esm/components/DatePicker/DatePicker.js +6 -6
  148. package/dist/esm/components/DatePicker/MobileCalendar.css +6 -6
  149. package/dist/esm/components/DatePicker/MobileCalendar.js +17 -12
  150. package/dist/esm/components/DatePicker/hooks/useDatePickerProps.js +5 -16
  151. package/dist/esm/components/DatePicker/hooks/useDatePickerState.d.ts +5 -4
  152. package/dist/esm/components/DatePicker/hooks/useDatePickerState.js +71 -56
  153. package/dist/esm/components/RangeCalendar/RangeCalendar.d.ts +3 -3
  154. package/dist/esm/components/RangeCalendar/RangeCalendar.js +4 -4
  155. package/dist/esm/components/RangeDateField/RangeDateField.css +4 -0
  156. package/dist/esm/components/RangeDateField/RangeDateField.d.ts +12 -0
  157. package/dist/esm/components/RangeDateField/RangeDateField.js +21 -0
  158. package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.d.ts +9 -0
  159. package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.js +222 -0
  160. package/dist/esm/components/RangeDateField/index.d.ts +2 -0
  161. package/dist/esm/components/RangeDateField/index.js +2 -0
  162. package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.d.ts +5 -0
  163. package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.js +5 -0
  164. package/dist/esm/components/RangeDateField/utils/getRangeEditableSections.d.ts +5 -0
  165. package/dist/esm/components/RangeDateField/utils/getRangeEditableSections.js +38 -0
  166. package/dist/esm/components/RangeDateField/utils/index.d.ts +3 -0
  167. package/dist/esm/components/RangeDateField/utils/index.js +3 -0
  168. package/dist/esm/components/RangeDateField/utils/isValidRange.d.ts +3 -0
  169. package/dist/esm/components/RangeDateField/utils/isValidRange.js +4 -0
  170. package/dist/esm/components/RelativeDateField/RelativeDateField.d.ts +2 -2
  171. package/dist/esm/components/RelativeDateField/RelativeDateField.js +5 -2
  172. package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +5 -11
  173. package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +3 -1
  174. package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.js +5 -4
  175. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.css +3 -0
  176. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.d.ts +2 -2
  177. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js +13 -2
  178. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +35 -27
  179. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.d.ts +2 -2
  180. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +12 -16
  181. package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.css +56 -0
  182. package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.d.ts +27 -0
  183. package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +85 -0
  184. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css +32 -0
  185. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +14 -0
  186. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +39 -0
  187. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/en.json +8 -0
  188. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.d.ts +1 -0
  189. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.js +5 -0
  190. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/ru.json +8 -0
  191. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +16 -0
  192. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +99 -0
  193. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.css +26 -0
  194. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.d.ts +18 -0
  195. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.js +62 -0
  196. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.css +14 -0
  197. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.d.ts +7 -0
  198. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.js +85 -0
  199. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/defaultPresets.d.ts +9 -0
  200. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/defaultPresets.js +183 -0
  201. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/en.json +40 -0
  202. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/index.d.ts +1 -0
  203. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/index.js +5 -0
  204. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/ru.json +40 -0
  205. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/utils.d.ts +16 -0
  206. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/utils.js +78 -0
  207. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.css +3 -0
  208. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.d.ts +9 -0
  209. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.js +58 -0
  210. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/en.json +4 -0
  211. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/index.d.ts +1 -0
  212. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/index.js +5 -0
  213. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/ru.json +4 -0
  214. package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.d.ts +26 -0
  215. package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +53 -0
  216. package/dist/esm/components/RelativeRangeDatePicker/i18n/en.json +8 -0
  217. package/dist/esm/components/RelativeRangeDatePicker/i18n/index.d.ts +1 -0
  218. package/dist/esm/components/RelativeRangeDatePicker/i18n/index.js +5 -0
  219. package/dist/esm/components/RelativeRangeDatePicker/i18n/ru.json +8 -0
  220. package/dist/esm/components/RelativeRangeDatePicker/index.d.ts +4 -0
  221. package/dist/esm/components/RelativeRangeDatePicker/index.js +3 -0
  222. package/dist/esm/components/RelativeRangeDatePicker/utils.d.ts +15 -0
  223. package/dist/esm/components/RelativeRangeDatePicker/utils.js +46 -0
  224. package/dist/esm/components/index.d.ts +3 -0
  225. package/dist/esm/components/index.js +2 -0
  226. package/dist/esm/components/types/datePicker.d.ts +5 -2
  227. package/dist/esm/components/types/events.d.ts +4 -4
  228. package/dist/esm/components/types/inputs.d.ts +10 -9
  229. package/dist/esm/components/utils/dates.d.ts +1 -2
  230. package/dist/esm/components/utils/useDefaultTimeZone.d.ts +2 -0
  231. package/dist/esm/components/utils/useDefaultTimeZone.js +10 -0
  232. package/dist/esm/components/utils/validation/datePicker.d.ts +6 -0
  233. package/dist/esm/components/utils/validation/datePicker.js +26 -0
  234. package/dist/esm/components/utils/validation/i18n/en.json +6 -0
  235. package/dist/esm/components/utils/validation/i18n/index.d.ts +1 -0
  236. package/dist/esm/components/utils/validation/i18n/index.js +5 -0
  237. package/dist/esm/components/utils/validation/i18n/ru.json +6 -0
  238. package/package.json +27 -27
  239. package/dist/cjs/components/CalendarBase/hooks/useRangeCalendarState.d.ts +0 -7
  240. package/dist/cjs/components/hooks/useControlledState.d.ts +0 -1
  241. package/dist/cjs/components/hooks/useControlledState.js +0 -28
  242. package/dist/esm/components/CalendarBase/hooks/useRangeCalendarState.d.ts +0 -7
  243. package/dist/esm/components/hooks/useControlledState.d.ts +0 -1
  244. package/dist/esm/components/hooks/useControlledState.js +0 -23
  245. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/types.js +0 -0
  246. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.d.ts +0 -0
  247. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.js +0 -0
  248. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.d.ts +0 -0
  249. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.js +0 -0
  250. /package/dist/cjs/components/{CalendarBase → CalendarView}/i18n/en.json +0 -0
  251. /package/dist/cjs/components/{CalendarBase → CalendarView}/i18n/index.d.ts +0 -0
  252. /package/dist/cjs/components/{CalendarBase → CalendarView}/i18n/index.js +0 -0
  253. /package/dist/cjs/components/{CalendarBase → CalendarView}/i18n/ru.json +0 -0
  254. /package/dist/cjs/components/{CalendarBase → CalendarView}/utils.d.ts +0 -0
  255. /package/dist/cjs/components/{CalendarBase → CalendarView}/utils.js +0 -0
  256. /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/types.js +0 -0
  257. /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.d.ts +0 -0
  258. /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.d.ts +0 -0
  259. /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.js +0 -0
  260. /package/dist/esm/components/{CalendarBase → CalendarView}/i18n/en.json +0 -0
  261. /package/dist/esm/components/{CalendarBase → CalendarView}/i18n/index.d.ts +0 -0
  262. /package/dist/esm/components/{CalendarBase → CalendarView}/i18n/index.js +0 -0
  263. /package/dist/esm/components/{CalendarBase → CalendarView}/i18n/ru.json +0 -0
  264. /package/dist/esm/components/{CalendarBase → CalendarView}/utils.d.ts +0 -0
  265. /package/dist/esm/components/{CalendarBase → CalendarView}/utils.js +0 -0
@@ -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;
@@ -14,12 +14,23 @@ export function RelativeDatePicker(props) {
14
14
  const state = useRelativeDatePickerState(props);
15
15
  const { groupProps, fieldProps, modeSwitcherProps, calendarButtonProps, popupProps, calendarProps, timeInputProps, } = useRelativeDatePickerProps(state, props);
16
16
  const anchorRef = React.useRef(null);
17
- const [isMobile] = useMobile();
17
+ const isMobile = useMobile();
18
18
  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
19
  id: props.id,
20
20
  disabled: props.disabled,
21
21
  readOnly: props.readOnly,
22
22
  placeholderValue: props.placeholderValue,
23
23
  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)) }))] }) })))] })));
24
+ } })), _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 && (_jsx(Button, Object.assign({}, calendarButtonProps, { children: _jsx(Icon, { data: CalendarIcon }) }))), isMobile && state.mode === 'absolute' && (_jsx(MobileCalendarIcon, { state: state.datePickerState, props: { size: props.size } }))] }) })), _jsx("input", { type: "text", hidden: true, name: props.name, value: getNativeValue(state.value),
25
+ // Ignore React warning
26
+ onChange: () => { } }), !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)) }))] }) })))] })));
27
+ }
28
+ function getNativeValue(value) {
29
+ if (!value) {
30
+ return '';
31
+ }
32
+ if (value.type === 'relative') {
33
+ return value.value;
34
+ }
35
+ return value.value.toISOString();
25
36
  }
@@ -2,24 +2,25 @@ import { __rest } from "tslib";
2
2
  import React from 'react';
3
3
  import { useFocusWithin, useForkRef } from '@gravity-ui/uikit';
4
4
  import { useDateFieldProps } from '../../DateField';
5
+ import { useRelativeDateFieldProps } from '../../RelativeDateField';
5
6
  import { getButtonSizeForInput } from '../../utils/getButtonSizeForInput';
6
7
  import { mergeProps } from '../../utils/mergeProps';
7
8
  import { i18n } from '../i18n';
8
9
  export function useRelativeDatePickerProps(state, _a) {
9
10
  var { onFocus, onBlur } = _a, props = __rest(_a, ["onFocus", "onBlur"]);
10
- const { mode, setMode, datePickerState, dateFieldState, relativeDateState } = state;
11
- const [focusedDate, setFocusedDate] = React.useState(relativeDateState.lastCorrectDate);
11
+ const { mode, setMode, datePickerState, relativeDateState } = state;
12
+ const [focusedDate, setFocusedDate] = React.useState(mode === 'relative'
13
+ ? relativeDateState.lastCorrectDate
14
+ : datePickerState.dateFieldState.displayValue);
12
15
  const [prevCorrectDate, setPrevCorrectDate] = React.useState(relativeDateState.lastCorrectDate);
13
16
  if (prevCorrectDate !== relativeDateState.lastCorrectDate) {
14
17
  setPrevCorrectDate(relativeDateState.lastCorrectDate);
15
18
  setFocusedDate(relativeDateState.lastCorrectDate);
16
19
  }
17
- const [prevDateValue, setPrevDateValue] = React.useState(datePickerState.dateValue);
18
- if (datePickerState.dateValue !== prevDateValue) {
19
- setPrevDateValue(datePickerState.dateValue);
20
- if (datePickerState.dateValue) {
21
- setFocusedDate(datePickerState.dateValue);
22
- }
20
+ const [prevDateValue, setPrevDateValue] = React.useState(datePickerState.dateFieldState.displayValue);
21
+ if (!datePickerState.dateFieldState.displayValue.isSame(prevDateValue, 'day')) {
22
+ setPrevDateValue(datePickerState.dateFieldState.displayValue);
23
+ setFocusedDate(datePickerState.dateFieldState.displayValue);
23
24
  }
24
25
  const { focusWithinProps } = useFocusWithin({
25
26
  onFocusWithin: onFocus,
@@ -34,6 +35,18 @@ export function useRelativeDatePickerProps(state, _a) {
34
35
  if (!state.isActive && isOpen) {
35
36
  setOpen(false);
36
37
  }
38
+ const [prevOpen, setPrevOpen] = React.useState(isOpen);
39
+ if (isOpen !== prevOpen) {
40
+ setPrevOpen(isOpen);
41
+ if (!isOpen) {
42
+ // FIXME: use popup afterOpenChange instead.
43
+ setTimeout(() => {
44
+ setFocusedDate(mode === 'relative'
45
+ ? relativeDateState.lastCorrectDate
46
+ : datePickerState.dateFieldState.displayValue);
47
+ }, 200);
48
+ }
49
+ }
37
50
  const commonInputProps = {
38
51
  onFocus: () => {
39
52
  if (!state.isActive) {
@@ -41,27 +54,17 @@ export function useRelativeDatePickerProps(state, _a) {
41
54
  setOpen(true);
42
55
  }
43
56
  },
57
+ errorMessage: props.errorMessage,
58
+ errorPlacement: props.errorPlacement,
44
59
  };
45
- const { inputProps } = useDateFieldProps(dateFieldState, Object.assign(Object.assign({}, props), { value: undefined, defaultValue: undefined, onUpdate: undefined }));
46
- const relativeDateProps = {
47
- disabled: relativeDateState.disabled,
48
- value: relativeDateState.text,
49
- onUpdate: relativeDateState.setText,
50
- hasClear: props.hasClear && !relativeDateState.readOnly,
51
- placeholder: props.placeholder,
52
- size: props.size,
53
- };
54
- let error;
60
+ const { inputProps } = useDateFieldProps(datePickerState.dateFieldState, Object.assign(Object.assign({}, props), { value: undefined, defaultValue: undefined, onUpdate: undefined }));
61
+ const { inputProps: relativeDateProps } = useRelativeDateFieldProps(relativeDateState, Object.assign(Object.assign({}, props), { value: undefined, defaultValue: undefined, onUpdate: undefined }));
55
62
  let validationState = props.validationState;
56
- if (validationState) {
57
- error = validationState === 'invalid' ? props.errorMessage || true : undefined;
58
- }
59
- else {
63
+ if (!validationState) {
60
64
  validationState =
61
65
  mode === 'relative'
62
66
  ? relativeDateState.validationState
63
- : dateFieldState.validationState;
64
- error = validationState === 'invalid';
67
+ : datePickerState.dateFieldState.validationState;
65
68
  }
66
69
  const inputRef = React.useRef(null);
67
70
  const handleRef = useForkRef(inputRef, mode === 'relative' ? relativeDateProps.controlRef : inputProps.controlRef);
@@ -87,14 +90,17 @@ export function useRelativeDatePickerProps(state, _a) {
87
90
  focusCalendar();
88
91
  }
89
92
  } }),
90
- fieldProps: mergeProps(commonInputProps, mode === 'relative' ? relativeDateProps : inputProps, mode === 'absolute' && dateFieldState.isEmpty && !state.isActive && props.placeholder
93
+ fieldProps: mergeProps(commonInputProps, mode === 'relative' ? relativeDateProps : inputProps, mode === 'absolute' &&
94
+ datePickerState.dateFieldState.isEmpty &&
95
+ !state.isActive &&
96
+ props.placeholder
91
97
  ? { value: '' }
92
- : undefined, { controlRef: handleRef, error }),
98
+ : undefined, { controlRef: handleRef, validationState }),
93
99
  modeSwitcherProps: {
94
100
  size: getButtonSizeForInput(props.size),
95
101
  disabled: state.readOnly || state.disabled,
96
102
  view: 'flat-secondary',
97
- style: { zIndex: 2 },
103
+ style: { zIndex: 2, marginInlineEnd: 2 },
98
104
  selected: mode === 'relative',
99
105
  extraProps: {
100
106
  'aria-label': i18n('Formula input mode'),
@@ -151,6 +157,8 @@ export function useRelativeDatePickerProps(state, _a) {
151
157
  },
152
158
  focusedValue: focusedDate,
153
159
  onFocusUpdate: setFocusedDate,
160
+ minValue: props.minValue,
161
+ maxValue: props.maxValue,
154
162
  },
155
163
  timeInputProps: {
156
164
  value: datePickerState.timeValue,
@@ -1,5 +1,4 @@
1
1
  import type { DateTime } from '@gravity-ui/date-utils';
2
- import type { DateFieldState } from '../../DateField';
3
2
  import type { DatePickerState } from '../../DatePicker';
4
3
  import type { RelativeDateFieldState } from '../../RelativeDateField';
5
4
  import type { DateFieldBase } from '../../types';
@@ -12,6 +11,8 @@ export type Value = {
12
11
  };
13
12
  export type RelativeDatePickerMode = Value['type'];
14
13
  export interface RelativeDatePickerStateOptions extends DateFieldBase<Value> {
14
+ /** Round up parsed date to the nearest granularity. */
15
+ roundUp?: boolean;
15
16
  }
16
17
  export interface RelativeDatePickerState {
17
18
  value: Value | null;
@@ -19,7 +20,6 @@ export interface RelativeDatePickerState {
19
20
  mode: RelativeDatePickerMode;
20
21
  setMode: (mode: RelativeDatePickerMode) => void;
21
22
  datePickerState: DatePickerState;
22
- dateFieldState: DateFieldState;
23
23
  relativeDateState: RelativeDateFieldState;
24
24
  selectedDate: DateTime | null;
25
25
  /**