-
-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathIIdleTimerProps.ts
More file actions
206 lines (181 loc) · 5.02 KB
/
IIdleTimerProps.ts
File metadata and controls
206 lines (181 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import { RefObject } from 'react'
import { EventsType } from './EventsType'
import { PresenceType } from './PresenceType'
import { IIdleTimer } from './IIdleTimer'
import { ITimers } from './ITimers'
export interface IIdleTimerProps {
/**
* IdleTimer ref for class components.
*
* @default undefined
*/
ref?: RefObject<IIdleTimer>
/**
* Activity Timeout in milliseconds.
*
* @default 1200000
*/
timeout?: number
/**
* When the user becomes idle, the onPrompt function is called and
* after the prompt timeout in milliseconds is reached, the onIdle function
* is called.
*
* @default 0
* @deprecated use promptBeforeIdle
*/
promptTimeout?: number
/**
* The amount of milliseconds before timeout to call the onPrompt event handler.
*
* @default 0
*/
promptBeforeIdle?: number
/**
* Element to bind activity listeners to.
*
* @default document
*/
element?: Document | HTMLElement
/**
* DOM events to watch for activity on.
*
* @default DefaultEvents
* @link [default events](https://idletimer.dev/docs/props#events).
*/
events?: EventsType[]
/**
* DOM events that will bypass the timeout and immediately emit onPrompt/onIdle
* events. The events in this array take precedence over the events array.
*
* @default []
*/
immediateEvents?: EventsType[]
/**
* Function to call when the users presence state changes.
*
* @default () => {}
*/
onPresenceChange?: (presence: PresenceType, idleTimer?: IIdleTimer) => void
/**
* When promptTimeout is set, this function is called after the user becomes
* idle. This is useful for displaying a confirm prompt. If the prompt timeout
* is reached, onIdle is then called.
*
* @default () => {}
*/
onPrompt?: (event?: Event, idleTimer?: IIdleTimer) => void
/**
* Function to call when user is idle.
*
* @default () => {}
*/
onIdle?: (event?: Event, idleTimer?: IIdleTimer) => void
/**
* Function to call when user becomes active.
*
* @default () => {}
*/
onActive?: (event?: Event, idleTimer?: IIdleTimer) => void
/**
* Function to call on user activity. Can be throttled or debounced using the
* `throttle` and `debounce` props.
*
* @default () => {}
*/
onAction?: (event?: Event, idleTimer?: IIdleTimer) => void
/**
* Function to call when message is has been emitted, when `crossTab` is set
* to `true`.
*
* @default () => {}
*/
onMessage?: (data: any, idleTimer?: IIdleTimer) => void
/**
* Debounce the onAction function by setting delay in milliseconds.
*
* @default 0
*/
debounce?: number
/**
* Throttle the onAction function by setting delay in milliseconds.
*
* @default 0
*/
throttle?: number
/**
* Throttle the activity events. Useful if you are listening to mouse events.
* Helps to cut down on cpu usage.
*
* @default 200
*/
eventsThrottle?: number
/**
* Start the timer when the hook mounts.
*
* @default true
*/
startOnMount?: boolean
/**
* Require the timer to be started manually.
*
* @default false
*/
startManually?: boolean
/**
* Once the user goes idle the IdleTimer will not reset on user input instead,
* start() or reset() must be called manually to restart the timer.
*
* @default false
*/
stopOnIdle?: boolean
/**
* Timer interface to use. By default the main thread timers are used to keep
* the module tree shakeable. If you want to use worker timers, import them
* and set them here.
*
* @default Main Thread Timers
*/
timers?: ITimers
/**
* Enable cross tab event replication.
*
* @default false
*/
crossTab?: boolean
/**
* Name of this IdleTimer instance. Useful if you are instantiating multiple
* IdleTimer instances with `crossTab` enabled.
*/
name?: string
/**
* Sync the timers across all tabs,, when `crossTab` is set to `true`. The value
* is the interval in which timers will be synced. Setting it to 0 is equivalent
* to turning the feature off. A good baseline value would be 200(ms).
*
* Generally, set either this or `leaderElection: true`, not both.
* If you want all your tabs to be in the same state, use `syncTimers`
*
* @default 0
*/
syncTimers?: number
/**
* Enables the leader election feature, when `crossTab` is set to `true`.
* Leader Election will assign one tab to be the leader. Determine if a tab
* is leader using the `isLeader` method.
*
* Generally, set either this or `syncTimers`, not both.
* If you want your events to fire only in one tab, use `leaderElection`
*
* @default false
*/
leaderElection?: boolean
/**
* Disables the timer. Disabling the timer resets the internal state.
* When the property is set to true (enabled), the timer will be restarted,
* respecting the `startManually` property. When the timer is disabled
* the control methods `start`, `reset`, `activate`, `pause` and `resume`
* will not do anything.
*/
disabled?: boolean
}