@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,227 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRangeDateFieldState = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /* eslint-disable complexity */
6
+ const react_1 = tslib_1.__importDefault(require("react"));
7
+ const date_utils_1 = require("@gravity-ui/date-utils");
8
+ const uikit_1 = require("@gravity-ui/uikit");
9
+ const DateField_1 = require("../../DateField");
10
+ const utils_1 = require("../../DateField/utils");
11
+ const dates_1 = require("../../utils/dates");
12
+ const useDefaultTimeZone_1 = require("../../utils/useDefaultTimeZone");
13
+ const utils_2 = require("../utils");
14
+ const RANGE_FORMAT_DELIMITER = ' — ';
15
+ function useRangeDateFieldState(props) {
16
+ var _a, _b, _c, _d, _e;
17
+ const [value, setRange] = (0, uikit_1.useControlledState)(props.value, props.defaultValue || null, props.onUpdate);
18
+ const inputTimeZone = (0, useDefaultTimeZone_1.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);
19
+ const timeZone = props.timeZone || inputTimeZone;
20
+ const handleUpdateRange = (v) => {
21
+ setRange(v ? { start: v.start.timeZone(inputTimeZone), end: v.end.timeZone(inputTimeZone) } : v);
22
+ };
23
+ const [placeholderDate, setPlaceholderDate] = react_1.default.useState(() => {
24
+ return (0, utils_2.createPlaceholderRangeValue)({
25
+ placeholderValue: props.placeholderValue,
26
+ timeZone,
27
+ });
28
+ });
29
+ const format = props.format || 'L';
30
+ const delimiter = (_c = props.delimiter) !== null && _c !== void 0 ? _c : RANGE_FORMAT_DELIMITER;
31
+ const sections = (0, utils_1.useFormatSections)(format);
32
+ const allSegments = react_1.default.useMemo(() => {
33
+ return sections
34
+ .filter((seg) => utils_1.EDITABLE_SEGMENTS[seg.type])
35
+ .reduce((p, seg) => (Object.assign(Object.assign({}, p), { [seg.type]: true })), {});
36
+ }, [sections]);
37
+ // eslint-disable-next-line prefer-const
38
+ let [validSegments, setValidSegments] = react_1.default.useState(() => (value ? { start: Object.assign({}, allSegments), end: Object.assign({}, allSegments) } : { start: {}, end: {} }));
39
+ if (value &&
40
+ (!(0, utils_1.isAllSegmentsValid)(allSegments, validSegments.start) ||
41
+ !(0, utils_1.isAllSegmentsValid)(allSegments, validSegments.end))) {
42
+ setValidSegments({ start: Object.assign({}, allSegments), end: Object.assign({}, allSegments) });
43
+ }
44
+ if (!value &&
45
+ (0, utils_1.isAllSegmentsValid)(allSegments, validSegments.start) &&
46
+ Object.keys(validSegments.start).length === Object.keys(allSegments).length &&
47
+ (0, utils_1.isAllSegmentsValid)(allSegments, validSegments.end) &&
48
+ Object.keys(validSegments.end).length === Object.keys(allSegments).length) {
49
+ validSegments = { start: {}, end: {} };
50
+ setValidSegments(validSegments);
51
+ setPlaceholderDate((0, utils_2.createPlaceholderRangeValue)({
52
+ placeholderValue: props.placeholderValue,
53
+ timeZone,
54
+ }));
55
+ }
56
+ const displayValue = value &&
57
+ (0, date_utils_1.isValid)(value.start) &&
58
+ (0, date_utils_1.isValid)(value.end) &&
59
+ Object.keys(validSegments.start).length >= Object.keys(allSegments).length &&
60
+ Object.keys(validSegments.end).length >= Object.keys(allSegments).length
61
+ ? { start: value.start.timeZone(timeZone), end: value.end.timeZone(timeZone) }
62
+ : {
63
+ start: placeholderDate.start.timeZone(timeZone),
64
+ end: placeholderDate.end.timeZone(timeZone),
65
+ };
66
+ const sectionsState = useSectionsState(sections, displayValue, validSegments, delimiter);
67
+ const [selectedSections, setSelectedSections] = react_1.default.useState(-1);
68
+ const selectedSectionIndexes = react_1.default.useMemo(() => {
69
+ if (selectedSections === -1) {
70
+ return null;
71
+ }
72
+ if (selectedSections === 'all') {
73
+ return {
74
+ startIndex: 0,
75
+ endIndex: sectionsState.editableSections.length - 1,
76
+ };
77
+ }
78
+ if (typeof selectedSections === 'number') {
79
+ return { startIndex: selectedSections, endIndex: selectedSections };
80
+ }
81
+ if (typeof selectedSections === 'string') {
82
+ const selectedSectionIndex = sectionsState.editableSections.findIndex((section) => section.type === selectedSections);
83
+ return { startIndex: selectedSectionIndex, endIndex: selectedSectionIndex };
84
+ }
85
+ return selectedSections;
86
+ }, [selectedSections, sectionsState.editableSections]);
87
+ function setValue(newValue) {
88
+ if (props.disabled || props.readOnly) {
89
+ return;
90
+ }
91
+ if ((0, utils_1.isAllSegmentsValid)(allSegments, validSegments.start) &&
92
+ (0, utils_1.isAllSegmentsValid)(allSegments, validSegments.end)) {
93
+ if (!value || !(newValue.start.isSame(value.start) && newValue.end.isSame(value.end))) {
94
+ handleUpdateRange(newValue);
95
+ }
96
+ }
97
+ else {
98
+ if (value) {
99
+ handleUpdateRange(null);
100
+ }
101
+ setPlaceholderDate(newValue);
102
+ }
103
+ }
104
+ function markValid(portion, part) {
105
+ validSegments[portion][part] = true;
106
+ if (validSegments[portion].day &&
107
+ validSegments[portion].month &&
108
+ validSegments[portion].year &&
109
+ allSegments.weekday) {
110
+ validSegments[portion].weekday = true;
111
+ }
112
+ if (validSegments[portion].hour && allSegments.dayPeriod) {
113
+ validSegments[portion].dayPeriod = true;
114
+ }
115
+ setValidSegments(Object.assign(Object.assign({}, validSegments), { [portion]: Object.assign({}, validSegments[portion]) }));
116
+ }
117
+ function setSection(sectionIndex, amount) {
118
+ const portion = sectionIndex <= sections.length ? 'start' : 'end';
119
+ const section = sectionsState.editableSections[sectionIndex];
120
+ markValid(portion, section.type);
121
+ setValue(Object.assign(Object.assign({}, displayValue), { [portion]: (0, utils_1.setSegment)(section, displayValue[portion], amount) }));
122
+ }
123
+ function adjustSection(sectionIndex, amount) {
124
+ const section = sectionsState.editableSections[sectionIndex];
125
+ const portion = sectionIndex <= sections.length ? 'start' : 'end';
126
+ if (validSegments[portion][section.type]) {
127
+ setValue(Object.assign(Object.assign({}, displayValue), { [portion]: (0, utils_1.addSegment)(section, displayValue[portion], amount) }));
128
+ }
129
+ else {
130
+ markValid(portion, section.type);
131
+ if (Object.keys(validSegments[portion]).length >= Object.keys(allSegments).length) {
132
+ setValue(displayValue);
133
+ }
134
+ }
135
+ }
136
+ function flushValidSection(sectionIndex) {
137
+ const portion = sectionIndex <= sections.length ? 'start' : 'end';
138
+ delete validSegments[portion][sectionsState.editableSections[sectionIndex].type];
139
+ setValidSegments(Object.assign(Object.assign({}, validSegments), { [portion]: Object.assign({}, validSegments[portion]) }));
140
+ }
141
+ function flushAllValidSections() {
142
+ validSegments = { start: {}, end: {} };
143
+ setValidSegments({ start: {}, end: {} });
144
+ }
145
+ function getSectionValue(sectionIndex) {
146
+ const portion = sectionIndex <= sections.length ? 'start' : 'end';
147
+ return displayValue[portion];
148
+ }
149
+ function setSectionValue(sectionIndex, currentValue) {
150
+ const portion = sectionIndex <= sections.length ? 'start' : 'end';
151
+ setValue(Object.assign(Object.assign({}, displayValue), { [portion]: currentValue }));
152
+ }
153
+ function createPlaceholder() {
154
+ return (0, utils_2.createPlaceholderRangeValue)({
155
+ placeholderValue: props.placeholderValue,
156
+ timeZone,
157
+ });
158
+ }
159
+ function setValueFromString(str) {
160
+ var _a, _b;
161
+ const list = str.split(delimiter);
162
+ const start = (0, utils_1.parseDateFromString)((_a = list === null || list === void 0 ? void 0 : list[0]) === null || _a === void 0 ? void 0 : _a.trim(), format, timeZone);
163
+ const end = (0, utils_1.parseDateFromString)((_b = list === null || list === void 0 ? void 0 : list[1]) === null || _b === void 0 ? void 0 : _b.trim(), format, timeZone);
164
+ const range = { start, end };
165
+ if ((0, date_utils_1.isValid)(range.start) && (0, date_utils_1.isValid)(range.end)) {
166
+ handleUpdateRange(range);
167
+ return true;
168
+ }
169
+ return false;
170
+ }
171
+ const validationState = props.validationState ||
172
+ ((0, dates_1.isInvalid)(value === null || value === void 0 ? void 0 : value.start, props.minValue, props.maxValue) ? 'invalid' : undefined) ||
173
+ ((0, dates_1.isInvalid)(value === null || value === void 0 ? void 0 : value.end, props.minValue, props.maxValue) ? 'invalid' : undefined) ||
174
+ (value && !(0, utils_2.isValidRange)(value) ? 'invalid' : undefined) ||
175
+ (value && ((_d = props.isDateUnavailable) === null || _d === void 0 ? void 0 : _d.call(props, value.start)) ? 'invalid' : undefined) ||
176
+ (value && ((_e = props.isDateUnavailable) === null || _e === void 0 ? void 0 : _e.call(props, value.end)) ? 'invalid' : undefined);
177
+ return (0, DateField_1.useBaseDateFieldState)({
178
+ value,
179
+ displayValue,
180
+ placeholderValue: props.placeholderValue,
181
+ timeZone,
182
+ validationState,
183
+ editableSections: sectionsState.editableSections,
184
+ readOnly: props.readOnly,
185
+ disabled: props.disabled,
186
+ selectedSectionIndexes,
187
+ selectedSections,
188
+ isEmpty: Object.keys(validSegments.start).length === 0 &&
189
+ Object.keys(validSegments.end).length === 0,
190
+ flushAllValidSections,
191
+ flushValidSection,
192
+ setSelectedSections,
193
+ setValue,
194
+ setDate: handleUpdateRange,
195
+ adjustSection,
196
+ setSection,
197
+ getSectionValue,
198
+ setSectionValue,
199
+ createPlaceholder,
200
+ setValueFromString,
201
+ });
202
+ }
203
+ exports.useRangeDateFieldState = useRangeDateFieldState;
204
+ function useSectionsState(sections, value, validSegments, delimiter) {
205
+ const [state, setState] = react_1.default.useState(() => {
206
+ return {
207
+ value,
208
+ sections,
209
+ validSegments,
210
+ delimiter,
211
+ editableSections: (0, utils_2.getRangeEditableSections)(sections, value, validSegments, delimiter),
212
+ };
213
+ });
214
+ if (sections !== state.sections ||
215
+ validSegments !== state.validSegments ||
216
+ !(value.start.isSame(state.value.start) && value.end.isSame(state.value.end)) ||
217
+ delimiter !== state.delimiter) {
218
+ setState({
219
+ value,
220
+ sections,
221
+ validSegments,
222
+ delimiter,
223
+ editableSections: (0, utils_2.getRangeEditableSections)(sections, value, validSegments, delimiter),
224
+ });
225
+ }
226
+ return state;
227
+ }
@@ -0,0 +1,2 @@
1
+ export * from './RangeDateField';
2
+ export * from './hooks/useRangeDateFieldState';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./RangeDateField"), exports);
5
+ tslib_1.__exportStar(require("./hooks/useRangeDateFieldState"), exports);
@@ -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,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPlaceholderRangeValue = void 0;
4
+ const dates_1 = require("../../utils/dates");
5
+ function createPlaceholderRangeValue({ placeholderValue, timeZone }) {
6
+ const date = (0, dates_1.createPlaceholderValue)({ placeholderValue, timeZone });
7
+ return { start: date, end: date };
8
+ }
9
+ exports.createPlaceholderRangeValue = createPlaceholderRangeValue;
@@ -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,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRangeEditableSections = void 0;
4
+ const utils_1 = require("../../DateField/utils");
5
+ function getRangeEditableSections(sections, value, validSegments, delimiter) {
6
+ const start = (0, utils_1.getEditableSections)(sections, value.start, validSegments.start);
7
+ const end = (0, utils_1.getEditableSections)(sections, value.end, validSegments.end);
8
+ const last = start[start.length - 1];
9
+ let position = last.end;
10
+ const previousEditableSection = last.nextEditableSection;
11
+ const sectionsCount = start.length + 1;
12
+ const delimiterSection = (0, utils_1.toEditableSection)({
13
+ type: 'literal',
14
+ contentType: 'letter',
15
+ format: delimiter,
16
+ placeholder: delimiter,
17
+ hasLeadingZeros: false,
18
+ }, value.start, validSegments.start, position, previousEditableSection);
19
+ position += delimiterSection.textValue.length - 1;
20
+ let nextEditableSection;
21
+ for (let index = 0; index < end.length; index++) {
22
+ const section = end[index];
23
+ section.start += position;
24
+ section.end += position;
25
+ if (section.previousEditableSection === 0 && nextEditableSection === undefined) {
26
+ section.previousEditableSection = previousEditableSection;
27
+ }
28
+ else {
29
+ section.previousEditableSection += sectionsCount;
30
+ }
31
+ section.nextEditableSection += sectionsCount;
32
+ if ((0, utils_1.isEditableSection)(section) && nextEditableSection === undefined) {
33
+ nextEditableSection = index + sectionsCount;
34
+ }
35
+ }
36
+ if (nextEditableSection !== undefined) {
37
+ delimiterSection.nextEditableSection = nextEditableSection;
38
+ start[previousEditableSection].nextEditableSection = nextEditableSection;
39
+ }
40
+ return [...start, delimiterSection, ...end];
41
+ }
42
+ exports.getRangeEditableSections = getRangeEditableSections;
@@ -0,0 +1,3 @@
1
+ export * from './getRangeEditableSections';
2
+ export * from './isValidRange';
3
+ export * from './createPlaceholderRangeValue';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./getRangeEditableSections"), exports);
5
+ tslib_1.__exportStar(require("./isValidRange"), exports);
6
+ tslib_1.__exportStar(require("./createPlaceholderRangeValue"), exports);
@@ -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,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidRange = void 0;
4
+ const date_utils_1 = require("@gravity-ui/date-utils");
5
+ function isValidRange({ start, end }) {
6
+ return (0, date_utils_1.isValid)(start) && (0, date_utils_1.isValid)(end) && (start.isSame(end) || start.isBefore(end));
7
+ }
8
+ exports.isValidRange = isValidRange;
@@ -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
@@ -13,9 +13,10 @@ const useRelativeDateFieldState_1 = require("./hooks/useRelativeDateFieldState")
13
13
  require("./RelativeDateField.css");
14
14
  const b = (0, cn_1.block)('relative-date-field');
15
15
  function RelativeDateField(props) {
16
+ var _a;
16
17
  const state = (0, useRelativeDateFieldState_1.useRelativeDateFieldState)(props);
17
18
  const { inputProps, calendarProps, timeInputProps } = (0, useRelativeDateFieldProps_1.useRelativeDateFieldProps)(state, props);
18
- const [isMobile] = (0, uikit_1.useMobile)();
19
+ const isMobile = (0, uikit_1.useMobile)();
19
20
  const anchorRef = react_1.default.useRef(null);
20
21
  const [isOpen, setOpen] = react_1.default.useState(false);
21
22
  const { focusWithinProps } = (0, uikit_1.useFocusWithin)({
@@ -30,6 +31,8 @@ function RelativeDateField(props) {
30
31
  setOpen(true);
31
32
  }
32
33
  (_a = props.onFocus) === null || _a === void 0 ? void 0 : _a.call(props, e);
33
- }, onBlur: props.onBlur })), !isMobile && ((0, jsx_runtime_1.jsx)(uikit_1.Popup, { anchorRef: anchorRef, open: isOpen, children: (0, jsx_runtime_1.jsxs)("div", { className: b('popup-content'), children: [(0, jsx_runtime_1.jsx)(Calendar_1.Calendar, Object.assign({}, calendarProps)), props.hasTime ? ((0, jsx_runtime_1.jsx)("div", { className: b('time-field-wrapper'), children: (0, jsx_runtime_1.jsx)(DateField_1.DateField, Object.assign({ className: b('time-field') }, timeInputProps)) })) : null] }) }))] })));
34
+ }, onBlur: props.onBlur })), (0, jsx_runtime_1.jsx)("input", { type: "text", hidden: true, name: props.name, value: (_a = state.value) !== null && _a !== void 0 ? _a : '',
35
+ // Ignore React warning
36
+ onChange: () => { } }), !isMobile && ((0, jsx_runtime_1.jsx)(uikit_1.Popup, { anchorRef: anchorRef, open: isOpen, children: (0, jsx_runtime_1.jsxs)("div", { className: b('popup-content'), children: [(0, jsx_runtime_1.jsx)(Calendar_1.Calendar, Object.assign({}, calendarProps)), props.hasTime ? ((0, jsx_runtime_1.jsx)("div", { className: b('time-field-wrapper'), children: (0, jsx_runtime_1.jsx)(DateField_1.DateField, Object.assign({ className: b('time-field') }, timeInputProps)) })) : null] }) }))] })));
34
37
  }
35
38
  exports.RelativeDateField = RelativeDateField;
@@ -10,13 +10,6 @@ function useRelativeDateFieldProps(state, props) {
10
10
  setPrevCorrectDate(state.lastCorrectDate);
11
11
  setFocusedDate(state.lastCorrectDate);
12
12
  }
13
- let error;
14
- if (props.validationState === 'invalid') {
15
- error = props.errorMessage || true;
16
- }
17
- else {
18
- error = state.validationState === 'invalid';
19
- }
20
13
  return {
21
14
  inputProps: {
22
15
  size: props.size,
@@ -25,12 +18,13 @@ function useRelativeDateFieldProps(state, props) {
25
18
  onUpdate: state.setText,
26
19
  disabled: state.disabled,
27
20
  hasClear: props.hasClear,
28
- //@ts-expect-error TODO: use new TextInput API
29
- error,
21
+ validationState: state.validationState,
22
+ errorMessage: props.errorMessage,
23
+ errorPlacement: props.errorPlacement,
30
24
  label: props.label,
31
25
  id: props.id,
32
- leftContent: props.leftContent,
33
- rightContent: props.rightContent,
26
+ startContent: props.startContent,
27
+ endContent: props.endContent,
34
28
  pin: props.pin,
35
29
  view: props.view,
36
30
  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;
@@ -4,9 +4,10 @@ exports.useRelativeDateFieldState = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const date_utils_1 = require("@gravity-ui/date-utils");
7
- const useControlledState_1 = require("../../hooks/useControlledState");
7
+ const uikit_1 = require("@gravity-ui/uikit");
8
8
  function useRelativeDateFieldState(props) {
9
- const [value, setValue] = (0, useControlledState_1.useControlledState)(props.value, props.defaultValue, props.onUpdate);
9
+ var _a;
10
+ const [value, setValue] = (0, uikit_1.useControlledState)(props.value, (_a = props.defaultValue) !== null && _a !== void 0 ? _a : null, props.onUpdate);
10
11
  const [text, setText] = react_1.default.useState(value !== null && value !== void 0 ? value : '');
11
12
  if (value && value !== text) {
12
13
  setText(value);
@@ -34,7 +35,7 @@ function useRelativeDateFieldState(props) {
34
35
  if (!value) {
35
36
  return null;
36
37
  }
37
- return (_a = (0, date_utils_1.dateTimeParse)(value, { timeZone: props.timeZone })) !== null && _a !== void 0 ? _a : null;
38
+ return (_a = (0, date_utils_1.dateTimeParse)(value, { timeZone: props.timeZone, roundUp: props.roundUp })) !== null && _a !== void 0 ? _a : null;
38
39
  }, [value, props.timeZone]);
39
40
  const [lastCorrectDate, setLastCorrectDate] = react_1.default.useState(parsedDate);
40
41
  if (parsedDate && parsedDate !== lastCorrectDate) {
@@ -42,7 +43,7 @@ function useRelativeDateFieldState(props) {
42
43
  }
43
44
  const validationState = props.validationState || (text && !parsedDate) ? 'invalid' : undefined;
44
45
  return {
45
- value: value !== null && value !== void 0 ? value : null,
46
+ value,
46
47
  setValue(v) {
47
48
  if (props.disabled || props.readOnly) {
48
49
  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;
@@ -18,13 +18,24 @@ function RelativeDatePicker(props) {
18
18
  const state = (0, useRelativeDatePickerState_1.useRelativeDatePickerState)(props);
19
19
  const { groupProps, fieldProps, modeSwitcherProps, calendarButtonProps, popupProps, calendarProps, timeInputProps, } = (0, useRelativeDatePickerProps_1.useRelativeDatePickerProps)(state, props);
20
20
  const anchorRef = react_1.default.useRef(null);
21
- const [isMobile] = (0, uikit_1.useMobile)();
21
+ const isMobile = (0, uikit_1.useMobile)();
22
22
  return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ ref: anchorRef, className: b(null, props.className) }, groupProps, { children: [isMobile && state.mode === 'absolute' && ((0, jsx_runtime_1.jsx)(MobileCalendar_1.MobileCalendar, { state: state.datePickerState, props: {
23
23
  id: props.id,
24
24
  disabled: props.disabled,
25
25
  readOnly: props.readOnly,
26
26
  placeholderValue: props.placeholderValue,
27
27
  timeZone: props.timeZone,
28
- } })), (0, jsx_runtime_1.jsx)(uikit_1.TextInput, Object.assign({}, fieldProps, { leftContent: (0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, modeSwitcherProps, { children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Function }) })), rightContent: (0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [!isMobile && ((0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, calendarButtonProps, { children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Calendar }) }))), isMobile && state.mode === 'absolute' && ((0, jsx_runtime_1.jsx)(MobileCalendar_1.MobileCalendarIcon, { state: state.datePickerState, props: { size: props.size } }))] }) })), !isMobile && ((0, jsx_runtime_1.jsx)(uikit_1.Popup, Object.assign({}, popupProps, { anchorRef: anchorRef, children: (0, jsx_runtime_1.jsxs)("div", { className: b('popup-content'), children: [typeof props.children === 'function' ? (props.children(calendarProps)) : ((0, jsx_runtime_1.jsx)(Calendar_1.Calendar, Object.assign({}, calendarProps))), state.datePickerState.hasTime && ((0, jsx_runtime_1.jsx)("div", { className: b('time-field-wrapper'), children: (0, jsx_runtime_1.jsx)(DateField_1.DateField, Object.assign({}, timeInputProps)) }))] }) })))] })));
28
+ } })), (0, jsx_runtime_1.jsx)(uikit_1.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: (0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, modeSwitcherProps, { children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Function }) })), endContent: (0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [!isMobile && ((0, jsx_runtime_1.jsx)(uikit_1.Button, Object.assign({}, calendarButtonProps, { children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Calendar }) }))), isMobile && state.mode === 'absolute' && ((0, jsx_runtime_1.jsx)(MobileCalendar_1.MobileCalendarIcon, { state: state.datePickerState, props: { size: props.size } }))] }) })), (0, jsx_runtime_1.jsx)("input", { type: "text", hidden: true, name: props.name, value: getNativeValue(state.value),
29
+ // Ignore React warning
30
+ onChange: () => { } }), !isMobile && ((0, jsx_runtime_1.jsx)(uikit_1.Popup, Object.assign({}, popupProps, { anchorRef: anchorRef, children: (0, jsx_runtime_1.jsxs)("div", { className: b('popup-content'), children: [typeof props.children === 'function' ? (props.children(calendarProps)) : ((0, jsx_runtime_1.jsx)(Calendar_1.Calendar, Object.assign({}, calendarProps))), state.datePickerState.hasTime && ((0, jsx_runtime_1.jsx)("div", { className: b('time-field-wrapper'), children: (0, jsx_runtime_1.jsx)(DateField_1.DateField, Object.assign({}, timeInputProps)) }))] }) })))] })));
29
31
  }
30
32
  exports.RelativeDatePicker = RelativeDatePicker;
33
+ function getNativeValue(value) {
34
+ if (!value) {
35
+ return '';
36
+ }
37
+ if (value.type === 'relative') {
38
+ return value.value;
39
+ }
40
+ return value.value.toISOString();
41
+ }
@@ -5,24 +5,25 @@ const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const uikit_1 = require("@gravity-ui/uikit");
7
7
  const DateField_1 = require("../../DateField");
8
+ const RelativeDateField_1 = require("../../RelativeDateField");
8
9
  const getButtonSizeForInput_1 = require("../../utils/getButtonSizeForInput");
9
10
  const mergeProps_1 = require("../../utils/mergeProps");
10
11
  const i18n_1 = require("../i18n");
11
12
  function useRelativeDatePickerProps(state, _a) {
12
13
  var { onFocus, onBlur } = _a, props = tslib_1.__rest(_a, ["onFocus", "onBlur"]);
13
- const { mode, setMode, datePickerState, dateFieldState, relativeDateState } = state;
14
- const [focusedDate, setFocusedDate] = react_1.default.useState(relativeDateState.lastCorrectDate);
14
+ const { mode, setMode, datePickerState, relativeDateState } = state;
15
+ const [focusedDate, setFocusedDate] = react_1.default.useState(mode === 'relative'
16
+ ? relativeDateState.lastCorrectDate
17
+ : datePickerState.dateFieldState.displayValue);
15
18
  const [prevCorrectDate, setPrevCorrectDate] = react_1.default.useState(relativeDateState.lastCorrectDate);
16
19
  if (prevCorrectDate !== relativeDateState.lastCorrectDate) {
17
20
  setPrevCorrectDate(relativeDateState.lastCorrectDate);
18
21
  setFocusedDate(relativeDateState.lastCorrectDate);
19
22
  }
20
- const [prevDateValue, setPrevDateValue] = react_1.default.useState(datePickerState.dateValue);
21
- if (datePickerState.dateValue !== prevDateValue) {
22
- setPrevDateValue(datePickerState.dateValue);
23
- if (datePickerState.dateValue) {
24
- setFocusedDate(datePickerState.dateValue);
25
- }
23
+ const [prevDateValue, setPrevDateValue] = react_1.default.useState(datePickerState.dateFieldState.displayValue);
24
+ if (!datePickerState.dateFieldState.displayValue.isSame(prevDateValue, 'day')) {
25
+ setPrevDateValue(datePickerState.dateFieldState.displayValue);
26
+ setFocusedDate(datePickerState.dateFieldState.displayValue);
26
27
  }
27
28
  const { focusWithinProps } = (0, uikit_1.useFocusWithin)({
28
29
  onFocusWithin: onFocus,
@@ -37,6 +38,18 @@ function useRelativeDatePickerProps(state, _a) {
37
38
  if (!state.isActive && isOpen) {
38
39
  setOpen(false);
39
40
  }
41
+ const [prevOpen, setPrevOpen] = react_1.default.useState(isOpen);
42
+ if (isOpen !== prevOpen) {
43
+ setPrevOpen(isOpen);
44
+ if (!isOpen) {
45
+ // FIXME: use popup afterOpenChange instead.
46
+ setTimeout(() => {
47
+ setFocusedDate(mode === 'relative'
48
+ ? relativeDateState.lastCorrectDate
49
+ : datePickerState.dateFieldState.displayValue);
50
+ }, 200);
51
+ }
52
+ }
40
53
  const commonInputProps = {
41
54
  onFocus: () => {
42
55
  if (!state.isActive) {
@@ -44,27 +57,17 @@ function useRelativeDatePickerProps(state, _a) {
44
57
  setOpen(true);
45
58
  }
46
59
  },
60
+ errorMessage: props.errorMessage,
61
+ errorPlacement: props.errorPlacement,
47
62
  };
48
- const { inputProps } = (0, DateField_1.useDateFieldProps)(dateFieldState, Object.assign(Object.assign({}, props), { value: undefined, defaultValue: undefined, onUpdate: undefined }));
49
- const relativeDateProps = {
50
- disabled: relativeDateState.disabled,
51
- value: relativeDateState.text,
52
- onUpdate: relativeDateState.setText,
53
- hasClear: props.hasClear && !relativeDateState.readOnly,
54
- placeholder: props.placeholder,
55
- size: props.size,
56
- };
57
- let error;
63
+ const { inputProps } = (0, DateField_1.useDateFieldProps)(datePickerState.dateFieldState, Object.assign(Object.assign({}, props), { value: undefined, defaultValue: undefined, onUpdate: undefined }));
64
+ const { inputProps: relativeDateProps } = (0, RelativeDateField_1.useRelativeDateFieldProps)(relativeDateState, Object.assign(Object.assign({}, props), { value: undefined, defaultValue: undefined, onUpdate: undefined }));
58
65
  let validationState = props.validationState;
59
- if (validationState) {
60
- error = validationState === 'invalid' ? props.errorMessage || true : undefined;
61
- }
62
- else {
66
+ if (!validationState) {
63
67
  validationState =
64
68
  mode === 'relative'
65
69
  ? relativeDateState.validationState
66
- : dateFieldState.validationState;
67
- error = validationState === 'invalid';
70
+ : datePickerState.dateFieldState.validationState;
68
71
  }
69
72
  const inputRef = react_1.default.useRef(null);
70
73
  const handleRef = (0, uikit_1.useForkRef)(inputRef, mode === 'relative' ? relativeDateProps.controlRef : inputProps.controlRef);
@@ -90,14 +93,17 @@ function useRelativeDatePickerProps(state, _a) {
90
93
  focusCalendar();
91
94
  }
92
95
  } }),
93
- fieldProps: (0, mergeProps_1.mergeProps)(commonInputProps, mode === 'relative' ? relativeDateProps : inputProps, mode === 'absolute' && dateFieldState.isEmpty && !state.isActive && props.placeholder
96
+ fieldProps: (0, mergeProps_1.mergeProps)(commonInputProps, mode === 'relative' ? relativeDateProps : inputProps, mode === 'absolute' &&
97
+ datePickerState.dateFieldState.isEmpty &&
98
+ !state.isActive &&
99
+ props.placeholder
94
100
  ? { value: '' }
95
- : undefined, { controlRef: handleRef, error }),
101
+ : undefined, { controlRef: handleRef, validationState }),
96
102
  modeSwitcherProps: {
97
103
  size: (0, getButtonSizeForInput_1.getButtonSizeForInput)(props.size),
98
104
  disabled: state.readOnly || state.disabled,
99
105
  view: 'flat-secondary',
100
- style: { zIndex: 2 },
106
+ style: { zIndex: 2, marginInlineEnd: 2 },
101
107
  selected: mode === 'relative',
102
108
  extraProps: {
103
109
  'aria-label': (0, i18n_1.i18n)('Formula input mode'),
@@ -154,6 +160,8 @@ function useRelativeDatePickerProps(state, _a) {
154
160
  },
155
161
  focusedValue: focusedDate,
156
162
  onFocusUpdate: setFocusedDate,
163
+ minValue: props.minValue,
164
+ maxValue: props.maxValue,
157
165
  },
158
166
  timeInputProps: {
159
167
  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
  /**