Skip to content

Commit 96dd900

Browse files
committed
feat: icon name props for date and time pickers
1 parent 2146e20 commit 96dd900

File tree

8 files changed

+59
-9
lines changed

8 files changed

+59
-9
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ export default function ReadMeExampleSingle() {
151151
// uppercase={false} // optional, default is true
152152
// label="Select date" // optional
153153
// animationType="slide" // optional, default is 'slide' on ios/android and 'none' on web
154+
// closeIcon="close" // optional, default is "close"
155+
// editIcon="pencil" // optional, default is "pencil"
156+
// calendarIcon="calendar" // optional, default is "calendar"
154157
/>
155158
</>
156159
);
@@ -209,6 +212,9 @@ export default function ReadMeExampleRange() {
209212
// startLabel="From" // optional
210213
// endLabel="To" // optional
211214
// animationType="slide" // optional, default is slide on ios/android and none on web
215+
// closeIcon="close" // optional, default is "close"
216+
// editIcon="pencil" // optional, default is "pencil"
217+
// calendarIcon="calendar" // optional, default is "calendar"
212218
/>
213219
</>
214220
);
@@ -263,6 +269,7 @@ export default function ReadMeExampleMultiple() {
263269
// startLabel="From" // optional
264270
// endLabel="To" // optional
265271
// animationType="slide" // optional, default is slide on ios/android and none on web
272+
// closeIcon="close" // optional, default is "close"
266273
/>
267274
</>
268275
);
@@ -283,6 +290,7 @@ export default function ReadMeExampleDatePickerInput() {
283290
onChange={(d) => setInputDate(d)}
284291
inputMode="start"
285292
// mode="outlined" (see react-native-paper docs)
293+
// calendarIcon="calendar" // optional, default is "calendar"
286294
// other react native TextInput props
287295
/>
288296
</>
@@ -326,6 +334,8 @@ export default function TimePickerPage() {
326334
confirmLabel="Ok" // optional, default: 'Ok'
327335
animationType="fade" // optional, default is 'none'
328336
locale="en" // optional, default is automically detected by your system
337+
// keyboardIcon="keyboard-outline" // optional, default is "keyboard-outline"
338+
// clockIcon="clock-outline" // optional, default is "clock-outline"
329339
/>
330340
<Button onPress={()=> setVisible(true)}>
331341
Pick time

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
@@ -144,6 +144,7 @@ export function DatePickerModalContent(
144144
saveLabel={props.saveLabel}
145145
uppercase={props.uppercase ?? true}
146146
disableSafeTop={disableSafeTop}
147+
closeIcon={props.closeIcon}
147148
/>
148149
<DatePickerModalContentHeader
149150
state={state}
@@ -158,6 +159,8 @@ export function DatePickerModalContent(
158159
endLabel={props.endLabel}
159160
uppercase={props.uppercase ?? true}
160161
locale={locale}
162+
editIcon={props.editIcon}
163+
calendarIcon={props.calendarIcon}
161164
/>
162165
</DatePickerModalHeaderBackground>
163166

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

0 commit comments

Comments
 (0)