Skip to content

Commit 6f1078c

Browse files
Merge pull request #244 from cbernier2/master
feat: Enable changing the input font size and the 24 hour mode
2 parents 9608906 + 612b2c3 commit 6f1078c

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

docusaurus/docs/time-picker.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,11 @@ The icon used to toggle between the OS input. Defaults to `keyboard-outline`. Yo
105105
**clockIcon**
106106
`Type: string | undefined`
107107
The icon used to toggle between time picker and input. Defaults to `clock-outline`. You can pass the name of an icon from [MaterialCommunityIcons](https://materialdesignicons.com/).
108+
109+
**use24HourClock**
110+
`Type: boolean | undefined`
111+
Flag indicating if the time input should use the 24 hours clock. Defaults to the system clock.
112+
113+
**inputFontSize**
114+
`Type: number | undefined`
115+
Font size of the time input. Defaults to 57. Useful when using a custom font.

src/Time/TimeInput.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface TimeInputProps
2424
pressed: boolean
2525
onChanged: (n: number) => any
2626
inputType: PossibleInputTypes
27+
inputFontSize?: number
2728
}
2829

2930
function TimeInput(
@@ -34,6 +35,7 @@ function TimeInput(
3435
onPress,
3536
onChanged,
3637
inputType,
38+
inputFontSize = 57,
3739
...rest
3840
}: TimeInputProps,
3941
ref: any
@@ -77,6 +79,7 @@ function TimeInput(
7779
// eslint-disable-next-line react-native/no-inline-styles
7880
{
7981
color,
82+
fontSize: inputFontSize,
8083
backgroundColor,
8184
borderRadius: theme.roundness * 2,
8285
borderColor:
@@ -123,7 +126,6 @@ function TimeInput(
123126
const styles = StyleSheet.create({
124127
root: { position: 'relative', height: 80, width: 96 },
125128
input: {
126-
fontSize: 57,
127129
textAlign: 'center',
128130
textAlignVertical: 'center',
129131
width: 96,

src/Time/TimeInputs.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function TimeInputs({
2727
inputType,
2828
onChange,
2929
is24Hour,
30+
inputFontSize,
3031
}: {
3132
inputType: PossibleInputTypes
3233
focused: PossibleClockTypes
@@ -39,6 +40,7 @@ function TimeInputs({
3940
focused?: undefined | PossibleClockTypes
4041
}) => any
4142
is24Hour: boolean
43+
inputFontSize?: number
4244
}) {
4345
const startInput = React.useRef<TextInputNative | null>(null)
4446
const endInput = React.useRef<TextInputNative | null>(null)
@@ -78,6 +80,7 @@ function TimeInputs({
7880
<View style={styles.column}>
7981
<TimeInput
8082
ref={startInput}
83+
inputFontSize={inputFontSize}
8184
placeholder={'00'}
8285
value={toHourInputFormat(hours, is24Hour)}
8386
clockType={clockTypes.hours}
@@ -145,6 +148,7 @@ function TimeInputs({
145148
<View style={styles.column}>
146149
<TimeInput
147150
ref={endInput}
151+
inputFontSize={inputFontSize}
148152
placeholder={'00'}
149153
value={minutes}
150154
clockType={clockTypes.minutes}

src/Time/TimePicker.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ function TimePicker({
3636
inputType,
3737
onChange,
3838
locale,
39+
use24HourClock,
40+
inputFontSize,
3941
}: {
4042
locale?: undefined | string
4143
inputType: PossibleInputTypes
@@ -44,6 +46,8 @@ function TimePicker({
4446
minutes: number
4547
onFocusInput: (type: PossibleClockTypes) => any
4648
onChange: onChangeFunc
49+
use24HourClock?: boolean
50+
inputFontSize?: number
4751
}) {
4852
const [displayMode, setDisplayMode] = React.useState<'AM' | 'PM' | undefined>(
4953
undefined
@@ -53,14 +57,17 @@ function TimePicker({
5357

5458
// method to check whether we have 24 hours in clock or 12
5559
const is24Hour = React.useMemo(() => {
60+
if (use24HourClock !== undefined) {
61+
return use24HourClock
62+
}
5663
const formatter = new Intl.DateTimeFormat(locale, {
5764
hour: '2-digit',
5865
minute: '2-digit',
5966
timeZone: 'UTC',
6067
})
6168
const formatted = formatter.format(new Date(Date.UTC(2020, 1, 1, 23)))
6269
return formatted.includes('23')
63-
}, [locale])
70+
}, [locale, use24HourClock])
6471

6572
// Initialize display Mode according the hours value
6673
React.useEffect(() => {
@@ -104,6 +111,7 @@ function TimePicker({
104111
>
105112
<TimeInputs
106113
inputType={inputType}
114+
inputFontSize={inputFontSize}
107115
hours={hours}
108116
minutes={minutes}
109117
is24Hour={is24Hour}

src/Time/TimePickerModal.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export function TimePickerModal({
5555
locale,
5656
keyboardIcon = 'keyboard-outline',
5757
clockIcon = 'clock-outline',
58+
use24HourClock,
59+
inputFontSize,
5860
}: {
5961
locale?: undefined | string
6062
label?: string
@@ -69,6 +71,8 @@ export function TimePickerModal({
6971
animationType?: 'slide' | 'fade' | 'none'
7072
keyboardIcon?: string
7173
clockIcon?: string
74+
use24HourClock?: boolean
75+
inputFontSize?: number
7276
}) {
7377
const theme = useTheme()
7478

@@ -188,6 +192,8 @@ export function TimePickerModal({
188192
<TimePicker
189193
locale={locale}
190194
inputType={inputType}
195+
use24HourClock={use24HourClock}
196+
inputFontSize={inputFontSize}
191197
focused={focused}
192198
hours={localHours}
193199
minutes={localMinutes}

0 commit comments

Comments
 (0)