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.
- package/README.md +79 -22
- package/lib/commonjs/Date/AnimatedCrossView.js +9 -8
- package/lib/commonjs/Date/AnimatedCrossView.js.map +1 -1
- package/lib/commonjs/Date/AutoSizer.js +6 -5
- package/lib/commonjs/Date/AutoSizer.js.map +1 -1
- package/lib/commonjs/Date/Calendar.js +46 -39
- package/lib/commonjs/Date/Calendar.js.map +1 -1
- package/lib/commonjs/Date/CalendarEdit.js +32 -111
- package/lib/commonjs/Date/CalendarEdit.js.map +1 -1
- package/lib/commonjs/Date/CalendarHeader.js +23 -12
- package/lib/commonjs/Date/CalendarHeader.js.map +1 -1
- package/lib/commonjs/Date/DatePickerInput.js +93 -20
- package/lib/commonjs/Date/DatePickerInput.js.map +1 -1
- package/lib/commonjs/Date/DatePickerModal.js +2 -2
- package/lib/commonjs/Date/DatePickerModalContent.js +7 -4
- package/lib/commonjs/Date/DatePickerModalContent.js.map +1 -1
- package/lib/commonjs/Date/DatePickerModalContentHeader.js +43 -34
- package/lib/commonjs/Date/DatePickerModalContentHeader.js.map +1 -1
- package/lib/commonjs/Date/DatePickerModalHeader.js +12 -5
- package/lib/commonjs/Date/DatePickerModalHeader.js.map +1 -1
- package/lib/commonjs/Date/DatePickerModalHeaderBackground.js +6 -5
- package/lib/commonjs/Date/DatePickerModalHeaderBackground.js.map +1 -1
- package/lib/commonjs/Date/DateRangeInput.js +23 -24
- package/lib/commonjs/Date/DateRangeInput.js.map +1 -1
- package/lib/commonjs/Date/Day.js +7 -3
- package/lib/commonjs/Date/Day.js.map +1 -1
- package/lib/commonjs/Date/DayName.js +6 -5
- package/lib/commonjs/Date/DayName.js.map +1 -1
- package/lib/commonjs/Date/DayNames.js +7 -6
- package/lib/commonjs/Date/DayNames.js.map +1 -1
- package/lib/commonjs/Date/DayRange.js +9 -8
- package/lib/commonjs/Date/DayRange.js.map +1 -1
- package/lib/commonjs/Date/Month.js +59 -49
- package/lib/commonjs/Date/Month.js.map +1 -1
- package/lib/commonjs/Date/Swiper.js +35 -29
- package/lib/commonjs/Date/Swiper.js.map +1 -1
- package/lib/commonjs/Date/Swiper.native.js +29 -23
- package/lib/commonjs/Date/Swiper.native.js.map +1 -1
- package/lib/commonjs/Date/SwiperUtils.js +7 -6
- package/lib/commonjs/Date/SwiperUtils.js.map +1 -1
- package/lib/commonjs/Date/YearPicker.js +30 -20
- package/lib/commonjs/Date/YearPicker.js.map +1 -1
- package/lib/commonjs/Date/dateUtils.js +106 -37
- package/lib/commonjs/Date/dateUtils.js.map +1 -1
- package/lib/commonjs/Date/inputUtils.js +84 -0
- package/lib/commonjs/Date/inputUtils.js.map +1 -0
- package/lib/commonjs/TextInputMask.js +11 -10
- package/lib/commonjs/TextInputMask.js.map +1 -1
- package/lib/commonjs/Time/AmPmSwitcher.js +37 -19
- package/lib/commonjs/Time/AmPmSwitcher.js.map +1 -1
- package/lib/commonjs/Time/AnalogClock.js +25 -15
- package/lib/commonjs/Time/AnalogClock.js.map +1 -1
- package/lib/commonjs/Time/AnalogClockHours.js +17 -11
- package/lib/commonjs/Time/AnalogClockHours.js.map +1 -1
- package/lib/commonjs/Time/AnalogClockMinutes.js +7 -6
- package/lib/commonjs/Time/AnalogClockMinutes.js.map +1 -1
- package/lib/commonjs/Time/AnimatedClockSwitcher.js +8 -7
- package/lib/commonjs/Time/AnimatedClockSwitcher.js.map +1 -1
- package/lib/commonjs/Time/TimeInput.js +16 -12
- package/lib/commonjs/Time/TimeInput.js.map +1 -1
- package/lib/commonjs/Time/TimeInputs.js +12 -11
- package/lib/commonjs/Time/TimeInputs.js.map +1 -1
- package/lib/commonjs/Time/TimePicker.js +37 -15
- package/lib/commonjs/Time/TimePicker.js.map +1 -1
- package/lib/commonjs/Time/TimePickerModal.js +19 -15
- package/lib/commonjs/Time/TimePickerModal.js.map +1 -1
- package/lib/commonjs/Time/timeUtils.js +14 -9
- package/lib/commonjs/Time/timeUtils.js.map +1 -1
- package/lib/commonjs/index.js +66 -5
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/translations/en.js +25 -0
- package/lib/commonjs/translations/en.js.map +1 -0
- package/lib/commonjs/translations/enGB.js +25 -0
- package/lib/commonjs/translations/enGB.js.map +1 -0
- package/lib/commonjs/translations/nl.js +25 -0
- package/lib/commonjs/translations/nl.js.map +1 -0
- package/lib/commonjs/translations/pl.js +25 -0
- package/lib/commonjs/translations/pl.js.map +1 -0
- package/lib/commonjs/translations/utils.js +31 -0
- package/lib/commonjs/translations/utils.js.map +1 -0
- package/lib/commonjs/utils.js +19 -9
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/Date/AnimatedCrossView.js +7 -6
- package/lib/module/Date/AnimatedCrossView.js.map +1 -1
- package/lib/module/Date/AutoSizer.js +4 -3
- package/lib/module/Date/AutoSizer.js.map +1 -1
- package/lib/module/Date/Calendar.js +46 -39
- package/lib/module/Date/Calendar.js.map +1 -1
- package/lib/module/Date/CalendarEdit.js +28 -104
- package/lib/module/Date/CalendarEdit.js.map +1 -1
- package/lib/module/Date/CalendarHeader.js +19 -9
- package/lib/module/Date/CalendarHeader.js.map +1 -1
- package/lib/module/Date/DatePickerInput.js +88 -18
- package/lib/module/Date/DatePickerInput.js.map +1 -1
- package/lib/module/Date/DatePickerModalContent.js +5 -2
- package/lib/module/Date/DatePickerModalContent.js.map +1 -1
- package/lib/module/Date/DatePickerModalContentHeader.js +38 -30
- package/lib/module/Date/DatePickerModalContentHeader.js.map +1 -1
- package/lib/module/Date/DatePickerModalHeader.js +9 -3
- package/lib/module/Date/DatePickerModalHeader.js.map +1 -1
- package/lib/module/Date/DatePickerModalHeaderBackground.js +4 -3
- package/lib/module/Date/DatePickerModalHeaderBackground.js.map +1 -1
- package/lib/module/Date/DateRangeInput.js +22 -22
- package/lib/module/Date/DateRangeInput.js.map +1 -1
- package/lib/module/Date/Day.js +5 -1
- package/lib/module/Date/Day.js.map +1 -1
- package/lib/module/Date/DayName.js +4 -3
- package/lib/module/Date/DayName.js.map +1 -1
- package/lib/module/Date/DayNames.js +5 -4
- package/lib/module/Date/DayNames.js.map +1 -1
- package/lib/module/Date/DayRange.js +7 -6
- package/lib/module/Date/DayRange.js.map +1 -1
- package/lib/module/Date/Month.js +54 -45
- package/lib/module/Date/Month.js.map +1 -1
- package/lib/module/Date/Swiper.js +32 -26
- package/lib/module/Date/Swiper.js.map +1 -1
- package/lib/module/Date/Swiper.native.js +27 -21
- package/lib/module/Date/Swiper.native.js.map +1 -1
- package/lib/module/Date/SwiperUtils.js +5 -4
- package/lib/module/Date/SwiperUtils.js.map +1 -1
- package/lib/module/Date/YearPicker.js +28 -18
- package/lib/module/Date/YearPicker.js.map +1 -1
- package/lib/module/Date/dateUtils.js +78 -29
- package/lib/module/Date/dateUtils.js.map +1 -1
- package/lib/module/Date/inputUtils.js +70 -0
- package/lib/module/Date/inputUtils.js.map +1 -0
- package/lib/module/TextInputMask.js +9 -8
- package/lib/module/TextInputMask.js.map +1 -1
- package/lib/module/Time/AmPmSwitcher.js +35 -18
- package/lib/module/Time/AmPmSwitcher.js.map +1 -1
- package/lib/module/Time/AnalogClock.js +23 -14
- package/lib/module/Time/AnalogClock.js.map +1 -1
- package/lib/module/Time/AnalogClockHours.js +14 -9
- package/lib/module/Time/AnalogClockHours.js.map +1 -1
- package/lib/module/Time/AnalogClockMinutes.js +5 -4
- package/lib/module/Time/AnalogClockMinutes.js.map +1 -1
- package/lib/module/Time/AnimatedClockSwitcher.js +6 -5
- package/lib/module/Time/AnimatedClockSwitcher.js.map +1 -1
- package/lib/module/Time/TimeInput.js +14 -10
- package/lib/module/Time/TimeInput.js.map +1 -1
- package/lib/module/Time/TimeInputs.js +10 -9
- package/lib/module/Time/TimeInputs.js.map +1 -1
- package/lib/module/Time/TimePicker.js +32 -12
- package/lib/module/Time/TimePicker.js.map +1 -1
- package/lib/module/Time/TimePickerModal.js +17 -13
- package/lib/module/Time/TimePickerModal.js.map +1 -1
- package/lib/module/Time/timeUtils.js +5 -1
- package/lib/module/Time/timeUtils.js.map +1 -1
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/translations/en.js +18 -0
- package/lib/module/translations/en.js.map +1 -0
- package/lib/module/translations/enGB.js +18 -0
- package/lib/module/translations/enGB.js.map +1 -0
- package/lib/module/translations/nl.js +18 -0
- package/lib/module/translations/nl.js.map +1 -0
- package/lib/module/translations/pl.js +18 -0
- package/lib/module/translations/pl.js.map +1 -0
- package/lib/module/translations/utils.js +22 -0
- package/lib/module/translations/utils.js.map +1 -0
- package/lib/module/utils.js +11 -5
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/{src/Date → Date}/AnimatedCrossView.d.ts +0 -0
- package/lib/typescript/{src/Date → Date}/AutoSizer.d.ts +0 -0
- package/lib/typescript/{src/Date → Date}/Calendar.d.ts +5 -3
- package/lib/typescript/{src/Date → Date}/CalendarEdit.d.ts +3 -3
- package/lib/typescript/{src/Date → Date}/CalendarHeader.d.ts +1 -1
- package/lib/typescript/Date/DatePickerInput.d.ts +18 -0
- package/lib/typescript/{src/Date → Date}/DatePickerModal.d.ts +0 -0
- package/lib/typescript/{src/Date → Date}/DatePickerModalContent.d.ts +2 -1
- package/lib/typescript/{src/Date → Date}/DatePickerModalContentHeader.d.ts +4 -4
- package/lib/typescript/{src/Date → Date}/DatePickerModalHeader.d.ts +1 -0
- package/lib/typescript/{src/Date → Date}/DatePickerModalHeaderBackground.d.ts +0 -0
- package/lib/typescript/Date/DateRangeInput.d.ts +3 -0
- package/lib/typescript/{src/Date → Date}/Day.d.ts +0 -0
- package/lib/typescript/{src/Date → Date}/DayName.d.ts +0 -0
- package/lib/typescript/{src/Date → Date}/DayNames.d.ts +0 -0
- package/lib/typescript/{src/Date → Date}/DayRange.d.ts +0 -0
- package/lib/typescript/{src/Date → Date}/Month.d.ts +0 -0
- package/lib/typescript/{src/Date → Date}/Swiper.d.ts +0 -0
- package/lib/typescript/{src/Date → Date}/Swiper.native.d.ts +0 -0
- package/lib/typescript/{src/Date → Date}/SwiperUtils.d.ts +1 -1
- package/lib/typescript/{src/Date → Date}/Week.d.ts +0 -0
- package/lib/typescript/{src/Date → Date}/YearPicker.d.ts +0 -0
- package/lib/typescript/{src/Date → Date}/dateUtils.d.ts +15 -0
- package/lib/typescript/{src/Date → Date}/dateUtils.test.d.ts +0 -0
- package/lib/typescript/Date/inputUtils.d.ts +14 -0
- package/lib/typescript/TextInputMask.d.ts +11 -0
- package/lib/typescript/Time/AmPmSwitcher.d.ts +4 -0
- package/lib/typescript/{src/Time → Time}/AnalogClock.d.ts +1 -1
- package/lib/typescript/{src/Time → Time}/AnalogClockHours.d.ts +0 -0
- package/lib/typescript/{src/Time → Time}/AnalogClockMinutes.d.ts +0 -0
- package/lib/typescript/{src/Time → Time}/AnimatedClockSwitcher.d.ts +0 -0
- package/lib/typescript/{src/Time → Time}/TimeInput.d.ts +0 -0
- package/lib/typescript/{src/Time → Time}/TimeInputs.d.ts +1 -1
- package/lib/typescript/{src/Time → Time}/TimePicker.d.ts +4 -0
- package/lib/typescript/{src/Time → Time}/TimePickerModal.d.ts +1 -1
- package/lib/typescript/{src/Time → Time}/timeUtils.d.ts +0 -0
- package/lib/typescript/index.d.ts +13 -0
- package/lib/typescript/translations/en.d.ts +3 -0
- package/lib/typescript/translations/enGB.d.ts +3 -0
- package/lib/typescript/translations/nl.d.ts +3 -0
- package/lib/typescript/translations/pl.d.ts +3 -0
- package/lib/typescript/translations/utils.d.ts +18 -0
- package/lib/typescript/utils.d.ts +58 -0
- package/package.json +39 -38
- package/src/.DS_Store +0 -0
- package/src/Date/Calendar.tsx +14 -13
- package/src/Date/CalendarEdit.tsx +17 -121
- package/src/Date/CalendarHeader.tsx +18 -3
- package/src/Date/DatePickerInput.tsx +103 -25
- package/src/Date/DatePickerModalContent.tsx +5 -1
- package/src/Date/DatePickerModalContentHeader.tsx +26 -12
- package/src/Date/DatePickerModalHeader.tsx +8 -1
- package/src/Date/DateRangeInput.tsx +26 -17
- package/src/Date/Day.tsx +4 -0
- package/src/Date/Month.tsx +20 -44
- package/src/Date/Swiper.tsx +1 -0
- package/src/Date/SwiperUtils.ts +1 -1
- package/src/Date/YearPicker.tsx +6 -1
- package/src/Date/dateUtils.tsx +70 -9
- package/src/Date/inputUtils.ts +94 -0
- package/src/TextInputMask.tsx +10 -3
- package/src/Time/AmPmSwitcher.tsx +20 -11
- package/src/Time/AnalogClock.tsx +12 -14
- package/src/Time/AnalogClockHours.tsx +14 -5
- package/src/Time/AnalogClockMinutes.tsx +4 -1
- package/src/Time/TimeInput.tsx +3 -0
- package/src/Time/TimeInputs.tsx +1 -5
- package/src/Time/TimePicker.tsx +44 -22
- package/src/Time/TimePickerModal.tsx +4 -1
- package/src/Time/timeUtils.ts +4 -1
- package/src/index.tsx +7 -0
- package/src/translations/en.ts +20 -0
- package/src/translations/enGB.ts +20 -0
- package/src/translations/nl.ts +20 -0
- package/src/translations/pl.ts +21 -0
- package/src/translations/utils.ts +47 -0
- package/src/utils.ts +13 -5
- package/lib/typescript/src/Date/DatePickerInput.d.ts +0 -1
- package/lib/typescript/src/Date/DateRangeInput.d.ts +0 -1
- package/lib/typescript/src/TextInputMask.d.ts +0 -3
- package/lib/typescript/src/Time/AmPmSwitcher.d.ts +0 -4
- package/lib/typescript/src/index.d.ts +0 -6
- 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 {
|
|
10
|
-
import { LocalState } from './DatePickerModalContent'
|
|
11
|
-
|
|
12
|
-
import
|
|
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
|
|
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
|
-
<
|
|
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
|
-
<
|
|
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
|
-
<
|
|
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
|
|
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
|
|
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
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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
|
|
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:
|
|
25
|
+
locale: string | undefined
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
function getLabel(
|
|
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
|
|
37
|
+
return getTranslation(locale, 'selectRange')
|
|
33
38
|
}
|
|
34
|
-
if (mode === 'single') {
|
|
35
|
-
return 'Select date'
|
|
36
|
-
}
|
|
37
|
-
|
|
38
39
|
if (mode === 'multiple') {
|
|
39
|
-
return
|
|
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
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
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