0.1.0 • Published 2 years ago

@medilies/countdown-component v0.1.0

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

Countdown JS

A simple and lightweight library for adding coundowns to the frontend in declarative way.

Features

  • Simple inline setup using HTML attributes.
  • Custom display format options.
  • Custom update interval.
  • Custom callback action.

Setup

NPM

npm i @medilies/countdown-component
import { autoStartCountown } from "@medilies/countdown-component/lib/countdownComponent";

autoStartCountown();

CDN

<script src="https://cdn.jsdelivr.net/gh/medilies/countdown-component.js/dist/countdown-component.js"></script>

Usage

Write a div or many with the following attributes.

AttributeDescription
autoCountdownStarts the countdown on page loadRequried
countdown-durationSets the coundown duration (an integer in seconds)Required
countdown-formatSets the display format (see the formatting table)Required
countdown-tick-sizeSets the update interval size (a timespan)Default: 1s
countdown-handlerTakes as value the name the function you defined to call as an action in the end of the countdownOptional

Note a timespan is a string that is in the format "2m", "1h5s" or "2h20m40s"

Format

keyOutput
ssSeconds with leading zeros 00 through 59
sSeconds without leading zeros 0 through 59
mmMinutes with leading zeros 00 to 59
mMinutes without leading zeros 0 to 59
hh24-hour format of an hour with leading zeros 00 through 23
h24-hour format of an hour without leading zeros 0 through 23

Example

<div autoCountdown countdown-duration='10' countdown-format='hh:m:s'></div>

<div autoCountdown countdown-duration='13' countdown-format='mm:ss' countdown-handler="reload"></div>

<div autoCountdown countdown-duration='3660' countdown-format='hh:mm:ss' countdown-tick-size='5s'
    countdown-handler="reload"></div>

<script>
    function reload() {
        location.reload();
    }
</script>

<script src='/dist/countdown-component.js'></script>

<script>
    autoStartCountown();
</script>

See: pen

Todo

  1. Add countdowns that start rolling on an event beside those that autostart when the page loads because they have the autoCountdown attribute.
  2. Add other types of countdowns display beside the possibility of displaying as a formatted time. For example a progress bar.
  3. Share the library through a CDN.
  4. Add the possibility to aboart the countdown.

Contributing

Any kind of contribution is very welcomed, so feel free to get in touch so I can add you to the repo :)

Help needed to do

...

0.1.0

2 years ago

1.0.11

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago