react-native-timer-picker 1.3.0 → 1.5.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 +7 -0
- package/dist/commonjs/components/Modal/index.js +13 -14
- package/dist/commonjs/components/Modal/index.js.map +1 -1
- package/dist/commonjs/components/TimerPicker/DurationScroll.js +55 -32
- package/dist/commonjs/components/TimerPicker/DurationScroll.js.map +1 -1
- package/dist/commonjs/components/TimerPicker/TimerPicker.styles.js +23 -3
- package/dist/commonjs/components/TimerPicker/TimerPicker.styles.js.map +1 -1
- package/dist/commonjs/components/TimerPicker/index.js +37 -28
- package/dist/commonjs/components/TimerPicker/index.js.map +1 -1
- package/dist/commonjs/components/TimerPickerModal.styles.js.map +1 -1
- package/dist/commonjs/components/index.js +46 -39
- package/dist/commonjs/components/index.js.map +1 -1
- package/dist/commonjs/tests/Modal.test.js +3 -1
- package/dist/commonjs/tests/Modal.test.js.map +1 -1
- package/dist/commonjs/utils/generateNumbers.js +33 -10
- package/dist/commonjs/utils/generateNumbers.js.map +1 -1
- package/dist/commonjs/utils/padNumber.js +15 -0
- package/dist/commonjs/utils/padNumber.js.map +1 -0
- package/dist/module/components/Modal/index.js +13 -14
- package/dist/module/components/Modal/index.js.map +1 -1
- package/dist/module/components/TimerPicker/DurationScroll.js +56 -33
- package/dist/module/components/TimerPicker/DurationScroll.js.map +1 -1
- package/dist/module/components/TimerPicker/TimerPicker.styles.js +23 -3
- package/dist/module/components/TimerPicker/TimerPicker.styles.js.map +1 -1
- package/dist/module/components/TimerPicker/index.js +37 -28
- package/dist/module/components/TimerPicker/index.js.map +1 -1
- package/dist/module/components/TimerPickerModal.styles.js.map +1 -1
- package/dist/module/components/index.js +46 -39
- package/dist/module/components/index.js.map +1 -1
- package/dist/module/tests/Modal.test.js +3 -1
- package/dist/module/tests/Modal.test.js.map +1 -1
- package/dist/module/utils/generateNumbers.js +31 -9
- package/dist/module/utils/generateNumbers.js.map +1 -1
- package/dist/module/utils/padNumber.js +8 -0
- package/dist/module/utils/padNumber.js.map +1 -0
- package/dist/typescript/components/TimerPicker/DurationScroll.d.ts +4 -0
- package/dist/typescript/components/TimerPicker/TimerPicker.styles.d.ts +4 -0
- package/dist/typescript/components/TimerPicker/index.d.ts +4 -0
- package/dist/typescript/components/TimerPickerModal.styles.d.ts +283 -10
- package/dist/typescript/utils/generateNumbers.d.ts +7 -2
- package/dist/typescript/utils/padNumber.d.ts +3 -0
- package/package.json +2 -2
- package/src/components/Modal/index.tsx +2 -2
- package/src/components/TimerPicker/DurationScroll.tsx +63 -11
- package/src/components/TimerPicker/TimerPicker.styles.ts +32 -1
- package/src/components/TimerPicker/index.tsx +31 -9
- package/src/components/TimerPickerModal.styles.ts +9 -8
- package/src/components/index.tsx +11 -3
- package/src/tests/Modal.test.tsx +1 -1
- package/src/utils/generateNumbers.ts +40 -10
- package/src/utils/padNumber.ts +10 -0
- package/dist/commonjs/utils/padWithZero.js +0 -15
- package/dist/commonjs/utils/padWithZero.js.map +0 -1
- package/dist/module/utils/padWithZero.js +0 -8
- package/dist/module/utils/padWithZero.js.map +0 -1
- package/dist/typescript/utils/padWithZero.d.ts +0 -1
- package/src/utils/padWithZero.ts +0 -7
|
@@ -32,6 +32,7 @@ export interface TimerPickerRef {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export interface TimerPickerProps {
|
|
35
|
+
allowFontScaling?: boolean;
|
|
35
36
|
onDurationChange?: (duration: {
|
|
36
37
|
hours: number;
|
|
37
38
|
minutes: number;
|
|
@@ -41,6 +42,9 @@ export interface TimerPickerProps {
|
|
|
41
42
|
initialMinutes?: number;
|
|
42
43
|
initialSeconds?: number;
|
|
43
44
|
aggressivelyGetLatestDuration?: boolean;
|
|
45
|
+
use12HourPicker?: boolean;
|
|
46
|
+
amLabel?: string;
|
|
47
|
+
pmLabel?: string;
|
|
44
48
|
hideHours?: boolean;
|
|
45
49
|
hideMinutes?: boolean;
|
|
46
50
|
hideSeconds?: boolean;
|
|
@@ -64,6 +68,7 @@ export interface TimerPickerProps {
|
|
|
64
68
|
const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
|
|
65
69
|
(
|
|
66
70
|
{
|
|
71
|
+
allowFontScaling = false,
|
|
67
72
|
onDurationChange,
|
|
68
73
|
initialHours = 0,
|
|
69
74
|
initialMinutes = 0,
|
|
@@ -74,12 +79,15 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
|
|
|
74
79
|
hourLimit,
|
|
75
80
|
minuteLimit,
|
|
76
81
|
secondLimit,
|
|
77
|
-
hourLabel
|
|
78
|
-
minuteLabel
|
|
79
|
-
secondLabel
|
|
82
|
+
hourLabel,
|
|
83
|
+
minuteLabel,
|
|
84
|
+
secondLabel,
|
|
80
85
|
padWithNItems = 1,
|
|
81
86
|
disableInfiniteScroll = false,
|
|
82
87
|
aggressivelyGetLatestDuration = false,
|
|
88
|
+
use12HourPicker = false,
|
|
89
|
+
amLabel = "am",
|
|
90
|
+
pmLabel = "pm",
|
|
83
91
|
LinearGradient,
|
|
84
92
|
pickerContainerProps,
|
|
85
93
|
pickerGradientOverlayProps,
|
|
@@ -157,9 +165,14 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
|
|
|
157
165
|
<DurationScroll
|
|
158
166
|
ref={hoursDurationScrollRef}
|
|
159
167
|
numberOfItems={23}
|
|
160
|
-
label={
|
|
168
|
+
label={
|
|
169
|
+
hourLabel ?? (!use12HourPicker ? "h" : undefined)
|
|
170
|
+
}
|
|
161
171
|
initialValue={initialHours}
|
|
162
|
-
|
|
172
|
+
allowFontScaling={allowFontScaling}
|
|
173
|
+
aggressivelyGetLatestDuration={
|
|
174
|
+
aggressivelyGetLatestDuration
|
|
175
|
+
}
|
|
163
176
|
onDurationChange={setSelectedHours}
|
|
164
177
|
pickerGradientOverlayProps={pickerGradientOverlayProps}
|
|
165
178
|
topPickerGradientOverlayProps={
|
|
@@ -172,6 +185,9 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
|
|
|
172
185
|
padWithNItems={checkedPadWithNItems}
|
|
173
186
|
limit={hourLimit}
|
|
174
187
|
LinearGradient={LinearGradient}
|
|
188
|
+
is12HourPicker={use12HourPicker}
|
|
189
|
+
amLabel={amLabel}
|
|
190
|
+
pmLabel={pmLabel}
|
|
175
191
|
styles={styles}
|
|
176
192
|
testID="duration-scroll-hour"
|
|
177
193
|
/>
|
|
@@ -180,9 +196,12 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
|
|
|
180
196
|
<DurationScroll
|
|
181
197
|
ref={minutesDurationScrollRef}
|
|
182
198
|
numberOfItems={59}
|
|
183
|
-
label={minuteLabel}
|
|
199
|
+
label={minuteLabel ?? "m"}
|
|
184
200
|
initialValue={initialMinutes}
|
|
185
|
-
|
|
201
|
+
allowFontScaling={allowFontScaling}
|
|
202
|
+
aggressivelyGetLatestDuration={
|
|
203
|
+
aggressivelyGetLatestDuration
|
|
204
|
+
}
|
|
186
205
|
onDurationChange={setSelectedMinutes}
|
|
187
206
|
padNumbersWithZero
|
|
188
207
|
pickerGradientOverlayProps={pickerGradientOverlayProps}
|
|
@@ -204,9 +223,12 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
|
|
|
204
223
|
<DurationScroll
|
|
205
224
|
ref={secondsDurationScrollRef}
|
|
206
225
|
numberOfItems={59}
|
|
207
|
-
label={secondLabel}
|
|
226
|
+
label={secondLabel ?? "s"}
|
|
208
227
|
initialValue={initialSeconds}
|
|
209
|
-
|
|
228
|
+
allowFontScaling={allowFontScaling}
|
|
229
|
+
aggressivelyGetLatestDuration={
|
|
230
|
+
aggressivelyGetLatestDuration
|
|
231
|
+
}
|
|
210
232
|
onDurationChange={setSelectedSeconds}
|
|
211
233
|
padNumbersWithZero
|
|
212
234
|
pickerGradientOverlayProps={pickerGradientOverlayProps}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { StyleSheet } from "react-native";
|
|
2
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
3
3
|
|
|
4
4
|
import type { CustomTimerPickerStyles } from "./TimerPicker/TimerPicker.styles";
|
|
5
|
+
import { ComponentProps } from "react";
|
|
5
6
|
|
|
6
7
|
export interface CustomTimerPickerModalStyles extends CustomTimerPickerStyles {
|
|
7
|
-
container?:
|
|
8
|
-
contentContainer?:
|
|
9
|
-
buttonContainer?:
|
|
10
|
-
button?:
|
|
11
|
-
cancelButton?:
|
|
12
|
-
confirmButton?:
|
|
13
|
-
modalTitle?:
|
|
8
|
+
container?: ComponentProps<typeof View>;
|
|
9
|
+
contentContainer?: ComponentProps<typeof View>;
|
|
10
|
+
buttonContainer?: ComponentProps<typeof View>;
|
|
11
|
+
button?: ComponentProps<typeof Text>;
|
|
12
|
+
cancelButton?: ComponentProps<typeof Text>;
|
|
13
|
+
confirmButton?: ComponentProps<typeof Text>;
|
|
14
|
+
modalTitle?: ComponentProps<typeof Text>;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
const DARK_MODE_BACKGROUND_COLOR = "#232323";
|
package/src/components/index.tsx
CHANGED
|
@@ -78,11 +78,15 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
|
|
|
78
78
|
hourLimit,
|
|
79
79
|
minuteLimit,
|
|
80
80
|
secondLimit,
|
|
81
|
-
hourLabel
|
|
82
|
-
minuteLabel
|
|
83
|
-
secondLabel
|
|
81
|
+
hourLabel,
|
|
82
|
+
minuteLabel,
|
|
83
|
+
secondLabel,
|
|
84
84
|
padWithNItems = 1,
|
|
85
85
|
disableInfiniteScroll = false,
|
|
86
|
+
allowFontScaling = false,
|
|
87
|
+
use12HourPicker,
|
|
88
|
+
amLabel,
|
|
89
|
+
pmLabel,
|
|
86
90
|
hideCancelButton = false,
|
|
87
91
|
confirmButtonText = "Confirm",
|
|
88
92
|
cancelButtonText = "Cancel",
|
|
@@ -216,6 +220,10 @@ const TimerPickerModal = forwardRef<TimerPickerModalRef, TimerPickerModalProps>(
|
|
|
216
220
|
secondLabel={secondLabel}
|
|
217
221
|
padWithNItems={padWithNItems}
|
|
218
222
|
disableInfiniteScroll={disableInfiniteScroll}
|
|
223
|
+
allowFontScaling={allowFontScaling}
|
|
224
|
+
use12HourPicker={use12HourPicker}
|
|
225
|
+
amLabel={amLabel}
|
|
226
|
+
pmLabel={pmLabel}
|
|
219
227
|
LinearGradient={LinearGradient}
|
|
220
228
|
pickerContainerProps={pickerContainerProps}
|
|
221
229
|
pickerGradientOverlayProps={
|
package/src/tests/Modal.test.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import Modal from "../components/Modal";
|
|
|
5
5
|
|
|
6
6
|
describe("Modal", () => {
|
|
7
7
|
it("renders without crashing", () => {
|
|
8
|
-
const { getByTestId } = render(<Modal />);
|
|
8
|
+
const { getByTestId } = render(<Modal isVisible/>);
|
|
9
9
|
const component = getByTestId("modal");
|
|
10
10
|
expect(component).toBeDefined();
|
|
11
11
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { padNumber } from "./padNumber";
|
|
2
2
|
|
|
3
3
|
export const generateNumbers = (
|
|
4
4
|
numberOfItems: number,
|
|
5
5
|
options: {
|
|
6
6
|
repeatNTimes?: number;
|
|
7
|
-
|
|
7
|
+
padNumbersWithZero?: boolean;
|
|
8
8
|
disableInfiniteScroll?: boolean;
|
|
9
9
|
padWithNItems: number;
|
|
10
10
|
}
|
|
@@ -14,15 +14,10 @@ export const generateNumbers = (
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
let numbers: string[] = [];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
numbers.push(padWithZero(i));
|
|
20
|
-
}
|
|
21
|
-
} else {
|
|
22
|
-
for (let i = 0; i <= numberOfItems; i++) {
|
|
23
|
-
numbers.push(String(i));
|
|
24
|
-
}
|
|
17
|
+
for (let i = 0; i <= numberOfItems; i++) {
|
|
18
|
+
numbers.push(padNumber(i, { padWithZero: options.padNumbersWithZero }));
|
|
25
19
|
}
|
|
20
|
+
|
|
26
21
|
if ((options.repeatNTimes ?? 1) > 1) {
|
|
27
22
|
numbers = Array(options.repeatNTimes).fill(numbers).flat();
|
|
28
23
|
}
|
|
@@ -32,3 +27,38 @@ export const generateNumbers = (
|
|
|
32
27
|
}
|
|
33
28
|
return numbers;
|
|
34
29
|
};
|
|
30
|
+
|
|
31
|
+
export const generate12HourNumbers = (options: {
|
|
32
|
+
repeatNTimes?: number;
|
|
33
|
+
padNumbersWithZero?: boolean;
|
|
34
|
+
disableInfiniteScroll?: boolean;
|
|
35
|
+
padWithNItems: number;
|
|
36
|
+
}) => {
|
|
37
|
+
let numbers: string[] = [];
|
|
38
|
+
|
|
39
|
+
// Generate numbers from 0 to 11 for AM
|
|
40
|
+
for (let i = 0; i <= 11; i++) {
|
|
41
|
+
numbers.push(
|
|
42
|
+
`${padNumber(i, { padWithZero: options.padNumbersWithZero })} AM`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Generate numbers from 12 to 11 for PM
|
|
47
|
+
for (let i = 12; i <= 23; i++) {
|
|
48
|
+
const hour = i > 12 ? i - 12 : i;
|
|
49
|
+
numbers.push(
|
|
50
|
+
`${padNumber(hour, { padWithZero: options.padNumbersWithZero })} PM`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if ((options.repeatNTimes ?? 1) > 1) {
|
|
55
|
+
numbers = Array(options.repeatNTimes).fill(numbers).flat();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (options.disableInfiniteScroll) {
|
|
59
|
+
numbers.push(...Array(options.padWithNItems).fill(""));
|
|
60
|
+
numbers.unshift(...Array(options.padWithNItems).fill(""));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return numbers;
|
|
64
|
+
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.padWithZero = void 0;
|
|
7
|
-
const padWithZero = value => {
|
|
8
|
-
if (value < 10) {
|
|
9
|
-
return "0" + value;
|
|
10
|
-
} else {
|
|
11
|
-
return String(value);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
exports.padWithZero = padWithZero;
|
|
15
|
-
//# sourceMappingURL=padWithZero.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["padWithZero","value","String","exports"],"sources":["padWithZero.ts"],"sourcesContent":["export const padWithZero = (value: number): string => {\n if (value < 10) {\n return \"0\" + value;\n } else {\n return String(value);\n }\n};"],"mappings":";;;;;;AAAO,MAAMA,WAAW,GAAIC,KAAa,IAAa;EAClD,IAAIA,KAAK,GAAG,EAAE,EAAE;IACZ,OAAO,GAAG,GAAGA,KAAK;EACtB,CAAC,MAAM;IACH,OAAOC,MAAM,CAACD,KAAK,CAAC;EACxB;AACJ,CAAC;AAACE,OAAA,CAAAH,WAAA,GAAAA,WAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["padWithZero","value","String"],"sources":["padWithZero.ts"],"sourcesContent":["export const padWithZero = (value: number): string => {\n if (value < 10) {\n return \"0\" + value;\n } else {\n return String(value);\n }\n};"],"mappings":"AAAA,OAAO,MAAMA,WAAW,GAAIC,KAAa,IAAa;EAClD,IAAIA,KAAK,GAAG,EAAE,EAAE;IACZ,OAAO,GAAG,GAAGA,KAAK;EACtB,CAAC,MAAM;IACH,OAAOC,MAAM,CAACD,KAAK,CAAC;EACxB;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const padWithZero: (value: number) => string;
|