0.0.3 • Published 3 years ago

idle-timeout-component v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

idle-timeout-component

This is an idle timeout component built with the purpose of allowing for developers to easily implement an idle timeout feature into their website. A modal comes up to log users out of the website. There is a high degree of customizability using features of web components and taking advantage of the shadow DOM.

Benefits

  • Easy to implement
  • Easy to use
  • Works in React, Angular, Vue
  • Will work in any framework at all
  • Highly customizable
  • Highly reactive to different screen sizes

Dependencies

  • Built using lit

Features

  • Can be created straight in the HTML tag
  • Has 15+ CSS variables that can be edited
  • Has 7 direct properties that can be edited
  • Reactive styling
  • Notification and logout times can be changed easily by the developer

Installation

$ npm install idle-timeout-component

Importing

After installing the web component, it must also be imported.

This can be done in one of three ways.

Javascript module:

import 'idle-timeout-component';

Or through HTML as follows:

<script type="module">
import 'idle-timeout-component';
</script>

or

<script type="module" src="idle-timeout-component"></script>

Usage

After importing simply using the tag will add the web component to the application.

<idle-timeout-component></idle-timeout-component>

If you want to use this on an entire React, Angular, or Vue site, put the HTML tag at the root. For example, in React, you would put the tag in the index.js file.

But this will not include any information and all editing of the pugh chart will have to be done via the website on which the component is hosted. If you wish to have persistent data inputted. This must be passed as an HTML property as seen in the following example.

  <idle-timeout-component timeToNotify=100 timeToLogout=60 style="--logout-button-color: blue; --logout-button-font: Serif"><idle-timeout-component>>

The above would bring up the notification of logout after being idle for 100 seconds and then once the user is notified the user would have 60 seconds to remain on the site or they would be logged out. The logout button color and the logout button font have also been edited inline. All editable CSS and all properties are down below.

Then somewhere else in your code you would need to listen to the event listner about a logout as see in the following example.

document.addEventListener("logout",()=>{console.log("Logout")});

For the "logout" event, composed and bubbles are both set to true so your entire DOM tree will be able to see the event. Not naming another event "logout" in order to reduce conflicts is highly recommended.

Properties

PropertyAttributeTypeDefaultDescription
logoutButtonTextlogoutButtonTextString"Logout"This is the text on the logout button for the modal.
logoutWarninglogoutWarningString"Logging out!"This is the text that the title of the website flashes when the notification of logout is showing (when the modal is showing).
modalBodyTextmodalBodyTextString"Indicate if you are still there or you will be logged out!"This is the text in the body of the modal popup.
modalHeaderTextmodalHeaderTextString"Are you still there?"This is the text at the top of the modal popup.
remainButtonTextremainButtonTextString"Still here"This is the text on the button that allows the user to continue using the site.
switchbooleantrue
timeToLogouttimeToLogoutNumber60This is the number in seconds that is the amount of time that the user is notified for before being completely logged out. This is how long the modal is shown for.
timeToNotifytimeToNotifyNumber10This is the number in seconds that is the amount of time that the user is idle before they receive notification that they will be logged out.
timerStartedtimerStartedStringstartedIf the property is equal to 'started' then the timer will tick down. However, if it is not, the timer will not move.

Events

EventTypeDescription
logoutCustomEvent<{ message: string; }>Event that dispatches when the user should be logged out. Composed and bubbles are true.

CSS Custom Stylings

PropertyTypeDescriptionDefault
--body-fontstringFont for the modalSans-Serif
--body-text-colorcolor(string)Text color for the modalblack
--time-text-fontstringFont for the timer countdownSans-serif
--timer-text-colorcolor(string)Text color for the timer countdownblack
--timer-circle-colorcolor(string)Color for the circle part of the timerblack
--header-background-colorcolor(string)Background color for the header of the modalgray
--header-fontstringFont for the header of the modalSans-serif
--header-text-colorcolor(string)Color for the text in the header of the modalwhite
--modal-z-indexnumberz-index for the modal500
--logout-button-colorcolor(string)Color of the logout buttonrgb(202, 60, 60)
--logout-button-fontstringFont of the logout buttonSans-Serif
--logout-button-text-colorcolor(string)Text color for the logout buttonwhite
--stya-button-colorcolor(string)Color of the stay buttongreen
--stay-button-fontstringFont of the stay buttonSans-Serif
--stay-button-text-colorcolor(string)Text color for the stay buttonwhite