react-native-paper-dates 0.4.5 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/README.md +80 -16
  2. package/lib/commonjs/Date/AnimatedCrossView.js +9 -8
  3. package/lib/commonjs/Date/AnimatedCrossView.js.map +1 -1
  4. package/lib/commonjs/Date/AutoSizer.js +6 -5
  5. package/lib/commonjs/Date/AutoSizer.js.map +1 -1
  6. package/lib/commonjs/Date/Calendar.js +46 -39
  7. package/lib/commonjs/Date/Calendar.js.map +1 -1
  8. package/lib/commonjs/Date/CalendarEdit.js +35 -110
  9. package/lib/commonjs/Date/CalendarEdit.js.map +1 -1
  10. package/lib/commonjs/Date/CalendarHeader.js +19 -12
  11. package/lib/commonjs/Date/CalendarHeader.js.map +1 -1
  12. package/lib/commonjs/Date/DatePickerInput.js +93 -20
  13. package/lib/commonjs/Date/DatePickerInput.js.map +1 -1
  14. package/lib/commonjs/Date/DatePickerModal.js +4 -6
  15. package/lib/commonjs/Date/DatePickerModal.js.map +1 -1
  16. package/lib/commonjs/Date/DatePickerModalContent.js +9 -5
  17. package/lib/commonjs/Date/DatePickerModalContent.js.map +1 -1
  18. package/lib/commonjs/Date/DatePickerModalContentHeader.js +42 -34
  19. package/lib/commonjs/Date/DatePickerModalContentHeader.js.map +1 -1
  20. package/lib/commonjs/Date/DatePickerModalHeader.js +14 -6
  21. package/lib/commonjs/Date/DatePickerModalHeader.js.map +1 -1
  22. package/lib/commonjs/Date/DatePickerModalHeaderBackground.js +6 -5
  23. package/lib/commonjs/Date/DatePickerModalHeaderBackground.js.map +1 -1
  24. package/lib/commonjs/Date/DateRangeInput.js +23 -24
  25. package/lib/commonjs/Date/DateRangeInput.js.map +1 -1
  26. package/lib/commonjs/Date/Day.js +7 -3
  27. package/lib/commonjs/Date/Day.js.map +1 -1
  28. package/lib/commonjs/Date/DayName.js +6 -5
  29. package/lib/commonjs/Date/DayName.js.map +1 -1
  30. package/lib/commonjs/Date/DayNames.js +7 -6
  31. package/lib/commonjs/Date/DayNames.js.map +1 -1
  32. package/lib/commonjs/Date/DayRange.js +9 -8
  33. package/lib/commonjs/Date/DayRange.js.map +1 -1
  34. package/lib/commonjs/Date/Month.js +57 -49
  35. package/lib/commonjs/Date/Month.js.map +1 -1
  36. package/lib/commonjs/Date/Swiper.js +35 -29
  37. package/lib/commonjs/Date/Swiper.js.map +1 -1
  38. package/lib/commonjs/Date/Swiper.native.js +29 -23
  39. package/lib/commonjs/Date/Swiper.native.js.map +1 -1
  40. package/lib/commonjs/Date/SwiperUtils.js +7 -6
  41. package/lib/commonjs/Date/SwiperUtils.js.map +1 -1
  42. package/lib/commonjs/Date/YearPicker.js +28 -20
  43. package/lib/commonjs/Date/YearPicker.js.map +1 -1
  44. package/lib/commonjs/Date/dateUtils.js +107 -38
  45. package/lib/commonjs/Date/dateUtils.js.map +1 -1
  46. package/lib/commonjs/Date/inputUtils.js +84 -0
  47. package/lib/commonjs/Date/inputUtils.js.map +1 -0
  48. package/lib/commonjs/TextInputMask.js +11 -10
  49. package/lib/commonjs/TextInputMask.js.map +1 -1
  50. package/lib/commonjs/Time/AmPmSwitcher.js +37 -19
  51. package/lib/commonjs/Time/AmPmSwitcher.js.map +1 -1
  52. package/lib/commonjs/Time/AnalogClock.js +28 -26
  53. package/lib/commonjs/Time/AnalogClock.js.map +1 -1
  54. package/lib/commonjs/Time/AnalogClockHours.js +18 -12
  55. package/lib/commonjs/Time/AnalogClockHours.js.map +1 -1
  56. package/lib/commonjs/Time/AnalogClockMinutes.js +9 -8
  57. package/lib/commonjs/Time/AnalogClockMinutes.js.map +1 -1
  58. package/lib/commonjs/Time/AnimatedClockSwitcher.js +8 -7
  59. package/lib/commonjs/Time/AnimatedClockSwitcher.js.map +1 -1
  60. package/lib/commonjs/Time/TimeInput.js +16 -12
  61. package/lib/commonjs/Time/TimeInput.js.map +1 -1
  62. package/lib/commonjs/Time/TimeInputs.js +12 -11
  63. package/lib/commonjs/Time/TimeInputs.js.map +1 -1
  64. package/lib/commonjs/Time/TimePicker.js +39 -17
  65. package/lib/commonjs/Time/TimePicker.js.map +1 -1
  66. package/lib/commonjs/Time/TimePickerModal.js +19 -15
  67. package/lib/commonjs/Time/TimePickerModal.js.map +1 -1
  68. package/lib/commonjs/Time/timeUtils.js +17 -9
  69. package/lib/commonjs/Time/timeUtils.js.map +1 -1
  70. package/lib/commonjs/index.js +66 -5
  71. package/lib/commonjs/index.js.map +1 -1
  72. package/lib/commonjs/translations/en.js +20 -0
  73. package/lib/commonjs/translations/en.js.map +1 -0
  74. package/lib/commonjs/translations/enGB.js +20 -0
  75. package/lib/commonjs/translations/enGB.js.map +1 -0
  76. package/lib/commonjs/translations/nl.js +20 -0
  77. package/lib/commonjs/translations/nl.js.map +1 -0
  78. package/lib/commonjs/translations/pl.js +20 -0
  79. package/lib/commonjs/translations/pl.js.map +1 -0
  80. package/lib/commonjs/translations/utils.js +31 -0
  81. package/lib/commonjs/translations/utils.js.map +1 -0
  82. package/lib/commonjs/utils.js +19 -9
  83. package/lib/commonjs/utils.js.map +1 -1
  84. package/lib/module/Date/AnimatedCrossView.js +7 -6
  85. package/lib/module/Date/AnimatedCrossView.js.map +1 -1
  86. package/lib/module/Date/AutoSizer.js +4 -3
  87. package/lib/module/Date/AutoSizer.js.map +1 -1
  88. package/lib/module/Date/Calendar.js +46 -39
  89. package/lib/module/Date/Calendar.js.map +1 -1
  90. package/lib/module/Date/CalendarEdit.js +31 -103
  91. package/lib/module/Date/CalendarEdit.js.map +1 -1
  92. package/lib/module/Date/CalendarHeader.js +16 -9
  93. package/lib/module/Date/CalendarHeader.js.map +1 -1
  94. package/lib/module/Date/DatePickerInput.js +88 -18
  95. package/lib/module/Date/DatePickerInput.js.map +1 -1
  96. package/lib/module/Date/DatePickerModal.js +3 -5
  97. package/lib/module/Date/DatePickerModal.js.map +1 -1
  98. package/lib/module/Date/DatePickerModalContent.js +7 -3
  99. package/lib/module/Date/DatePickerModalContent.js.map +1 -1
  100. package/lib/module/Date/DatePickerModalContentHeader.js +37 -30
  101. package/lib/module/Date/DatePickerModalContentHeader.js.map +1 -1
  102. package/lib/module/Date/DatePickerModalHeader.js +11 -4
  103. package/lib/module/Date/DatePickerModalHeader.js.map +1 -1
  104. package/lib/module/Date/DatePickerModalHeaderBackground.js +4 -3
  105. package/lib/module/Date/DatePickerModalHeaderBackground.js.map +1 -1
  106. package/lib/module/Date/DateRangeInput.js +22 -22
  107. package/lib/module/Date/DateRangeInput.js.map +1 -1
  108. package/lib/module/Date/Day.js +5 -1
  109. package/lib/module/Date/Day.js.map +1 -1
  110. package/lib/module/Date/DayName.js +4 -3
  111. package/lib/module/Date/DayName.js.map +1 -1
  112. package/lib/module/Date/DayNames.js +5 -4
  113. package/lib/module/Date/DayNames.js.map +1 -1
  114. package/lib/module/Date/DayRange.js +7 -6
  115. package/lib/module/Date/DayRange.js.map +1 -1
  116. package/lib/module/Date/Month.js +52 -45
  117. package/lib/module/Date/Month.js.map +1 -1
  118. package/lib/module/Date/Swiper.js +32 -26
  119. package/lib/module/Date/Swiper.js.map +1 -1
  120. package/lib/module/Date/Swiper.native.js +27 -21
  121. package/lib/module/Date/Swiper.native.js.map +1 -1
  122. package/lib/module/Date/SwiperUtils.js +5 -4
  123. package/lib/module/Date/SwiperUtils.js.map +1 -1
  124. package/lib/module/Date/YearPicker.js +26 -18
  125. package/lib/module/Date/YearPicker.js.map +1 -1
  126. package/lib/module/Date/dateUtils.js +79 -30
  127. package/lib/module/Date/dateUtils.js.map +1 -1
  128. package/lib/module/Date/inputUtils.js +70 -0
  129. package/lib/module/Date/inputUtils.js.map +1 -0
  130. package/lib/module/TextInputMask.js +9 -8
  131. package/lib/module/TextInputMask.js.map +1 -1
  132. package/lib/module/Time/AmPmSwitcher.js +35 -18
  133. package/lib/module/Time/AmPmSwitcher.js.map +1 -1
  134. package/lib/module/Time/AnalogClock.js +20 -17
  135. package/lib/module/Time/AnalogClock.js.map +1 -1
  136. package/lib/module/Time/AnalogClockHours.js +15 -10
  137. package/lib/module/Time/AnalogClockHours.js.map +1 -1
  138. package/lib/module/Time/AnalogClockMinutes.js +6 -5
  139. package/lib/module/Time/AnalogClockMinutes.js.map +1 -1
  140. package/lib/module/Time/AnimatedClockSwitcher.js +6 -5
  141. package/lib/module/Time/AnimatedClockSwitcher.js.map +1 -1
  142. package/lib/module/Time/TimeInput.js +14 -10
  143. package/lib/module/Time/TimeInput.js.map +1 -1
  144. package/lib/module/Time/TimeInputs.js +10 -9
  145. package/lib/module/Time/TimeInputs.js.map +1 -1
  146. package/lib/module/Time/TimePicker.js +34 -13
  147. package/lib/module/Time/TimePicker.js.map +1 -1
  148. package/lib/module/Time/TimePickerModal.js +17 -13
  149. package/lib/module/Time/TimePickerModal.js.map +1 -1
  150. package/lib/module/Time/timeUtils.js +8 -2
  151. package/lib/module/Time/timeUtils.js.map +1 -1
  152. package/lib/module/index.js +6 -0
  153. package/lib/module/index.js.map +1 -1
  154. package/lib/module/translations/en.js +13 -0
  155. package/lib/module/translations/en.js.map +1 -0
  156. package/lib/module/translations/enGB.js +13 -0
  157. package/lib/module/translations/enGB.js.map +1 -0
  158. package/lib/module/translations/nl.js +13 -0
  159. package/lib/module/translations/nl.js.map +1 -0
  160. package/lib/module/translations/pl.js +13 -0
  161. package/lib/module/translations/pl.js.map +1 -0
  162. package/lib/module/translations/utils.js +22 -0
  163. package/lib/module/translations/utils.js.map +1 -0
  164. package/lib/module/utils.js +11 -5
  165. package/lib/module/utils.js.map +1 -1
  166. package/lib/typescript/{src/Date → Date}/AnimatedCrossView.d.ts +0 -0
  167. package/lib/typescript/{src/Date → Date}/AutoSizer.d.ts +0 -0
  168. package/lib/typescript/{src/Date → Date}/Calendar.d.ts +5 -3
  169. package/lib/typescript/{src/Date → Date}/CalendarEdit.d.ts +4 -3
  170. package/lib/typescript/{src/Date → Date}/CalendarHeader.d.ts +1 -1
  171. package/lib/typescript/Date/DatePickerInput.d.ts +18 -0
  172. package/lib/typescript/{src/Date → Date}/DatePickerModal.d.ts +0 -0
  173. package/lib/typescript/{src/Date → Date}/DatePickerModalContent.d.ts +2 -0
  174. package/lib/typescript/{src/Date → Date}/DatePickerModalContentHeader.d.ts +4 -4
  175. package/lib/typescript/{src/Date → Date}/DatePickerModalHeader.d.ts +1 -0
  176. package/lib/typescript/{src/Date → Date}/DatePickerModalHeaderBackground.d.ts +0 -0
  177. package/lib/typescript/Date/DateRangeInput.d.ts +3 -0
  178. package/lib/typescript/{src/Date → Date}/Day.d.ts +0 -0
  179. package/lib/typescript/{src/Date → Date}/DayName.d.ts +0 -0
  180. package/lib/typescript/{src/Date → Date}/DayNames.d.ts +0 -0
  181. package/lib/typescript/{src/Date → Date}/DayRange.d.ts +0 -0
  182. package/lib/typescript/{src/Date → Date}/Month.d.ts +0 -0
  183. package/lib/typescript/{src/Date → Date}/Swiper.d.ts +0 -0
  184. package/lib/typescript/{src/Date → Date}/Swiper.native.d.ts +0 -0
  185. package/lib/typescript/{src/Date → Date}/SwiperUtils.d.ts +1 -1
  186. package/lib/typescript/{src/Date → Date}/Week.d.ts +0 -0
  187. package/lib/typescript/{src/Date → Date}/YearPicker.d.ts +0 -0
  188. package/lib/typescript/{src/Date → Date}/dateUtils.d.ts +15 -0
  189. package/lib/typescript/{src/Date → Date}/dateUtils.test.d.ts +0 -0
  190. package/lib/typescript/Date/inputUtils.d.ts +14 -0
  191. package/lib/typescript/TextInputMask.d.ts +11 -0
  192. package/lib/typescript/Time/AmPmSwitcher.d.ts +4 -0
  193. package/lib/typescript/{src/Time → Time}/AnalogClock.d.ts +1 -2
  194. package/lib/typescript/{src/Time → Time}/AnalogClockHours.d.ts +0 -0
  195. package/lib/typescript/{src/Time → Time}/AnalogClockMinutes.d.ts +0 -0
  196. package/lib/typescript/{src/Time → Time}/AnimatedClockSwitcher.d.ts +0 -0
  197. package/lib/typescript/{src/Time → Time}/TimeInput.d.ts +0 -0
  198. package/lib/typescript/{src/Time → Time}/TimeInputs.d.ts +1 -1
  199. package/lib/typescript/{src/Time → Time}/TimePicker.d.ts +4 -0
  200. package/lib/typescript/{src/Time → Time}/TimePickerModal.d.ts +1 -1
  201. package/lib/typescript/{src/Time → Time}/timeUtils.d.ts +1 -0
  202. package/lib/typescript/index.d.ts +13 -0
  203. package/lib/typescript/translations/en.d.ts +3 -0
  204. package/lib/typescript/translations/enGB.d.ts +3 -0
  205. package/lib/typescript/translations/nl.d.ts +3 -0
  206. package/lib/typescript/translations/pl.d.ts +3 -0
  207. package/lib/typescript/translations/utils.d.ts +13 -0
  208. package/lib/typescript/utils.d.ts +58 -0
  209. package/package.json +39 -31
  210. package/src/.DS_Store +0 -0
  211. package/src/Date/Calendar.tsx +14 -13
  212. package/src/Date/CalendarEdit.tsx +21 -120
  213. package/src/Date/CalendarHeader.tsx +15 -3
  214. package/src/Date/DatePickerInput.tsx +103 -25
  215. package/src/Date/DatePickerModal.tsx +3 -8
  216. package/src/Date/DatePickerModalContent.tsx +6 -0
  217. package/src/Date/DatePickerModalContentHeader.tsx +21 -12
  218. package/src/Date/DatePickerModalHeader.tsx +13 -2
  219. package/src/Date/DateRangeInput.tsx +26 -17
  220. package/src/Date/Day.tsx +4 -0
  221. package/src/Date/Month.tsx +18 -44
  222. package/src/Date/Swiper.tsx +1 -0
  223. package/src/Date/SwiperUtils.ts +1 -1
  224. package/src/Date/YearPicker.tsx +4 -1
  225. package/src/Date/dateUtils.tsx +71 -10
  226. package/src/Date/inputUtils.ts +94 -0
  227. package/src/TextInputMask.tsx +10 -3
  228. package/src/Time/AmPmSwitcher.tsx +20 -11
  229. package/src/Time/AnalogClock.tsx +10 -18
  230. package/src/Time/AnalogClockHours.tsx +15 -6
  231. package/src/Time/AnalogClockMinutes.tsx +5 -2
  232. package/src/Time/TimeInput.tsx +3 -0
  233. package/src/Time/TimeInputs.tsx +1 -5
  234. package/src/Time/TimePicker.tsx +46 -23
  235. package/src/Time/TimePickerModal.tsx +4 -1
  236. package/src/Time/timeUtils.ts +7 -1
  237. package/src/index.tsx +7 -0
  238. package/src/translations/en.ts +15 -0
  239. package/src/translations/enGB.ts +15 -0
  240. package/src/translations/nl.ts +15 -0
  241. package/src/translations/pl.ts +15 -0
  242. package/src/translations/utils.ts +42 -0
  243. package/src/utils.ts +13 -5
  244. package/lib/typescript/src/Date/DatePickerInput.d.ts +0 -1
  245. package/lib/typescript/src/Date/DateRangeInput.d.ts +0 -1
  246. package/lib/typescript/src/TextInputMask.d.ts +0 -3
  247. package/lib/typescript/src/Time/AmPmSwitcher.d.ts +0 -4
  248. package/lib/typescript/src/index.d.ts +0 -6
  249. package/lib/typescript/src/utils.d.ts +0 -7
@@ -6,11 +6,10 @@ import {
6
6
  Keyboard,
7
7
  } from 'react-native'
8
8
 
9
- import { CalendarDate, ModeType, ValidRangeType } from './Calendar'
10
- import { LocalState } from './DatePickerModalContent'
11
- import TextInputWithMask from '../TextInputMask'
12
- import { HelperText, useTheme } from 'react-native-paper'
13
- import { dateToUnix, isDateWithinOptionalRange } from './dateUtils'
9
+ import type { ModeType, ValidRangeType } from './Calendar'
10
+ import type { LocalState } from './DatePickerModalContent'
11
+
12
+ import DatePickerInput from './DatePickerInput'
14
13
 
15
14
  function CalendarEdit({
16
15
  mode,
@@ -21,6 +20,7 @@ function CalendarEdit({
21
20
  collapsed,
22
21
  onChange,
23
22
  validRange,
23
+ locale,
24
24
  }: {
25
25
  mode: ModeType
26
26
  label?: string
@@ -30,6 +30,7 @@ function CalendarEdit({
30
30
  collapsed: boolean
31
31
  onChange: (s: LocalState) => any
32
32
  validRange: ValidRangeType | undefined
33
+ locale: string
33
34
  }) {
34
35
  const dateInput = React.useRef<TextInputNative | null>(null)
35
36
  const startInput = React.useRef<TextInputNative | null>(null)
@@ -77,18 +78,23 @@ function CalendarEdit({
77
78
  <View style={styles.root}>
78
79
  <View style={styles.inner}>
79
80
  {mode === 'single' ? (
80
- <CalendarInput
81
+ <DatePickerInput
82
+ inputMode="start"
81
83
  ref={dateInput}
82
84
  label={label}
83
85
  value={state.date}
84
86
  onChange={(date) => onChange({ ...state, date })}
85
87
  onSubmitEditing={onSubmitInput}
86
88
  validRange={validRange}
89
+ locale={locale}
90
+ withModal={false}
91
+ autoCompleteType={'off'}
87
92
  />
88
93
  ) : null}
89
94
  {mode === 'range' ? (
90
95
  <>
91
- <CalendarInput
96
+ <DatePickerInput
97
+ inputMode="start"
92
98
  ref={startInput}
93
99
  label={startLabel}
94
100
  value={state.startDate}
@@ -96,16 +102,22 @@ function CalendarEdit({
96
102
  returnKeyType={'next'}
97
103
  onSubmitEditing={onSubmitStartInput}
98
104
  validRange={validRange}
105
+ locale={locale}
106
+ withModal={false}
107
+ autoCompleteType={'off'}
99
108
  />
100
109
  <View style={styles.separator} />
101
- <CalendarInput
110
+ <DatePickerInput
111
+ inputMode="end"
102
112
  ref={endInput}
103
113
  label={endLabel}
104
114
  value={state.endDate}
105
115
  onChange={(endDate) => onChange({ ...state, endDate })}
106
- isEndDate
107
116
  onSubmitEditing={onSubmitEndInput}
108
117
  validRange={validRange}
118
+ locale={locale}
119
+ withModal={false}
120
+ autoCompleteType={'off'}
109
121
  />
110
122
  </>
111
123
  ) : null}
@@ -114,117 +126,6 @@ function CalendarEdit({
114
126
  )
115
127
  }
116
128
 
117
- function CalendarInputPure(
118
- {
119
- label,
120
- value,
121
- onChange,
122
- isEndDate,
123
- returnKeyType,
124
- onSubmitEditing,
125
- locale,
126
- validRange,
127
- }: {
128
- locale?: undefined | string
129
- label: string
130
- value: CalendarDate
131
- onChange: (d: Date | undefined) => any
132
- isEndDate?: boolean
133
- returnKeyType?: string
134
- onSubmitEditing?: () => any
135
- validRange: ValidRangeType | undefined
136
- },
137
- ref: any
138
- ) {
139
- const theme = useTheme()
140
- const [error, setError] = React.useState<null | string>(null)
141
- const formatter = React.useMemo(() => {
142
- return new Intl.DateTimeFormat(locale, {
143
- month: '2-digit',
144
- day: '2-digit',
145
- year: 'numeric',
146
- })
147
- }, [locale])
148
-
149
- const inputFormat = React.useMemo(() => {
150
- // TODO: something cleaner and more universal?
151
- const inputDate = formatter.format(new Date(2020, 10 - 1, 1))
152
- return inputDate
153
- .replace('2020', 'YYYY')
154
- .replace('10', 'MM')
155
- .replace('01', 'DD')
156
- }, [formatter])
157
-
158
- const formattedValue = formatter.format(value)
159
- const onChangeText = (date: string) => {
160
- const dayIndex = inputFormat.indexOf('DD')
161
- const monthIndex = inputFormat.indexOf('MM')
162
- const yearIndex = inputFormat.indexOf('YYYY')
163
-
164
- const day = Number(date.slice(dayIndex, dayIndex + 2))
165
- const year = Number(date.slice(yearIndex, yearIndex + 4))
166
- const month = Number(date.slice(monthIndex, monthIndex + 2))
167
-
168
- if (Number.isNaN(day) || Number.isNaN(year) || Number.isNaN(month)) {
169
- setError(inputFormat)
170
- return
171
- }
172
-
173
- const finalDate = isEndDate
174
- ? new Date(year, month - 1, day, 23, 59, 59)
175
- : new Date(year, month - 1, day)
176
-
177
- const validStart = validRange?.startDate
178
- const validEnd = validRange?.endDate
179
- if (
180
- !isDateWithinOptionalRange(finalDate, {
181
- startUnix: validStart ? dateToUnix(validStart) : undefined,
182
- endUnix: validEnd ? dateToUnix(validEnd) : undefined,
183
- })
184
- ) {
185
- let errors =
186
- validStart && validEnd
187
- ? [`${formatter.format(validStart)} - ${formatter.format(validEnd)}`]
188
- : [
189
- validStart ? `> ${formatter.format(validStart)}` : '',
190
- validEnd ? `< ${formatter.format(validEnd)}` : '',
191
- ]
192
- setError(errors.filter((n) => n).join(' '))
193
- return
194
- }
195
-
196
- setError(null)
197
- if (isEndDate) {
198
- onChange(finalDate)
199
- } else {
200
- onChange(finalDate)
201
- }
202
- }
203
- return (
204
- <View style={styles.inputContainer}>
205
- <TextInputWithMask
206
- ref={ref}
207
- value={formattedValue}
208
- style={styles.input}
209
- label={`${label} (${inputFormat})`}
210
- keyboardType={'number-pad'}
211
- placeholder={inputFormat}
212
- mask={inputFormat}
213
- onChangeText={onChangeText}
214
- returnKeyType={returnKeyType}
215
- onSubmitEditing={onSubmitEditing}
216
- keyboardAppearance={theme.dark ? 'dark' : 'default'}
217
- error={!!error}
218
- />
219
- <HelperText type="error" visible={!!error}>
220
- {error}
221
- </HelperText>
222
- </View>
223
- )
224
- }
225
-
226
- const CalendarInput = React.forwardRef(CalendarInputPure)
227
-
228
129
  const styles = StyleSheet.create({
229
130
  root: { padding: 12 },
230
131
  inner: { flexDirection: 'row' },
@@ -2,7 +2,7 @@ import * as React from 'react'
2
2
  import { StyleSheet, View } from 'react-native'
3
3
  import { IconButton, useTheme } from 'react-native-paper'
4
4
  import DayNames, { dayNamesHeight } from './DayNames'
5
- import { DisableWeekDaysType } from './dateUtils'
5
+ import type { DisableWeekDaysType } from './dateUtils'
6
6
 
7
7
  const buttonContainerHeight = 56
8
8
  const buttonContainerMarginTop = 4
@@ -46,7 +46,13 @@ function CalendarHeader({
46
46
  { backgroundColor: theme.colors.surface },
47
47
  ]}
48
48
  >
49
- <IconButton icon="chevron-left" onPress={onPrev} />
49
+ <IconButton
50
+ icon="chevron-left"
51
+ onPress={onPrev}
52
+ // RN types bug
53
+ hasTVPreferredFocus={undefined}
54
+ tvParallaxProperties={undefined}
55
+ />
50
56
  </View>
51
57
 
52
58
  <View
@@ -55,7 +61,13 @@ function CalendarHeader({
55
61
  { backgroundColor: theme.colors.surface },
56
62
  ]}
57
63
  >
58
- <IconButton icon="chevron-right" onPress={onNext} />
64
+ <IconButton
65
+ icon="chevron-right"
66
+ onPress={onNext}
67
+ // RN types bug
68
+ hasTVPreferredFocus={undefined}
69
+ tvParallaxProperties={undefined}
70
+ />
59
71
  </View>
60
72
  </View>
61
73
  ) : null}
@@ -1,54 +1,132 @@
1
1
  import * as React from 'react'
2
2
 
3
3
  import TextInputWithMask from '../TextInputMask'
4
- import { IconButton } from 'react-native-paper'
4
+ import { HelperText, IconButton, TextInput, useTheme } from 'react-native-paper'
5
5
  import { View, StyleSheet } from 'react-native'
6
6
  import DatePickerModal from './DatePickerModal'
7
+ import useDateInput from './inputUtils'
8
+ import type { ValidRangeType } from './Calendar'
9
+ import { useLatest } from '../utils'
10
+
11
+ function DatePickerInput(
12
+ {
13
+ label,
14
+ value,
15
+ onChange,
16
+ style,
17
+ locale,
18
+ validRange,
19
+ inputMode,
20
+ withModal = true,
21
+ withDateFormatInLabel = true,
22
+ ...rest
23
+ }: Omit<React.ComponentProps<typeof TextInput>, 'value' | 'onChange'> & {
24
+ inputMode: 'start' | 'end'
25
+ locale: string
26
+ onChange: (date: Date | undefined) => void
27
+ value: Date | undefined
28
+ validRange?: ValidRangeType | undefined
29
+ withModal?: boolean
30
+ withDateFormatInLabel?: boolean
31
+ },
32
+ ref: any
33
+ ) {
34
+ const theme = useTheme()
35
+ const { formattedValue, inputFormat, onChangeText, error } = useDateInput({
36
+ locale,
37
+ value,
38
+ validRange,
39
+ inputMode,
40
+ onChange,
41
+ })
7
42
 
8
- export default function DatePickerInput() {
9
43
  const [visible, setVisible] = React.useState<boolean>(false)
10
44
  const onDismiss = React.useCallback(() => {
11
45
  setVisible(false)
12
46
  }, [setVisible])
13
- const onConfirm = React.useCallback(() => {
14
- setVisible(false)
15
- }, [setVisible])
47
+ const onChangeRef = useLatest(onChange)
48
+ const onInnerConfirm = React.useCallback(
49
+ ({ date }) => {
50
+ setVisible(false)
51
+ onChangeRef.current(date)
52
+ },
53
+ [setVisible, onChangeRef]
54
+ )
16
55
 
17
56
  return (
18
57
  <>
19
58
  <View style={styles.root}>
20
59
  <TextInputWithMask
21
- value={''}
22
- keyboardType={'numeric'}
23
- placeholder={'DD-MM-YYY'}
24
- mask={'DD-MM-YYY'}
25
- onChangeText={() => {}}
26
- style={styles.input}
27
- />
28
- <IconButton
29
- size={24}
30
- style={styles.calendarButton}
31
- icon="calendar"
32
- onPress={() => setVisible(true)}
60
+ {...rest}
61
+ ref={ref}
62
+ label={getLabel({ label, inputFormat, withDateFormatInLabel })}
63
+ value={formattedValue}
64
+ keyboardType={'number-pad'}
65
+ placeholder={inputFormat}
66
+ mask={inputFormat}
67
+ onChangeText={onChangeText}
68
+ keyboardAppearance={theme.dark ? 'dark' : 'default'}
69
+ error={!!error}
70
+ style={[styles.input, style]}
33
71
  />
72
+ {withModal ? (
73
+ <IconButton
74
+ size={24}
75
+ style={styles.calendarButton}
76
+ icon="calendar"
77
+ onPress={() => setVisible(true)}
78
+ // RN types bug
79
+ hasTVPreferredFocus={undefined}
80
+ tvParallaxProperties={undefined}
81
+ />
82
+ ) : null}
34
83
  </View>
35
- <DatePickerModal
36
- mode="single"
37
- visible={visible}
38
- onDismiss={onDismiss}
39
- onConfirm={onConfirm}
40
- />
84
+ <HelperText type="error" visible={!!error}>
85
+ {error}
86
+ </HelperText>
87
+
88
+ {withModal ? (
89
+ <DatePickerModal
90
+ date={value}
91
+ mode="single"
92
+ visible={visible}
93
+ onDismiss={onDismiss}
94
+ onConfirm={onInnerConfirm}
95
+ locale={locale}
96
+ dateMode={inputMode}
97
+ />
98
+ ) : null}
41
99
  </>
42
100
  )
43
101
  }
44
102
 
103
+ function getLabel({
104
+ withDateFormatInLabel,
105
+ inputFormat,
106
+ label,
107
+ }: {
108
+ withDateFormatInLabel: boolean
109
+ inputFormat: string
110
+ label: string | undefined
111
+ }) {
112
+ if (withDateFormatInLabel) {
113
+ return label ? `${label} (${inputFormat})` : inputFormat
114
+ }
115
+ return label || ''
116
+ }
117
+
45
118
  const styles = StyleSheet.create({
46
119
  root: {
120
+ minWidth: 150,
47
121
  flexDirection: 'row',
48
122
  position: 'relative',
49
123
  alignItems: 'center',
50
- flex: 1,
124
+ flexGrow: 1,
125
+ alignSelf: 'flex-start',
126
+ },
127
+ input: {
128
+ flexGrow: 1,
51
129
  },
52
- input: { flex: 1 },
53
130
  calendarButton: { position: 'absolute', right: 0 },
54
131
  })
132
+ export default React.forwardRef(DatePickerInput)
@@ -15,9 +15,7 @@ import DatePickerModalContent, {
15
15
  DatePickerModalContentRangeProps,
16
16
  DatePickerModalContentSingleProps,
17
17
  } from './DatePickerModalContent'
18
- import { useMemo } from 'react'
19
- import Color from 'color'
20
- import { useHeaderColorIsLight } from '../utils'
18
+ import { useHeaderBackgroundColor, useHeaderColorIsLight } from '../utils'
21
19
 
22
20
  interface DatePickerModalProps {
23
21
  visible: boolean
@@ -61,10 +59,7 @@ export function DatePickerModal(
61
59
  })
62
60
 
63
61
  const isLight = useHeaderColorIsLight()
64
- const statusBarColor = useMemo<string>(
65
- () => Color(theme.colors.primary).darken(0.2).hex(),
66
- [theme]
67
- )
62
+ const headerBackgroundColor = useHeaderBackgroundColor()
68
63
 
69
64
  return (
70
65
  <View style={[StyleSheet.absoluteFill]} pointerEvents="box-none">
@@ -110,7 +105,7 @@ export function DatePickerModal(
110
105
  style={[
111
106
  {
112
107
  height: StatusBar.currentHeight,
113
- backgroundColor: statusBarColor,
108
+ backgroundColor: headerBackgroundColor,
114
109
  },
115
110
  ]}
116
111
  />
@@ -28,6 +28,7 @@ export type LocalState = {
28
28
 
29
29
  interface DatePickerModalContentBaseProps {
30
30
  inputFormat?: string
31
+ locale: string
31
32
  onDismiss: () => any
32
33
  disableSafeTop?: boolean
33
34
  }
@@ -51,6 +52,7 @@ export interface DatePickerModalContentSingleProps
51
52
  date?: CalendarDate
52
53
  onChange?: SingleChange
53
54
  onConfirm: SingleChange
55
+ dateMode?: 'start' | 'end'
54
56
  }
55
57
 
56
58
  export interface DatePickerModalContentMultiProps
@@ -78,6 +80,7 @@ export function DatePickerModalContent(
78
80
  disableWeekDays,
79
81
  locale,
80
82
  validRange,
83
+ dateMode,
81
84
  } = props
82
85
 
83
86
  const anyProps = props as any
@@ -135,6 +138,7 @@ export function DatePickerModalContent(
135
138
  <>
136
139
  <DatePickerModalHeaderBackground>
137
140
  <DatePickerModalHeader
141
+ locale={locale}
138
142
  onSave={onInnerConfirm}
139
143
  onDismiss={onDismiss}
140
144
  saveLabel={props.saveLabel}
@@ -168,6 +172,7 @@ export function DatePickerModalContent(
168
172
  disableWeekDays={disableWeekDays}
169
173
  dates={state.dates}
170
174
  validRange={validRange}
175
+ dateMode={dateMode}
171
176
  />
172
177
  }
173
178
  calendarEdit={
@@ -180,6 +185,7 @@ export function DatePickerModalContent(
180
185
  collapsed={collapsed}
181
186
  onChange={onInnerChange}
182
187
  validRange={validRange}
188
+ locale={locale}
183
189
  />
184
190
  }
185
191
  />
@@ -1,10 +1,11 @@
1
1
  import * as React from 'react'
2
2
  import { View, StyleSheet } from 'react-native'
3
3
  import { IconButton, Text } from 'react-native-paper'
4
- import { ModeType } from './Calendar'
5
- import { LocalState } from './DatePickerModalContent'
4
+ import type { ModeType } from './Calendar'
5
+ import type { LocalState } from './DatePickerModalContent'
6
6
  import { useHeaderTextColor } from '../utils'
7
7
  import Color from 'color'
8
+ import { getTranslation } from '../translations/utils'
8
9
 
9
10
  export interface HeaderPickProps {
10
11
  moreLabel?: string
@@ -21,30 +22,35 @@ export interface HeaderContentProps extends HeaderPickProps {
21
22
  mode: ModeType
22
23
  collapsed: boolean
23
24
  onToggle: () => any
24
- locale: undefined | string
25
+ locale: string | undefined
25
26
  }
26
27
 
27
- function getLabel(mode: ModeType, configuredLabel?: string) {
28
+ function getLabel(
29
+ locale: string | undefined,
30
+ mode: ModeType,
31
+ configuredLabel?: string
32
+ ) {
28
33
  if (configuredLabel) {
29
34
  return configuredLabel
30
35
  }
31
36
  if (mode === 'range') {
32
- return 'Select period'
37
+ return getTranslation(locale, 'selectRange')
33
38
  }
34
- if (mode === 'single') {
35
- return 'Select date'
36
- }
37
-
38
39
  if (mode === 'multiple') {
39
- return 'Select dates'
40
+ return getTranslation(locale, 'selectMultiple')
41
+ }
42
+ if (mode === 'single') {
43
+ return getTranslation(locale, 'selectSingle')
40
44
  }
41
45
  return '...?'
42
46
  }
43
47
 
44
- export default function DatePickerModalHeader(props: HeaderContentProps) {
48
+ export default function DatePickerModalContentHeader(
49
+ props: HeaderContentProps
50
+ ) {
45
51
  const { onToggle, collapsed, mode, moreLabel } = props
46
52
 
47
- const label = getLabel(props.mode, props.label)
53
+ const label = getLabel(props.locale, props.mode, props.label)
48
54
 
49
55
  const color = useHeaderTextColor()
50
56
  const allowEditing = mode !== 'multiple'
@@ -75,6 +81,9 @@ export default function DatePickerModalHeader(props: HeaderContentProps) {
75
81
  icon={collapsed ? 'pencil' : 'calendar'}
76
82
  color={color}
77
83
  onPress={onToggle}
84
+ // RN types bug
85
+ hasTVPreferredFocus={undefined}
86
+ tvParallaxProperties={undefined}
78
87
  />
79
88
  ) : null}
80
89
  </View>
@@ -3,18 +3,21 @@ import { Animated, StyleSheet, SafeAreaView } from 'react-native'
3
3
  import { Appbar, Button } from 'react-native-paper'
4
4
 
5
5
  import { useHeaderTextColor } from '../utils'
6
+ import { getTranslation } from '../translations/utils'
6
7
 
7
8
  export interface DatePickerModalHeaderProps {
8
9
  disableSafeTop?: boolean
9
10
  saveLabel?: string
10
11
  onDismiss: () => void
11
12
  onSave: () => void
13
+ locale: string | undefined
12
14
  }
13
15
 
14
16
  export default function DatePickerModalHeader(
15
17
  props: DatePickerModalHeaderProps
16
18
  ) {
17
- const { saveLabel = 'Save', disableSafeTop } = props
19
+ const { disableSafeTop, locale } = props
20
+ const saveLabel = props.saveLabel || getTranslation(locale, 'save')
18
21
  const color = useHeaderTextColor()
19
22
  return (
20
23
  <>
@@ -30,9 +33,17 @@ export default function DatePickerModalHeader(
30
33
  icon="close"
31
34
  onPress={props.onDismiss}
32
35
  color={color}
36
+ testID="react-native-paper-dates-close"
37
+ // RN types bug
38
+ hasTVPreferredFocus={undefined}
39
+ tvParallaxProperties={undefined}
33
40
  />
34
41
  <Appbar.Content title={''} />
35
- <Button color={color} onPress={props.onSave}>
42
+ <Button
43
+ color={color}
44
+ onPress={props.onSave}
45
+ testID="react-native-paper-dates-save"
46
+ >
36
47
  {saveLabel}
37
48
  </Button>
38
49
  </Appbar>
@@ -2,10 +2,10 @@ import * as React from 'react'
2
2
  import { View } from 'react-native'
3
3
  import { Text, IconButton } from 'react-native-paper'
4
4
 
5
- import TextInputWithMask from '../TextInputMask'
6
5
  import DatePickerModal from './DatePickerModal'
7
6
 
8
- export default function DateRangeInput() {
7
+ // WORK IN PROGRESS
8
+ export default function DateRangeInput({ locale }: { locale: string }) {
9
9
  const [visible, setVisible] = React.useState<boolean>(false)
10
10
  const onDismiss = React.useCallback(() => {
11
11
  setVisible(false)
@@ -14,19 +14,21 @@ export default function DateRangeInput() {
14
14
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
15
  ({ startDate, endDate }: { startDate: any; endDate: any }) => {
16
16
  setVisible(false)
17
+ console.log({ startDate, endDate })
17
18
  },
18
19
  [setVisible]
19
20
  )
21
+
20
22
  return (
21
23
  <View style={{ flexDirection: 'row', alignItems: 'center' }}>
22
24
  <View style={{ flex: 1 }}>
23
- <TextInputWithMask
24
- value={''}
25
- keyboardType={'numeric'}
26
- placeholder={'DD-MM-YYY'}
27
- mask={'DD-MM-YYY'}
28
- onChangeText={() => {}}
29
- />
25
+ {/*<DatePickerInput*/}
26
+ {/* value={''}*/}
27
+ {/* keyboardType={'numeric'}*/}
28
+ {/* placeholder={'DD-MM-YYY'}*/}
29
+ {/* mask={'DD-MM-YYY'}*/}
30
+ {/* onChangeText={() => {}}*/}
31
+ {/*/>*/}
30
32
  <Text>Van</Text>
31
33
  </View>
32
34
  <View>
@@ -38,22 +40,29 @@ export default function DateRangeInput() {
38
40
  </Text>
39
41
  </View>
40
42
  <View style={{ flex: 1 }}>
41
- <TextInputWithMask
42
- value={''}
43
- keyboardType={'numeric'}
44
- placeholder={'DD-MM-YYY'}
45
- mask={'DD-MM-YYY'}
46
- onChangeText={() => {}}
47
- />
43
+ {/*<DatePickerInput*/}
44
+ {/* // value={''}*/}
45
+ {/* // keyboardType={'numeric'}*/}
46
+ {/* // placeholder={'DD-MM-YYY'}*/}
47
+ {/* // mask={'DD-MM-YYY'}*/}
48
+ {/* // onChangeText={() => {}}*/}
49
+ {/*/>*/}
48
50
  <Text>Tot</Text>
49
51
  </View>
50
52
  <View>
51
- <IconButton icon="calendar" onPress={() => setVisible(true)} />
53
+ <IconButton
54
+ icon="calendar"
55
+ onPress={() => setVisible(true)}
56
+ // RN types bug
57
+ hasTVPreferredFocus={undefined}
58
+ tvParallaxProperties={undefined}
59
+ />
52
60
  <Text style={{ opacity: 0 }} accessible={false}>
53
61
  tot
54
62
  </Text>
55
63
  </View>
56
64
  <DatePickerModal
65
+ locale={locale}
57
66
  mode="range"
58
67
  visible={visible}
59
68
  onDismiss={onDismiss}
package/src/Date/Day.tsx CHANGED
@@ -65,6 +65,7 @@ function Day(props: {
65
65
  />
66
66
 
67
67
  <TouchableRipple
68
+ testID={`react-native-paper-dates-day-${year}-${month}-${day}`}
68
69
  disabled={disabled}
69
70
  borderless={true}
70
71
  onPress={disabled ? undefined : onPress}
@@ -72,6 +73,9 @@ function Day(props: {
72
73
  styles.button,
73
74
  { backgroundColor: inRange ? selectColor : undefined },
74
75
  ]}
76
+ // RN types bug
77
+ hasTVPreferredFocus={undefined}
78
+ tvParallaxProperties={undefined}
75
79
  >
76
80
  <View
77
81
  style={[