GithubHelp home page GithubHelp logo

khank8476 / tick Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pqina/tick

0.0 0.0 0.0 1.59 MB

⏱ A counter component to render different countdown styles with

License: MIT License

JavaScript 95.35% HTML 2.12% SCSS 2.52%

tick's Introduction

Tick Counter

A ticker for declaritive building of countdowns and counters.

Supports:

  • Counting towards a date
  • Counting up from a date
  • Scheduling multiple intervals
  • Polling a value from a server
  • Presenting a simple value

Some examples:

You can also use Tick to create Flip counters

Made with ❤ By Rik Schennink

Docs

Information on how to customize Tick and use the Tick API can be found on the product website.

See index below:

Install from NPM

npm i @pqina/tick --save
import Tick from '@pqina/tick';

console.log(Tick);
// logs {supported: true, options: {…}, helper: {…}, data: {…}, DOM: {…}, …}

Quick Introduction

Building Tick Counters is very similar to building with Legos. Open the example implementation, clear the existing example, and follow along.

Start with the base .tick block:

<div class="tick">

</div>

We haven't yet entered a value so we won't see anything on the screen.

Let's do that now, add a value using the data-value attribute.

<div class="tick"
     data-value="50">

</div>

Tick now automatically adds a plain "text" view to present our value.

We can also present strings instead of numbers.

<div class="tick"
     data-value="Hello World">

</div

This is useful but not very spectacular, let's do something more interesting. We'll switch back to numbers and setup a "line" progress counter.

We tell Tick to render a different view by adding an HTML element with a data-view attribute. In this case the line view.

<div class="tick"
     data-value="50">

    <span data-view="line"></span>

</div>

It does not show the set progress. Maybe it's because there's no room to render our line view. We'll replace the span element with a div to make it stretch the entire width of the demo area.

<div class="tick"
     data-value="50">

    <div data-view="line"></div>

</div>

That wasn't it.

We don't see anything because line doesn't know its maximum value and therefor cannot determine what progress to show. We have to feed line a a value between 0 and 1, where 0 is empty and 1 is full.

We can do this by telling it the maximum value. We'll add a transform that calculates the value between 0 and 1 for a value in a certain range (in this case 0 and 100).

<div class="tick"
     data-value="50">

    <div data-view="line" data-transform="fraction(0,100)"></div>

</div>

There we go! We put in a value of 50 and the fraction transform turns it into 0.5

Let's update our counter each second so we can see the progress bar fill up. Bind a function to the data-did-init callback. We'll limit its value to a 100.

We'll also add a nice animation using the spring transform. See how we can pipe values from one transform to the other.

<div class="tick"
     data-value="50"
     data-did-init="handleTickInit">

    <div data-view="line" data-transform="fraction(0,100) -> spring"></div>

</div>
<script>
function handleTickInit(tick) {

    // The Tick `interval` function is an easy way to quickly setup a timer
    Tick.helper.interval(function() {

        // We simply increase the value of our ticker each second
        if (tick.value < 100) {
            tick.value += 5;
        }
        else {
            tick.value = 0;
        }

    });

}
</script>

There you have it, a simple progress bar build with Tick.

Read the documentation to take a deep dive into what's possible with Tick.

License

MIT License, Enjoy!

tick's People

Contributors

rikschennink avatar ryno1234 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.