react-native-paper-dates 0.11.5 → 0.11.7

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 (66) hide show
  1. package/lib/commonjs/Time/AmPmSwitcher.js +13 -10
  2. package/lib/commonjs/Time/AmPmSwitcher.js.map +1 -1
  3. package/lib/commonjs/Time/AnalogClock.js +6 -7
  4. package/lib/commonjs/Time/AnalogClock.js.map +1 -1
  5. package/lib/commonjs/Time/AnalogClockHours.js +16 -17
  6. package/lib/commonjs/Time/AnalogClockHours.js.map +1 -1
  7. package/lib/commonjs/Time/AnalogClockMinutes.js +8 -7
  8. package/lib/commonjs/Time/AnalogClockMinutes.js.map +1 -1
  9. package/lib/commonjs/Time/TimeInput.js +9 -7
  10. package/lib/commonjs/Time/TimeInput.js.map +1 -1
  11. package/lib/commonjs/Time/TimeInputs.js +22 -9
  12. package/lib/commonjs/Time/TimeInputs.js.map +1 -1
  13. package/lib/commonjs/Time/TimePicker.js +4 -3
  14. package/lib/commonjs/Time/TimePicker.js.map +1 -1
  15. package/lib/commonjs/Time/TimePickerModal.js +20 -12
  16. package/lib/commonjs/Time/TimePickerModal.js.map +1 -1
  17. package/lib/commonjs/Time/timeUtils.js +14 -19
  18. package/lib/commonjs/Time/timeUtils.js.map +1 -1
  19. package/lib/commonjs/index.js +10 -1
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/translations/tr.js +25 -0
  22. package/lib/commonjs/translations/tr.js.map +1 -0
  23. package/lib/commonjs/utils.js +9 -0
  24. package/lib/commonjs/utils.js.map +1 -1
  25. package/lib/module/Time/AmPmSwitcher.js +14 -11
  26. package/lib/module/Time/AmPmSwitcher.js.map +1 -1
  27. package/lib/module/Time/AnalogClock.js +6 -7
  28. package/lib/module/Time/AnalogClock.js.map +1 -1
  29. package/lib/module/Time/AnalogClockHours.js +16 -17
  30. package/lib/module/Time/AnalogClockHours.js.map +1 -1
  31. package/lib/module/Time/AnalogClockMinutes.js +8 -7
  32. package/lib/module/Time/AnalogClockMinutes.js.map +1 -1
  33. package/lib/module/Time/TimeInput.js +10 -8
  34. package/lib/module/Time/TimeInput.js.map +1 -1
  35. package/lib/module/Time/TimeInputs.js +23 -10
  36. package/lib/module/Time/TimeInputs.js.map +1 -1
  37. package/lib/module/Time/TimePicker.js +4 -3
  38. package/lib/module/Time/TimePicker.js.map +1 -1
  39. package/lib/module/Time/TimePickerModal.js +20 -12
  40. package/lib/module/Time/TimePickerModal.js.map +1 -1
  41. package/lib/module/Time/timeUtils.js +15 -20
  42. package/lib/module/Time/timeUtils.js.map +1 -1
  43. package/lib/module/index.js +1 -0
  44. package/lib/module/index.js.map +1 -1
  45. package/lib/module/translations/tr.js +18 -0
  46. package/lib/module/translations/tr.js.map +1 -0
  47. package/lib/module/utils.js +9 -0
  48. package/lib/module/utils.js.map +1 -1
  49. package/lib/typescript/Time/AmPmSwitcher.d.ts +3 -1
  50. package/lib/typescript/Time/timeUtils.d.ts +1 -1
  51. package/lib/typescript/index.d.ts +1 -0
  52. package/lib/typescript/translations/tr.d.ts +3 -0
  53. package/lib/typescript/utils.d.ts +1 -1
  54. package/package.json +1 -1
  55. package/src/Time/AmPmSwitcher.tsx +15 -9
  56. package/src/Time/AnalogClock.tsx +16 -9
  57. package/src/Time/AnalogClockHours.tsx +18 -16
  58. package/src/Time/AnalogClockMinutes.tsx +7 -7
  59. package/src/Time/TimeInput.tsx +21 -6
  60. package/src/Time/TimeInputs.tsx +82 -58
  61. package/src/Time/TimePicker.tsx +18 -2
  62. package/src/Time/TimePickerModal.tsx +35 -14
  63. package/src/Time/timeUtils.ts +23 -17
  64. package/src/index.tsx +1 -0
  65. package/src/translations/tr.ts +21 -0
  66. package/src/utils.ts +9 -0
@@ -1,5 +1,11 @@
1
1
  import * as React from 'react'
2
- import { View, TextInput, TextInputProps, StyleSheet } from 'react-native'
2
+ import {
3
+ View,
4
+ TextInput,
5
+ TextInputProps,
6
+ StyleSheet,
7
+ Platform,
8
+ } from 'react-native'
3
9
  import { useTheme, TouchableRipple } from 'react-native-paper'
4
10
 
5
11
  import Color from 'color'
@@ -68,10 +74,17 @@ function TimeInput(
68
74
  ref={ref}
69
75
  style={[
70
76
  styles.input,
77
+ // eslint-disable-next-line react-native/no-inline-styles
71
78
  {
72
79
  color,
73
80
  backgroundColor,
74
- borderRadius: theme.roundness,
81
+ borderRadius: theme.roundness * 2,
82
+ borderColor:
83
+ theme.isV3 && highlighted
84
+ ? theme.colors.onPrimaryContainer
85
+ : undefined,
86
+ borderWidth: theme.isV3 && highlighted ? 2 : 0,
87
+ height: inputType === inputTypes.keyboard ? 72 : 80,
75
88
  },
76
89
  ]}
77
90
  value={formattedValue}
@@ -89,11 +102,14 @@ function TimeInput(
89
102
  StyleSheet.absoluteFill,
90
103
  styles.buttonOverlay,
91
104
  {
92
- // backgroundColor: 'blue',
93
105
  borderRadius: theme.roundness,
94
106
  },
95
107
  ]}
96
- rippleColor={Color(theme.colors.primary).fade(0.7).hex()}
108
+ rippleColor={
109
+ Platform.OS !== 'ios'
110
+ ? Color(theme.colors.onSurface).fade(0.7).hex()
111
+ : undefined
112
+ }
97
113
  onPress={() => onPress(clockType)}
98
114
  borderless={true}
99
115
  >
@@ -107,11 +123,10 @@ function TimeInput(
107
123
  const styles = StyleSheet.create({
108
124
  root: { position: 'relative', height: 80, width: 96 },
109
125
  input: {
110
- fontSize: 50,
126
+ fontSize: 57,
111
127
  textAlign: 'center',
112
128
  textAlignVertical: 'center',
113
129
  width: 96,
114
- height: 80,
115
130
  },
116
131
  buttonOverlay: { overflow: 'hidden' },
117
132
  })
@@ -1,6 +1,3 @@
1
- // @typescript-eslint/no-unused-vars
2
- // WORK IN PROGRESS
3
-
4
1
  import * as React from 'react'
5
2
  import {
6
3
  View,
@@ -8,7 +5,7 @@ import {
8
5
  useWindowDimensions,
9
6
  TextInput as TextInputNative,
10
7
  } from 'react-native'
11
- import { MD2Theme, useTheme } from 'react-native-paper'
8
+ import { MD2Theme, Text, useTheme } from 'react-native-paper'
12
9
 
13
10
  import {
14
11
  clockTypes,
@@ -78,41 +75,56 @@ function TimeInputs({
78
75
  isLandscape && styles.inputContainerLandscape,
79
76
  ]}
80
77
  >
81
- <TimeInput
82
- ref={startInput}
83
- placeholder={'00'}
84
- value={toHourInputFormat(hours, is24Hour)}
85
- clockType={clockTypes.hours}
86
- pressed={focused === clockTypes.hours}
87
- onPress={onFocusInput}
88
- inputType={inputType}
89
- selectionColor={
90
- theme.dark
91
- ? Color(theme.colors.primary).darken(0.2).hex()
92
- : theme.colors.primary
93
- }
94
- returnKeyType={'next'}
95
- onSubmitEditing={onSubmitStartInput}
96
- blurOnSubmit={false}
97
- onChanged={(newHoursFromInput) => {
98
- let newHours = toHourOutputFormat(newHoursFromInput, hours, is24Hour)
99
- if (newHoursFromInput > 24) {
100
- newHours = 24
78
+ <View style={styles.column}>
79
+ <TimeInput
80
+ ref={startInput}
81
+ placeholder={'00'}
82
+ value={toHourInputFormat(hours, is24Hour)}
83
+ clockType={clockTypes.hours}
84
+ pressed={focused === clockTypes.hours}
85
+ onPress={onFocusInput}
86
+ inputType={inputType}
87
+ selectionColor={
88
+ theme.dark
89
+ ? Color(theme.colors.primary).darken(0.2).hex()
90
+ : theme.colors.primary
101
91
  }
102
- onChange({
103
- hours: newHours,
104
- minutes,
105
- })
106
- }}
107
- />
108
- <View style={styles.hoursAndMinutesSeparator}>
92
+ returnKeyType={'next'}
93
+ onSubmitEditing={onSubmitStartInput}
94
+ blurOnSubmit={false}
95
+ onChanged={(newHoursFromInput) => {
96
+ let newHours = toHourOutputFormat(
97
+ newHoursFromInput,
98
+ hours,
99
+ is24Hour
100
+ )
101
+ if (newHoursFromInput > 24) {
102
+ newHours = 24
103
+ }
104
+ onChange({
105
+ hours: newHours,
106
+ minutes,
107
+ })
108
+ }}
109
+ />
110
+ {inputType === 'keyboard' ? (
111
+ <Text variant="bodySmall">Hour</Text>
112
+ ) : null}
113
+ </View>
114
+ <View
115
+ style={[
116
+ styles.hoursAndMinutesSeparator,
117
+ // eslint-disable-next-line react-native/no-inline-styles
118
+ { marginBottom: inputType === 'keyboard' ? 24 : 0 },
119
+ ]}
120
+ >
109
121
  <View style={styles.spaceDot} />
110
122
  <View
111
123
  style={[
112
124
  styles.dot,
113
125
  {
114
126
  backgroundColor: theme?.isV3
115
- ? theme.colors.onBackground
127
+ ? theme.colors.onSurface
116
128
  : (theme as any as MD2Theme).colors.text,
117
129
  },
118
130
  ]}
@@ -123,42 +135,51 @@ function TimeInputs({
123
135
  styles.dot,
124
136
  {
125
137
  backgroundColor: theme?.isV3
126
- ? theme.colors.onBackground
138
+ ? theme.colors.onSurface
127
139
  : (theme as any as MD2Theme).colors.text,
128
140
  },
129
141
  ]}
130
142
  />
131
143
  <View style={styles.spaceDot} />
132
144
  </View>
133
- <TimeInput
134
- ref={endInput}
135
- placeholder={'00'}
136
- value={minutes}
137
- clockType={clockTypes.minutes}
138
- pressed={focused === clockTypes.minutes}
139
- onPress={onFocusInput}
140
- inputType={inputType}
141
- selectionColor={
142
- theme.dark
143
- ? Color(theme.colors.primary).darken(0.2).hex()
144
- : theme.colors.primary
145
- }
146
- onSubmitEditing={onSubmitEndInput}
147
- onChanged={(newMinutesFromInput) => {
148
- let newMinutes = newMinutesFromInput
149
- if (newMinutesFromInput > 59) {
150
- newMinutes = 59
145
+ <View style={styles.column}>
146
+ <TimeInput
147
+ ref={endInput}
148
+ placeholder={'00'}
149
+ value={minutes}
150
+ clockType={clockTypes.minutes}
151
+ pressed={focused === clockTypes.minutes}
152
+ onPress={onFocusInput}
153
+ inputType={inputType}
154
+ selectionColor={
155
+ theme.dark
156
+ ? Color(theme.colors.primary).darken(0.2).hex()
157
+ : theme.colors.primary
151
158
  }
152
- onChange({
153
- hours,
154
- minutes: newMinutes,
155
- })
156
- }}
157
- />
159
+ onSubmitEditing={onSubmitEndInput}
160
+ onChanged={(newMinutesFromInput) => {
161
+ let newMinutes = newMinutesFromInput
162
+ if (newMinutesFromInput > 59) {
163
+ newMinutes = 59
164
+ }
165
+ onChange({
166
+ hours,
167
+ minutes: newMinutes,
168
+ })
169
+ }}
170
+ />
171
+ {inputType === 'keyboard' ? (
172
+ <Text variant="bodySmall">Minute</Text>
173
+ ) : null}
174
+ </View>
158
175
  {!is24Hour && (
159
176
  <>
160
177
  <View style={styles.spaceBetweenInputsAndSwitcher} />
161
- <AmPmSwitcher hours={hours} onChange={onChangeHours} />
178
+ <AmPmSwitcher
179
+ hours={hours}
180
+ onChange={onChangeHours}
181
+ inputType={inputType}
182
+ />
162
183
  </>
163
184
  )}
164
185
  </View>
@@ -166,6 +187,9 @@ function TimeInputs({
166
187
  }
167
188
 
168
189
  const styles = StyleSheet.create({
190
+ column: {
191
+ flexDirection: 'column',
192
+ },
169
193
  spaceBetweenInputsAndSwitcher: { width: 12 },
170
194
  inputContainer: {
171
195
  flexDirection: 'row',
@@ -84,7 +84,24 @@ function TimePicker({
84
84
  <DisplayModeContext.Provider
85
85
  value={{ mode: displayMode, setMode: setDisplayMode }}
86
86
  >
87
- <View style={isLandscape ? styles.rootLandscape : styles.rootPortrait}>
87
+ <View
88
+ style={
89
+ isLandscape
90
+ ? [
91
+ styles.rootLandscape,
92
+ {
93
+ width:
94
+ 24 * 3 +
95
+ 96 * 2 +
96
+ 52 +
97
+ (inputType === inputTypes.picker
98
+ ? circleSize
99
+ : -circleSize),
100
+ },
101
+ ]
102
+ : styles.rootPortrait
103
+ }
104
+ >
88
105
  <TimeInputs
89
106
  inputType={inputType}
90
107
  hours={hours}
@@ -115,7 +132,6 @@ const styles = StyleSheet.create({
115
132
  flexDirection: 'row',
116
133
  alignItems: 'center',
117
134
  justifyContent: 'center',
118
- width: 24 * 3 + 96 * 2 + 52 + circleSize,
119
135
  },
120
136
  rootPortrait: {
121
137
  alignItems: 'center',
@@ -27,7 +27,13 @@ import {
27
27
  reverseInputTypes,
28
28
  } from './timeUtils'
29
29
 
30
- const supportedOrientations: any[] = [
30
+ const supportedOrientations: (
31
+ | 'portrait'
32
+ | 'portrait-upside-down'
33
+ | 'landscape'
34
+ | 'landscape-left'
35
+ | 'landscape-right'
36
+ )[] = [
31
37
  'portrait',
32
38
  'portrait-upside-down',
33
39
  'landscape',
@@ -67,9 +73,10 @@ export function TimePickerModal({
67
73
  const theme = useTheme()
68
74
 
69
75
  let textFont
76
+ let labelText = label
70
77
 
71
78
  if (theme.isV3) {
72
- textFont = theme.fonts.bodyMedium
79
+ textFont = theme.fonts.labelMedium
73
80
  } else {
74
81
  textFont = (theme as any as MD2Theme)?.fonts.medium
75
82
  }
@@ -85,6 +92,10 @@ export function TimePickerModal({
85
92
  getMinutes(minutes)
86
93
  )
87
94
 
95
+ if (inputType === inputTypes.keyboard && !label) {
96
+ labelText = 'Enter time'
97
+ }
98
+
88
99
  React.useEffect(() => {
89
100
  setLocalHours(getHours(hours))
90
101
  }, [setLocalHours, hours])
@@ -120,7 +131,6 @@ export function TimePickerModal({
120
131
  onRequestClose={onDismiss}
121
132
  presentationStyle="overFullScreen"
122
133
  supportedOrientations={supportedOrientations}
123
- //@ts-ignore
124
134
  statusBarTranslucent={true}
125
135
  >
126
136
  <>
@@ -133,7 +143,6 @@ export function TimePickerModal({
133
143
  ]}
134
144
  />
135
145
  </TouchableWithoutFeedback>
136
-
137
146
  <View
138
147
  style={[StyleSheet.absoluteFill, styles.modalRoot]}
139
148
  pointerEvents="box-none"
@@ -146,10 +155,17 @@ export function TimePickerModal({
146
155
  style={[
147
156
  styles.modalContent,
148
157
  {
149
- backgroundColor: theme.dark
150
- ? overlay(10, theme.colors.surface)
151
- : theme.colors.surface,
152
- borderRadius: theme.roundness,
158
+ backgroundColor:
159
+ theme.dark && theme.isV3
160
+ ? theme.colors.elevation.level3
161
+ : theme.isV3
162
+ ? theme.colors.surface
163
+ : theme.dark
164
+ ? overlay(10, theme.colors.surface)
165
+ : theme.colors.surface,
166
+ borderRadius: theme.isV3
167
+ ? theme.roundness * 6
168
+ : theme.roundness,
153
169
  },
154
170
  ]}
155
171
  >
@@ -160,12 +176,12 @@ export function TimePickerModal({
160
176
  {
161
177
  ...textFont,
162
178
  color: theme?.isV3
163
- ? theme.colors.onBackground
179
+ ? theme.colors.onSurfaceVariant
164
180
  : (theme as any as MD2Theme).colors.text,
165
181
  },
166
182
  ]}
167
183
  >
168
- {uppercase ? label.toUpperCase() : label}
184
+ {uppercase ? labelText.toUpperCase() : labelText}
169
185
  </Text>
170
186
  </View>
171
187
  <View style={styles.timePickerContainer}>
@@ -242,21 +258,26 @@ const styles = StyleSheet.create({
242
258
  },
243
259
  shadowOpacity: 0.34,
244
260
  shadowRadius: 6.27,
245
- elevation: 10,
261
+ elevation: 3,
246
262
  minWidth: 287,
263
+ paddingVertical: 8,
247
264
  },
248
265
  labelContainer: {
249
- height: 28,
250
266
  justifyContent: 'flex-end',
251
267
  paddingLeft: 24,
252
268
  paddingRight: 24,
253
- marginTop: 8,
269
+ paddingTop: 16,
254
270
  },
255
271
  label: {
256
272
  letterSpacing: 1,
257
273
  fontSize: 13,
258
274
  },
259
- timePickerContainer: { padding: 24 },
275
+ timePickerContainer: {
276
+ paddingLeft: 24,
277
+ paddingTop: 20,
278
+ paddingBottom: 16,
279
+ paddingRight: 24,
280
+ },
260
281
  bottom: {
261
282
  flexDirection: 'row',
262
283
  alignItems: 'center',
@@ -2,8 +2,7 @@ import * as React from 'react'
2
2
  import Color from 'color'
3
3
  import { MD2Theme, useTheme } from 'react-native-paper'
4
4
 
5
- // 250? when bigger?
6
- export const circleSize = 215
5
+ export const circleSize = 256
7
6
 
8
7
  export type PossibleHourTypes = 'am' | 'pm'
9
8
  export type HourTypeMap = {
@@ -161,10 +160,9 @@ export function useSwitchColors(highlighted: boolean) {
161
160
  const backgroundColor = React.useMemo<string>(() => {
162
161
  if (theme.dark) {
163
162
  if (highlighted) {
164
- return Color(theme.colors.primary).hex()
165
- }
166
- if (theme.isV3) {
167
- return Color(theme.colors.surface).lighten(1.4).hex()
163
+ return theme.isV3
164
+ ? theme.colors.tertiaryContainer
165
+ : Color(theme.colors.primary).hex()
168
166
  }
169
167
  return theme.colors.backdrop
170
168
  }
@@ -181,10 +179,12 @@ export function useSwitchColors(highlighted: boolean) {
181
179
 
182
180
  const color = React.useMemo<string>(() => {
183
181
  if (highlighted && !theme.dark) {
184
- return theme.colors.primary
182
+ return theme.isV3 ? theme.colors.onSurfaceVariant : theme.colors.primary
185
183
  }
186
184
  if (highlighted && theme.dark) {
187
- return theme.colors.background
185
+ return theme.isV3
186
+ ? theme.colors.onTertiaryContainer
187
+ : theme.colors.background
188
188
  }
189
189
  if (theme.isV3) {
190
190
  return theme.colors.onSurfaceVariant
@@ -201,33 +201,39 @@ export function useInputColors(highlighted: boolean) {
201
201
  const backgroundColor = React.useMemo<string>(() => {
202
202
  if (theme.dark) {
203
203
  if (highlighted) {
204
- return Color(theme.colors.primary).hex()
204
+ return theme.isV3
205
+ ? theme.colors.primaryContainer
206
+ : Color(theme.colors.primary).hex()
205
207
  }
206
- return Color(theme.colors.surface).lighten(1.4).hex()
208
+ return theme.isV3
209
+ ? theme.colors.surfaceVariant
210
+ : Color(theme.colors.surface).lighten(1.4).hex()
207
211
  }
208
212
 
209
213
  if (highlighted) {
210
214
  if (theme.isV3) {
211
- return Color(theme.colors.primaryContainer).hex()
215
+ return theme.colors.secondaryContainer
212
216
  }
213
217
  return Color(theme.colors.primary).lighten(1).hex()
214
218
  }
215
219
  if (theme.isV3) {
216
- return Color(theme.colors.outline).lighten(0.9).hex()
220
+ return theme.colors.surfaceVariant
217
221
  }
218
222
  return Color(theme.colors.surface).darken(0.1).hex()
219
223
  }, [highlighted, theme])
220
224
 
221
225
  const color = React.useMemo<string>(() => {
222
- if (highlighted && !theme.dark) {
223
- return theme.colors.primary
224
- }
225
226
  if (theme.isV3) {
226
227
  if (!highlighted) {
227
- return theme.colors.onBackground
228
+ return theme.isV3 ? theme.colors.onSurface : theme.colors.onBackground
228
229
  }
229
- return theme.colors.background
230
+ return theme.isV3
231
+ ? theme.colors.onPrimaryContainer
232
+ : theme.colors.onBackground
230
233
  } else {
234
+ if (highlighted && !theme.dark) {
235
+ return theme.colors.primary
236
+ }
231
237
  return (theme as any as MD2Theme).colors.text
232
238
  }
233
239
  }, [highlighted, theme])
package/src/index.tsx CHANGED
@@ -13,3 +13,4 @@ export { default as pl } from './translations/pl'
13
13
  export { default as pt } from './translations/pt'
14
14
  export { default as enGB } from './translations/enGB'
15
15
  export { default as de } from './translations/de'
16
+ export { default as tr } from './translations/tr'
@@ -0,0 +1,21 @@
1
+ import type { TranslationsType } from './utils'
2
+
3
+ const tr: TranslationsType = {
4
+ save: 'Kaydet',
5
+ selectSingle: 'Tarih seç',
6
+ selectMultiple: 'Tarihleri seç',
7
+ selectRange: 'Periyot seç',
8
+ notAccordingToDateFormat: (inputFormat) =>
9
+ `Tarih formatı ${inputFormat} olmalı`,
10
+ mustBeHigherThan: (date) => `${date} tarihinden sonra olmalı`,
11
+ mustBeLowerThan: (date) => `${date} tarihinden önce olmalı`,
12
+ mustBeBetween: (startDate, endDate) =>
13
+ `${startDate} - ${endDate} tarihleri arasında olmalı`,
14
+ dateIsDisabled: 'Gün seçilemez',
15
+ previous: 'Önceki',
16
+ next: 'Sonraki',
17
+ typeInDate: 'Tarihi yazın',
18
+ pickDateFromCalendar: 'Takvimden tarih seçin',
19
+ close: 'Kapat',
20
+ }
21
+ export default tr
package/src/utils.ts CHANGED
@@ -39,6 +39,15 @@ export function useHeaderTextColor() {
39
39
  export function useTextColorOnPrimary() {
40
40
  const theme = useTheme()
41
41
  const isDark = !Color(theme.colors.primary).isLight()
42
+
43
+ if (theme.isV3) {
44
+ if (isDark && theme.dark) {
45
+ return theme.colors.onSurface
46
+ } else {
47
+ return theme.colors.onPrimary
48
+ }
49
+ }
50
+
42
51
  return isDark ? '#fff' : '#000'
43
52
  }
44
53