🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

react-time-ticker

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-time-ticker

react-time-ticker is a customizable React countdown timer with smooth animations and flexible styling options. It integrates easily into projects and supports various configurations.

0.1.911
latest
Source
npm
Version published
Weekly downloads
4
-75%
Maintainers
0
Weekly downloads
 
Created
Source

react-time-ticker

A customizable countdown timer component for React applications. The react-time-ticker component displays a countdown timer with various units and styling options.

Table of Contents

  • Features
  • Prerequisites
  • Installation
  • Usage
  • Demo
  • Changelog
  • Contributing
  • License

Features

  • Display time in years, months, days, hours, minutes, and seconds.
  • Customizable labels and styles.
  • Responsive design with support for single and double-line layouts.
  • Countdown functionality with a callback for when the countdown ends.
  • Configurable display units (e.g., show only hours and minutes, hide seconds).

Prerequisites

Before using this component, ensure that you have the following:

  • React: v16.8 or higher.
  • Node.js: v12 or higher.
  • A package manager like npm or yarn.

Installation

To install the TimeTicker component, use npm or yarn:

npm install react-time-ticker

or

yarn add react-time-ticker

Usage

Basic Example

The most basic usage of the react-time-ticker component involves providing an initialSeconds prop for the countdown and an optional onTimesUp callback.

import React from 'react';
import TimeTicker from 'react-time-ticker';

const App = () => (
<TimeTicker
initialSeconds={3600} // 1 hour countdown
onTimesUp={() => console.log('Time is up!')}
/>
);

export default App;

Advanced Example with Custom Styling

In this example, we will customize the appearance of the TimeTicker by passing customStyles, and only show hours, minutes, and seconds.

import React from 'react';
import TimeTicker from 'react-time-ticker';

const App = () => (
  <TimeTicker
    initialSeconds={7200} // 2 hours countdown
    displayUnitsConfig={{
      hours: true,
      minutes: true,
      seconds: true,
    }}
    customStyles={{
      digitBg: '#222222',
      digitColor: '#FFFFFF',
      digitFontSize: '1.5rem',
      labelColor: '#F1C40F',
      labelFontSize: '0.875rem',
      labelBg: '#333333',
      separatorColor: '#E74C3C',
    }}
    labels={{
      hours: 'Hours',
      minutes: 'Minutes',
      seconds: 'Seconds',
    }}
    emphasizeLabels={false}
    isDoubleLine={true}
    onTimesUp={() => alert('Countdown finished!')}
  />
);

export default App;

Props

NameTypeDefault ValueDescription
initialSecondsnumber0The initial time in seconds.
displayUnitsConfigobject*Configures which time units are displayed (years, months, days, etc.).
onTimesUp() => void() => {}Callback function that is called when the timer ends.
customStylesobject*Custom styles object to override default styles (see the Styles section below).
labelsobject*Custom labels for each time unit (see the Labels section below).
showLabelsbooleantrueDetermines if labels should be shown.
emphasizeLabelsbooleantrueDetermines if labels should be emphasized.
isDoubleLinebooleanfalseDetermines if the display should be in double-line mode.

customStyles (Styles Object)

The customStyles prop is an object that allows you to define specific styles for the timer. You can override the default styles by providing values for the following properties:

PropertyTypeDefault ValueDescription
labelBgstring#1f2937Background color for labels.
labelColorstring#f9fafbText color for labels.
labelFontSizestring0.6875remFont size for labels.
labelPaddingYstring0.3remVertical padding for labels.
fontFamilystringsans-serifFont family for the component.
separatorColorstring#1f2937Color for separators.
verticalSeparatorColorstring#1f2937Color for vertical separators.
digitBgstring#1f2937Background color for digits.
digitColorstring#f9fafbText color for digits.
digitFontSizestring0.875remFont size for digits.
digitWidthstring1.75remWidth of each digit.
digitHeightstring2remHeight of each digit.

displayUnitsConfig (Units Object)

PropertyTypeDefaultDescription
yearsbooleantrueShow the years unit in the ticker.
monthsbooleantrueShow the months unit in the ticker.
daysbooleantrueShow the days unit in the ticker.
hoursbooleantrueShow the hours unit in the ticker.
minutesbooleantrueShow the minutes unit in the ticker.
secondsbooleantrueShow the seconds unit in the ticker.

labels (Labels Object)

The labels prop is an object that allows you to provide custom labels for each time unit. The object can include the following properties:

PropertyTypeDescription
yearsstringLabel for the "years" unit.
monthsstringLabel for the "months" unit.
daysstringLabel for the "days" unit.
hoursstringLabel for the "hours" unit.
minutesstringLabel for the "minutes" unit.
secondsstringLabel for the "seconds" unit.

Customizing Timer Behavior

You can pass a custom function using the onTimesUp prop, which is triggered when the countdown reaches zero. This allows you to implement any custom logic, such as redirecting the user, showing a message, or starting a new countdown.

<TimeTicker
  initialSeconds={1800} // 30 minutes
  onTimesUp={() => {
    console.log('Countdown finished!');
    // Custom behavior here
  }}
/>

Demo

You can view a live demo of the React Time Ticker component here.

Changelog

[1.0.0] - YYYY-MM-DD

  • Initial release of the TimeTicker component with core features:
    • Time unit configuration (years, months, days, hours, minutes, seconds).
    • Customizable styles for digits, labels, and separators.
    • Optional onTimesUp callback function.
    • Configuration to show/hide time units (e.g., hide years or months).
    • Support for double-line layout and label emphasis.

Contributing

Feel free to open issues and submit pull requests on GitHub.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

react-component

FAQs

Package last updated on 18 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts