- Notifications
You must be signed in to change notification settings - Fork3
Higher order react component for redux-idle-monitor.
License
noderaider/react-redux-idle-monitor
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
React Redux higher order component for idle state monitoring.
npm i -S react-redux-idle-monitor
0.3.x5/19/2016 => Less bundled dependencies and server side rendering
In effort to allow freedom of build systems and keep bundles as small and least redundant as possible, this module now exports factories that take in heavy React / Redux dependencies and export the same functions as they used to expose. Documentation has been updated accordingly.
Style loading moved to componentDidMount allowing server side rendering to work now.
Works in tandem withredux-idle-monitor to connect information about a users activity / idle state into your React components.
This project includes an optional React IdleMonitor component that can be imported and used standalone or as a wrapper for your components (auto-connects to your redux store and pulls out the idle state information for you). When developing, you may set the "showStatus" prop to true on the IdleMonitor component, which will add a docked element to your page that shows the current active / idle state of the user, last event that triggered activity, and additional information.
See a working demo in a real project atredux-webpack-boilerplate
There are a couple of ways to use react-redux-idle-monitor.
The simplest way to get idle props to your component is to wrap the component with the connector component. Import thecreateConnector factory fromreact-redux-idle-monitor and pass it the connect dependency from 'react-redux'. This may seem unusual, but it ensures this library is as small as possible and works with all build systems.
Wrapping your component with theconnectIdleMonitor function as depicted below will inject your component with the idle properties all of the idle properties.
importReact,{Component,PropTypes}from'react'import{connect}from'react-redux'import{createConnector}from'react-redux-idle-monitor'constconnectIdleMonitor=createConnector({ connect})classMyMonitoringComponentextendsComponent{// connectIdleMonitor will tack these props from your redux 'idle' statestaticpropTypes={idleStatus:PropTypes.string.isRequired// 'ACTIVE' if user is active or one of your other configured idle states.,isIdle:PropTypes.bool.isRequired// false if user is active or idle if user is in one of your idle states.,isPaused:PropTypes.bool.isRequired// true if idle detection has been paused.,isDetectionRunning:PropTypes.bool.isRequired// true if redux idle middleware is currently monitoring user mouse / keyboard activity.,lastActive:PropTypes.number.isRequired// the last time that the user was active (when detection is running).,lastEvent:PropTypes.object.isRequired// the last mouse event coordinates that were triggered (when detection is running).};render(){const{ idleStatus, isIdle, isPaused, isDetectionRunning, lastActive, lastEvent}=this.propsreturn(<divstyle={{color:isIdle ?'#f00' :'#0f0'}}>{idleStatus}</div>)}}exportdefaultconnectIdleMonitor(MyMonitoringComponent)
Another option is to export the createIdleMonitor React component factory as shown below. This monitor has an option toshowStatus which will add a docked bar to the page with realtime information on the users idle status and is useful during development. It is the same component from the example atredux-webpack-boilerplate.
importReactfrom'react'import{connect}from'react-redux'importcreateIdleMonitorfrom'react-redux-idle-monitor'constIdleMonitor=createIdleMonitor({ React, connect})constMyComponent=props=>(<IdleMonitorshowStatus={true}/>)
These props can be passed to the IdleMonitor React component to control the look and feel.
| Name | Description |
|---|---|
showStatus | By default, set totrue. |
showControls | By default, set tofalse |
idleTitle | By default, set toIDLEMONITOR |
idleTheme | By default, set tosolarized |
invertTheme | By default, set tofalse (dark is the standard) |
dockTo | By default, set to 'bottom'. Supports 'top' and 'bottom'. |
opacity | By default, set to1 |
paletteMap | Maps theme base16 colors to control. By default, set to{ background: ['base00', 'base01'], content: ['base04', 'base02', 'base05'], accent: ['base0D', 'base0E', 'base0C'] } |
About
Higher order react component for redux-idle-monitor.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.

