Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@smithalan2/vue-countdown

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smithalan2/vue-countdown

A simple countdown timer component for Vue 3 written using the composition API.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
decreased by-26.09%
Maintainers
1
Weekly downloads
 
Created
Source

Vue Countdown

A simple countdown timer component for Vue 3 written using the composition API.

Demo https://smithalan92.github.io/vue-countdown/


Installation

Install with npm

npm i --save @smithalan2/vue-countdown

Props

NameTypeRequiredDefaultNotes
startDateTimeDatenonew Date() on each tickPassing a start date time will result in only 1 calc being made.
endDateTimeDateyesn/a----
startImmediatelyBooleanfalsetrueIf passed as false, you need to call run on the component ref.
tickDelayNumberno1000ms to run each recalculation.

Events

NameArgsNotes
startNoneEmitted the first time a countdown starts
finishedNoneEmitted when the countdown has reached the end time
cancelledNoneEmitted when the countdown has been cancelled
tickCountdownThe newely calculated countdown values

Slot props

If the component is passed a default slot. The slot will recieve a prop with Countdown data


Exposed Properties

The component instance exposes a number of properties that can be used if required.

NameNotes
runA function to manually start the countdown.
cancelA function to cancel the countdown
countdownThe actual reactive countdown data

Countdown Data

The countdown data is a reactive object. It is passed as a slot prop and also given as a param to the tick event.

The countdown prop contains the values for the countown, as well as formatted text that can be used for display. The countdown data object is structured as follows

{
  remainingSeconds: { value: Number, text: String },
  remainingMinutes: { value: Number, text: String },
  remainingHours: { value: Number, text: String },
  remainingDays: { value: Number, text: String },
  remainingWeeks: { value: Number, text: String },
  remainingMonths: { value: Number, text: String },
  remainingYears: { value: Number, text: String },
}

Sample key values may are

remainingYears: { value: 0, text: '0 years' },
remainingDays: { value: 1, text: '1 day' },
remainingSeconds: { value: 54, text: '54 seconds' },

Sample Usage

vue-countdown can be used in 2 ways. You can either use slots to render out the countdown, or provide no slot and listen to the tick event to get countdown updates and do whatever you need to.

With slots

<vue-countdown
  :end-date-time="endDateTime">
  <template
    v-slot:default="{ countdown }">
    {{ countdown }}
  </template>
</vue-countdown>

With event

<vue-countdown
  :end-date-time="endDateTime"
  @tick="onTick">
...
onTick(countdown) {
  ...
}

License

See License.md

Keywords

FAQs

Package last updated on 24 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc