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

@marcelo-diament/dynamic-countdown

v1.3.2

Published

A dynamic countdown package in vanilla javascript

Downloads

3

Readme

theme-options

Dynamic Countdown v1.3.0

Updated at July 9th, 2021 by Marcelo Diament.

This is a public npm package that aims to make it easier to use countdown by simply adding data attributes to you HTML.

Check our demo here. And don't forget to check our style theme options table.

Visit our the dynamic-countdown npm page.

Summary


Getting Started

There are two ways of using this package - setting HTML elements or mounting it through vanilla JS

You can construct you countdown by setting HTML tags with its necessary and optional data attributes or you can create a custom countdown with vanilla JS and append your on-the-fly countdown element in the container tag of your choice. Or you can also use both of them. Finally, just call the counter() method.

Make sure you have node installed

Just make sure you have the node and npm installed. You can check it by running the following commands:

node -v
# Expected return: v12.18.4 (or a more recent version)
npm -v
# Expected return: v6.14.8 (or a more recent version)

Install the package as a dependency

The first step is to install this package as a dependency:

npm i dynamic-countdown --save

Using HTML data attributes

In order to use the Dynamic Countdown by using data attributes, you just need to follow those 2 simple steps:

Call the script module to your HTML

Before closing the body tag, just add the following code snippet:

<script type="module" src="./node_modules/dynamic-countdown/index.js"></script>

Create your own counter element

It is necessary that your countdown component uses the counter class and also to declare some specific data attributes.

Then you must add its children, according to the date format desired.

Counter Container

The required data attributes are (default values for optional attributes in bold):

| Data Attribute | Options | Role | | -------------- | ------- | ---- | | data-target-date (required) | 'MM/DD/YYYY HH: MM' (month/day/year hour:minute) | Defines the time difference between current time and this target date | | data-time-format (optional) | 'DHMS', 'DHM', 'DH', 'D', 'HMS', 'HM', 'H', 'MS', 'M', 'S' | Defines which time units will be shown on the countdown | | data-min-digits (optional) | '2' or more | Defines the minimum length of each time unit counter | | data-lang (optional) | 'pt', 'en', 'es', 'fr', 'it' | Defines if the language in wich the time units will be displayed |

Counter Children

Within the container, you must create children elements to show each desired time unit. Each children must have the counter__unit class declared.

And you must also declare each children elements time unit by declaring the data-time-unit attribute, that can have the following values: days , hours , minutes and/or seconds .

Example

Here is a simple example:

<p class="counter" data-target-date="12/31/2021 23:59" data-time-format="DHMS" data-min-digits="2" data-lang="en">
    <span data-unit="days" class="counter__unit"></span>
    <span data-unit="hours" class="counter__unit"></span>
    <span data-unit="minutes" class="counter__unit"></span>
    <span data-unit="seconds" class="counter__unit"></span>
</p>

And another example, with the minimum required data-attributes:

<p class="counter" data-target-date="12/31/2021 23:59">
    <span data-unit="days" class="counter__unit"></span>
    <span data-unit="hours" class="counter__unit"></span>
    <span data-unit="minutes" class="counter__unit"></span>
    <span data-unit="seconds" class="counter__unit"></span>
</p>

Using vanilla JS method

You can create as many counters as you want to by using the mountCounter method. Then, you must call the counter method on you main file.

Import

Firstly, you must import the counter to your file:

import { mountCounter } from 'dynamic-countdown'

MountCountdown

Now you must call the mountCountdown method and append the mounted countdown to the HTML element you need:

// Creating the countdown
const myCountdown = mountCounter('08/01/2021 16:20', 'DH', '2', 'en', 'primary-light-inverted')
// Appending it to the main HTML tag
document.querySelector('main').appendChild(myCountdown)

Running the Countdown

On your main file, you must import the counter method and execute it after window loads:

import { counter } from 'dynamic-countdown'
window.onload = () => {
    counter()
}

Style Theme

You can also add extra classes in order to take advantage of the dynamic-countdown theme.

In order to use the dynamic-countdown theme you must add its style too (right before the closing head tag):

<link rel="stylesheet" href="./node_modules/dynamic-countdown/style/style.min.css">

Or you may use this other link: https://marcelo-diament.github.io/dynamic-countdown/style/style.min.css .

You can check each possible value (declared below) in the demo version ( ./index.html ):

Default

Tons of grey

default-theme

  • .counter--light

  • .counter-inverted

  • .counter--light-inverted

Highlight

Pink and black

highlight-theme

  • .counter--highlight

  • .counter--highlight-light

  • .counter--highlight-inverted

  • .counter---highlight-light-inverted

Primary

Yellow and black

primary-theme

  • .counter--primary

  • .counter--primary-light

  • .counter--primary-inverted

  • .counter---primary-light-inverted

Secondary

Blue and black

secondary-theme

  • .counter--secondary

  • .counter--secondary-light

  • .counter--secondary-inverted

  • .counter---secondary-light-inverted

Tertiary

Green and black

tertiary-theme

  • .counter--tertiary

  • .counter--tertiary-light

  • .counter--tertiary-inverted

  • .counter---tertiary-light-inverted


Changelog

v1.3.0

07/09/2021 by Marcelo Diament

Features

  • Script minified

  • Documentation updated

v1.2.0

07/09/2021 by Marcelo Diament

Features

  • Main script renamed (and imports updated)

  • Export updated

  • Documentation updated

v1.1.0

07/04/2021 by Marcelo Diament

Features

  • Demo main page and theme table page updated

  • Cover image updated

  • Documentation updated

v1.0.0

07/04/2021 by Marcelo Diament

Features

v0.2.2

07/03/2021 by Marcelo Diament

Bugfixes

  • Extensions added to import statements

v0.2.1

07/03/2021 by Marcelo Diament

Bugfixes

  • Documentation updated

v0.2.0

07/03/2021 by Marcelo Diament

Features

  • Files structure updated

  • Demo updated

  • Screenshots added to documentation

  • Documentation updated

v0.1.1

07/03/2021 by Marcelo Diament

Bugfixes

  • Documentation updated

v0.1.0

07/03/2021 by Marcelo Diament

Features

  • Mounts countdown based on HTML data attributes of .counter elements

  • Documentation