@gravity-ui/date-components 1.6.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,311 @@
1
+ import React from 'react';
2
+ import { createPlaceholderValue } from '../../utils/dates';
3
+ import { EDITABLE_SEGMENTS, formatSections, getCurrentEditableSectionIndex, getDurationUnitFromSectionType, } from '../utils';
4
+ const PAGE_STEP = {
5
+ year: 5,
6
+ month: 2,
7
+ weekday: 3,
8
+ day: 7,
9
+ hour: 2,
10
+ minute: 15,
11
+ second: 15,
12
+ };
13
+ export function useBaseDateFieldState(props) {
14
+ const { value, validationState, displayValue, editableSections, selectedSectionIndexes, selectedSections, isEmpty, flushAllValidSections, flushValidSection, setSelectedSections, setValue, setDate, adjustSection, setSection, getSectionValue, setSectionValue, createPlaceholder, setValueFromString, } = props;
15
+ const enteredKeys = React.useRef('');
16
+ const { hasDate, hasTime } = React.useMemo(() => {
17
+ let hasDateInner = false;
18
+ let hasTimeInner = false;
19
+ for (const s of editableSections) {
20
+ hasTimeInner || (hasTimeInner = ['hour', 'minute', 'second'].includes(s.type));
21
+ hasDateInner || (hasDateInner = ['day', 'month', 'year'].includes(s.type));
22
+ }
23
+ return {
24
+ hasTime: hasTimeInner,
25
+ hasDate: hasDateInner,
26
+ };
27
+ }, [editableSections]);
28
+ return {
29
+ value,
30
+ isEmpty,
31
+ displayValue,
32
+ setValue,
33
+ text: formatSections(editableSections),
34
+ readOnly: props.readOnly,
35
+ disabled: props.disabled,
36
+ sections: editableSections,
37
+ hasDate,
38
+ hasTime,
39
+ selectedSectionIndexes,
40
+ validationState,
41
+ setSelectedSections(position) {
42
+ enteredKeys.current = '';
43
+ setSelectedSections(position);
44
+ },
45
+ focusSectionInPosition(position) {
46
+ const nextSectionIndex = this.sections.findIndex((s) => s.end >= position);
47
+ const index = nextSectionIndex === -1 ? 0 : nextSectionIndex;
48
+ const nextSection = this.sections[index];
49
+ if (nextSection) {
50
+ this.setSelectedSections(EDITABLE_SEGMENTS[nextSection.type] ? index : nextSection.nextEditableSection);
51
+ }
52
+ },
53
+ focusNextSection() {
54
+ var _a, _b;
55
+ const currentIndex = selectedSections === 'all' ? 0 : selectedSections;
56
+ const newIndex = (_b = (_a = this.sections[currentIndex]) === null || _a === void 0 ? void 0 : _a.nextEditableSection) !== null && _b !== void 0 ? _b : -1;
57
+ if (newIndex !== -1) {
58
+ this.setSelectedSections(newIndex);
59
+ }
60
+ },
61
+ focusPreviousSection() {
62
+ var _a, _b;
63
+ const currentIndex = selectedSections === 'all' ? 0 : selectedSections;
64
+ const newIndex = (_b = (_a = this.sections[currentIndex]) === null || _a === void 0 ? void 0 : _a.previousEditableSection) !== null && _b !== void 0 ? _b : -1;
65
+ if (newIndex !== -1) {
66
+ this.setSelectedSections(newIndex);
67
+ }
68
+ },
69
+ focusFirstSection() {
70
+ var _a, _b;
71
+ const newIndex = (_b = (_a = this.sections[0]) === null || _a === void 0 ? void 0 : _a.previousEditableSection) !== null && _b !== void 0 ? _b : -1;
72
+ if (newIndex !== -1) {
73
+ setSelectedSections(newIndex);
74
+ }
75
+ },
76
+ focusLastSection() {
77
+ var _a, _b;
78
+ const newIndex = (_b = (_a = this.sections[this.sections.length - 1]) === null || _a === void 0 ? void 0 : _a.nextEditableSection) !== null && _b !== void 0 ? _b : -1;
79
+ if (newIndex !== -1) {
80
+ this.setSelectedSections(newIndex);
81
+ }
82
+ },
83
+ increment() {
84
+ if (this.readOnly || this.disabled) {
85
+ return;
86
+ }
87
+ enteredKeys.current = '';
88
+ const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
89
+ if (sectionIndex !== -1) {
90
+ adjustSection(sectionIndex, 1);
91
+ }
92
+ },
93
+ decrement() {
94
+ if (this.readOnly || this.disabled) {
95
+ return;
96
+ }
97
+ enteredKeys.current = '';
98
+ const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
99
+ if (sectionIndex !== -1) {
100
+ adjustSection(sectionIndex, -1);
101
+ }
102
+ },
103
+ incrementPage() {
104
+ if (this.readOnly || this.disabled) {
105
+ return;
106
+ }
107
+ enteredKeys.current = '';
108
+ const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
109
+ if (sectionIndex !== -1) {
110
+ adjustSection(sectionIndex, PAGE_STEP[this.sections[sectionIndex].type] || 1);
111
+ }
112
+ },
113
+ decrementPage() {
114
+ if (this.readOnly || this.disabled) {
115
+ return;
116
+ }
117
+ enteredKeys.current = '';
118
+ const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
119
+ if (sectionIndex !== -1) {
120
+ adjustSection(sectionIndex, -(PAGE_STEP[this.sections[sectionIndex].type] || 1));
121
+ }
122
+ },
123
+ incrementToMax() {
124
+ if (this.readOnly || this.disabled) {
125
+ return;
126
+ }
127
+ enteredKeys.current = '';
128
+ const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
129
+ if (sectionIndex !== -1) {
130
+ const section = this.sections[sectionIndex];
131
+ if (typeof section.maxValue === 'number') {
132
+ setSection(sectionIndex, section.maxValue);
133
+ }
134
+ }
135
+ },
136
+ decrementToMin() {
137
+ if (this.readOnly || this.disabled) {
138
+ return;
139
+ }
140
+ enteredKeys.current = '';
141
+ const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
142
+ if (sectionIndex !== -1) {
143
+ const section = this.sections[sectionIndex];
144
+ if (typeof section.minValue === 'number') {
145
+ setSection(sectionIndex, section.minValue);
146
+ }
147
+ }
148
+ },
149
+ clearSection() {
150
+ if (this.readOnly || this.disabled) {
151
+ return;
152
+ }
153
+ enteredKeys.current = '';
154
+ if (selectedSections === 'all') {
155
+ this.clearAll();
156
+ return;
157
+ }
158
+ const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
159
+ if (sectionIndex === -1) {
160
+ return;
161
+ }
162
+ flushValidSection(sectionIndex);
163
+ const section = this.sections[sectionIndex];
164
+ const placeholder = createPlaceholderValue({
165
+ placeholderValue: props.placeholderValue,
166
+ timeZone: props.timeZone,
167
+ }).timeZone(props.timeZone);
168
+ const displayPortion = getSectionValue(sectionIndex);
169
+ let currentValue = displayPortion;
170
+ // Reset day period to default without changing the hour.
171
+ if (section.type === 'dayPeriod') {
172
+ const isPM = displayPortion.hour() >= 12;
173
+ const shouldBePM = placeholder.hour() >= 12;
174
+ if (isPM && !shouldBePM) {
175
+ currentValue = displayPortion.set('hour', displayPortion.hour() - 12);
176
+ }
177
+ else if (!isPM && shouldBePM) {
178
+ currentValue = displayPortion.set('hour', displayPortion.hour() + 12);
179
+ }
180
+ }
181
+ else {
182
+ const type = getDurationUnitFromSectionType(section.type);
183
+ currentValue = displayPortion.set(type, placeholder[type]());
184
+ }
185
+ setSectionValue(sectionIndex, currentValue);
186
+ },
187
+ clearAll() {
188
+ if (this.readOnly || this.disabled) {
189
+ return;
190
+ }
191
+ enteredKeys.current = '';
192
+ flushAllValidSections();
193
+ if (value !== null) {
194
+ setDate(null);
195
+ }
196
+ const date = createPlaceholder();
197
+ setValue(date);
198
+ },
199
+ onInput(key) {
200
+ if (this.readOnly || this.disabled) {
201
+ return;
202
+ }
203
+ const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
204
+ if (sectionIndex === -1) {
205
+ return;
206
+ }
207
+ const section = this.sections[sectionIndex];
208
+ let newValue = enteredKeys.current + key;
209
+ const onInputNumber = (numberValue) => {
210
+ var _a, _b, _c;
211
+ let sectionValue = section.type === 'month' ? numberValue - 1 : numberValue;
212
+ const allowsZero = section.minValue === 0;
213
+ if (section.type === 'hour' &&
214
+ (section.minValue === 12 || section.maxValue === 11)) {
215
+ if (numberValue > 12) {
216
+ sectionValue = Number(key);
217
+ }
218
+ if (section.minValue === 12 && sectionValue > 1) {
219
+ sectionValue += 12;
220
+ }
221
+ }
222
+ else if (sectionValue > ((_a = section.maxValue) !== null && _a !== void 0 ? _a : 0)) {
223
+ sectionValue = Number(key) - (section.type === 'month' ? 1 : 0);
224
+ newValue = key;
225
+ if (sectionValue > ((_b = section.maxValue) !== null && _b !== void 0 ? _b : 0)) {
226
+ enteredKeys.current = '';
227
+ return;
228
+ }
229
+ }
230
+ const shouldSetValue = sectionValue > 0 || (sectionValue === 0 && allowsZero);
231
+ if (shouldSetValue) {
232
+ setSection(sectionIndex, sectionValue);
233
+ }
234
+ if (Number(numberValue + '0') > ((_c = section.maxValue) !== null && _c !== void 0 ? _c : 0) ||
235
+ newValue.length >= String(section.maxValue).length) {
236
+ enteredKeys.current = '';
237
+ if (shouldSetValue) {
238
+ this.focusNextSection();
239
+ }
240
+ }
241
+ else {
242
+ enteredKeys.current = newValue;
243
+ }
244
+ };
245
+ const onInputString = (stringValue) => {
246
+ var _a;
247
+ const options = (_a = section.options) !== null && _a !== void 0 ? _a : [];
248
+ let sectionValue = stringValue.toLocaleUpperCase();
249
+ let foundOptions = options.filter((v) => v.startsWith(sectionValue));
250
+ if (foundOptions.length === 0) {
251
+ if (stringValue !== key) {
252
+ sectionValue = key.toLocaleUpperCase();
253
+ foundOptions = options.filter((v) => v.startsWith(sectionValue));
254
+ }
255
+ if (foundOptions.length === 0) {
256
+ enteredKeys.current = '';
257
+ return;
258
+ }
259
+ }
260
+ const foundValue = foundOptions[0];
261
+ const index = options.indexOf(foundValue);
262
+ if (section.type === 'dayPeriod') {
263
+ setSection(sectionIndex, index === 1 ? 12 : 0);
264
+ }
265
+ else {
266
+ setSection(sectionIndex, index);
267
+ }
268
+ if (foundOptions.length > 1) {
269
+ enteredKeys.current = newValue;
270
+ }
271
+ else {
272
+ enteredKeys.current = '';
273
+ this.focusNextSection();
274
+ }
275
+ };
276
+ switch (section.type) {
277
+ case 'day':
278
+ case 'hour':
279
+ case 'minute':
280
+ case 'second':
281
+ case 'year': {
282
+ if (!Number.isInteger(Number(newValue))) {
283
+ return;
284
+ }
285
+ const numberValue = Number(newValue);
286
+ onInputNumber(numberValue);
287
+ break;
288
+ }
289
+ case 'dayPeriod': {
290
+ onInputString(newValue);
291
+ break;
292
+ }
293
+ case 'weekday':
294
+ case 'month': {
295
+ if (Number.isInteger(Number(newValue))) {
296
+ const numberValue = Number(newValue);
297
+ onInputNumber(numberValue);
298
+ }
299
+ else {
300
+ onInputString(newValue);
301
+ }
302
+ break;
303
+ }
304
+ }
305
+ },
306
+ setValueFromString(str) {
307
+ enteredKeys.current = '';
308
+ return setValueFromString(str);
309
+ },
310
+ };
311
+ }
@@ -1,6 +1,9 @@
1
+ import type { DateTime } from '@gravity-ui/date-utils';
1
2
  import type { TextInputProps } from '@gravity-ui/uikit';
2
- import type { DateFieldProps } from '../DateField';
3
- import type { DateFieldState } from './useDateFieldState';
4
- export declare function useDateFieldProps(state: DateFieldState, props: DateFieldProps): {
3
+ import type { AccessibilityProps, DateFieldBase, TextInputProps as DateFieldTextInputProps, DomProps, FocusableProps, InputDOMProps, KeyboardEvents, StyleProps, TextInputExtendProps } from '../../types';
4
+ import type { BaseDateFieldState } from './useBaseDateFieldState';
5
+ export interface DateFieldProps<T = DateTime> extends DateFieldBase<T>, DateFieldTextInputProps, TextInputExtendProps, DomProps, InputDOMProps, FocusableProps, KeyboardEvents, StyleProps, AccessibilityProps {
6
+ }
7
+ export declare function useDateFieldProps<T = DateTime>(state: BaseDateFieldState<T>, props: DateFieldProps<T>): {
5
8
  inputProps: TextInputProps;
6
9
  };
@@ -23,11 +23,13 @@ export function useDateFieldProps(state, props) {
23
23
  }
24
24
  const firstSelectedSection = state.sections[state.selectedSectionIndexes.startIndex];
25
25
  const lastSelectedSection = state.sections[state.selectedSectionIndexes.endIndex];
26
- const selectionStart = firstSelectedSection.start;
27
- const selectionEnd = lastSelectedSection.end;
28
- if (selectionStart !== inputElement.selectionStart ||
29
- selectionEnd !== inputElement.selectionEnd) {
30
- inputElement.setSelectionRange(selectionStart, selectionEnd);
26
+ if (firstSelectedSection && lastSelectedSection) {
27
+ const selectionStart = firstSelectedSection.start;
28
+ const selectionEnd = lastSelectedSection.end;
29
+ if (selectionStart !== inputElement.selectionStart ||
30
+ selectionEnd !== inputElement.selectionEnd) {
31
+ inputElement.setSelectionRange(selectionStart, selectionEnd);
32
+ }
31
33
  }
32
34
  });
33
35
  function syncSelectionFromDOM() {
@@ -59,16 +61,16 @@ export function useDateFieldProps(state, props) {
59
61
  placeholder: props.placeholder,
60
62
  id: props.id,
61
63
  label: props.label,
62
- leftContent: props.leftContent,
63
- rightContent: props.rightContent,
64
+ startContent: props.startContent,
65
+ endContent: props.endContent,
64
66
  pin: props.pin,
65
67
  autoFocus: props.autoFocus,
66
68
  controlRef: inputRef,
67
69
  autoComplete: 'off',
68
70
  type: 'text',
69
- // @ts-expect-error
70
- error: (state.validationState === 'invalid' && props.errorMessage) ||
71
- state.validationState === 'invalid',
71
+ validationState: state.validationState,
72
+ errorMessage: props.errorMessage,
73
+ errorPlacement: props.errorPlacement,
72
74
  onUpdate(value) {
73
75
  if (!value) {
74
76
  state.clearAll();
@@ -184,9 +186,9 @@ export function useDateFieldProps(state, props) {
184
186
  const activeSection = state.sections[state.selectedSectionIndexes.startIndex];
185
187
  const digitsOnly = /^\d+$/.test(pastedValue);
186
188
  const lettersOnly = /^[a-zA-Z]+$/.test(pastedValue);
187
- const isValidValue = Boolean(activeSection) &&
189
+ const isValidValue = Boolean(activeSection &&
188
190
  ((activeSection.contentType === 'digit' && digitsOnly) ||
189
- (activeSection.contentType === 'letter' && lettersOnly));
191
+ (activeSection.contentType === 'letter' && lettersOnly)));
190
192
  if (isValidValue) {
191
193
  state.onInput(pastedValue);
192
194
  return;
@@ -1,69 +1,6 @@
1
- import type { DateTime } from '@gravity-ui/date-utils';
2
1
  import type { DateFieldBase } from '../../types/datePicker';
3
- import type { ValidationState } from '../../types/inputs';
4
- import type { DateFieldSection } from '../types';
2
+ import type { BaseDateFieldState } from './useBaseDateFieldState';
5
3
  export interface DateFieldStateOptions extends DateFieldBase {
6
4
  }
7
- export type DateFieldState = {
8
- /** The current field value. */
9
- value: DateTime | null;
10
- /** Is no part of value is filled. */
11
- isEmpty: boolean;
12
- /** The current used value. value or placeholderValue */
13
- displayValue: DateTime;
14
- /** Sets the field's value. */
15
- setValue: (value: DateTime) => void;
16
- /** Formatted value */
17
- text: string;
18
- /** Whether the field is read only. */
19
- readOnly?: boolean;
20
- /** Whether the field is disabled. */
21
- disabled?: boolean;
22
- /** A list of segments for the current value. */
23
- sections: DateFieldSection[];
24
- /** Selected sections */
25
- selectedSectionIndexes: {
26
- startIndex: number;
27
- endIndex: number;
28
- } | null;
29
- /** The current validation state of the date field, based on the `validationState`, `minValue`, and `maxValue` props. */
30
- validationState?: ValidationState;
31
- /** Sets selection for segment in position. */
32
- setSelectedSections: (position: number | 'all') => void;
33
- /** Focuses segment in position */
34
- focusSectionInPosition: (position: number) => void;
35
- /** Focuses the next segment if present */
36
- focusNextSection: () => void;
37
- /** Focuses the previous segment if present */
38
- focusPreviousSection: () => void;
39
- /** Focuses the first segment */
40
- focusFirstSection: () => void;
41
- /** Focuses the last segment */
42
- focusLastSection: () => void;
43
- /** Increments the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */
44
- increment: () => void;
45
- /** Decrements the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */
46
- decrement: () => void;
47
- /**
48
- * Increments the currently selected segment by a larger amount, rounding it to the nearest increment.
49
- * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.
50
- * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.
51
- */
52
- incrementPage: () => void;
53
- /**
54
- * Decrements the currently selected segment by a larger amount, rounding it to the nearest decrement.
55
- * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.
56
- * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.
57
- */
58
- decrementPage: () => void;
59
- incrementToMax: () => void;
60
- decrementToMin: () => void;
61
- /** Clears the value of the currently selected segment, reverting it to the placeholder. */
62
- clearSection: () => void;
63
- /** Clears all segments, reverting them to the placeholder. */
64
- clearAll: () => void;
65
- /** Handles input key in the currently selected segment */
66
- onInput: (key: string) => void;
67
- setValueFromString: (str: string) => boolean;
68
- };
5
+ export type DateFieldState = BaseDateFieldState;
69
6
  export declare function useDateFieldState(props: DateFieldStateOptions): DateFieldState;