vue-flatpickr-jalili-component
Version:
Vue.js component for Flatpickr date-time picker
160 lines (120 loc) • 6.45 kB
Markdown
[](https://npm-stat.com/charts.html?package=vue-flatpickr-component&from=2018-01-01)
[](https://www.jsdelivr.com/package/npm/vue-flatpickr-component)
[](https://www.npmjs.com/package/vue-flatpickr-component)
[](https://github.com/ankurk91/vue-flatpickr-component/tags)
[](https://github.com/ankurk91/vue-flatpickr-component/actions)
[](https://codecov.io/gh/ankurk91/vue-flatpickr-component)
[](LICENSE.txt)

Vue.js component for [Flatpickr](https://flatpickr.js.org/) date-time picker.
This version is highly copied from the original with 1 difference which is use of flatpickr of jalali version so basically to support jalali dates thats it !
* Reactive `v-model` value
- You can change flatpickr value programmatically
* Reactive [config](https://flatpickr.js.org/options/) options
- You can change config options dynamically
- Component will watch for any changes and redraw itself
* Can emit all possible [events](https://flatpickr.js.org/events/)
* Compatible with [Bootstrap](http://getbootstrap.com/) or any other CSS framework
* Supports [wrapped](https://flatpickr.js.org/examples/#flatpickr--external-elements) mode
* Works with validation libraries
```bash
npm install vue-flatpickr-jalili-component
```
```html
<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>
```
Using Bootstrap [input group](https://getbootstrap.com/docs/4.6/components/input-group/) and Font Awesome icons
```html
<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>
```
* The component can emit all possible events, you can listen to them in your component
```html
<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.
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](https://flatpickr.js.org/options/) |
| events | Array | Array of sensible [events](./src/events.ts
* Clone this repo
* Make sure you have node-js `>=20.11` and [pnpm](https://pnpm.io/) `>=9.x` pre-installed
* Install dependencies `pnpm install`
* Run webpack dev server `npm start`
* This should open the demo page in your default web browser
* This package is using [Jest](https://github.com/facebook/jest)
and [vue-test-utils](https://github.com/vuejs/test-utils) for testing.
* Tests can be found in `__test__` folder.
* Execute tests with this command `npm test`
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
[](LICENSE.txt) License