trickling
TypeScript icon, indicating that this package has built-in type declarations

1.14.0 • Public • Published


Trickling

A modern progress bar for web APP. Featuring realistic trickle animations to convince your users that something is happening!

Features

  • Support programmatically modify the style of the progress bar.
  • Support RTL languages.
  • Support Typescript.

Installation

# pnpm
$ pnpm add trickling

# yarn
$ yarn add trickling

# npm
$ npm i trickling

Usage

  1. Imports style.
import 'trickling/lib/style.css'
  1. Create a trickling progress instance in a single file.
// @/plugins/trickling-progress.ts

import { createTrickling } from 'trickling'

// Create a Trickling progress instance
const tricklingProgress = createTrickling({
  // Options
  // ...
})

// You can also change options after creating a Trickling progress instance
tricklingProgress.setOptions({
  // ...
})

// Export the instance
export { tricklingProgress }
  1. Using it where needed.
import { tricklingProgress } from '@/plugins/trickling-progress.ts'

// ...
// shows the Trickling progress bar
tricklingProgress.start()

// ...
// Then, completes the Trickling progress
tricklingProgress.done()

Options

Key Type Default value Description
minimum number 0.08 Changes the minimum percentage used upon starting.
maximum number 0.994 Changes the maximum percentage used upon ending.
easing string ease Adjust animation settings using easing (a CSS easing string).
speed number 200 Adjust animation settings using speed (in ms).
trickle boolean true Turn off the automatic incrementing behavior by setting this to false.
trickleSpeed number 1000 Adjust how often to trickle/increment (in ms).
showSpinner boolean true Turn off loading spinner by setting it to false.
appendTo string, HTMLElement body Specify this to change the parent container.
customWrapperClassName string '' Specify this to add a class name into the parent container.
color string #2299dd Specify this to change color of the progress bar and spinner.
progressBarHeight string 2px Specify this to change height of the progress bar.
spinnerOpacity number 1 Specify this to change opacity of the loading spinner.
spinnerSize string 18px Specify this to change size of the loading spinner.
spinnerStrokeWidth string 2px Specify this to change stroke width of the loading spinner.
rtl
(Added in v1.6.0)
boolean false Change the progress direction to right-to-left.
removeFromDOMWhenDone
(Added in v1.9.0)
boolean true Remove the component from the DOM when done, re-add when needed. This can have performance implications on complex apps as style calculations are slow. If set to false, just hidden the DOM via display: none when progress done.
zIndex
(Added in v1.8.0)
number/string 1031 Specify this to change progress bar z-index.
trickleIncrementalCurve
(Added in v1.10.0)
function/Array See below You can use this option to configure the incremental curve of the trickle.

Trickle Incremental Curve

Using this configuration allows you to easily change the default trickle increasing curve. Thus, each Progress bar has different incremental expressions.

  1. Default value
[
  { from: 0, to: 0.2, value: 0.1 },
  { from: 0.2, to: 0.5, value: 0.04 },
  { from: 0.5, to: 0.8, value: 0.02 },
  { from: 0.8, to: 0.99, value: 0.005 },
]
  • from: This represents the starting range of the current progress status (including).
  • to: This represents the end range of the current progress status (excluding).
  • value: This represents the progress increment value of the current range.
  1. Type definition see here.
  • Function: If you use it as a function, should returns a number or array.
  • Array: Just set it via a array.

Advanced usage

  1. Percentages: To set a progress percentage, call .set(n), where n is a number between 0..1.
trickling.set(0.0);     // Just same as .start()
trickling.set(0.4);
trickling.set(1.0);     // Just same as .done()
  1. Incrementing: To increment the progress bar, just use .inc(). This increments it with a random amount. This will never get to 100%: use it for every image load (or similar).
trickling.inc();
  1. If you want to increment by a specific value, you can pass that as a parameter:
trickling.inc(0.2);    // This will get the current status value and adds 0.2 until status is 0.994
  1. Force-done: By passing true to done(), it will show the progress bar even if it's not being shown. (The default behavior is that .done() will not do anything if .start() isn't called).
trickling.done(true);
  1. Get the status value: To get the status value, use .status.
trickling.status

Package Sidebar

Install

npm i trickling

Weekly Downloads

1,139

Version

1.14.0

License

none

Unpacked Size

32.6 kB

Total Files

7

Last publish

Collaborators

  • elenh