├── .babelrc ├── .gitignore ├── README.md ├── dist ├── vue-date-picker.js └── vue-date-picker.min.js ├── example └── index.html ├── package.json ├── src ├── DatePicker.vue └── plugin.js └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "stage-2"], 3 | "plugins": ["transform-runtime"], 4 | "comments": false 5 | } 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | package-lock.json 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vue Date Picker 2 | 3 | > A vue date picker component inspired by material design 4 | 5 | ## Contents 6 | 7 | - [Installing](https://github.com/ridewn/vue-date-picker#installing) 8 | - [Examples](https://github.com/ridewn/vue-date-picker#examples) 9 | - [Formatting Selected Date](https://github.com/ridewn/vue-date-picker#formatting) 10 | - [API](https://github.com/ridewn/vue-date-picker#api) 11 | 12 | ## Installing 13 | 14 | `$ npm install vue-md-date-picker --save` 15 | 16 | `import DatePicker from 'vue-md-date-picker'` 17 | 18 | ## Examples 19 | 20 | The most common use case 21 | 22 | ```html 23 | 28 | ``` 29 | 30 | Note that there is a `v-if` directive and a `@close` event. This is because the date picker allows you to choose when it is displayed, and how to handle closing it. 31 | 32 | Setting a min date to choose from 33 | 34 | ```html 35 | 41 | ``` 42 | 43 | Setting a max date to choose from 44 | 45 | 46 | ```html 47 | 53 | ``` 54 | 55 | Setting a range of dates to choose from 56 | 57 | ```html 58 | 65 | ``` 66 | 67 | You may also specifiy a color to change the theme of the date picker 68 | 69 | ```html 70 | 76 | ``` 77 | There is also a provided transition if you want to fade the date picker in 78 | 79 | ```html 80 | 81 | 86 | 87 | ``` 88 | 89 | ## Formatting 90 | 91 | To format the date picker's value, you may use the `:format` prop. The format prop takes a reference to a function; this function receives the date picker's date value (e.g. 2016-4-19) and may format it however you wish 92 | 93 | 94 | ```html 95 | 101 | ``` 102 | 103 | In your component's methods... 104 | 105 | ```javascript 106 | formatDate (date) { 107 | return moment(date).format('LL') 108 | } 109 | ``` 110 | 111 | In the above example, if a user selected "2017-8-29" as the date, the `date` value would be "August 29, 2017". 112 | 113 | ## API 114 | 115 | ### Props 116 | 117 | | Name | Type | Description | 118 | | :----- | :------- | :---------------------------------------------------------------------- | 119 | | color | String | Changes the theme color of the date picker. | 120 | | format | Function | Formats the date picker's emitted date via a user specified function. | 121 | | min | String | Limits the date to a minimum specified value. | 122 | | max | String | Limits the date to a maximum specified value. | 123 | 124 | ### Events 125 | 126 | | Name | Description | 127 | | :----- | :---------- | 128 | | close | Closes the date picker. This is fired when the Cancel button is pressed, when the escape key is pressed, or when the input event is emitted. | 129 | | input | Sets the selected date. This is fired when the Ok button is pressed, or when the user presses the enter or space key after selecting a date. If a format function is passed to the date picker, the emitted value will be run through that before this event is emitted. | 130 | -------------------------------------------------------------------------------- /dist/vue-date-picker.js: -------------------------------------------------------------------------------- 1 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("vue-date-picker",[],t):"object"==typeof exports?exports["vue-date-picker"]=t():e["vue-date-picker"]=t()}(this,function(){return function(e){function t(r){if(a[r])return a[r].exports;var n=a[r]={exports:{},id:r,loaded:!1};return e[r].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var a={};return t.m=e,t.c=a,t.p="",t(0)}([function(e,t,a){a(1);var r=a(6)(a(7),a(8),"data-v-58e44443",null);e.exports=r.exports},function(e,t,a){var r=a(2);"string"==typeof r&&(r=[[e.id,r,""]]),r.locals&&(e.exports=r.locals);a(4)("326a8e33",r,!0)},function(e,t,a){t=e.exports=a(3)(!1),t.push([e.id,"[data-v-58e44443],[data-v-58e44443]:after,[data-v-58e44443]:before{box-sizing:inherit}button[data-v-58e44443],div[data-v-58e44443],h2[data-v-58e44443],h3[data-v-58e44443],h4[data-v-58e44443],table[data-v-58e44443],tbody[data-v-58e44443],td[data-v-58e44443],thead[data-v-58e44443],tr[data-v-58e44443]{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}button[data-v-58e44443]{border-radius:2px;cursor:pointer;display:inline-block;font-size:16px;padding:0 16px;outline:none;user-select:none}.flex[data-v-58e44443]{display:flex}.flex-center[data-v-58e44443]{display:flex;align-items:center;justify-content:center}.date-picker-background[data-v-58e44443],.date-picker-container[data-v-58e44443]{overflow-y:auto;position:fixed;top:0;left:0;width:100%;height:100%}.date-picker-container[data-v-58e44443]{line-height:1.5;z-index:9998}.date-picker-background[data-v-58e44443]{background-color:rgba(0,0,0,.5);z-index:9999}.calendar-faint[data-v-58e44443]{opacity:.75}.calendar-container[data-v-58e44443]{background-color:#fff;border-radius:2px;box-shadow:0 12px 52px rgba(0,0,0,.25);cursor:auto;position:relative;user-select:text;width:350px;z-index:10001;user-select:none}.calendar[data-v-58e44443]{height:500px;position:relative}.hidden-footer .calendar[data-v-58e44443]{height:470px}.calendar-header[data-v-58e44443]{border-top-left-radius:2px;border-top-right-radius:2px;color:#fff;display:flex;align-items:center;justify-content:space-between;padding:16px 28px}.calendar-header h2[data-v-58e44443],.calendar-header h3[data-v-58e44443]{cursor:default}.calendar-header h2.calendar-faint[data-v-58e44443],.calendar-header h3.calendar-faint[data-v-58e44443]{cursor:pointer}.calendar-header h2[data-v-58e44443]{font-size:28px;line-height:30px;margin-top:3px}.calendar-header h3[data-v-58e44443]{font-size:1.125rem;font-weight:300}.calendar-body[data-v-58e44443]{padding:16px}.calendar-date[data-v-58e44443]{display:flex}.calendar-date .calendar-arrows.left[data-v-58e44443]{display:flex;align-items:center;justify-content:flex-start}.calendar-current-date[data-v-58e44443]{cursor:default;text-align:center}.calendar-date .calendar-arrows.right[data-v-58e44443]{display:flex;align-items:center;justify-content:flex-end}.calendar-date>div[data-v-58e44443]{width:33.333%}.calendar-date h4[data-v-58e44443]{font-size:14px;font-weight:500}.calendar-arrows[data-v-58e44443]{cursor:pointer;padding:0 8px}.calendar-body table[data-v-58e44443]{border-spacing:2px;border-collapse:separate;cursor:default;font-size:12px;margin-top:8px;table-layout:fixed;text-align:center;width:100%}.calendar-body table thead[data-v-58e44443]{color:#757575}.calendar-body table thead td[data-v-58e44443]{cursor:default!important}.calendar-body tr[data-v-58e44443]{height:43px;vertical-align:middle}.calendar-body td[data-v-58e44443]{border-radius:50%;cursor:pointer;vertical-align:middle;transition:background-color .15s;width:43px}.calendar-body td[data-v-58e44443]:focus{outline:none}.calendar-body tbody td[data-v-58e44443]:hover{background-color:rgba(0,0,0,.1)}.calendar-body td[data-v-58e44443]:empty{background-color:transparent!important;cursor:default}.calendar-body td.current-day[data-v-58e44443]{font-weight:700}.calendar-body td.disabled[data-v-58e44443]{color:#c5c5c5;cursor:default;pointer-events:none}.calendar-body td.selected[data-v-58e44443]{border-radius:50%;color:#fff;cursor:pointer}.calendar-year-select[data-v-58e44443]{box-shadow:inset 0 -1px 1px rgba(0,0,0,.075);height:353px;overflow-y:scroll;text-align:center}.hidden-footer .calendar-year-select[data-v-58e44443]{height:378px}.calendar-year-select div[data-v-58e44443]{cursor:pointer;padding:8px 0;transition:background-color .15s}.calendar-year-select div[data-v-58e44443]:hover{background-color:rgba(0,0,0,.1)}.calendar-year-select .selected[data-v-58e44443]{font-size:24px}.calendar-footer[data-v-58e44443]{position:absolute;bottom:16px;right:16px}.calendar-footer button[data-v-58e44443]{background-color:transparent;border:1px solid transparent;box-shadow:none}.calendar-fade-enter-active[data-v-58e44443],.calendar-fade-leave-active[data-v-58e44443]{transition:opacity .15s}.calendar-fade-enter[data-v-58e44443],.calendar-fade-leave-to[data-v-58e44443]{opacity:0}",""])},function(e,t){function a(e,t){var a=e[1]||"",n=e[3];if(!n)return a;if(t&&"function"==typeof btoa){var o=r(n),i=n.sources.map(function(e){return"/*# sourceURL="+n.sourceRoot+e+" */"});return[a].concat(i).concat([o]).join("\n")}return[a].join("\n")}function r(e){var t=btoa(unescape(encodeURIComponent(JSON.stringify(e)))),a="sourceMappingURL=data:application/json;charset=utf-8;base64,"+t;return"/*# "+a+" */"}e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var r=a(t,e);return t[2]?"@media "+t[2]+"{"+r+"}":r}).join("")},t.i=function(e,a){"string"==typeof e&&(e=[[null,e,""]]);for(var r={},n=0;na.parts.length&&(r.parts.length=a.parts.length)}else{for(var i=[],n=0;nr?0:r+t),a=a>r?r:a,a<0&&(a+=r),r=t>a?0:a-t>>>0,t>>>=0;for(var n=-1,o=new Array(r);++n=10?this.selectedDay:"0"+this.selectedDay,t=this.selectedMonth+1>=10?this.selectedMonth+1:"0"+(this.selectedMonth+1);return this.selectedYear+"-"+t+"-"+e},abbrivatedDay:function(){return a[this.selectedDayOfWeek]},currentMonthWord:function(){return r[this.currentMonth]},selectedMonthWord:function(){return r[this.selectedMonth]},minDate:function(){if(this.min){var e=this.min.split("-");return new Date(e[0],e[1],e[2])}},maxDate:function(){if(this.max){var e=this.max.split("-");return new Date(e[0],e[1],e[2])}},showLeftArrow:function(){return!this.min||(this.minDate.getFullYear()!==this.currentYear||this.minDate.getMonth()-1!==this.currentMonth)},showRightArrow:function(){return!this.max||(this.maxDate.getFullYear()!==this.currentYear||this.maxDate.getMonth()-1!==this.currentMonth)},calendar:function(){for(var e=this,t=[],a=new Date(this.currentYear,this.currentMonth,1).getDay(),r=0,n=a;rthis.maxDate.getDate())},hideBodyOverflow:function(e){var t=document.querySelector("body");return e===!0?void(t.style.overflow="hidden"):void(t.style.overflow="")},setEscapeEvent:function(){var e=this;document.addEventListener("keydown",function(t){27!=t.keyCode&&"Escape"!=t.key||e.onClose()})},onInput:function(){var e=this.format?this.format(this.calculatedDate):this.calculatedDate;this.$emit("input",e),this.onClose()},onClose:function(){this.hideBodyOverflow(!1),this.$emit("close")}}}},function(e,t){e.exports={render:function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("div",{staticClass:"date-picker-container flex-center","class":{"hidden-footer":e.footer}},[a("div",{staticClass:"date-picker-background flex-center",on:{click:function(t){t.stopPropagation(),t.preventDefault(),e.onClose(t)}}}),e._v(" "),a("div",{staticClass:"calendar-container"},[a("div",{staticClass:"calendar"},[a("div",{staticClass:"calendar-header flex-center",style:{"background-color":e.color}},[a("div",[a("h3",{"class":{"calendar-faint":"date"===e.selecting},on:{click:function(t){e.setSelecting("year")}}},[e._v("\n "+e._s(e.selectedYear)+"\n ")]),e._v(" "),a("h2",{"class":{"calendar-faint":"year"===e.selecting},on:{click:function(t){e.setSelecting("date")}}},[e._v("\n "+e._s(e.abbrivatedDay)+", "+e._s(e.selectedMonthWord)+" "+e._s(e.selectedDay)+"\n ")])])]),e._v(" "),"date"===e.selecting?a("div",{staticClass:"calendar-body"},[a("div",{staticClass:"calendar-date"},[a("div",[e.showLeftArrow?a("div",{staticClass:"calendar-arrows flex left",on:{click:function(t){e.setByMonth(e.currentMonth-1)}}},[a("svg",{attrs:{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"}},[a("path",{attrs:{fill:"#212121",d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"}})])]):e._e()]),e._v(" "),a("div",{staticClass:"calendar-current-date flex-center"},[a("h4",[e._v(e._s(e.currentMonthWord)+" "+e._s(e.currentYear))])]),e._v(" "),a("div",[e.showRightArrow?a("div",{staticClass:"calendar-arrows flex right",on:{click:function(t){e.setByMonth(e.currentMonth+1)}}},[a("svg",{attrs:{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"}},[a("path",{attrs:{fill:"#212121",d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}})])]):e._e()])]),e._v(" "),a("table",[e._m(0),e._v(" "),a("tbody",e._l(e.calendar,function(t,r){return a("tr",{key:r},e._l(t,function(t,r){return a("td",{key:"day-"+r+"-"+t.day,"class":{"current-day":t.currentDay,disabled:t.disabled,selected:t.selected},style:{color:t.currentDay&&!t.selected?e.color:"","background-color":t.selected?e.color:""},attrs:{tabindex:"0"},on:{keydown:[function(t){return"button"in t||!e._k(t.keyCode,"enter",13,t.key)?void e.onInput(t):null},function(t){return"button"in t||!e._k(t.keyCode,"space",32,t.key)?(t.stopPropagation(),t.preventDefault(),void e.onInput(t)):null},function(t){return"button"in t||!e._k(t.keyCode,"esc",27,t.key)?void e.onClose(t):null}],click:function(a){e.setByDay(t)}}},[e._v(e._s(t.day))])}))}))])]):e._e(),e._v(" "),"year"===e.selecting?a("div",{staticClass:"calendar-year-select"},e._l(e.years,function(t){return a("div",{key:t.year,"class":{selected:t.selected},style:{color:t.selected?e.color:""},attrs:{id:t.year+"-calendar-year"},on:{click:function(a){e.setByYear(t.year)}}},[e._v("\n "+e._s(t.year)+"\n ")])})):e._e(),e._v(" "),e.footer?e._e():a("div",{staticClass:"calendar-footer"},[a("button",{style:{color:e.color},on:{click:function(t){t.stopPropagation(),t.preventDefault(),e.onClose(t)}}},[e._v("Cancel")]),e._v(" "),a("button",{style:{color:e.color},on:{click:function(t){t.stopPropagation(),t.preventDefault(),e.onInput(t)}}},[e._v("Ok")])])])])])},staticRenderFns:[function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("thead",[a("tr",[a("td",[e._v("S")]),e._v(" "),a("td",[e._v("M")]),e._v(" "),a("td",[e._v("T")]),e._v(" "),a("td",[e._v("W")]),e._v(" "),a("td",[e._v("T")]),e._v(" "),a("td",[e._v("F")]),e._v(" "),a("td",[e._v("S")])])])}]}}])}); -------------------------------------------------------------------------------- /dist/vue-date-picker.min.js: -------------------------------------------------------------------------------- 1 | window.DatePicker=function(e){function t(r){if(a[r])return a[r].exports;var n=a[r]={exports:{},id:r,loaded:!1};return e[r].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var a={};return t.m=e,t.c=a,t.p="",t(0)}([function(e,t,a){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}var n=a(1),o=r(n);e.exports={install:function(e,t){e.component("date-picker",o["default"])}}},function(e,t,a){a(2);var r=a(7)(a(8),a(9),"data-v-58e44443",null);e.exports=r.exports},function(e,t,a){var r=a(3);"string"==typeof r&&(r=[[e.id,r,""]]),r.locals&&(e.exports=r.locals);a(5)("326a8e33",r,!0)},function(e,t,a){t=e.exports=a(4)(!1),t.push([e.id,"[data-v-58e44443],[data-v-58e44443]:after,[data-v-58e44443]:before{box-sizing:inherit}button[data-v-58e44443],div[data-v-58e44443],h2[data-v-58e44443],h3[data-v-58e44443],h4[data-v-58e44443],table[data-v-58e44443],tbody[data-v-58e44443],td[data-v-58e44443],thead[data-v-58e44443],tr[data-v-58e44443]{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}button[data-v-58e44443]{border-radius:2px;cursor:pointer;display:inline-block;font-size:16px;padding:0 16px;outline:none;user-select:none}.flex[data-v-58e44443]{display:flex}.flex-center[data-v-58e44443]{display:flex;align-items:center;justify-content:center}.date-picker-background[data-v-58e44443],.date-picker-container[data-v-58e44443]{overflow-y:auto;position:fixed;top:0;left:0;width:100%;height:100%}.date-picker-container[data-v-58e44443]{line-height:1.5;z-index:9998}.date-picker-background[data-v-58e44443]{background-color:rgba(0,0,0,.5);z-index:9999}.calendar-faint[data-v-58e44443]{opacity:.75}.calendar-container[data-v-58e44443]{background-color:#fff;border-radius:2px;box-shadow:0 12px 52px rgba(0,0,0,.25);cursor:auto;position:relative;user-select:text;width:350px;z-index:10001;user-select:none}.calendar[data-v-58e44443]{height:500px;position:relative}.hidden-footer .calendar[data-v-58e44443]{height:470px}.calendar-header[data-v-58e44443]{border-top-left-radius:2px;border-top-right-radius:2px;color:#fff;display:flex;align-items:center;justify-content:space-between;padding:16px 28px}.calendar-header h2[data-v-58e44443],.calendar-header h3[data-v-58e44443]{cursor:default}.calendar-header h2.calendar-faint[data-v-58e44443],.calendar-header h3.calendar-faint[data-v-58e44443]{cursor:pointer}.calendar-header h2[data-v-58e44443]{font-size:28px;line-height:30px;margin-top:3px}.calendar-header h3[data-v-58e44443]{font-size:1.125rem;font-weight:300}.calendar-body[data-v-58e44443]{padding:16px}.calendar-date[data-v-58e44443]{display:flex}.calendar-date .calendar-arrows.left[data-v-58e44443]{display:flex;align-items:center;justify-content:flex-start}.calendar-current-date[data-v-58e44443]{cursor:default;text-align:center}.calendar-date .calendar-arrows.right[data-v-58e44443]{display:flex;align-items:center;justify-content:flex-end}.calendar-date>div[data-v-58e44443]{width:33.333%}.calendar-date h4[data-v-58e44443]{font-size:14px;font-weight:500}.calendar-arrows[data-v-58e44443]{cursor:pointer;padding:0 8px}.calendar-body table[data-v-58e44443]{border-spacing:2px;border-collapse:separate;cursor:default;font-size:12px;margin-top:8px;table-layout:fixed;text-align:center;width:100%}.calendar-body table thead[data-v-58e44443]{color:#757575}.calendar-body table thead td[data-v-58e44443]{cursor:default!important}.calendar-body tr[data-v-58e44443]{height:43px;vertical-align:middle}.calendar-body td[data-v-58e44443]{border-radius:50%;cursor:pointer;vertical-align:middle;transition:background-color .15s;width:43px}.calendar-body td[data-v-58e44443]:focus{outline:none}.calendar-body tbody td[data-v-58e44443]:hover{background-color:rgba(0,0,0,.1)}.calendar-body td[data-v-58e44443]:empty{background-color:transparent!important;cursor:default}.calendar-body td.current-day[data-v-58e44443]{font-weight:700}.calendar-body td.disabled[data-v-58e44443]{color:#c5c5c5;cursor:default;pointer-events:none}.calendar-body td.selected[data-v-58e44443]{border-radius:50%;color:#fff;cursor:pointer}.calendar-year-select[data-v-58e44443]{box-shadow:inset 0 -1px 1px rgba(0,0,0,.075);height:353px;overflow-y:scroll;text-align:center}.hidden-footer .calendar-year-select[data-v-58e44443]{height:378px}.calendar-year-select div[data-v-58e44443]{cursor:pointer;padding:8px 0;transition:background-color .15s}.calendar-year-select div[data-v-58e44443]:hover{background-color:rgba(0,0,0,.1)}.calendar-year-select .selected[data-v-58e44443]{font-size:24px}.calendar-footer[data-v-58e44443]{position:absolute;bottom:16px;right:16px}.calendar-footer button[data-v-58e44443]{background-color:transparent;border:1px solid transparent;box-shadow:none}.calendar-fade-enter-active[data-v-58e44443],.calendar-fade-leave-active[data-v-58e44443]{transition:opacity .15s}.calendar-fade-enter[data-v-58e44443],.calendar-fade-leave-to[data-v-58e44443]{opacity:0}",""])},function(e,t){function a(e,t){var a=e[1]||"",n=e[3];if(!n)return a;if(t&&"function"==typeof btoa){var o=r(n),i=n.sources.map(function(e){return"/*# sourceURL="+n.sourceRoot+e+" */"});return[a].concat(i).concat([o]).join("\n")}return[a].join("\n")}function r(e){var t=btoa(unescape(encodeURIComponent(JSON.stringify(e)))),a="sourceMappingURL=data:application/json;charset=utf-8;base64,"+t;return"/*# "+a+" */"}e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var r=a(t,e);return t[2]?"@media "+t[2]+"{"+r+"}":r}).join("")},t.i=function(e,a){"string"==typeof e&&(e=[[null,e,""]]);for(var r={},n=0;na.parts.length&&(r.parts.length=a.parts.length)}else{for(var i=[],n=0;nr?0:r+t),a=a>r?r:a,a<0&&(a+=r),r=t>a?0:a-t>>>0,t>>>=0;for(var n=-1,o=new Array(r);++n=10?this.selectedDay:"0"+this.selectedDay,t=this.selectedMonth+1>=10?this.selectedMonth+1:"0"+(this.selectedMonth+1);return this.selectedYear+"-"+t+"-"+e},abbrivatedDay:function(){return a[this.selectedDayOfWeek]},currentMonthWord:function(){return r[this.currentMonth]},selectedMonthWord:function(){return r[this.selectedMonth]},minDate:function(){if(this.min){var e=this.min.split("-");return new Date(e[0],e[1],e[2])}},maxDate:function(){if(this.max){var e=this.max.split("-");return new Date(e[0],e[1],e[2])}},showLeftArrow:function(){return!this.min||(this.minDate.getFullYear()!==this.currentYear||this.minDate.getMonth()-1!==this.currentMonth)},showRightArrow:function(){return!this.max||(this.maxDate.getFullYear()!==this.currentYear||this.maxDate.getMonth()-1!==this.currentMonth)},calendar:function(){for(var e=this,t=[],a=new Date(this.currentYear,this.currentMonth,1).getDay(),r=0,n=a;rthis.maxDate.getDate())},hideBodyOverflow:function(e){var t=document.querySelector("body");return e===!0?void(t.style.overflow="hidden"):void(t.style.overflow="")},setEscapeEvent:function(){var e=this;document.addEventListener("keydown",function(t){27!=t.keyCode&&"Escape"!=t.key||e.onClose()})},onInput:function(){var e=this.format?this.format(this.calculatedDate):this.calculatedDate;this.$emit("input",e),this.onClose()},onClose:function(){this.hideBodyOverflow(!1),this.$emit("close")}}}},function(e,t){e.exports={render:function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("div",{staticClass:"date-picker-container flex-center","class":{"hidden-footer":e.footer}},[a("div",{staticClass:"date-picker-background flex-center",on:{click:function(t){t.stopPropagation(),t.preventDefault(),e.onClose(t)}}}),e._v(" "),a("div",{staticClass:"calendar-container"},[a("div",{staticClass:"calendar"},[a("div",{staticClass:"calendar-header flex-center",style:{"background-color":e.color}},[a("div",[a("h3",{"class":{"calendar-faint":"date"===e.selecting},on:{click:function(t){e.setSelecting("year")}}},[e._v("\n "+e._s(e.selectedYear)+"\n ")]),e._v(" "),a("h2",{"class":{"calendar-faint":"year"===e.selecting},on:{click:function(t){e.setSelecting("date")}}},[e._v("\n "+e._s(e.abbrivatedDay)+", "+e._s(e.selectedMonthWord)+" "+e._s(e.selectedDay)+"\n ")])])]),e._v(" "),"date"===e.selecting?a("div",{staticClass:"calendar-body"},[a("div",{staticClass:"calendar-date"},[a("div",[e.showLeftArrow?a("div",{staticClass:"calendar-arrows flex left",on:{click:function(t){e.setByMonth(e.currentMonth-1)}}},[a("svg",{attrs:{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"}},[a("path",{attrs:{fill:"#212121",d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"}})])]):e._e()]),e._v(" "),a("div",{staticClass:"calendar-current-date flex-center"},[a("h4",[e._v(e._s(e.currentMonthWord)+" "+e._s(e.currentYear))])]),e._v(" "),a("div",[e.showRightArrow?a("div",{staticClass:"calendar-arrows flex right",on:{click:function(t){e.setByMonth(e.currentMonth+1)}}},[a("svg",{attrs:{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"}},[a("path",{attrs:{fill:"#212121",d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"}})])]):e._e()])]),e._v(" "),a("table",[e._m(0),e._v(" "),a("tbody",e._l(e.calendar,function(t,r){return a("tr",{key:r},e._l(t,function(t,r){return a("td",{key:"day-"+r+"-"+t.day,"class":{"current-day":t.currentDay,disabled:t.disabled,selected:t.selected},style:{color:t.currentDay&&!t.selected?e.color:"","background-color":t.selected?e.color:""},attrs:{tabindex:"0"},on:{keydown:[function(t){return"button"in t||!e._k(t.keyCode,"enter",13,t.key)?void e.onInput(t):null},function(t){return"button"in t||!e._k(t.keyCode,"space",32,t.key)?(t.stopPropagation(),t.preventDefault(),void e.onInput(t)):null},function(t){return"button"in t||!e._k(t.keyCode,"esc",27,t.key)?void e.onClose(t):null}],click:function(a){e.setByDay(t)}}},[e._v(e._s(t.day))])}))}))])]):e._e(),e._v(" "),"year"===e.selecting?a("div",{staticClass:"calendar-year-select"},e._l(e.years,function(t){return a("div",{key:t.year,"class":{selected:t.selected},style:{color:t.selected?e.color:""},attrs:{id:t.year+"-calendar-year"},on:{click:function(a){e.setByYear(t.year)}}},[e._v("\n "+e._s(t.year)+"\n ")])})):e._e(),e._v(" "),e.footer?e._e():a("div",{staticClass:"calendar-footer"},[a("button",{style:{color:e.color},on:{click:function(t){t.stopPropagation(),t.preventDefault(),e.onClose(t)}}},[e._v("Cancel")]),e._v(" "),a("button",{style:{color:e.color},on:{click:function(t){t.stopPropagation(),t.preventDefault(),e.onInput(t)}}},[e._v("Ok")])])])])])},staticRenderFns:[function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("thead",[a("tr",[a("td",[e._v("S")]),e._v(" "),a("td",[e._v("M")]),e._v(" "),a("td",[e._v("T")]),e._v(" "),a("td",[e._v("W")]),e._v(" "),a("td",[e._v("T")]),e._v(" "),a("td",[e._v("F")]),e._v(" "),a("td",[e._v("S")])])])}]}}]); -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Vue Date Picker 7 | 8 | 9 | 10 | 45 | 46 | 47 | 48 | 49 | 50 | Vue Date Picker 51 | 52 | 53 | Select a date: 54 | 55 | 56 | 57 | 61 | 62 | 63 | 64 | 65 | Select a date starting from today: 66 | 67 | 68 | 69 | 74 | 75 | 76 | 77 | 78 | Select a date less than a week from now: 79 | 80 | 81 | 82 | 87 | 88 | 89 | 90 | 91 | Select a date within a week from now: 92 | 93 | 94 | 95 | 101 | 102 | 103 | 104 | 105 | Start at a specified date: 106 | 107 | 108 | 109 | 113 | 114 | 115 | 116 | 117 | Format the chosen date: 118 | 119 | 120 | 121 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-md-date-picker", 3 | "version": "1.0.16", 4 | "description": "A vue date picker component inspired by material design", 5 | "main": "dist/vue-date-picker.js", 6 | "scripts": { 7 | "build": "rimraf ./dist && webpack --config ./webpack.config.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/ridewn/vue-date-picker.git" 12 | }, 13 | "keywords": [ 14 | "vue", 15 | "javascript", 16 | "date", 17 | "picker", 18 | "datepicker", 19 | "calendar", 20 | "time", 21 | "component", 22 | "material", 23 | "design" 24 | ], 25 | "author": "Trevor Stacy", 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/ridewn/vue-date-picker/issues" 29 | }, 30 | "homepage": "https://github.com/ridewn/vue-date-picker#readme", 31 | "devDependencies": { 32 | "babel-core": "^6.10.4", 33 | "babel-loader": "^6.2.4", 34 | "babel-plugin-transform-runtime": "^6.9.0", 35 | "babel-preset-es2015": "^6.9.0", 36 | "babel-preset-stage-2": "^6.11.0", 37 | "babel-runtime": "^6.9.2", 38 | "css-loader": "^0.28.5", 39 | "rimraf": "^2.6.1", 40 | "vue": "^2.2.1", 41 | "vue-html-loader": "^1.2.3", 42 | "vue-loader": "^11.1.4", 43 | "vue-style-loader": "^2.0.3", 44 | "vue-template-compiler": "^2.2.1", 45 | "webpack": "1.13.1", 46 | "webpack-merge": "^4.1.0" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/DatePicker.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | {{ selectedYear }} 12 | 13 | 14 | 16 | {{ abbrivatedDay }}, {{ selectedMonthWord }} {{ selectedDay }} 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | {{ currentMonthWord }} {{ currentYear }} 39 | 40 | 41 | 42 | 44 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | S 58 | M 59 | T 60 | W 61 | T 62 | F 63 | S 64 | 65 | 66 | 67 | 68 | 69 | {{ day.day }} 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 98 | {{ year.year }} 99 | 100 | 101 | 102 | 107 | 108 | 109 | 110 | 111 | 112 | 660 | 661 | 913 | -------------------------------------------------------------------------------- /src/plugin.js: -------------------------------------------------------------------------------- 1 | import DatePicker from './DatePicker.vue' 2 | 3 | module.exports = { 4 | install: function (Vue, options) { 5 | Vue.component('date-picker', DatePicker) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | const merge = require('webpack-merge'); 3 | const path = require('path'); 4 | 5 | var commonConfig = { 6 | output: { 7 | path: path.resolve(__dirname + '/dist/'), 8 | }, 9 | 10 | module: { 11 | loaders: [ 12 | { 13 | test: /\.js$/, 14 | loader: 'babel', 15 | include: __dirname, 16 | exclude: /node_modules/ 17 | }, 18 | 19 | { 20 | test: /\.vue$/, 21 | loader: 'vue' 22 | }, 23 | 24 | { 25 | test: /\.css$/, 26 | loader: 'style!less!css' 27 | } 28 | ] 29 | }, 30 | 31 | plugins: [ 32 | new webpack.optimize.UglifyJsPlugin( { 33 | minimize : true, 34 | sourceMap : false, 35 | mangle: true, 36 | compress: { 37 | warnings: false 38 | } 39 | }) 40 | ] 41 | }; 42 | 43 | module.exports = [ 44 | merge(commonConfig, { 45 | entry: path.resolve(__dirname + '/src/plugin.js'), 46 | output: { 47 | filename: 'vue-date-picker.min.js', 48 | libraryTarget: 'window', 49 | library: 'DatePicker', 50 | } 51 | }), 52 | 53 | merge(commonConfig, { 54 | entry: path.resolve(__dirname + '/src/DatePicker.vue'), 55 | output: { 56 | filename: 'vue-date-picker.js', 57 | libraryTarget: 'umd', 58 | library: 'vue-date-picker', 59 | umdNamedDefine: true 60 | } 61 | }) 62 | ]; 63 | --------------------------------------------------------------------------------