flatpickr-hijri-calendar
v1.0.0
Published
A plugin for flatpickr to display hijri calendar.
Downloads
5
Maintainers
Readme
flatpickr-hijri-calendar - A plugin for flatpickr (javascript datetime picker)
This plugin is meant to be used with flatpickr. It will display the hijri dates in the calendar picker.
Installation
npm install --save flatpickr-hijri-calendar
This plugin depends on luxon to display hijri dates.
npm install --save flatpickr-hijri-calendar
Setup
// (1) Import JS
import flatpickr from "flatpickr";
import "flatpickr/dist/l10n/ar";
import flatpickrHijriCalendar from "flatpickr-hijri-calendar";
import { DateTime } from "luxon";
// (2) Import the css files
import 'flatpickr/dist/flatpickr.css'
import "flatpickr-hijri-calendar/dist/flatpickr-hijri-calendar.css";
// Or in a saas file:
// @import "~flatpickr/dist/flatpickr.css";
// @import "~flatpickr-hijri-calendar/dist/flatpickr-hijri-calendar.css";
// (3) Add the plugin to flatpickr plugins option.
flatpickr('.date', {
locale: "ar",
plugins: [
flatpickrHijriCalendar(DateTime, {
showHijriToggle: true, // flase if you don't want to show the toggle button.
}),
],
});
Using CDN
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>flatpickr hijri calendar</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/flatpickr.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/flatpickr-hijri-calendar.min.css">
</head>
<body>
<div style="padding:15vw">
<div>
<div>Date 1</div>
<label>
<input placeholder="Select Date..." class=date />
</label>
</div>
</div>
<!-- classList polyfill for IE9 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.2.20171210/classList.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/flatpickr.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/l10n/ar.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/global/luxon.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/flatpickr-hijri-calendar.min.js"></script>
<script>
const fp = flatpickr('.date', {
locale: 'ar',
plugins: [
hijriCalendarPlugin(luxon.DateTime, {
showHijriDates: true,
showHijriToggle: false,
}),
]
});
</script>
</body>
</html>
Mobile Support
If you want to show hijri dates on mobile, you must disable flatpickr mobile support.
<script>
const fp = flatpickr('.date', {
disableMobile: "true" // Important to show hijri dates on mobile.
locale: 'ar',
plugins: [
hijriCalendarPlugin(luxon.DateTime, {
showHijriDates: true,
showHijriToggle: false,
}),
]
});
</script>