stimulus-flatpickr
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -1,2 +0,2 @@ | ||
var t,e=require("stimulus"),n=(t=require("flatpickr"))&&"object"==typeof t&&"default"in t?t.default:t,a={string:["altFormat","altInputClass","ariaDateFormat","dateFormat","defaultDate","mode","nextArrow","prevArrow"],boolean:["altInput","allowInput","clickOpens","disableMobile","enableTime","enableSeconds","inline","noCalendar","shorthandCurrentMonth","static","time_24hr","weekNumbers","wrap"],date:["maxDate","minDate"],array:["disable","enable"],number:["defaultHour","defaultMinute","hourIncrement","minuteIncrement"]},o=["change","open","close","monthChange","yearChange","ready","valueUpdate","dayCreate"],r=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.initialize=function(){this.config={}},e.prototype.connect=function(){this.initializeOptions(),this.initializeEvents(),this.fp=n(this.element,Object.assign({},this.config))},e.prototype.disconnect=function(){this.fp.destroy()},e.prototype.initializeEvents=function(){var t=this;o.forEach(function(e){var n,a="on"+((n=e).charAt(0).toUpperCase()+n.slice(1));t.config[a]=t[e]})},e.prototype.initializeOptions=function(){var t=this;Object.keys(a).forEach(function(e){a[e].forEach(function(n){var a=n.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-").toLowerCase();t.data.has(a)&&(t.config[n]=t[e](a))})})},e.prototype.string=function(t){return this.data.get(t)},e.prototype.date=function(t){return this.data.get(t)},e.prototype.boolean=function(t){return"true"===this.data.get(t)},e.prototype.array=function(t){return JSON.parse(this.data.get(t))},e.prototype.number=function(t){return parseInt(this.data.get(t))},e}(e.Controller);module.exports=r; | ||
var t,e=require("stimulus"),n=(t=require("flatpickr"))&&"object"==typeof t&&"default"in t?t.default:t,o={string:["altFormat","altInputClass","ariaDateFormat","dateFormat","defaultDate","mode","nextArrow","prevArrow"],boolean:["altInput","allowInput","clickOpens","disableMobile","enableTime","enableSeconds","inline","noCalendar","shorthandCurrentMonth","static","time_24hr","weekNumbers","wrap"],date:["maxDate","minDate"],array:["disable","enable"],number:["defaultHour","defaultMinute","hourIncrement","minuteIncrement"]},a=["change","open","close","monthChange","yearChange","ready","valueUpdate","dayCreate"],r=["input","calendarContainer","prevMonthNav","nextMonthNav","currentMonthElement","currentYearElement","days"],i=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.initialize=function(){this.config={}},e.prototype.connect=function(){this.initializeEvents(),this.initializeOptions(),this.fp=n(this.element,Object.assign({},this.config)),this.initializeElements()},e.prototype.disconnect=function(){this.fp.destroy()},e.prototype.initializeEvents=function(){var t=this;a.forEach(function(e){var n,o="on"+((n=e).charAt(0).toUpperCase()+n.slice(1));t.config[o]=t[e].bind(t)})},e.prototype.initializeOptions=function(){var t=this;Object.keys(o).forEach(function(e){o[e].forEach(function(n){var o=n.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-").toLowerCase();t.data.has(o)&&(t.config[n]=t[e](o))})})},e.prototype.initializeElements=function(){var t=this;r.forEach(function(e){t[e+"Target"]=t.fp[e]})},e.prototype.change=function(){},e.prototype.open=function(){},e.prototype.close=function(){},e.prototype.monthChange=function(){},e.prototype.yearChange=function(){},e.prototype.ready=function(){},e.prototype.valueUpdate=function(){},e.prototype.dayCreate=function(){},e.prototype.string=function(t){return this.data.get(t)},e.prototype.date=function(t){return this.data.get(t)},e.prototype.boolean=function(t){return"true"===this.data.get(t)},e.prototype.array=function(t){return JSON.parse(this.data.get(t))},e.prototype.number=function(t){return parseInt(this.data.get(t))},e}(e.Controller);module.exports=i; | ||
//# sourceMappingURL=stimulus-flatpickr.js.map |
@@ -1,2 +0,2 @@ | ||
import{Controller as t}from"stimulus";import e from"flatpickr";var n={string:["altFormat","altInputClass","ariaDateFormat","dateFormat","defaultDate","mode","nextArrow","prevArrow"],boolean:["altInput","allowInput","clickOpens","disableMobile","enableTime","enableSeconds","inline","noCalendar","shorthandCurrentMonth","static","time_24hr","weekNumbers","wrap"],date:["maxDate","minDate"],array:["disable","enable"],number:["defaultHour","defaultMinute","hourIncrement","minuteIncrement"]},a=["change","open","close","monthChange","yearChange","ready","valueUpdate","dayCreate"];export default function(t){function o(){t.apply(this,arguments)}return t&&(o.__proto__=t),(o.prototype=Object.create(t&&t.prototype)).constructor=o,o.prototype.initialize=function(){this.config={}},o.prototype.connect=function(){this.initializeOptions(),this.initializeEvents(),this.fp=e(this.element,Object.assign({},this.config))},o.prototype.disconnect=function(){this.fp.destroy()},o.prototype.initializeEvents=function(){var t=this;a.forEach(function(e){var n,a="on"+((n=e).charAt(0).toUpperCase()+n.slice(1));t.config[a]=t[e]})},o.prototype.initializeOptions=function(){var t=this;Object.keys(n).forEach(function(e){n[e].forEach(function(n){var a=n.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-").toLowerCase();t.data.has(a)&&(t.config[n]=t[e](a))})})},o.prototype.string=function(t){return this.data.get(t)},o.prototype.date=function(t){return this.data.get(t)},o.prototype.boolean=function(t){return"true"===this.data.get(t)},o.prototype.array=function(t){return JSON.parse(this.data.get(t))},o.prototype.number=function(t){return parseInt(this.data.get(t))},o}(t); | ||
import{Controller as t}from"stimulus";import e from"flatpickr";var n={string:["altFormat","altInputClass","ariaDateFormat","dateFormat","defaultDate","mode","nextArrow","prevArrow"],boolean:["altInput","allowInput","clickOpens","disableMobile","enableTime","enableSeconds","inline","noCalendar","shorthandCurrentMonth","static","time_24hr","weekNumbers","wrap"],date:["maxDate","minDate"],array:["disable","enable"],number:["defaultHour","defaultMinute","hourIncrement","minuteIncrement"]},o=["change","open","close","monthChange","yearChange","ready","valueUpdate","dayCreate"],a=["input","calendarContainer","prevMonthNav","nextMonthNav","currentMonthElement","currentYearElement","days"];export default function(t){function r(){t.apply(this,arguments)}return t&&(r.__proto__=t),(r.prototype=Object.create(t&&t.prototype)).constructor=r,r.prototype.initialize=function(){this.config={}},r.prototype.connect=function(){this.initializeEvents(),this.initializeOptions(),this.fp=e(this.element,Object.assign({},this.config)),this.initializeElements()},r.prototype.disconnect=function(){this.fp.destroy()},r.prototype.initializeEvents=function(){var t=this;o.forEach(function(e){var n,o="on"+((n=e).charAt(0).toUpperCase()+n.slice(1));t.config[o]=t[e].bind(t)})},r.prototype.initializeOptions=function(){var t=this;Object.keys(n).forEach(function(e){n[e].forEach(function(n){var o=n.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-").toLowerCase();t.data.has(o)&&(t.config[n]=t[e](o))})})},r.prototype.initializeElements=function(){var t=this;a.forEach(function(e){t[e+"Target"]=t.fp[e]})},r.prototype.change=function(){},r.prototype.open=function(){},r.prototype.close=function(){},r.prototype.monthChange=function(){},r.prototype.yearChange=function(){},r.prototype.ready=function(){},r.prototype.valueUpdate=function(){},r.prototype.dayCreate=function(){},r.prototype.string=function(t){return this.data.get(t)},r.prototype.date=function(t){return this.data.get(t)},r.prototype.boolean=function(t){return"true"===this.data.get(t)},r.prototype.array=function(t){return JSON.parse(this.data.get(t))},r.prototype.number=function(t){return parseInt(this.data.get(t))},r}(t); | ||
//# sourceMappingURL=stimulus-flatpickr.m.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("stimulus"),require("flatpickr")):"function"==typeof define&&define.amd?define(["stimulus","flatpickr"],e):t.stimulusFlatpickr=e(t.stimulus,t.flatpickr)}(this,function(t,e){e=e&&e.hasOwnProperty("default")?e.default:e;var n={string:["altFormat","altInputClass","ariaDateFormat","dateFormat","defaultDate","mode","nextArrow","prevArrow"],boolean:["altInput","allowInput","clickOpens","disableMobile","enableTime","enableSeconds","inline","noCalendar","shorthandCurrentMonth","static","time_24hr","weekNumbers","wrap"],date:["maxDate","minDate"],array:["disable","enable"],number:["defaultHour","defaultMinute","hourIncrement","minuteIncrement"]},o=["change","open","close","monthChange","yearChange","ready","valueUpdate","dayCreate"];return function(t){function i(){t.apply(this,arguments)}return t&&(i.__proto__=t),(i.prototype=Object.create(t&&t.prototype)).constructor=i,i.prototype.initialize=function(){this.config={}},i.prototype.connect=function(){this.initializeOptions(),this.initializeEvents(),this.fp=e(this.element,Object.assign({},this.config))},i.prototype.disconnect=function(){this.fp.destroy()},i.prototype.initializeEvents=function(){var t=this;o.forEach(function(e){var n,o="on"+((n=e).charAt(0).toUpperCase()+n.slice(1));t.config[o]=t[e]})},i.prototype.initializeOptions=function(){var t=this;Object.keys(n).forEach(function(e){n[e].forEach(function(n){var o=n.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-").toLowerCase();t.data.has(o)&&(t.config[n]=t[e](o))})})},i.prototype.string=function(t){return this.data.get(t)},i.prototype.date=function(t){return this.data.get(t)},i.prototype.boolean=function(t){return"true"===this.data.get(t)},i.prototype.array=function(t){return JSON.parse(this.data.get(t))},i.prototype.number=function(t){return parseInt(this.data.get(t))},i}(t.Controller)}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("stimulus"),require("flatpickr")):"function"==typeof define&&define.amd?define(["stimulus","flatpickr"],e):t.stimulusFlatpickr=e(t.stimulus,t.flatpickr)}(this,function(t,e){e=e&&e.hasOwnProperty("default")?e.default:e;var n={string:["altFormat","altInputClass","ariaDateFormat","dateFormat","defaultDate","mode","nextArrow","prevArrow"],boolean:["altInput","allowInput","clickOpens","disableMobile","enableTime","enableSeconds","inline","noCalendar","shorthandCurrentMonth","static","time_24hr","weekNumbers","wrap"],date:["maxDate","minDate"],array:["disable","enable"],number:["defaultHour","defaultMinute","hourIncrement","minuteIncrement"]},o=["change","open","close","monthChange","yearChange","ready","valueUpdate","dayCreate"],i=["input","calendarContainer","prevMonthNav","nextMonthNav","currentMonthElement","currentYearElement","days"];return function(t){function r(){t.apply(this,arguments)}return t&&(r.__proto__=t),(r.prototype=Object.create(t&&t.prototype)).constructor=r,r.prototype.initialize=function(){this.config={}},r.prototype.connect=function(){this.initializeEvents(),this.initializeOptions(),this.fp=e(this.element,Object.assign({},this.config)),this.initializeElements()},r.prototype.disconnect=function(){this.fp.destroy()},r.prototype.initializeEvents=function(){var t=this;o.forEach(function(e){var n,o="on"+((n=e).charAt(0).toUpperCase()+n.slice(1));t.config[o]=t[e].bind(t)})},r.prototype.initializeOptions=function(){var t=this;Object.keys(n).forEach(function(e){n[e].forEach(function(n){var o=n.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-").toLowerCase();t.data.has(o)&&(t.config[n]=t[e](o))})})},r.prototype.initializeElements=function(){var t=this;i.forEach(function(e){t[e+"Target"]=t.fp[e]})},r.prototype.change=function(){},r.prototype.open=function(){},r.prototype.close=function(){},r.prototype.monthChange=function(){},r.prototype.yearChange=function(){},r.prototype.ready=function(){},r.prototype.valueUpdate=function(){},r.prototype.dayCreate=function(){},r.prototype.string=function(t){return this.data.get(t)},r.prototype.date=function(t){return this.data.get(t)},r.prototype.boolean=function(t){return"true"===this.data.get(t)},r.prototype.array=function(t){return JSON.parse(this.data.get(t))},r.prototype.number=function(t){return parseInt(this.data.get(t))},r}(t.Controller)}); | ||
//# sourceMappingURL=stimulus-flatpickr.umd.js.map |
{ | ||
"name": "stimulus-flatpickr", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "A Stimulus Wrapper for Flatpickr library", | ||
@@ -5,0 +5,0 @@ "main": "dist/stimulus-flatpickr.js", |
@@ -5,3 +5,3 @@ # Stimulus Flatpickr | ||
This is an experimental wrapper on Flatpickr for using Stimulus.js. All configurations for the DateTime picker can be set directly from the `data-attributes` of the HTML. This can be handy when working as an example with a Rails backend so that all settings for the DateTime picker can be set by the backend when generating the view. | ||
This is an experimental wrapper of [Flatpickr](http://flatpickr.js.org/) for Stimulus.js. All configurations for the DateTime picker can be set directly from the `data-attributes` of the HTML. This can be handy when working as an example with a Rails backend. All settings for the DateTime picker can be set by the backend when generating the view. | ||
@@ -167,4 +167,24 @@ ## Install | ||
... coming | ||
#### Elements | ||
In your controller you can access the Flapickr [elements](https://flatpickr.js.org/instance-methods-properties-elements/#elements) using some Stimulus like targets. | ||
`this.inputTarget` : The text input element associated with flatpickr. | ||
`this.calendarContainerTarget` : Self-explanatory. This is the div.flatpickr-calendar element. | ||
`this.prevMonthNavTarget` : The “left arrow” element responsible for decrementing the current month. | ||
`this.nextMonthNavTarget` : The “right arrow” element responsible for incrementing the current month. | ||
`this.currentMonthElementTarget`: The span holding the current month’s name. | ||
`this.currentYearElementTarget`: The input holding the current year. | ||
`this.daysTarget` : The container for all the day elements. | ||
#### Properties | ||
.... | ||
## CSS | ||
@@ -171,0 +191,0 @@ |
@@ -6,2 +6,3 @@ import { Controller } from "stimulus"; | ||
import { events } from "./events"; | ||
import { elements } from "./elements"; | ||
@@ -14,4 +15,4 @@ class Flatpickr extends Controller { | ||
connect() { | ||
this.initializeEvents(); | ||
this.initializeOptions(); | ||
this.initializeEvents(); | ||
@@ -21,2 +22,4 @@ this.fp = flatpickr(this.element, { | ||
}); | ||
this.initializeElements(); | ||
} | ||
@@ -31,3 +34,3 @@ | ||
const hook = `on${capitalize(event)}`; | ||
this.config[hook] = this[event]; | ||
this.config[hook] = this[event].bind(this); | ||
}); | ||
@@ -48,2 +51,24 @@ } | ||
initializeElements() { | ||
elements.forEach(element => { | ||
this[`${element}Target`] = this.fp[element]; | ||
}); | ||
} | ||
change() {} | ||
open() {} | ||
close() {} | ||
monthChange() {} | ||
yearChange() {} | ||
ready() {} | ||
valueUpdate() {} | ||
dayCreate() {} | ||
string(option) { | ||
@@ -50,0 +75,0 @@ return this.data.get(option); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
151281
17
166
199