Skip to content

Commit

Permalink
confirmDate plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
chmln committed Jan 27, 2017
1 parent 15b9917 commit d375a02
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/plugins/confirmDate/confirmDate.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.flatpickr-confirm {
height: 40px;
max-height: 0px;
visibility: hidden;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}

.flatpickr-confirm:hover {

}

.flatpickr-confirm.visible {
max-height: 40px;
visibility: visible
}
37 changes: 37 additions & 0 deletions src/plugins/confirmDate/confirmDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function confirmIconPlugin(pluginConfig) {
const defaultConfig = {
confirmIcon: "<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='17' height='17' viewBox='0 0 17 17'> <g> </g> <path d='M15.418 1.774l-8.833 13.485-4.918-4.386 0.666-0.746 4.051 3.614 8.198-12.515 0.836 0.548z' fill='#000000' /> </svg>",
confirmText: "OK ",
showAlways: false
};

const config = Object.assign({}, defaultConfig, pluginConfig || {});

return function(fp) {
fp.confirmContainer = fp._createElement("div", "flatpickr-confirm", config.confirmText);
fp.confirmContainer.innerHTML += config.confirmIcon;

fp.confirmContainer.addEventListener("click", fp.close);

const hooks = {
onReady () {
fp.calendarContainer.appendChild(fp.confirmContainer);
}
};

if (config.showAlways)
fp.confirmContainer.classList.add("visible");

else
hooks.onChange = function(dateObj, dateStr) {
if(dateStr)
return fp.confirmContainer.classList.add("visible");
fp.confirmContainer.classList.remove("visible");
}

return hooks;
}
}

if (typeof module !== "undefined")
module.exports = confirmIconPlugin;

0 comments on commit d375a02

Please sign in to comment.