@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
@@ -8,7 +8,10 @@ export interface CalendarStateOptionsBase extends InputBase {
8
8
  maxValue?: DateTime;
9
9
  /** Callback that is called for each date of the calendar. If it returns true, then the date is unavailable. */
10
10
  isDateUnavailable?: (date: DateTime) => boolean;
11
- /** */
11
+ /**
12
+ * Which timezone use to show values. Example: 'default', 'system', 'Europe/Amsterdam'.
13
+ * @default The timezone of the `value` or `defaultValue` or `focusedValue` or `defaultFocusedValue`, 'default' otherwise.
14
+ */
12
15
  timeZone?: string;
13
16
  /**
14
17
  * Whether to automatically focus the calendar when it mounts.
@@ -35,7 +38,8 @@ interface CalendarStateBase {
35
38
  readonly disabled?: boolean;
36
39
  /** Whether the calendar is in a read only state. */
37
40
  readonly readOnly?: boolean;
38
- readonly timeZone?: string;
41
+ /** Which timezone use to show values. */
42
+ readonly timeZone: string;
39
43
  /** The minimum allowed date that a user may select. */
40
44
  readonly minValue?: DateTime;
41
45
  /** The maximum allowed date that a user may select. */
@@ -43,85 +47,87 @@ interface CalendarStateBase {
43
47
  /** The currently focused date. */
44
48
  readonly focusedDate: DateTime;
45
49
  /** Sets the focused date. */
46
- setFocusedDate(date: DateTime): void;
50
+ setFocusedDate: (date: DateTime) => void;
47
51
  /** Selects the currently focused date. */
48
- selectFocusedDate(): void;
52
+ selectFocusedDate: () => void;
49
53
  /** Selects the given date. */
50
- selectDate(date: DateTime, force?: boolean): void;
54
+ selectDate: (date: DateTime, force?: boolean) => void;
51
55
  /** Moves focus to the next calendar date. */
52
- focusNextCell(): void;
56
+ focusNextCell: () => void;
53
57
  /** Moves focus to the previous calendar date. */
54
- focusPreviousCell(): void;
58
+ focusPreviousCell: () => void;
55
59
  /** Moves focus to the next row of dates, e.g. the next week. */
56
- focusNextRow(): void;
60
+ focusNextRow: () => void;
57
61
  /** Moves focus to the previous row of dates, e.g. the previous work. */
58
- focusPreviousRow(): void;
62
+ focusPreviousRow: () => void;
59
63
  /**
60
64
  * Moves focus to the next page of dates, e.g. the next month.
61
65
  * If the `larger` option is `true`, the focus is moved by the next larger unit.
62
66
  * For example, if days are displayed, then focus moves to the next year.
63
67
  */
64
- focusNextPage(larger?: boolean): void;
68
+ focusNextPage: (larger?: boolean) => void;
65
69
  /**
66
70
  * Moves focus to the previous page of dates, e.g. the previous month.
67
71
  * If the `larger` option is `true`, the focus is moved by the next larger unit.
68
72
  * For example, if days are displayed, then focus moves to the previous year.
69
73
  */
70
- focusPreviousPage(larger?: boolean): void;
74
+ focusPreviousPage: (larger?: boolean) => void;
71
75
  /** Moves focus to the start of the current section of dates, e.g. the start of the current month. */
72
- focusSectionStart(): void;
76
+ focusSectionStart: () => void;
73
77
  /** Moves focus to the end of the current section of dates, e.g. the end of the current month month. */
74
- focusSectionEnd(): void;
78
+ focusSectionEnd: () => void;
75
79
  /** Switches to more detailed layout. */
76
- zoomIn(): void;
80
+ zoomIn: () => void;
77
81
  /** Switches to less detailed layout. */
78
- zoomOut(): void;
82
+ zoomOut: () => void;
79
83
  /** Whether focus is currently within the calendar. */
80
84
  readonly isFocused: boolean;
81
85
  /** Sets whether focus is currently within the calendar. */
82
- setFocused(isFocused: boolean): void;
86
+ setFocused: (isFocused: boolean) => void;
83
87
  /** Returns whether the given date is invalid according to the `minValue` and `maxValue` props. */
84
- isInvalid(date: DateTime): boolean;
88
+ isInvalid: (date: DateTime) => boolean;
85
89
  /** Returns whether the previous page is allowed to be selected according to the `minValue` prop. */
86
- isPreviousPageInvalid(): boolean;
90
+ isPreviousPageInvalid: () => boolean;
87
91
  /** Returns whether the next page is allowed to be selected according to the `maxValue` prop. */
88
- isNextPageInvalid(): boolean;
92
+ isNextPageInvalid: () => boolean;
89
93
  /** Returns whether the given date is currently selected. */
90
- isSelected(date: DateTime): boolean;
94
+ isSelected: (date: DateTime) => boolean;
91
95
  /** Returns whether the given date is unavailable according to the `isDateUnavailable` prop. */
92
- isCellUnavailable(date: DateTime): boolean;
96
+ isCellUnavailable: (date: DateTime) => boolean;
93
97
  /** Returns whether the given date is currently focused. */
94
- isCellFocused(date: DateTime): boolean;
98
+ isCellFocused: (date: DateTime) => boolean;
95
99
  /** Returns whether the given date is disabled according to the `minValue, `maxValue`, and `isDisabled` props. */
96
- isCellDisabled(date: DateTime): boolean;
100
+ isCellDisabled: (date: DateTime) => boolean;
97
101
  /** Returns whether the given date is weekend */
98
- isWeekend(date: DateTime): boolean;
102
+ isWeekend: (date: DateTime) => boolean;
103
+ /** Returns whether the given date is in current period */
104
+ isCurrent: (date: DateTime) => boolean;
99
105
  /** Current calendar layout */
100
106
  readonly mode: CalendarLayout;
101
107
  /** Sets calendar layout */
102
- setMode(mode: CalendarLayout): void;
108
+ setMode: (mode: CalendarLayout) => void;
103
109
  readonly availableModes: CalendarLayout[];
104
110
  readonly startDate: DateTime;
105
111
  readonly endDate: DateTime;
106
112
  }
107
113
  export interface CalendarState extends CalendarStateBase {
108
114
  /** The currently selected date. */
109
- readonly value?: DateTime | null;
115
+ readonly value: DateTime | null;
110
116
  /** Sets the currently selected date. */
111
- setValue(value: DateTime): void;
117
+ setValue: (value: DateTime) => void;
112
118
  }
113
119
  export interface RangeCalendarState extends CalendarStateBase {
114
120
  /** The currently selected range. */
115
- readonly value?: RangeValue<DateTime> | null;
121
+ readonly value: RangeValue<DateTime> | null;
116
122
  /** Sets the currently selected range. */
117
- setValue(value: RangeValue<DateTime>): void;
123
+ setValue: (value: RangeValue<DateTime>) => void;
118
124
  /** The current anchor date that the user clicked on to begin range selection. */
119
125
  readonly anchorDate: DateTime | undefined;
120
126
  /** Sets the anchor date that the user clicked on to begin range selection. */
121
- setAnchorDate(date: DateTime | undefined): void;
127
+ setAnchorDate: (date: DateTime | undefined) => void;
122
128
  /** The currently highlighted date range. */
123
129
  readonly highlightedRange: RangeValue<DateTime> | undefined;
124
130
  /** Highlights the given date during selection, e.g. by hovering. */
125
- highlightDate(date: DateTime): void;
131
+ highlightDate: (date: DateTime) => void;
126
132
  }
127
133
  export {};
@@ -1,5 +1,4 @@
1
1
  import React from 'react';
2
- import { dateTime } from '@gravity-ui/date-utils';
3
2
  export function useCalendarCellProps(date, state) {
4
3
  const ref = React.useRef(null);
5
4
  const isFocused = state.isCellFocused(date);
@@ -19,7 +18,7 @@ export function useCalendarCellProps(date, state) {
19
18
  const isOutsideCurrentRange = state.mode === 'days' ? !state.focusedDate.isSame(date, 'month') : false;
20
19
  const isUnavailable = state.isCellUnavailable(date);
21
20
  const isSelectable = !isDisabled && !isUnavailable;
22
- const isCurrent = dateTime().isSame(date, state.mode);
21
+ const isCurrent = state.isCurrent(date);
23
22
  const isWeekend = state.isWeekend(date);
24
23
  const label = getDateLabel(date, state.mode);
25
24
  const cellProps = {
@@ -1,5 +1,5 @@
1
- import React from 'react';
1
+ /// <reference types="react" />
2
2
  import type { CalendarState, RangeCalendarState } from './types';
3
3
  export declare function useCalendarGridProps(state: CalendarState | RangeCalendarState): {
4
- gridProps: React.HTMLAttributes<HTMLElement>;
4
+ gridProps: import("react").HTMLAttributes<HTMLElement>;
5
5
  };
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { useFocusWithin } from '@gravity-ui/uikit';
3
2
  export function useCalendarGridProps(state) {
4
3
  const { focusWithinProps } = useFocusWithin({
@@ -1,7 +1,7 @@
1
1
  import type { DateTime } from '@gravity-ui/date-utils';
2
2
  import type { ValueBase } from '../../types';
3
3
  import type { CalendarState, CalendarStateOptionsBase } from './types';
4
- export interface CalendarStateOptions extends ValueBase<DateTime>, CalendarStateOptionsBase {
4
+ export interface CalendarStateOptions<T = DateTime> extends ValueBase<T | null, T>, CalendarStateOptionsBase {
5
5
  }
6
6
  export type { CalendarState } from './types';
7
7
  export declare function useCalendarState(props: CalendarStateOptions): CalendarState;
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
- import { useControlledState } from '../../hooks/useControlledState';
3
- import { createPlaceholderValue } from '../../utils/dates';
2
+ import { dateTime } from '@gravity-ui/date-utils';
3
+ import { useControlledState } from '@gravity-ui/uikit';
4
+ import { createPlaceholderValue, mergeDateTime } from '../../utils/dates';
5
+ import { useDefaultTimeZone } from '../../utils/useDefaultTimeZone';
4
6
  import { calendarLayouts, constrainValue } from '../utils';
5
7
  const defaultModes = {
6
8
  days: true,
@@ -9,25 +11,34 @@ const defaultModes = {
9
11
  years: true,
10
12
  };
11
13
  export function useCalendarState(props) {
12
- const { disabled, readOnly, minValue, maxValue, timeZone, modes = defaultModes } = props;
13
- const [value, setValue] = useControlledState(props.value, props.defaultValue, props.onUpdate);
14
- const [mode, setMode] = useControlledState(props.mode, props.defaultMode, props.onUpdateMode);
14
+ var _a, _b, _c;
15
+ const { disabled, readOnly, modes = defaultModes } = props;
16
+ const [value, setValue] = useControlledState(props.value, (_a = props.defaultValue) !== null && _a !== void 0 ? _a : null, props.onUpdate);
15
17
  const availableModes = calendarLayouts.filter((l) => modes[l]);
16
18
  const minMode = availableModes[0] || 'days';
19
+ const [mode, setMode] = useControlledState(props.mode, (_b = props.defaultMode) !== null && _b !== void 0 ? _b : minMode, props.onUpdateMode);
17
20
  const currentMode = mode && availableModes.includes(mode) ? mode : minMode;
21
+ const inputTimeZone = useDefaultTimeZone(props.value || props.defaultValue || props.focusedValue || props.defaultFocusedValue);
22
+ const timeZone = props.timeZone || inputTimeZone;
23
+ const minValue = React.useMemo(() => (props.minValue ? props.minValue.timeZone(timeZone) : undefined), [timeZone, props.minValue]);
24
+ const maxValue = React.useMemo(() => (props.maxValue ? props.maxValue.timeZone(timeZone) : undefined), [timeZone, props.maxValue]);
18
25
  const focusedValue = React.useMemo(() => {
19
26
  if (!props.focusedValue) {
20
27
  return props.focusedValue;
21
28
  }
22
- return constrainValue(props.focusedValue, minValue, maxValue);
23
- }, [props.focusedValue, minValue, maxValue]);
29
+ return constrainValue(props.focusedValue.timeZone(timeZone), minValue, maxValue);
30
+ }, [props.focusedValue, minValue, maxValue, timeZone]);
24
31
  const defaultFocusedValue = React.useMemo(() => {
25
- const defaultValue = (props.defaultFocusedValue ? props.defaultFocusedValue : value) ||
32
+ var _a;
33
+ const defaultValue = ((_a = (props.defaultFocusedValue ? props.defaultFocusedValue : value)) === null || _a === void 0 ? void 0 : _a.timeZone(timeZone)) ||
26
34
  createPlaceholderValue({ timeZone }).startOf(minMode);
27
35
  return constrainValue(defaultValue, minValue, maxValue);
28
36
  }, [maxValue, minValue, props.defaultFocusedValue, timeZone, value, minMode]);
29
- const [focusedDateInner, setFocusedDate] = useControlledState(focusedValue, defaultFocusedValue, props.onFocusUpdate);
30
- const focusedDate = focusedDateInner !== null && focusedDateInner !== void 0 ? focusedDateInner : constrainValue(createPlaceholderValue({ timeZone }).startOf(minMode), minValue, maxValue);
37
+ const [focusedDateInner, setFocusedDate] = useControlledState(focusedValue, defaultFocusedValue, (date) => {
38
+ var _a;
39
+ (_a = props.onFocusUpdate) === null || _a === void 0 ? void 0 : _a.call(props, date.timeZone(inputTimeZone));
40
+ });
41
+ const focusedDate = (_c = focusedDateInner === null || focusedDateInner === void 0 ? void 0 : focusedDateInner.timeZone(timeZone)) !== null && _c !== void 0 ? _c : constrainValue(createPlaceholderValue({ timeZone }), minValue, maxValue);
31
42
  if (isInvalid(focusedDate, minValue, maxValue)) {
32
43
  // If the focused date was moved to an invalid value, it can't be focused, so constrain it.
33
44
  setFocusedDate(constrainValue(focusedDate, minValue, maxValue));
@@ -42,16 +53,24 @@ export function useCalendarState(props) {
42
53
  disabled,
43
54
  readOnly,
44
55
  value,
45
- setValue,
56
+ setValue(date) {
57
+ if (!disabled && !readOnly) {
58
+ let newValue = constrainValue(date, minValue, maxValue);
59
+ if (this.isCellUnavailable(newValue)) {
60
+ return;
61
+ }
62
+ if (value) {
63
+ // If there is a date already selected, then we want to keep its time
64
+ newValue = mergeDateTime(newValue, value.timeZone(timeZone));
65
+ }
66
+ setValue(newValue.timeZone(inputTimeZone));
67
+ }
68
+ },
46
69
  timeZone,
47
70
  selectDate(date, force = false) {
48
71
  if (!disabled) {
49
72
  if (!readOnly && (force || this.mode === minMode)) {
50
- const newValue = constrainValue(date, minValue, maxValue);
51
- if (this.isCellUnavailable(newValue)) {
52
- return;
53
- }
54
- setValue(newValue);
73
+ this.setValue(date.startOf(minMode));
55
74
  if (force && currentMode !== minMode) {
56
75
  setMode(minMode);
57
76
  }
@@ -127,15 +146,15 @@ export function useCalendarState(props) {
127
146
  focusCell(getEndDate(focusedDate, this.mode));
128
147
  },
129
148
  zoomIn() {
130
- const index = availableModes.indexOf(this.mode) - 1;
131
- if (index >= 0) {
132
- this.setMode(availableModes[index]);
149
+ const nextMode = availableModes[availableModes.indexOf(this.mode) - 1];
150
+ if (nextMode) {
151
+ this.setMode(nextMode);
133
152
  }
134
153
  },
135
154
  zoomOut() {
136
- const index = availableModes.indexOf(this.mode) + 1;
137
- if (index < availableModes.length) {
138
- this.setMode(availableModes[index]);
155
+ const nextMode = availableModes[availableModes.indexOf(this.mode) + 1];
156
+ if (nextMode) {
157
+ this.setMode(nextMode);
139
158
  }
140
159
  },
141
160
  selectFocusedDate() {
@@ -155,8 +174,8 @@ export function useCalendarState(props) {
155
174
  return this.isInvalid(next);
156
175
  },
157
176
  isSelected(date) {
158
- return (Boolean(value) &&
159
- date.isSame(value !== null && value !== void 0 ? value : undefined, currentMode) &&
177
+ return Boolean(value &&
178
+ date.isSame(value.timeZone(timeZone), currentMode) &&
160
179
  !this.isCellDisabled(date));
161
180
  },
162
181
  isCellUnavailable(date) {
@@ -176,6 +195,9 @@ export function useCalendarState(props) {
176
195
  isWeekend(date) {
177
196
  return this.mode === 'days' && [0, 6].includes(date.day());
178
197
  },
198
+ isCurrent(date) {
199
+ return dateTime({ timeZone }).isSame(date, this.mode);
200
+ },
179
201
  mode: currentMode,
180
202
  setMode,
181
203
  availableModes,
@@ -0,0 +1,8 @@
1
+ import type { DateTime } from '@gravity-ui/date-utils';
2
+ import type { RangeValue } from '../../types';
3
+ import type { RangeCalendarState } from './types';
4
+ import type { CalendarStateOptions } from './useCalendarState';
5
+ export interface RangeCalendarStateOptions extends CalendarStateOptions<RangeValue<DateTime>> {
6
+ }
7
+ export type { RangeCalendarState } from './types';
8
+ export declare function useRangeCalendarState(props: RangeCalendarStateOptions): RangeCalendarState;
@@ -1,18 +1,31 @@
1
1
  import { __rest } from "tslib";
2
2
  import React from 'react';
3
- import { useControlledState } from '../../hooks/useControlledState';
3
+ import { useControlledState } from '@gravity-ui/uikit';
4
+ import { mergeDateTime } from '../../utils/dates';
5
+ import { useDefaultTimeZone } from '../../utils/useDefaultTimeZone';
4
6
  import { constrainValue } from '../utils';
5
7
  import { useCalendarState } from './useCalendarState';
6
8
  export function useRangeCalendarState(props) {
7
- var _a, _b;
8
- const { value: valueProp, defaultValue, onUpdate } = props, calendarProps = __rest(props, ["value", "defaultValue", "onUpdate"]);
9
+ var _a;
10
+ const { value: valueProp, defaultValue = null, onUpdate } = props, calendarProps = __rest(props, ["value", "defaultValue", "onUpdate"]);
9
11
  const [value, setValue] = useControlledState(valueProp, defaultValue, onUpdate);
10
12
  const [anchorDate, setAnchorDateState] = React.useState();
11
- const calendar = useCalendarState(Object.assign(Object.assign({}, calendarProps), { value: (_a = value === null || value === void 0 ? void 0 : value.start) !== null && _a !== void 0 ? _a : null }));
13
+ const inputTimeZone = useDefaultTimeZone((valueProp === null || valueProp === void 0 ? void 0 : valueProp.start) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.start) || props.focusedValue || props.defaultFocusedValue);
14
+ const timeZone = props.timeZone || inputTimeZone;
15
+ const calendar = useCalendarState(Object.assign(Object.assign({}, calendarProps), { value: null, timeZone }));
12
16
  const highlightedRange = anchorDate
13
17
  ? makeRange(anchorDate, calendar.focusedDate, calendar.mode)
14
- : (_b = (value && makeRange(value.start, value.end, calendar.mode))) !== null && _b !== void 0 ? _b : undefined;
18
+ : (_a = (value &&
19
+ makeRange(value.start.timeZone(timeZone), value.end.timeZone(timeZone), calendar.mode))) !== null && _a !== void 0 ? _a : undefined;
15
20
  const minMode = calendar.availableModes[0];
21
+ const handleSetValue = (v) => {
22
+ let { start, end } = v;
23
+ if (value) {
24
+ start = mergeDateTime(start, value.start.timeZone(timeZone));
25
+ end = mergeDateTime(end, value.end.timeZone(timeZone));
26
+ }
27
+ setValue({ start: start.timeZone(inputTimeZone), end: end.timeZone(inputTimeZone) });
28
+ };
16
29
  const selectDate = (date, force = false) => {
17
30
  if (props.disabled) {
18
31
  return;
@@ -24,22 +37,20 @@ export function useRangeCalendarState(props) {
24
37
  if (props.readOnly) {
25
38
  return;
26
39
  }
27
- date = constrainValue(date, props.minValue, props.maxValue);
28
- if (calendar.isCellUnavailable(date)) {
40
+ const newDate = constrainValue(date, calendar.minValue, calendar.maxValue);
41
+ if (calendar.isCellUnavailable(newDate)) {
29
42
  return;
30
43
  }
31
44
  if (anchorDate) {
32
- const range = makeRange(anchorDate, date, calendar.mode);
33
- setValue(range);
45
+ const range = makeRange(anchorDate, newDate, calendar.mode);
46
+ handleSetValue(range);
34
47
  setAnchorDateState(undefined);
35
48
  }
36
49
  else {
37
- setAnchorDateState(date);
50
+ setAnchorDateState(newDate);
38
51
  }
39
52
  };
40
- return Object.assign(Object.assign({}, calendar), { value,
41
- setValue,
42
- selectDate,
53
+ return Object.assign(Object.assign({}, calendar), { value, setValue: handleSetValue, selectDate,
43
54
  anchorDate, setAnchorDate: setAnchorDateState, highlightedRange,
44
55
  isSelected(date) {
45
56
  if (!highlightedRange) {
@@ -1,6 +1,3 @@
1
- import type { AccessibilityProps, DomProps, FocusableProps, KeyboardEvents, StyleProps, TextInputExtendProps, TextInputProps } from '../types';
2
- import type { DateFieldStateOptions } from './hooks/useDateFieldState';
1
+ import type { DateFieldProps } from './hooks/useDateFieldProps';
3
2
  import './DateField.css';
4
- export interface DateFieldProps extends DateFieldStateOptions, TextInputProps, TextInputExtendProps, DomProps, FocusableProps, KeyboardEvents, StyleProps, AccessibilityProps {
5
- }
6
3
  export declare function DateField({ className, ...props }: DateFieldProps): import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import { __rest } from "tslib";
2
- import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import React from 'react';
4
4
  import { TextInput, useFocusWithin } from '@gravity-ui/uikit';
5
5
  import { block } from '../../utils/cn';
@@ -17,5 +17,7 @@ export function DateField(_a) {
17
17
  setActive(isFocusWithin);
18
18
  },
19
19
  });
20
- return (_jsx("div", Object.assign({ className: b(null, className), style: props.style }, focusWithinProps, { children: _jsx(TextInput, Object.assign({}, inputProps, { value: state.isEmpty && !isActive && props.placeholder ? '' : inputProps.value })) })));
20
+ return (_jsxs("div", Object.assign({ className: b(null, className), style: props.style }, focusWithinProps, { children: [_jsx(TextInput, Object.assign({}, inputProps, { value: state.isEmpty && !isActive && props.placeholder ? '' : inputProps.value })), _jsx("input", { type: "text", hidden: true, name: props.name, value: state.value ? state.value.toISOString() : '',
21
+ // Ignore React warning
22
+ onChange: () => { } })] })));
21
23
  }
@@ -0,0 +1,97 @@
1
+ import type { DateTime } from '@gravity-ui/date-utils';
2
+ import type { ValidationState } from '../../types';
3
+ import type { DateFieldSection } from '../types';
4
+ export type BaseDateFieldStateOptions<T = DateTime> = {
5
+ value: T | null;
6
+ displayValue: T;
7
+ placeholderValue?: DateTime;
8
+ timeZone: string;
9
+ validationState?: ValidationState;
10
+ editableSections: DateFieldSection[];
11
+ readOnly?: boolean;
12
+ disabled?: boolean;
13
+ selectedSectionIndexes: {
14
+ startIndex: number;
15
+ endIndex: number;
16
+ } | null;
17
+ selectedSections: number | 'all';
18
+ isEmpty: boolean;
19
+ flushAllValidSections: () => void;
20
+ flushValidSection: (sectionIndex: number) => void;
21
+ setSelectedSections: (position: number | 'all') => void;
22
+ setValue: (value: T) => void;
23
+ setDate: (value: T | null) => void;
24
+ adjustSection: (sectionIndex: number, amount: number) => void;
25
+ setSection: (sectionIndex: number, amount: number) => void;
26
+ getSectionValue: (sectionIndex: number) => DateTime;
27
+ setSectionValue: (sectionIndex: number, currentValue: DateTime) => void;
28
+ createPlaceholder: () => T;
29
+ setValueFromString: (str: string) => boolean;
30
+ };
31
+ export type BaseDateFieldState<T = DateTime> = {
32
+ /** The current field value. */
33
+ value: T | null;
34
+ /** Is no part of value is filled. */
35
+ isEmpty: boolean;
36
+ /** The current used value. value or placeholderValue */
37
+ displayValue: T;
38
+ /** Sets the field's value. */
39
+ setValue: (value: T) => void;
40
+ /** Formatted value */
41
+ text: string;
42
+ /** Whether the field is read only. */
43
+ readOnly?: boolean;
44
+ /** Whether the field is disabled. */
45
+ disabled?: boolean;
46
+ /** A list of segments for the current value. */
47
+ sections: DateFieldSection[];
48
+ /** Whether the the format is containing date parts */
49
+ hasDate: boolean;
50
+ /** Whether the the format is containing time parts */
51
+ hasTime: boolean;
52
+ /** Selected sections */
53
+ selectedSectionIndexes: {
54
+ startIndex: number;
55
+ endIndex: number;
56
+ } | null;
57
+ /** The current validation state of the date field, based on the `validationState`, `minValue`, and `maxValue` props. */
58
+ validationState?: ValidationState;
59
+ /** Sets selection for segment in position. */
60
+ setSelectedSections: (position: number | 'all') => void;
61
+ /** Focuses segment in position */
62
+ focusSectionInPosition: (position: number) => void;
63
+ /** Focuses the next segment if present */
64
+ focusNextSection: () => void;
65
+ /** Focuses the previous segment if present */
66
+ focusPreviousSection: () => void;
67
+ /** Focuses the first segment */
68
+ focusFirstSection: () => void;
69
+ /** Focuses the last segment */
70
+ focusLastSection: () => void;
71
+ /** Increments the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */
72
+ increment: () => void;
73
+ /** Decrements the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */
74
+ decrement: () => void;
75
+ /**
76
+ * Increments the currently selected segment by a larger amount, rounding it to the nearest increment.
77
+ * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.
78
+ * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.
79
+ */
80
+ incrementPage: () => void;
81
+ /**
82
+ * Decrements the currently selected segment by a larger amount, rounding it to the nearest decrement.
83
+ * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.
84
+ * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.
85
+ */
86
+ decrementPage: () => void;
87
+ incrementToMax: () => void;
88
+ decrementToMin: () => void;
89
+ /** Clears the value of the currently selected segment, reverting it to the placeholder. */
90
+ clearSection: () => void;
91
+ /** Clears all segments, reverting them to the placeholder. */
92
+ clearAll: () => void;
93
+ /** Handles input key in the currently selected segment */
94
+ onInput: (key: string) => void;
95
+ setValueFromString: (str: string) => boolean;
96
+ };
97
+ export declare function useBaseDateFieldState<T = DateTime>(props: BaseDateFieldStateOptions<T>): BaseDateFieldState<T>;