Skip to content

Commit 6a61039

Browse files
Merge branch 'master' into feature/start-end-year
2 parents 06e5efa + 73a645b commit 6a61039

File tree

10 files changed

+106
-10
lines changed

10 files changed

+106
-10
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ npm install react-native-paper-dates --save
5757

5858
## Import some localized strings
5959
Ideally you do this somewhere in your `index.js` before `react-native-paper-dates` is used.
60-
Currently we have en/nl/de/pl/pt translations but it's really easy to add one extra since it are only some labels and error messages.
60+
Currently we have en/nl/de/pl/pt/ar translations but it's really easy to add one extra since it are only some labels and error messages.
6161

6262
```tsx
6363
// e.g in your index.js
@@ -67,6 +67,7 @@ import {
6767
// de,
6868
// pl,
6969
// pt,
70+
//ar,
7071
enGB,
7172
registerTranslation,
7273
} from 'react-native-paper-dates'
@@ -75,6 +76,7 @@ import {
7576
// registerTranslation('pl', pl)
7677
// registerTranslation('pt', pt)
7778
// registerTranslation('de', de)
79+
// registerTranslation('ar', ar)
7880
registerTranslation('en-GB', enGB)
7981
```
8082

@@ -153,6 +155,9 @@ export default function ReadMeExampleSingle() {
153155
// animationType="slide" // optional, default is 'slide' on ios/android and 'none' on web
154156
// startYear={2000} // optional, default is 1800
155157
// endYear={2100} // optional, default is 2200
158+
// closeIcon="close" // optional, default is "close"
159+
// editIcon="pencil" // optional, default is "pencil"
160+
// calendarIcon="calendar" // optional, default is "calendar"
156161
/>
157162
</>
158163
);
@@ -213,6 +218,9 @@ export default function ReadMeExampleRange() {
213218
// animationType="slide" // optional, default is slide on ios/android and none on web
214219
// startYear={2000} // optional, default is 1800
215220
// endYear={2100} // optional, default is 2200
221+
// closeIcon="close" // optional, default is "close"
222+
// editIcon="pencil" // optional, default is "pencil"
223+
// calendarIcon="calendar" // optional, default is "calendar"
216224
/>
217225
</>
218226
);
@@ -269,6 +277,7 @@ export default function ReadMeExampleMultiple() {
269277
// animationType="slide" // optional, default is slide on ios/android and none on web
270278
// startYear={2000} // optional, default is 1800
271279
// endYear={2100} // optional, default is 2200
280+
// closeIcon="close" // optional, default is "close"
272281
/>
273282
</>
274283
);
@@ -289,6 +298,7 @@ export default function ReadMeExampleDatePickerInput() {
289298
onChange={(d) => setInputDate(d)}
290299
inputMode="start"
291300
// mode="outlined" (see react-native-paper docs)
301+
// calendarIcon="calendar" // optional, default is "calendar"
292302
// other react native TextInput props
293303
/>
294304
</>
@@ -332,6 +342,8 @@ export default function TimePickerPage() {
332342
confirmLabel="Ok" // optional, default: 'Ok'
333343
animationType="fade" // optional, default is 'none'
334344
locale="en" // optional, default is automically detected by your system
345+
// keyboardIcon="keyboard-outline" // optional, default is "keyboard-outline"
346+
// clockIcon="clock-outline" // optional, default is "clock-outline"
335347
/>
336348
<Button onPress={()=> setVisible(true)}>
337349
Pick time
@@ -387,6 +399,8 @@ or npm
387399
npm install react-native-localize @formatjs/intl-pluralrules @formatjs/intl-getcanonicallocales @formatjs/intl-listformat @formatjs/intl-displaynames @formatjs/intl-locale @formatjs/intl-datetimeformat @formatjs/intl-numberformat @formatjs/intl-relativetimeformat --save
388400
```
389401

402+
If using Expo, omit `react-native-localize` and use `expo install expo-localization` instead. Read more [here](https://docs.expo.dev/versions/latest/sdk/localization/#installation).
403+
390404
In your app starting entrypoint e.g. `./index.js` or even better use a `index.android.js` to prevent importing on iOS/web put the following code. (don't forget to import the languages you want to support, in the example only english language is supported)
391405

392406
```javascript

src/Date/DatePickerInput.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function DatePickerInput(
1919
inputMode,
2020
withModal = true,
2121
withDateFormatInLabel = true,
22+
calendarIcon = 'calendar',
2223
...rest
2324
}: {
2425
inputMode: 'start' | 'end'
@@ -28,6 +29,7 @@ function DatePickerInput(
2829
validRange?: ValidRangeType | undefined
2930
withModal?: boolean
3031
withDateFormatInLabel?: boolean
32+
calendarIcon?: string
3133
} & Omit<
3234
React.ComponentProps<typeof TextInput>,
3335
'value' | 'onChange' | 'onChangeText'
@@ -81,7 +83,7 @@ function DatePickerInput(
8183
<IconButton
8284
size={24}
8385
style={styles.calendarButton}
84-
icon="calendar"
86+
icon={calendarIcon}
8587
onPress={() => setVisible(true)}
8688
/>
8789
) : null}

src/Date/DatePickerModalContent.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export function DatePickerModalContent(
146146
saveLabel={props.saveLabel}
147147
uppercase={props.uppercase ?? true}
148148
disableSafeTop={disableSafeTop}
149+
closeIcon={props.closeIcon}
149150
/>
150151
<DatePickerModalContentHeader
151152
state={state}
@@ -160,6 +161,8 @@ export function DatePickerModalContent(
160161
endLabel={props.endLabel}
161162
uppercase={props.uppercase ?? true}
162163
locale={locale}
164+
editIcon={props.editIcon}
165+
calendarIcon={props.calendarIcon}
163166
/>
164167
</DatePickerModalHeaderBackground>
165168

src/Date/DatePickerModalContentHeader.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export interface HeaderPickProps {
1616
headerSeparator?: string
1717
startLabel?: string
1818
endLabel?: string
19+
editIcon?: string
20+
calendarIcon?: string
21+
closeIcon?: string
1922
}
2023

2124
export interface HeaderContentProps extends HeaderPickProps {
@@ -49,7 +52,15 @@ function getLabel(
4952
export default function DatePickerModalContentHeader(
5053
props: HeaderContentProps
5154
) {
52-
const { onToggle, collapsed, mode, moreLabel, uppercase } = props
55+
const {
56+
onToggle,
57+
collapsed,
58+
mode,
59+
moreLabel,
60+
uppercase,
61+
editIcon = 'pencil',
62+
calendarIcon = 'calendar',
63+
} = props
5364

5465
const label = getLabel(props.locale, props.mode, props.label)
5566

@@ -80,7 +91,7 @@ export default function DatePickerModalContentHeader(
8091
<View style={styles.fill} />
8192
{allowEditing ? (
8293
<IconButton
83-
icon={collapsed ? 'pencil' : 'calendar'}
94+
icon={collapsed ? editIcon : calendarIcon}
8495
accessibilityLabel={
8596
collapsed
8697
? getTranslation(props.locale, 'typeInDate')

src/Date/DatePickerModalHeader.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ export interface DatePickerModalHeaderProps {
1212
onDismiss: () => void
1313
onSave: () => void
1414
locale: string | undefined
15+
closeIcon?: string
1516
}
1617

1718
export default function DatePickerModalHeader(
1819
props: DatePickerModalHeaderProps
1920
) {
20-
const { disableSafeTop, locale } = props
21+
const { disableSafeTop, locale, closeIcon = 'close' } = props
2122
const saveLabel = props.saveLabel || getTranslation(locale, 'save')
2223
const color = useHeaderTextColor()
2324
return (
@@ -31,7 +32,7 @@ export default function DatePickerModalHeader(
3132
>
3233
<Appbar style={styles.appbarHeader}>
3334
<Appbar.Action
34-
icon="close"
35+
icon={closeIcon}
3536
accessibilityLabel={getTranslation(locale, 'close')}
3637
onPress={props.onDismiss}
3738
color={color}

src/Date/DateRangeInput.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { Text, IconButton } from 'react-native-paper'
55
import DatePickerModal from './DatePickerModal'
66

77
// WORK IN PROGRESS
8-
export default function DateRangeInput({ locale }: { locale: string }) {
8+
export default function DateRangeInput({
9+
locale,
10+
calendarIcon = 'calendar',
11+
}: {
12+
locale: string
13+
calendarIcon?: string
14+
}) {
915
const [visible, setVisible] = React.useState<boolean>(false)
1016
const onDismiss = React.useCallback(() => {
1117
setVisible(false)
@@ -50,7 +56,7 @@ export default function DateRangeInput({ locale }: { locale: string }) {
5056
<Text>Tot</Text>
5157
</View>
5258
<View>
53-
<IconButton icon="calendar" onPress={() => setVisible(true)} />
59+
<IconButton icon={calendarIcon} onPress={() => setVisible(true)} />
5460
<Text style={{ opacity: 0 }} accessible={false}>
5561
tot
5662
</Text>

src/Time/TimePickerModal.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Button, IconButton, overlay, useTheme } from 'react-native-paper'
1313
import TimePicker from './TimePicker'
1414
import {
1515
clockTypes,
16-
inputTypeIcons,
16+
getTimeInputTypeIcon,
1717
inputTypes,
1818
PossibleClockTypes,
1919
PossibleInputTypes,
@@ -40,6 +40,8 @@ export function TimePickerModal({
4040
confirmLabel = 'Ok',
4141
animationType = 'none',
4242
locale,
43+
keyboardIcon = 'keyboard-outline',
44+
clockIcon = 'clock-outline',
4345
}: {
4446
locale?: undefined | string
4547
label?: string
@@ -52,6 +54,8 @@ export function TimePickerModal({
5254
onDismiss: () => any
5355
onConfirm: (hoursAndMinutes: { hours: number; minutes: number }) => any
5456
animationType?: 'slide' | 'fade' | 'none'
57+
keyboardIcon?: string
58+
clockIcon?: string
5559
}) {
5660
const theme = useTheme()
5761

@@ -152,7 +156,10 @@ export function TimePickerModal({
152156
</View>
153157
<View style={styles.bottom}>
154158
<IconButton
155-
icon={inputTypeIcons[reverseInputTypes[inputType]]}
159+
icon={getTimeInputTypeIcon(inputType, {
160+
keyboard: keyboardIcon,
161+
picker: clockIcon,
162+
})}
156163
onPress={() => setInputType(reverseInputTypes[inputType])}
157164
size={24}
158165
style={styles.inputTypeToggle}

src/Time/timeUtils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ export const inputTypeIcons: InputIconMap = {
4545
picker: 'clock-outline',
4646
}
4747

48+
export const getTimeInputTypeIcon = (
49+
inputType: PossibleInputTypes,
50+
inputIconMap?: InputIconMap
51+
) => {
52+
return (
53+
inputIconMap?.[reverseInputTypes[inputType]] ||
54+
inputTypeIcons?.[reverseInputTypes[inputType]]
55+
)
56+
}
57+
4858
export type PossibleClockTypes = 'hours' | 'minutes'
4959
export type ClockTypeMap = {
5060
[clockType in PossibleClockTypes]: PossibleClockTypes

src/translations/ar.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { TranslationsType } from './utils'
2+
3+
const ar: TranslationsType = {
4+
save: 'حفظ',
5+
selectSingle: 'حدد تاريخ',
6+
selectMultiple: 'حدد التواريخ',
7+
selectRange: 'حدد الفترة',
8+
notAccordingToDateFormat: (inputFormat:string) =>
9+
`يجب أن يكون تنسيق التاريخ ${inputFormat}`,
10+
mustBeHigherThan: (date) => `يجب أن يكون بعد ${date}`,
11+
mustBeLowerThan: (date) => `يجب أن يكون قبل ${date}`,
12+
mustBeBetween: (startDate, endDate) =>
13+
`يجب أن يكون بين ${startDate} - ${endDate}`,
14+
dateIsDisabled: 'اليوم غير مسموح به',
15+
previous: 'السابق',
16+
next: 'التالي',
17+
typeInDate: 'اكتب التاريخ',
18+
pickDateFromCalendar: 'اختر التاريخ من التقويم',
19+
close: 'أغلق',
20+
}
21+
export default ar

src/translations/ko.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { TranslationsType } from './utils'
2+
3+
const ko: TranslationsType = {
4+
save: '저장,
5+
selectSingle: '날짜 선택',
6+
selectMultiple: '여러 날짜 선택',
7+
selectRange: '기간 선택',
8+
notAccordingToDateFormat: (inputFormat) =>
9+
`날짜 형식은 ${inputFormat}가 되어야 합니다`,
10+
mustBeHigherThan: (date) => `${date} 보다 커야 합니다`,
11+
mustBeLowerThan: (date) => `${date} 보다 작아야 합니다`,
12+
mustBeBetween: (startDate, endDate) =>
13+
`${startDate} - ${endDate} 사이여야 합니다`,
14+
dateIsDisabled: '날짜는 허용되지 않습니다',
15+
previous: '이전',
16+
next: '다음',
17+
typeInDate: '날짜 입력',
18+
pickDateFromCalendar: '달력에서 날짜 선택',
19+
close: '닫기',
20+
}
21+
export default ko

0 commit comments

Comments
 (0)