@react-hive/honey-layout 10.5.0 → 10.7.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/dist/components/HoneyBox/HoneyBox.d.ts +1 -1
- package/dist/components/HoneyFlex/HoneyFlex.d.ts +1 -1
- package/dist/components/HoneyGrid/HoneyGridStyled.d.ts +1 -1
- package/dist/components/HoneyGridColumn/HoneyGridColumnStyled.d.ts +1 -1
- package/dist/components/HoneyList/HoneyListStyled.d.ts +1 -1
- package/dist/components/HoneyPopup/HoneyPopupStyled.d.ts +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/use-honey-raf-loop.d.ts +27 -26
- package/dist/hooks/use-honey-timer.d.ts +104 -0
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.dev.cjs +146 -27
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.mjs +15 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timer operating mode.
|
|
3
|
+
*
|
|
4
|
+
* - `countdown` — decreases time until it reaches `targetTimeMs`
|
|
5
|
+
* - `countup` — increases time until it reaches `targetTimeMs` (if provided)
|
|
6
|
+
*/
|
|
7
|
+
type UseHoneyTimerMode = 'countdown' | 'countup';
|
|
8
|
+
type UseHoneyTimerOnEndHandler = () => void;
|
|
9
|
+
export interface UseHoneyTimerOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Initial timer value in milliseconds.
|
|
12
|
+
*
|
|
13
|
+
* - Countdown: starting time
|
|
14
|
+
* - Count-up: initial offset
|
|
15
|
+
*/
|
|
16
|
+
initialTimeMs: number;
|
|
17
|
+
/**
|
|
18
|
+
* Target time in milliseconds.
|
|
19
|
+
*
|
|
20
|
+
* - Countdown: usually `0`
|
|
21
|
+
* - Count-up: optional upper limit
|
|
22
|
+
*
|
|
23
|
+
* When reached, the timer stops and `onEnd` is invoked.
|
|
24
|
+
*
|
|
25
|
+
* @default 0
|
|
26
|
+
*/
|
|
27
|
+
targetTimeMs?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Direction in which the timer progresses.
|
|
30
|
+
*
|
|
31
|
+
* @default 'countdown'
|
|
32
|
+
*/
|
|
33
|
+
mode?: UseHoneyTimerMode;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the timer should automatically start on mount.
|
|
36
|
+
*
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
autoStart?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Optional callback invoked exactly once when the timer reaches the target time.
|
|
42
|
+
*/
|
|
43
|
+
onEnd?: UseHoneyTimerOnEndHandler;
|
|
44
|
+
}
|
|
45
|
+
export interface UseHoneyTimerApi {
|
|
46
|
+
/**
|
|
47
|
+
* Current timer value in milliseconds.
|
|
48
|
+
*
|
|
49
|
+
* This value updates over time while the timer is running.
|
|
50
|
+
*/
|
|
51
|
+
timerTimeMs: number;
|
|
52
|
+
/**
|
|
53
|
+
* Indicates whether the timer is currently progressing.
|
|
54
|
+
*/
|
|
55
|
+
isTimerRunning: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Starts the timer from `initialTimeMs`, resetting any previous state.
|
|
58
|
+
*/
|
|
59
|
+
startTimer: () => void;
|
|
60
|
+
/**
|
|
61
|
+
* Pauses the timer while preserving the current time value.
|
|
62
|
+
*/
|
|
63
|
+
pauseTimer: () => void;
|
|
64
|
+
/**
|
|
65
|
+
* Resumes the timer from its current time value.
|
|
66
|
+
*
|
|
67
|
+
* Has no effect if the timer is already running.
|
|
68
|
+
*/
|
|
69
|
+
resumeTimer: () => void;
|
|
70
|
+
/**
|
|
71
|
+
* Resets the timer to a specific time value.
|
|
72
|
+
*
|
|
73
|
+
* @param timeMs - Optional new timer value. Defaults to `initialTimeMs`.
|
|
74
|
+
*/
|
|
75
|
+
resetTimer: (timeMs?: number) => void;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A high-precision timer hook built on top of {@link useHoneyRafLoop}.
|
|
79
|
+
*
|
|
80
|
+
* Features:
|
|
81
|
+
* - Frame-accurate time progression using `requestAnimationFrame`
|
|
82
|
+
* - Supports countdown and count-up modes
|
|
83
|
+
* - Explicit lifecycle control (start / pause / resume / reset)
|
|
84
|
+
* - Drift-free timing using delta-based updates
|
|
85
|
+
* - Safe completion handling via `onEnd`
|
|
86
|
+
*
|
|
87
|
+
* Architectural notes:
|
|
88
|
+
* - Time progression is handled imperatively via refs to avoid stale closures and unnecessary re-renders.
|
|
89
|
+
* - React state is updated only with the derived timer value.
|
|
90
|
+
* - RAF lifecycle is fully delegated to `useHoneyRafLoop`.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* const timer = useHoneyTimer({
|
|
95
|
+
* initialTimeMs: 10_000,
|
|
96
|
+
* targetTimeMs: 0,
|
|
97
|
+
* onEnd: () => console.log('Done'),
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* timer.startTimer();
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare const useHoneyTimer: ({ initialTimeMs, targetTimeMs, mode, autoStart, onEnd, }: UseHoneyTimerOptions) => UseHoneyTimerApi;
|
|
104
|
+
export {};
|