react-native-paper-dates 0.4.6 → 0.7.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 (245) hide show
  1. package/README.md +79 -22
  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 +32 -111
  9. package/lib/commonjs/Date/CalendarEdit.js.map +1 -1
  10. package/lib/commonjs/Date/CalendarHeader.js +23 -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 +2 -2
  15. package/lib/commonjs/Date/DatePickerModalContent.js +7 -4
  16. package/lib/commonjs/Date/DatePickerModalContent.js.map +1 -1
  17. package/lib/commonjs/Date/DatePickerModalContentHeader.js +43 -34
  18. package/lib/commonjs/Date/DatePickerModalContentHeader.js.map +1 -1
  19. package/lib/commonjs/Date/DatePickerModalHeader.js +12 -5
  20. package/lib/commonjs/Date/DatePickerModalHeader.js.map +1 -1
  21. package/lib/commonjs/Date/DatePickerModalHeaderBackground.js +6 -5
  22. package/lib/commonjs/Date/DatePickerModalHeaderBackground.js.map +1 -1
  23. package/lib/commonjs/Date/DateRangeInput.js +23 -24
  24. package/lib/commonjs/Date/DateRangeInput.js.map +1 -1
  25. package/lib/commonjs/Date/Day.js +7 -3
  26. package/lib/commonjs/Date/Day.js.map +1 -1
  27. package/lib/commonjs/Date/DayName.js +6 -5
  28. package/lib/commonjs/Date/DayName.js.map +1 -1
  29. package/lib/commonjs/Date/DayNames.js +7 -6
  30. package/lib/commonjs/Date/DayNames.js.map +1 -1
  31. package/lib/commonjs/Date/DayRange.js +9 -8
  32. package/lib/commonjs/Date/DayRange.js.map +1 -1
  33. package/lib/commonjs/Date/Month.js +59 -49
  34. package/lib/commonjs/Date/Month.js.map +1 -1
  35. package/lib/commonjs/Date/Swiper.js +35 -29
  36. package/lib/commonjs/Date/Swiper.js.map +1 -1
  37. package/lib/commonjs/Date/Swiper.native.js +29 -23
  38. package/lib/commonjs/Date/Swiper.native.js.map +1 -1
  39. package/lib/commonjs/Date/SwiperUtils.js +7 -6
  40. package/lib/commonjs/Date/SwiperUtils.js.map +1 -1
  41. package/lib/commonjs/Date/YearPicker.js +30 -20
  42. package/lib/commonjs/Date/YearPicker.js.map +1 -1
  43. package/lib/commonjs/Date/dateUtils.js +106 -37
  44. package/lib/commonjs/Date/dateUtils.js.map +1 -1
  45. package/lib/commonjs/Date/inputUtils.js +84 -0
  46. package/lib/commonjs/Date/inputUtils.js.map +1 -0
  47. package/lib/commonjs/TextInputMask.js +11 -10
  48. package/lib/commonjs/TextInputMask.js.map +1 -1
  49. package/lib/commonjs/Time/AmPmSwitcher.js +37 -19
  50. package/lib/commonjs/Time/AmPmSwitcher.js.map +1 -1
  51. package/lib/commonjs/Time/AnalogClock.js +25 -15
  52. package/lib/commonjs/Time/AnalogClock.js.map +1 -1
  53. package/lib/commonjs/Time/AnalogClockHours.js +17 -11
  54. package/lib/commonjs/Time/AnalogClockHours.js.map +1 -1
  55. package/lib/commonjs/Time/AnalogClockMinutes.js +7 -6
  56. package/lib/commonjs/Time/AnalogClockMinutes.js.map +1 -1
  57. package/lib/commonjs/Time/AnimatedClockSwitcher.js +8 -7
  58. package/lib/commonjs/Time/AnimatedClockSwitcher.js.map +1 -1
  59. package/lib/commonjs/Time/TimeInput.js +16 -12
  60. package/lib/commonjs/Time/TimeInput.js.map +1 -1
  61. package/lib/commonjs/Time/TimeInputs.js +12 -11
  62. package/lib/commonjs/Time/TimeInputs.js.map +1 -1
  63. package/lib/commonjs/Time/TimePicker.js +37 -15
  64. package/lib/commonjs/Time/TimePicker.js.map +1 -1
  65. package/lib/commonjs/Time/TimePickerModal.js +19 -15
  66. package/lib/commonjs/Time/TimePickerModal.js.map +1 -1
  67. package/lib/commonjs/Time/timeUtils.js +14 -9
  68. package/lib/commonjs/Time/timeUtils.js.map +1 -1
  69. package/lib/commonjs/index.js +66 -5
  70. package/lib/commonjs/index.js.map +1 -1
  71. package/lib/commonjs/translations/en.js +25 -0
  72. package/lib/commonjs/translations/en.js.map +1 -0
  73. package/lib/commonjs/translations/enGB.js +25 -0
  74. package/lib/commonjs/translations/enGB.js.map +1 -0
  75. package/lib/commonjs/translations/nl.js +25 -0
  76. package/lib/commonjs/translations/nl.js.map +1 -0
  77. package/lib/commonjs/translations/pl.js +25 -0
  78. package/lib/commonjs/translations/pl.js.map +1 -0
  79. package/lib/commonjs/translations/utils.js +31 -0
  80. package/lib/commonjs/translations/utils.js.map +1 -0
  81. package/lib/commonjs/utils.js +19 -9
  82. package/lib/commonjs/utils.js.map +1 -1
  83. package/lib/module/Date/AnimatedCrossView.js +7 -6
  84. package/lib/module/Date/AnimatedCrossView.js.map +1 -1
  85. package/lib/module/Date/AutoSizer.js +4 -3
  86. package/lib/module/Date/AutoSizer.js.map +1 -1
  87. package/lib/module/Date/Calendar.js +46 -39
  88. package/lib/module/Date/Calendar.js.map +1 -1
  89. package/lib/module/Date/CalendarEdit.js +28 -104
  90. package/lib/module/Date/CalendarEdit.js.map +1 -1
  91. package/lib/module/Date/CalendarHeader.js +19 -9
  92. package/lib/module/Date/CalendarHeader.js.map +1 -1
  93. package/lib/module/Date/DatePickerInput.js +88 -18
  94. package/lib/module/Date/DatePickerInput.js.map +1 -1
  95. package/lib/module/Date/DatePickerModalContent.js +5 -2
  96. package/lib/module/Date/DatePickerModalContent.js.map +1 -1
  97. package/lib/module/Date/DatePickerModalContentHeader.js +38 -30
  98. package/lib/module/Date/DatePickerModalContentHeader.js.map +1 -1
  99. package/lib/module/Date/DatePickerModalHeader.js +9 -3
  100. package/lib/module/Date/DatePickerModalHeader.js.map +1 -1
  101. package/lib/module/Date/DatePickerModalHeaderBackground.js +4 -3
  102. package/lib/module/Date/DatePickerModalHeaderBackground.js.map +1 -1
  103. package/lib/module/Date/DateRangeInput.js +22 -22
  104. package/lib/module/Date/DateRangeInput.js.map +1 -1
  105. package/lib/module/Date/Day.js +5 -1
  106. package/lib/module/Date/Day.js.map +1 -1
  107. package/lib/module/Date/DayName.js +4 -3
  108. package/lib/module/Date/DayName.js.map +1 -1
  109. package/lib/module/Date/DayNames.js +5 -4
  110. package/lib/module/Date/DayNames.js.map +1 -1
  111. package/lib/module/Date/DayRange.js +7 -6
  112. package/lib/module/Date/DayRange.js.map +1 -1
  113. package/lib/module/Date/Month.js +54 -45
  114. package/lib/module/Date/Month.js.map +1 -1
  115. package/lib/module/Date/Swiper.js +32 -26
  116. package/lib/module/Date/Swiper.js.map +1 -1
  117. package/lib/module/Date/Swiper.native.js +27 -21
  118. package/lib/module/Date/Swiper.native.js.map +1 -1
  119. package/lib/module/Date/SwiperUtils.js +5 -4
  120. package/lib/module/Date/SwiperUtils.js.map +1 -1
  121. package/lib/module/Date/YearPicker.js +28 -18
  122. package/lib/module/Date/YearPicker.js.map +1 -1
  123. package/lib/module/Date/dateUtils.js +78 -29
  124. package/lib/module/Date/dateUtils.js.map +1 -1
  125. package/lib/module/Date/inputUtils.js +70 -0
  126. package/lib/module/Date/inputUtils.js.map +1 -0
  127. package/lib/module/TextInputMask.js +9 -8
  128. package/lib/module/TextInputMask.js.map +1 -1
  129. package/lib/module/Time/AmPmSwitcher.js +35 -18
  130. package/lib/module/Time/AmPmSwitcher.js.map +1 -1
  131. package/lib/module/Time/AnalogClock.js +23 -14
  132. package/lib/module/Time/AnalogClock.js.map +1 -1
  133. package/lib/module/Time/AnalogClockHours.js +14 -9
  134. package/lib/module/Time/AnalogClockHours.js.map +1 -1
  135. package/lib/module/Time/AnalogClockMinutes.js +5 -4
  136. package/lib/module/Time/AnalogClockMinutes.js.map +1 -1
  137. package/lib/module/Time/AnimatedClockSwitcher.js +6 -5
  138. package/lib/module/Time/AnimatedClockSwitcher.js.map +1 -1
  139. package/lib/module/Time/TimeInput.js +14 -10
  140. package/lib/module/Time/TimeInput.js.map +1 -1
  141. package/lib/module/Time/TimeInputs.js +10 -9
  142. package/lib/module/Time/TimeInputs.js.map +1 -1
  143. package/lib/module/Time/TimePicker.js +32 -12
  144. package/lib/module/Time/TimePicker.js.map +1 -1
  145. package/lib/module/Time/TimePickerModal.js +17 -13
  146. package/lib/module/Time/TimePickerModal.js.map +1 -1
  147. package/lib/module/Time/timeUtils.js +5 -1
  148. package/lib/module/Time/timeUtils.js.map +1 -1
  149. package/lib/module/index.js +6 -0
  150. package/lib/module/index.js.map +1 -1
  151. package/lib/module/translations/en.js +18 -0
  152. package/lib/module/translations/en.js.map +1 -0
  153. package/lib/module/translations/enGB.js +18 -0
  154. package/lib/module/translations/enGB.js.map +1 -0
  155. package/lib/module/translations/nl.js +18 -0
  156. package/lib/module/translations/nl.js.map +1 -0
  157. package/lib/module/translations/pl.js +18 -0
  158. package/lib/module/translations/pl.js.map +1 -0
  159. package/lib/module/translations/utils.js +22 -0
  160. package/lib/module/translations/utils.js.map +1 -0
  161. package/lib/module/utils.js +11 -5
  162. package/lib/module/utils.js.map +1 -1
  163. package/lib/typescript/{src/Date → Date}/AnimatedCrossView.d.ts +0 -0
  164. package/lib/typescript/{src/Date → Date}/AutoSizer.d.ts +0 -0
  165. package/lib/typescript/{src/Date → Date}/Calendar.d.ts +5 -3
  166. package/lib/typescript/{src/Date → Date}/CalendarEdit.d.ts +3 -3
  167. package/lib/typescript/{src/Date → Date}/CalendarHeader.d.ts +1 -1
  168. package/lib/typescript/Date/DatePickerInput.d.ts +18 -0
  169. package/lib/typescript/{src/Date → Date}/DatePickerModal.d.ts +0 -0
  170. package/lib/typescript/{src/Date → Date}/DatePickerModalContent.d.ts +2 -1
  171. package/lib/typescript/{src/Date → Date}/DatePickerModalContentHeader.d.ts +4 -4
  172. package/lib/typescript/{src/Date → Date}/DatePickerModalHeader.d.ts +1 -0
  173. package/lib/typescript/{src/Date → Date}/DatePickerModalHeaderBackground.d.ts +0 -0
  174. package/lib/typescript/Date/DateRangeInput.d.ts +3 -0
  175. package/lib/typescript/{src/Date → Date}/Day.d.ts +0 -0
  176. package/lib/typescript/{src/Date → Date}/DayName.d.ts +0 -0
  177. package/lib/typescript/{src/Date → Date}/DayNames.d.ts +0 -0
  178. package/lib/typescript/{src/Date → Date}/DayRange.d.ts +0 -0
  179. package/lib/typescript/{src/Date → Date}/Month.d.ts +0 -0
  180. package/lib/typescript/{src/Date → Date}/Swiper.d.ts +0 -0
  181. package/lib/typescript/{src/Date → Date}/Swiper.native.d.ts +0 -0
  182. package/lib/typescript/{src/Date → Date}/SwiperUtils.d.ts +1 -1
  183. package/lib/typescript/{src/Date → Date}/Week.d.ts +0 -0
  184. package/lib/typescript/{src/Date → Date}/YearPicker.d.ts +0 -0
  185. package/lib/typescript/{src/Date → Date}/dateUtils.d.ts +15 -0
  186. package/lib/typescript/{src/Date → Date}/dateUtils.test.d.ts +0 -0
  187. package/lib/typescript/Date/inputUtils.d.ts +14 -0
  188. package/lib/typescript/TextInputMask.d.ts +11 -0
  189. package/lib/typescript/Time/AmPmSwitcher.d.ts +4 -0
  190. package/lib/typescript/{src/Time → Time}/AnalogClock.d.ts +1 -1
  191. package/lib/typescript/{src/Time → Time}/AnalogClockHours.d.ts +0 -0
  192. package/lib/typescript/{src/Time → Time}/AnalogClockMinutes.d.ts +0 -0
  193. package/lib/typescript/{src/Time → Time}/AnimatedClockSwitcher.d.ts +0 -0
  194. package/lib/typescript/{src/Time → Time}/TimeInput.d.ts +0 -0
  195. package/lib/typescript/{src/Time → Time}/TimeInputs.d.ts +1 -1
  196. package/lib/typescript/{src/Time → Time}/TimePicker.d.ts +4 -0
  197. package/lib/typescript/{src/Time → Time}/TimePickerModal.d.ts +1 -1
  198. package/lib/typescript/{src/Time → Time}/timeUtils.d.ts +0 -0
  199. package/lib/typescript/index.d.ts +13 -0
  200. package/lib/typescript/translations/en.d.ts +3 -0
  201. package/lib/typescript/translations/enGB.d.ts +3 -0
  202. package/lib/typescript/translations/nl.d.ts +3 -0
  203. package/lib/typescript/translations/pl.d.ts +3 -0
  204. package/lib/typescript/translations/utils.d.ts +18 -0
  205. package/lib/typescript/utils.d.ts +58 -0
  206. package/package.json +39 -38
  207. package/src/.DS_Store +0 -0
  208. package/src/Date/Calendar.tsx +14 -13
  209. package/src/Date/CalendarEdit.tsx +17 -121
  210. package/src/Date/CalendarHeader.tsx +18 -3
  211. package/src/Date/DatePickerInput.tsx +103 -25
  212. package/src/Date/DatePickerModalContent.tsx +5 -1
  213. package/src/Date/DatePickerModalContentHeader.tsx +26 -12
  214. package/src/Date/DatePickerModalHeader.tsx +8 -1
  215. package/src/Date/DateRangeInput.tsx +26 -17
  216. package/src/Date/Day.tsx +4 -0
  217. package/src/Date/Month.tsx +20 -44
  218. package/src/Date/Swiper.tsx +1 -0
  219. package/src/Date/SwiperUtils.ts +1 -1
  220. package/src/Date/YearPicker.tsx +6 -1
  221. package/src/Date/dateUtils.tsx +70 -9
  222. package/src/Date/inputUtils.ts +94 -0
  223. package/src/TextInputMask.tsx +10 -3
  224. package/src/Time/AmPmSwitcher.tsx +20 -11
  225. package/src/Time/AnalogClock.tsx +12 -14
  226. package/src/Time/AnalogClockHours.tsx +14 -5
  227. package/src/Time/AnalogClockMinutes.tsx +4 -1
  228. package/src/Time/TimeInput.tsx +3 -0
  229. package/src/Time/TimeInputs.tsx +1 -5
  230. package/src/Time/TimePicker.tsx +44 -22
  231. package/src/Time/TimePickerModal.tsx +4 -1
  232. package/src/Time/timeUtils.ts +4 -1
  233. package/src/index.tsx +7 -0
  234. package/src/translations/en.ts +20 -0
  235. package/src/translations/enGB.ts +20 -0
  236. package/src/translations/nl.ts +20 -0
  237. package/src/translations/pl.ts +21 -0
  238. package/src/translations/utils.ts +47 -0
  239. package/src/utils.ts +13 -5
  240. package/lib/typescript/src/Date/DatePickerInput.d.ts +0 -1
  241. package/lib/typescript/src/Date/DateRangeInput.d.ts +0 -1
  242. package/lib/typescript/src/TextInputMask.d.ts +0 -3
  243. package/lib/typescript/src/Time/AmPmSwitcher.d.ts +0 -4
  244. package/lib/typescript/src/index.d.ts +0 -6
  245. 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,
@@ -31,7 +30,7 @@ function CalendarEdit({
31
30
  collapsed: boolean
32
31
  onChange: (s: LocalState) => any
33
32
  validRange: ValidRangeType | undefined
34
- locale?: undefined | string
33
+ locale: string
35
34
  }) {
36
35
  const dateInput = React.useRef<TextInputNative | null>(null)
37
36
  const startInput = React.useRef<TextInputNative | null>(null)
@@ -79,7 +78,8 @@ function CalendarEdit({
79
78
  <View style={styles.root}>
80
79
  <View style={styles.inner}>
81
80
  {mode === 'single' ? (
82
- <CalendarInput
81
+ <DatePickerInput
82
+ inputMode="start"
83
83
  ref={dateInput}
84
84
  label={label}
85
85
  value={state.date}
@@ -87,11 +87,14 @@ function CalendarEdit({
87
87
  onSubmitEditing={onSubmitInput}
88
88
  validRange={validRange}
89
89
  locale={locale}
90
+ withModal={false}
91
+ autoCompleteType={'off'}
90
92
  />
91
93
  ) : null}
92
94
  {mode === 'range' ? (
93
95
  <>
94
- <CalendarInput
96
+ <DatePickerInput
97
+ inputMode="start"
95
98
  ref={startInput}
96
99
  label={startLabel}
97
100
  value={state.startDate}
@@ -100,17 +103,21 @@ function CalendarEdit({
100
103
  onSubmitEditing={onSubmitStartInput}
101
104
  validRange={validRange}
102
105
  locale={locale}
106
+ withModal={false}
107
+ autoCompleteType={'off'}
103
108
  />
104
109
  <View style={styles.separator} />
105
- <CalendarInput
110
+ <DatePickerInput
111
+ inputMode="end"
106
112
  ref={endInput}
107
113
  label={endLabel}
108
114
  value={state.endDate}
109
115
  onChange={(endDate) => onChange({ ...state, endDate })}
110
- isEndDate
111
116
  onSubmitEditing={onSubmitEndInput}
112
117
  validRange={validRange}
113
118
  locale={locale}
119
+ withModal={false}
120
+ autoCompleteType={'off'}
114
121
  />
115
122
  </>
116
123
  ) : null}
@@ -119,117 +126,6 @@ function CalendarEdit({
119
126
  )
120
127
  }
121
128
 
122
- function CalendarInputPure(
123
- {
124
- label,
125
- value,
126
- onChange,
127
- isEndDate,
128
- returnKeyType,
129
- onSubmitEditing,
130
- locale,
131
- validRange,
132
- }: {
133
- locale?: undefined | string
134
- label: string
135
- value: CalendarDate
136
- onChange: (d: Date | undefined) => any
137
- isEndDate?: boolean
138
- returnKeyType?: string
139
- onSubmitEditing?: () => any
140
- validRange: ValidRangeType | undefined
141
- },
142
- ref: any
143
- ) {
144
- const theme = useTheme()
145
- const [error, setError] = React.useState<null | string>(null)
146
- const formatter = React.useMemo(() => {
147
- return new Intl.DateTimeFormat(locale, {
148
- month: '2-digit',
149
- day: '2-digit',
150
- year: 'numeric',
151
- })
152
- }, [locale])
153
-
154
- const inputFormat = React.useMemo(() => {
155
- // TODO: something cleaner and more universal?
156
- const inputDate = formatter.format(new Date(2020, 10 - 1, 1))
157
- return inputDate
158
- .replace('2020', 'YYYY')
159
- .replace('10', 'MM')
160
- .replace('01', 'DD')
161
- }, [formatter])
162
-
163
- const formattedValue = formatter.format(value)
164
- const onChangeText = (date: string) => {
165
- const dayIndex = inputFormat.indexOf('DD')
166
- const monthIndex = inputFormat.indexOf('MM')
167
- const yearIndex = inputFormat.indexOf('YYYY')
168
-
169
- const day = Number(date.slice(dayIndex, dayIndex + 2))
170
- const year = Number(date.slice(yearIndex, yearIndex + 4))
171
- const month = Number(date.slice(monthIndex, monthIndex + 2))
172
-
173
- if (Number.isNaN(day) || Number.isNaN(year) || Number.isNaN(month)) {
174
- setError(inputFormat)
175
- return
176
- }
177
-
178
- const finalDate = isEndDate
179
- ? new Date(year, month - 1, day, 23, 59, 59)
180
- : new Date(year, month - 1, day)
181
-
182
- const validStart = validRange?.startDate
183
- const validEnd = validRange?.endDate
184
- if (
185
- !isDateWithinOptionalRange(finalDate, {
186
- startUnix: validStart ? dateToUnix(validStart) : undefined,
187
- endUnix: validEnd ? dateToUnix(validEnd) : undefined,
188
- })
189
- ) {
190
- let errors =
191
- validStart && validEnd
192
- ? [`${formatter.format(validStart)} - ${formatter.format(validEnd)}`]
193
- : [
194
- validStart ? `> ${formatter.format(validStart)}` : '',
195
- validEnd ? `< ${formatter.format(validEnd)}` : '',
196
- ]
197
- setError(errors.filter((n) => n).join(' '))
198
- return
199
- }
200
-
201
- setError(null)
202
- if (isEndDate) {
203
- onChange(finalDate)
204
- } else {
205
- onChange(finalDate)
206
- }
207
- }
208
- return (
209
- <View style={styles.inputContainer}>
210
- <TextInputWithMask
211
- ref={ref}
212
- value={formattedValue}
213
- style={styles.input}
214
- label={`${label} (${inputFormat})`}
215
- keyboardType={'number-pad'}
216
- placeholder={inputFormat}
217
- mask={inputFormat}
218
- onChangeText={onChangeText}
219
- returnKeyType={returnKeyType}
220
- onSubmitEditing={onSubmitEditing}
221
- keyboardAppearance={theme.dark ? 'dark' : 'default'}
222
- error={!!error}
223
- />
224
- <HelperText type="error" visible={!!error}>
225
- {error}
226
- </HelperText>
227
- </View>
228
- )
229
- }
230
-
231
- const CalendarInput = React.forwardRef(CalendarInputPure)
232
-
233
129
  const styles = StyleSheet.create({
234
130
  root: { padding: 12 },
235
131
  inner: { flexDirection: 'row' },
@@ -2,7 +2,8 @@ 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
+ import { getTranslation } from '../translations/utils'
6
7
 
7
8
  const buttonContainerHeight = 56
8
9
  const buttonContainerMarginTop = 4
@@ -46,7 +47,14 @@ function CalendarHeader({
46
47
  { backgroundColor: theme.colors.surface },
47
48
  ]}
48
49
  >
49
- <IconButton icon="chevron-left" onPress={onPrev} />
50
+ <IconButton
51
+ icon="chevron-left"
52
+ accessibilityLabel={getTranslation(locale, 'previous')}
53
+ onPress={onPrev}
54
+ // RN types bug
55
+ hasTVPreferredFocus={undefined}
56
+ tvParallaxProperties={undefined}
57
+ />
50
58
  </View>
51
59
 
52
60
  <View
@@ -55,7 +63,14 @@ function CalendarHeader({
55
63
  { backgroundColor: theme.colors.surface },
56
64
  ]}
57
65
  >
58
- <IconButton icon="chevron-right" onPress={onNext} />
66
+ <IconButton
67
+ icon="chevron-right"
68
+ accessibilityLabel={getTranslation(locale, 'next')}
69
+ onPress={onNext}
70
+ // RN types bug
71
+ hasTVPreferredFocus={undefined}
72
+ tvParallaxProperties={undefined}
73
+ />
59
74
  </View>
60
75
  </View>
61
76
  ) : 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)
@@ -28,7 +28,7 @@ export type LocalState = {
28
28
 
29
29
  interface DatePickerModalContentBaseProps {
30
30
  inputFormat?: string
31
- locale?: undefined | string
31
+ locale: string
32
32
  onDismiss: () => any
33
33
  disableSafeTop?: boolean
34
34
  }
@@ -52,6 +52,7 @@ export interface DatePickerModalContentSingleProps
52
52
  date?: CalendarDate
53
53
  onChange?: SingleChange
54
54
  onConfirm: SingleChange
55
+ dateMode?: 'start' | 'end'
55
56
  }
56
57
 
57
58
  export interface DatePickerModalContentMultiProps
@@ -79,6 +80,7 @@ export function DatePickerModalContent(
79
80
  disableWeekDays,
80
81
  locale,
81
82
  validRange,
83
+ dateMode,
82
84
  } = props
83
85
 
84
86
  const anyProps = props as any
@@ -136,6 +138,7 @@ export function DatePickerModalContent(
136
138
  <>
137
139
  <DatePickerModalHeaderBackground>
138
140
  <DatePickerModalHeader
141
+ locale={locale}
139
142
  onSave={onInnerConfirm}
140
143
  onDismiss={onDismiss}
141
144
  saveLabel={props.saveLabel}
@@ -169,6 +172,7 @@ export function DatePickerModalContent(
169
172
  disableWeekDays={disableWeekDays}
170
173
  dates={state.dates}
171
174
  validRange={validRange}
175
+ dateMode={dateMode}
172
176
  />
173
177
  }
174
178
  calendarEdit={
@@ -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'
@@ -73,8 +79,16 @@ export default function DatePickerModalHeader(props: HeaderContentProps) {
73
79
  {allowEditing ? (
74
80
  <IconButton
75
81
  icon={collapsed ? 'pencil' : 'calendar'}
82
+ accessibilityLabel={
83
+ collapsed
84
+ ? getTranslation(props.locale, 'typeInDate')
85
+ : getTranslation(props.locale, 'pickDateFromCalendar')
86
+ }
76
87
  color={color}
77
88
  onPress={onToggle}
89
+ // RN types bug
90
+ hasTVPreferredFocus={undefined}
91
+ tvParallaxProperties={undefined}
78
92
  />
79
93
  ) : null}
80
94
  </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
  <>
@@ -28,9 +31,13 @@ export default function DatePickerModalHeader(
28
31
  <Appbar style={styles.appbarHeader}>
29
32
  <Appbar.Action
30
33
  icon="close"
34
+ accessibilityLabel={getTranslation(locale, 'close')}
31
35
  onPress={props.onDismiss}
32
36
  color={color}
33
37
  testID="react-native-paper-dates-close"
38
+ // RN types bug
39
+ hasTVPreferredFocus={undefined}
40
+ tvParallaxProperties={undefined}
34
41
  />
35
42
  <Appbar.Content title={''} />
36
43
  <Button
@@ -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
@@ -73,6 +73,10 @@ function Day(props: {
73
73
  styles.button,
74
74
  { backgroundColor: inRange ? selectColor : undefined },
75
75
  ]}
76
+ accessibilityRole="button"
77
+ // RN types bug
78
+ hasTVPreferredFocus={undefined}
79
+ tvParallaxProperties={undefined}
76
80
  >
77
81
  <View
78
82
  style={[