• Stars
    star
    964
  • Rank 47,452 (Top 1.0 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vue.js component for Flatpickr datetime picker πŸ“†

Vue FlatPickr Component

downloads jsdelivr npm-version github-tag build codecov license ts

Vue.js component for Flatpickr date-time picker.

Demo or JSFiddle

Version matrix

Vue.js version Package version Branch
2.x 8.x 8.x
3.x 11.x main

Features

  • Reactive v-model value
    • You can change flatpickr value programmatically
  • Reactive config options
    • You can change config options dynamically
    • Component will watch for any changes and redraw itself
  • Can emit all possible events
  • Compatible with Bootstrap or any other CSS framework
  • Supports wrapped mode
  • Works with validation libraries

Installation

npm install vue-flatpickr-component@^11

Usage

Minimal example

<template>
    <flat-pickr v-model="date"/>
</template>

<script setup>
    import {ref} from 'vue';
    import flatPickr from 'vue-flatpickr-component';
    import 'flatpickr/dist/flatpickr.css';

    const date = ref(null);
</script>

Detailed example

Using Bootstrap input group and Font Awesome icons

<template>
    <section>
        <div class="form-group">
            <label>Select a date</label>
            <div class="input-group">
                <flat-pickr
                    v-model="date"
                    :config="config"
                    class="form-control"
                    placeholder="Select date"
                    name="date"/>
                <div class="input-group-append">
                    <button class="btn btn-default" type="button" title="Toggle" data-toggle>
                        <i class="fa fa-calendar"/>
                        <span aria-hidden="true" class="sr-only">Toggle</span>
                    </button>
                    <button class="btn btn-default" type="button" title="Clear" data-clear>
                        <i class="fa fa-times"/>
                        <span aria-hidden="true" class="sr-only">Clear</span>
                    </button>
                </div>
            </div>
        </div>
        <pre>Selected date is - {{date}}</pre>
    </section>
</template>

<script setup>
    import {ref} from 'vue';
    import 'bootstrap/dist/css/bootstrap.css';
    // import this component
    import flatPickr from 'vue-flatpickr-component';
    import 'flatpickr/dist/flatpickr.css';
    // theme is optional
    // try more themes at - https://flatpickr.js.org/themes/
    import 'flatpickr/dist/themes/material_blue.css';
    // localization is optional
    import {Hindi} from 'flatpickr/dist/l10n/hi.js';

    const date = ref('2022-10-28');

    // Read more at https://flatpickr.js.org/options/
    const config = ref({
        wrap: true, // set wrap to true only when using 'input-group'
        altFormat: 'M j, Y',
        altInput: true,
        dateFormat: 'Y-m-d',
        locale: Hindi, // locale for this instance only          
    });
</script>

Events

  • The component can emit all possible events, you can listen to them in your component
<flat-pickr v-model="date" @on-change="doSomethingOnChange" @on-close="doSomethingOnClose"/>
  • Event names has been converted to kebab-case.
  • You can still pass your callback methods in :config like original flatpickr do.

Available props

The component accepts these props:

Attribute Type Default Description
v-model String / Date Object / Array / Timestamp / null null Set or Get date-picker value (required)
config Object { wrap: false } Flatpickr configuration options
events Array Array of sensible events Customise the events to be emitted

Use in browser with CDN

<!-- Flatpickr related files -->
<link href="https://cdn.jsdelivr.net/npm/flatpickr@4/dist/flatpickr.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/flatpickr@4/dist/flatpickr.min.js"></script>
<!-- Vue.js -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<!-- Lastly add this package -->
<script src="https://cdn.jsdelivr.net/npm/vue-flatpickr-component@11"></script>
<script>
    const app = Vue.createApp({})
    app.component('flat-pickr', VueFlatpickr.default);
    app.mount("#app");
</script>

Run examples on your localhost

  • Clone this repo
  • Make sure you have node-js >=18.16 and pnpm >=8.x pre-installed
  • Install dependencies pnpm install
  • Run webpack dev server npm start
  • This should open the demo page in your default web browser

Testing

  • This package is using Jest and vue-test-utils for testing.
  • Tests can be found in __test__ folder.
  • Execute tests with this command npm test

Changelog

Please see CHANGELOG for more information what has changed recently.

License

MIT License

More Repositories

1

vue-loading-overlay

Vue.js component for full screen loading indicator πŸŒ€
JavaScript
1,219
star
2

vue-toast-notification

Yet another toast notification plugin for Vue.js 🌷
JavaScript
615
star
3

vue-cleave-component

Vue.js component for Cleave.js input mask library ⌨️
JavaScript
281
star
4

vue-trumbowyg

Vue.js component for Trumbowyg WYSIWYG editor πŸ“
JavaScript
236
star
5

vue-bootstrap-datetimepicker

Vue.js component for eonasdan bootstrap datetimepicker
JavaScript
224
star
6

google-chat-electron

An unofficial desktop app for Google Chat :electron:
TypeScript
158
star
7

vue-web-storage

Vue.js plugin for local storage and session storage (1.8 kb min+gz) πŸ’Ύ
TypeScript
85
star
8

fcm-notification-channel

All in One Firebase push notification channel for Laravel πŸ””
PHP
68
star
9

laravel-eloquent-relationships

Add some more eloquent relationships to Laravel php framework. πŸ‘«
PHP
57
star
10

phpunit-travis-ci-coverage-example

phpUnit Testing on Travis-CI with Code Coverage on CodeCov
PHP
28
star
11

laravel-mix-auto-extract

[DEPRECATED] Laravel Mix v2/3 plugin to auto extract vendor js
JavaScript
25
star
12

laravel-ses-webhooks

AWS SES Webhooks client for Laravel πŸ“¬
PHP
22
star
13

laravel-socialite-multiple-providers-example

Laravel socialite with multiple providers example
PHP
20
star
14

vue-jquery-mask

Vue.js component for jQuery mask plugin
JavaScript
20
star
15

vue-lunch-order-app

Lunch order app, built with Vue.js v2 and Google Spreadsheet
JavaScript
17
star
16

laravel-paypal-webhooks

Handle PayPal webhooks in Laravel πŸ’΅
PHP
16
star
17

bandwidth-notification-channel

Bandwidth SMS notification channel for Laravel php framework πŸ“©
PHP
12
star
18

wp-google-map

Google Map Plugin for WordPress
PHP
11
star
19

laravel-bundler

Modern asset building tool for Laravel framework with better defaults. πŸ“¦
JavaScript
11
star
20

codeception-travis-ci-example

[READ-ONLY] Codeception Acceptance Testing on Travis-CI
PHP
9
star
21

wp-prism-js

Prism Syntax Highlighter Plugin for WordPress
PHP
7
star
22

vue-bugsnag

[DEPRECATED] Vue.js plugin for Bugsnag js v3.x error reporting
JavaScript
6
star
23

vue-progress-indicator

Vue.js component for progress indicator
JavaScript
5
star
24

electron-update-notifier

Update notifier for Electron apps πŸ””
TypeScript
5
star
25

laravel-form-validation

Yet another form validation (JS) helper for Laravel. β˜‚οΈ
TypeScript
5
star
26

laravel-blogger-api-example

Laravel demo blog REST api πŸ§™β€β™‚οΈ
PHP
4
star
27

laravel-stripe-exceptions

Handle Stripe exceptions gracefully in Laravel php framework. β˜„οΈ
PHP
4
star
28

node-webkit-angular-starter-kit

[READ-ONLY] A node-webkit and Angular js based desktop app
JavaScript
3
star
29

laravel-alert

A Bootstrap alert helper for Laravel php framework πŸ₯­
PHP
3
star
30

laravel-lunch-order-app

[WIP] Lunch order app built with Laravel
PHP
2
star
31

laravel-vonage-inbound-sms

Vonage Inbound SMS Webhooks Client for Laravel ☎️
PHP
2
star
32

wp-google-analytics

Google Analytics Plugin for WordPress
PHP
2
star
33

gulp-3-browsersync-scss-seed

[READ-ONLY] Front-end development starter kit for beginners
JavaScript
2
star
34

vue-php-demo-2021

Sample app to demo vue.js with php
PHP
2
star
35

laravel-otp

One time password (OTP) generator and verifier for Laravel πŸ“²
PHP
2
star
36

ankurk91.github.io

Ankur Kumar's GitHub Profile πŸŽ‰
HTML
1
star
37

ankurk91

The README repo πŸ˜‰
1
star
38

laravel-passport-socialite-example

Laravel passport with socialite
PHP
1
star
39

laravel-shopping-cart

Shopping cart manager for Laravel. πŸ›’
PHP
1
star
40

wp-tabs-example

WordPress plugin to demonstrate how to use in-built tabs on plugin options page
PHP
1
star
41

wp-lazy-intercom

WordPress plugin to lazy load Intercom widget
PHP
1
star
42

wp-screen-options-example

WordPress plugin to demonstrate screen options usage in your plugin options page
PHP
1
star