11.0.5 • Published 1 year ago

vue-flatpickr-component v11.0.5

Weekly downloads
36,605
License
MIT
Repository
github
Last release
1 year ago

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 versionPackage versionBranch
2.x8.x8.x
3.x11.xmain

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:

AttributeTypeDefaultDescription
v-modelString / Date Object / Array / Timestamp / nullnullSet or Get date-picker value (required)
configObject{ wrap: false }Flatpickr configuration options
eventsArrayArray of sensible eventsCustomise 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/vue@3.3"></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 >=20.11 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

cb-building-blocksac-components-dynamicdefipro-bscdefi-pro-makersg-skellyvite-wallet@infinitebrahmanuniverse/nolb-vue-fwbu-design-system@everything-registry/sub-chunk-3080vue-gardenwd-frontend-sharedvuravel-flatpickrvue-komposuperv-jsspinzartestingtransteststarlighttest-template-pkgvite-gardenveeroll-vue-packagevue-argon-dashboard@doaglobal/personalized-components@cwa/nuxt-module-next@bytefury/spacewind@bproto/themekitaokitao-componentslaravel-vue-crudvuestic-02vfg-field-datetime-pickerknack-clientsoumya-vue-components@adncorp/frappejs@airvertco/frappejs@burh/nuxt-core@chec/ui-libraryvue_form_builder_bootstrap4vue-stepper-ohdnfuncle-argon@e9ine/vue-form-plugin@e9ine/vue_components@haakma-org/molgenis-vue-forms@mtntop/utils@mv-template/cameravision@mv-template/dev@mv-template/telkom@mv-template/toyota@netis/search@dynapp/webc-documents@molgenis/molgenis-ui-form@ia-ghc/nuxt-components@juntei/ui@kmhgmbh/form-generator@oetsky/pm-ui@salamander.be/vue-gantt@raichev-dima/vuestic-ui@remp/remp-segment-buildermv-templatemv-template-kumv-template-pagemv-mes-rendermv-mes-renderermy-account-componentsmv-cms-rendermv-form-rendermochavsky-uinannar-form-makingoneblink-apps-vuenuxt-flatpickrnuxt-mvmnt-basenextgen-frontendportabilis-uipurettoaststorybookprowork-uismartekcmslily-frontendlyc-testmagma-design-system-testlabelbaker-creative-editorkoishi-plugin-statskompo-vuekompo-allkompo-flatpickrkompo-reactkoala-kumalmayank-appsmau-vue-componentsmcdsmcdstest@superv/ui@tedbree/eventbree-vue@tripla/tripla-date-range-picker@supplycart/ui@whitedigital-eu/wd-frontend-sharedam_table_vueaffinity-app-uiardor-testcloudxin-aiot-admincraftabledefibsc
11.0.5

1 year ago

11.0.4

1 year ago

11.0.2

2 years ago

11.0.3

2 years ago

8.1.8

2 years ago

10.0.0

3 years ago

11.0.0

2 years ago

11.0.1

2 years ago

9.0.8

3 years ago

9.0.7

3 years ago

9.0.6

3 years ago

9.0.5

4 years ago

9.0.4

4 years ago

8.1.7

4 years ago

9.0.3

4 years ago

9.0.2

5 years ago

9.0.1

5 years ago

9.0.0

5 years ago

8.1.6

5 years ago

8.1.5

5 years ago

8.1.4

6 years ago

8.1.3

6 years ago

8.1.2

6 years ago

8.1.1

6 years ago

8.1.0

6 years ago

8.0.0

7 years ago

7.0.6

7 years ago

7.0.5

7 years ago

7.0.4

7 years ago

7.0.3

7 years ago

7.0.2

7 years ago

7.0.1

7 years ago

7.0.0

7 years ago

6.2.0

7 years ago

6.1.0

7 years ago

6.0.0

7 years ago

5.0.5

7 years ago

5.0.4

7 years ago

5.0.3

7 years ago

5.0.2

7 years ago

5.0.1

7 years ago

5.0.0

7 years ago

4.0.0

8 years ago

3.1.3

8 years ago

3.1.2

8 years ago

3.1.1

8 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.4.1

8 years ago

1.2.5

8 years ago

2.4.0

8 years ago

2.3.0

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

1.2.4

8 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.6

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago