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
@@ -9,9 +9,15 @@ import {
9
9
  toHourOutputFormat,
10
10
  } from './timeUtils'
11
11
 
12
- import AnalogClock, { circleSize } from './AnalogClock'
12
+ import AnalogClock from './AnalogClock'
13
+ import { circleSize } from './timeUtils'
13
14
  import TimeInputs from './TimeInputs'
14
15
 
16
+ export const DisplayModeContext = React.createContext<{
17
+ mode: 'AM' | 'PM' | undefined
18
+ setMode: React.Dispatch<React.SetStateAction<'AM' | 'PM' | undefined>>
19
+ }>({ mode: 'AM', setMode: () => {} })
20
+
15
21
  type onChangeFunc = ({
16
22
  hours,
17
23
  minutes,
@@ -39,6 +45,9 @@ function TimePicker({
39
45
  onFocusInput: (type: PossibleClockTypes) => any
40
46
  onChange: onChangeFunc
41
47
  }) {
48
+ const [displayMode, setDisplayMode] = React.useState<'AM' | 'PM' | undefined>(
49
+ undefined
50
+ )
42
51
  const dimensions = useWindowDimensions()
43
52
  const isLandscape = dimensions.width > dimensions.height
44
53
 
@@ -53,6 +62,16 @@ function TimePicker({
53
62
  return formatted.includes('23')
54
63
  }, [locale])
55
64
 
65
+ // Initialize display Mode according the hours value
66
+ React.useEffect(() => {
67
+ if (hours >= 12) {
68
+ setDisplayMode('PM')
69
+ } else {
70
+ setDisplayMode('AM')
71
+ }
72
+ // eslint-disable-next-line react-hooks/exhaustive-deps
73
+ }, [])
74
+
56
75
  const onInnerChange = React.useCallback<onChangeFunc>(
57
76
  (params) => {
58
77
  params.hours = toHourOutputFormat(params.hours, hours, is24Hour)
@@ -62,28 +81,32 @@ function TimePicker({
62
81
  )
63
82
 
64
83
  return (
65
- <View style={isLandscape ? styles.rootLandscape : styles.rootPortrait}>
66
- <TimeInputs
67
- inputType={inputType}
68
- hours={hours}
69
- minutes={minutes}
70
- is24Hour={is24Hour}
71
- onChange={onChange}
72
- onFocusInput={onFocusInput}
73
- focused={focused}
74
- />
75
- {inputType === inputTypes.picker ? (
76
- <View style={styles.clockContainer}>
77
- <AnalogClock
78
- hours={toHourInputFormat(hours, is24Hour)}
79
- minutes={minutes}
80
- focused={focused}
81
- is24Hour={is24Hour}
82
- onChange={onInnerChange}
83
- />
84
- </View>
85
- ) : null}
86
- </View>
84
+ <DisplayModeContext.Provider
85
+ value={{ mode: displayMode, setMode: setDisplayMode }}
86
+ >
87
+ <View style={isLandscape ? styles.rootLandscape : styles.rootPortrait}>
88
+ <TimeInputs
89
+ inputType={inputType}
90
+ hours={hours}
91
+ minutes={minutes}
92
+ is24Hour={is24Hour}
93
+ onChange={onChange}
94
+ onFocusInput={onFocusInput}
95
+ focused={focused}
96
+ />
97
+ {inputType === inputTypes.picker ? (
98
+ <View style={styles.clockContainer}>
99
+ <AnalogClock
100
+ hours={toHourInputFormat(hours, is24Hour)}
101
+ minutes={minutes}
102
+ focused={focused}
103
+ is24Hour={is24Hour}
104
+ onChange={onInnerChange}
105
+ />
106
+ </View>
107
+ ) : null}
108
+ </View>
109
+ </DisplayModeContext.Provider>
87
110
  )
88
111
  }
89
112
 
@@ -48,7 +48,7 @@ export function TimePickerModal({
48
48
  minutes?: number | undefined
49
49
  visible: boolean | undefined
50
50
  onDismiss: () => any
51
- onConfirm: ({ hours, minutes }: { hours: number; minutes: number }) => any
51
+ onConfirm: (hoursAndMinutes: { hours: number; minutes: number }) => any
52
52
  animationType?: 'slide' | 'fade' | 'none'
53
53
  }) {
54
54
  const theme = useTheme()
@@ -155,6 +155,9 @@ export function TimePickerModal({
155
155
  size={24}
156
156
  style={styles.inputTypeToggle}
157
157
  accessibilityLabel="toggle keyboard"
158
+ // RN types bug
159
+ hasTVPreferredFocus={undefined}
160
+ tvParallaxProperties={undefined}
158
161
  />
159
162
  <View style={styles.fill} />
160
163
  <Button onPress={onDismiss}>{cancelLabel}</Button>
@@ -2,6 +2,9 @@ import * as React from 'react'
2
2
  import Color from 'color'
3
3
  import { useTheme } from 'react-native-paper'
4
4
 
5
+ // 250? when bigger?
6
+ export const circleSize = 215
7
+
5
8
  export type PossibleHourTypes = 'am' | 'pm'
6
9
  export type HourTypeMap = {
7
10
  [hourType in PossibleHourTypes]: PossibleHourTypes
@@ -196,6 +199,9 @@ export function useInputColors(highlighted: boolean) {
196
199
  }
197
200
 
198
201
  export function toHourInputFormat(hours: number, is24Hour: boolean): number {
202
+ if (hours === 24) {
203
+ return 0
204
+ }
199
205
  if (is24Hour) {
200
206
  return hours
201
207
  }
@@ -213,7 +219,7 @@ export function toHourOutputFormat(
213
219
  if (is24Hour) {
214
220
  return newHours
215
221
  }
216
- if (previousHours > 12 && newHours <= 12) {
222
+ if (previousHours > 12 && newHours < 12) {
217
223
  return newHours + 12
218
224
  }
219
225
  return newHours
package/src/index.tsx CHANGED
@@ -4,3 +4,10 @@ export * from './Date/DatePickerModal'
4
4
  export { default as DatePickerModalContent } from './Date/DatePickerModalContent'
5
5
  export { default as TimePickerModal } from './Time/TimePickerModal'
6
6
  export { default as TimePicker } from './Time/TimePicker'
7
+ export { default as DatePickerInput } from './Date/DatePickerInput'
8
+ export type { TranslationsType } from './translations/utils'
9
+ export { registerTranslation, getTranslation } from './translations/utils'
10
+ export { default as nl } from './translations/nl'
11
+ export { default as en } from './translations/en'
12
+ export { default as pl } from './translations/pl'
13
+ export { default as enGB } from './translations/enGB'
@@ -0,0 +1,15 @@
1
+ import type { TranslationsType } from './utils'
2
+
3
+ const en: TranslationsType = {
4
+ save: 'Save',
5
+ selectSingle: 'Select date',
6
+ selectMultiple: 'Select dates',
7
+ selectRange: 'Select period',
8
+ notAccordingToDateFormat: (inputFormat: string) =>
9
+ `Date format must be ${inputFormat}`,
10
+ mustBeHigherThan: 'Must be later then',
11
+ mustBeLowerThan: 'Must be earlier then',
12
+ mustBeBetween: 'Must be between',
13
+ dateIsDisabled: 'Day is not allowed',
14
+ }
15
+ export default en
@@ -0,0 +1,15 @@
1
+ import type { TranslationsType } from './utils'
2
+
3
+ const enGB: TranslationsType = {
4
+ save: 'Save',
5
+ selectSingle: 'Select date',
6
+ selectMultiple: 'Select dates',
7
+ selectRange: 'Select period',
8
+ notAccordingToDateFormat: (inputFormat: string) =>
9
+ `Date format must be ${inputFormat}`,
10
+ mustBeHigherThan: 'Must be later then',
11
+ mustBeLowerThan: 'Must be earlier then',
12
+ mustBeBetween: 'Must be between',
13
+ dateIsDisabled: 'Day is not allowed',
14
+ }
15
+ export default enGB
@@ -0,0 +1,15 @@
1
+ import type { TranslationsType } from './utils'
2
+
3
+ const nl: TranslationsType = {
4
+ save: 'Opslaan',
5
+ selectSingle: 'Selecteer datum',
6
+ selectMultiple: 'Selecteer datums',
7
+ selectRange: 'Selecteer periode',
8
+ notAccordingToDateFormat: (inputFormat: string) =>
9
+ `Datumformaat moet ${inputFormat} zijn`,
10
+ mustBeHigherThan: 'Moet later dan',
11
+ mustBeLowerThan: 'Moet eerder dan',
12
+ mustBeBetween: 'Moet tussen',
13
+ dateIsDisabled: 'Deze dag mag niet',
14
+ }
15
+ export default nl
@@ -0,0 +1,15 @@
1
+ import type { TranslationsType } from './utils'
2
+
3
+ const pl: TranslationsType = {
4
+ save: 'Zapisz',
5
+ selectSingle: 'Wybierz datę',
6
+ selectMultiple: 'Wybierz daty',
7
+ selectRange: 'Wybierz zakres',
8
+ notAccordingToDateFormat: (inputFormat: string) =>
9
+ `Data musi mieć format ${inputFormat}`,
10
+ mustBeHigherThan: 'Nie wcześniej niż',
11
+ mustBeLowerThan: 'Nie później niż',
12
+ mustBeBetween: 'Pomiędzy',
13
+ dateIsDisabled: 'Niedozwolona data',
14
+ }
15
+ export default pl
@@ -0,0 +1,42 @@
1
+ export type TranslationsType = {
2
+ selectSingle: string
3
+ selectMultiple: string
4
+ selectRange: string
5
+ save: string
6
+ notAccordingToDateFormat: (inputFormat: string) => string
7
+ mustBeHigherThan: string
8
+ mustBeLowerThan: string
9
+ mustBeBetween: string
10
+ dateIsDisabled: string
11
+ }
12
+
13
+ let translationsPerLocale: Record<string, TranslationsType> = {}
14
+
15
+ export function getTranslation(
16
+ locale: string | undefined,
17
+ key: keyof TranslationsType,
18
+ fallback?: any
19
+ ) {
20
+ const l = locale || 'en'
21
+ const translationForLocale = translationsPerLocale[l]
22
+ if (!translationForLocale) {
23
+ console.warn(
24
+ `[react-native-paper-dates] ${locale} is not registered, key: ${key}`
25
+ )
26
+ return fallback || key
27
+ }
28
+ const translation = translationsPerLocale[l][key]
29
+ if (!translationForLocale) {
30
+ console.warn(
31
+ `[react-native-paper-dates] ${locale} is registered, but ${key} is missing`
32
+ )
33
+ }
34
+ return translation || fallback || key
35
+ }
36
+
37
+ export function registerTranslation(
38
+ locale: string,
39
+ translations: TranslationsType
40
+ ) {
41
+ translationsPerLocale[locale] = translations
42
+ }
package/src/utils.ts CHANGED
@@ -3,11 +3,9 @@ import { overlay, useTheme } from 'react-native-paper'
3
3
  import Color from 'color'
4
4
 
5
5
  export function useLatest<T>(value: T) {
6
- const valueRef = React.useRef<T>(value)
7
- React.useEffect(() => {
8
- valueRef.current = value
9
- }, [value])
10
- return valueRef
6
+ const ref = React.useRef(value)
7
+ ref.current = value
8
+ return ref
11
9
  }
12
10
 
13
11
  export function useHeaderBackgroundColor() {
@@ -42,3 +40,13 @@ export function range(start: number, end: number) {
42
40
  .fill(null)
43
41
  .map((_, i) => start + i)
44
42
  }
43
+
44
+ export function lightenBy(color: Color, ratio: number) {
45
+ const lightness = color.lightness()
46
+ return color.lightness(lightness + (100 - lightness) * ratio)
47
+ }
48
+
49
+ export function darkenBy(color: Color, ratio: number) {
50
+ const lightness = color.lightness()
51
+ return color.lightness(lightness - lightness * ratio)
52
+ }
@@ -1 +0,0 @@
1
- export default function DatePickerInput(): JSX.Element;
@@ -1 +0,0 @@
1
- export default function DateRangeInput(): JSX.Element;
@@ -1,3 +0,0 @@
1
- import * as React from 'react';
2
- declare const _default: React.ForwardRefExoticComponent<Pick<any, string | number | symbol> & React.RefAttributes<unknown>>;
3
- export default _default;
@@ -1,4 +0,0 @@
1
- export default function AmPmSwitcher({ hours, onChange, }: {
2
- hours: number;
3
- onChange: (hours: number) => any;
4
- }): JSX.Element;
@@ -1,6 +0,0 @@
1
- export { default as Calendar } from './Date/Calendar';
2
- export { default as DatePickerModal } from './Date/DatePickerModal';
3
- export * from './Date/DatePickerModal';
4
- export { default as DatePickerModalContent } from './Date/DatePickerModalContent';
5
- export { default as TimePickerModal } from './Time/TimePickerModal';
6
- export { default as TimePicker } from './Time/TimePicker';
@@ -1,7 +0,0 @@
1
- import * as React from 'react';
2
- export declare function useLatest<T>(value: T): React.MutableRefObject<T>;
3
- export declare function useHeaderBackgroundColor(): string;
4
- export declare function useHeaderColorIsLight(): boolean;
5
- export declare function useHeaderTextColor(): "#fff" | "#000";
6
- export declare function useTextColorOnPrimary(): "#fff" | "#000";
7
- export declare function range(start: number, end: number): number[];