Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ timerPickerRef.current.reset(options?: { animated: boolean });
`setValue` - imperative method to set the selected duration to a particular value

```javascript
timerPickerRef.current.setValue({ hours: number, minutes: number, seconds: number }, options?: { animated: boolean });
timerPickerRef.current.setValue({ days?: number, hours?: number, minutes?: number, seconds?: number }, options?: { animated: boolean });
```

It also exposes the following ref object:
Expand All @@ -587,6 +587,7 @@ It also exposes the following ref object:
```javascript
const latestDuration = timerPickerRef.current?.latestDuration;
const newDuration = {
days: latestDuration?.days?.current,
hours: latestDuration?.hours?.current,
minutes: latestDuration?.minutes?.current,
seconds: latestDuration?.seconds?.current,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"url": "https://github.com/troberts-28"
},
"license": "MIT",
"version": "2.2.1",
"version": "2.2.2",
"main": "dist/commonjs/index.js",
"module": "dist/module/index.js",
"types": "dist/typescript/index.d.ts",
Expand Down
42 changes: 28 additions & 14 deletions src/components/TimerPicker/TimerPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,34 @@ const TimerPicker = forwardRef<TimerPickerRef, TimerPickerProps>(
secondsDurationScrollRef.current?.reset(options);
},
setValue: (value, options) => {
setSelectedDays(value.days);
setSelectedHours(value.hours);
setSelectedMinutes(value.minutes);
setSelectedSeconds(value.seconds);
daysDurationScrollRef.current?.setValue(value.days, options);
hoursDurationScrollRef.current?.setValue(value.hours, options);
minutesDurationScrollRef.current?.setValue(
value.minutes,
options
);
secondsDurationScrollRef.current?.setValue(
value.seconds,
options
);
if (value.days) {
setSelectedDays(value.days);
daysDurationScrollRef.current?.setValue(
value.days,
options
);
}
if (value.hours) {
setSelectedHours(value.hours);
hoursDurationScrollRef.current?.setValue(
value.hours,
options
);
}
if (value.minutes) {
setSelectedMinutes(value.minutes);
minutesDurationScrollRef.current?.setValue(
value.minutes,
options
);
}
if (value.seconds) {
setSelectedSeconds(value.seconds);
secondsDurationScrollRef.current?.setValue(
value.seconds,
options
);
}
},
latestDuration: {
days: daysDurationScrollRef.current?.latestDuration,
Expand Down
8 changes: 4 additions & 4 deletions src/components/TimerPicker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export interface TimerPickerRef {
reset: (options?: { animated?: boolean }) => void;
setValue: (
value: {
days: number;
hours: number;
minutes: number;
seconds: number;
days?: number;
hours?: number;
minutes?: number;
seconds?: number;
},
options?: { animated?: boolean }
) => void;
Expand Down