npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-time-ticker

v0.1.911

Published

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.

Downloads

314

Readme

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

  • 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

| Name | Type | Default Value | Description | |----------------------|--------------|---------------|---------------------------------------------------------------------------------| | initialSeconds | number | 0 | The initial time in seconds. | | displayUnitsConfig | object | * | Configures which time units are displayed (years, months, days, etc.). | | onTimesUp | () => void | () => {} | Callback function that is called when the timer ends. | | customStyles | object | * | Custom styles object to override default styles (see the Styles section below). | | labels | object | * | Custom labels for each time unit (see the Labels section below). | | showLabels | boolean | true | Determines if labels should be shown. | | emphasizeLabels | boolean | true | Determines if labels should be emphasized. | | isDoubleLine | boolean | false | Determines 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:

| Property | Type | Default Value | Description | |--------------------------|----------|---------------|--------------------------------| | labelBg | string | #1f2937 | Background color for labels. | | labelColor | string | #f9fafb | Text color for labels. | | labelFontSize | string | 0.6875rem | Font size for labels. | | labelPaddingY | string | 0.3rem | Vertical padding for labels. | | fontFamily | string | sans-serif | Font family for the component. | | separatorColor | string | #1f2937 | Color for separators. | | verticalSeparatorColor | string | #1f2937 | Color for vertical separators. | | digitBg | string | #1f2937 | Background color for digits. | | digitColor | string | #f9fafb | Text color for digits. | | digitFontSize | string | 0.875rem | Font size for digits. | | digitWidth | string | 1.75rem | Width of each digit. | | digitHeight | string | 2rem | Height of each digit. |

displayUnitsConfig (Units Object)

| Property | Type | Default | Description | |-----------|---------|---------|--------------------------------------| | years | boolean | true | Show the years unit in the ticker. | | months | boolean | true | Show the months unit in the ticker. | | days | boolean | true | Show the days unit in the ticker. | | hours | boolean | true | Show the hours unit in the ticker. | | minutes | boolean | true | Show the minutes unit in the ticker. | | seconds | boolean | true | Show 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:

| Property | Type | Description | |-----------|----------|-------------------------------| | years | string | Label for the "years" unit. | | months | string | Label for the "months" unit. | | days | string | Label for the "days" unit. | | hours | string | Label for the "hours" unit. | | minutes | string | Label for the "minutes" unit. | | seconds | string | Label 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.