Skip to content

Commit

Permalink
🚀 {feature} Add disabled dates array (#24)
Browse files Browse the repository at this point in the history
🚀 v1.2.0 : {feature} Add disabled dates array
  • Loading branch information
LouisMazel authored Oct 9, 2018
1 parent 8ed8e17 commit 9043a07
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 67 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Vue.component('vue-ctk-date-time-picker', VueCtkDateTimePicker);
| color*** | String (hex) | no | dodgerblue |
| minute-interval | Int | no | 1 |
| formatted | string | no | 'llll' (momentjs format) |
| format | string | no | 'YYYY-MM-DDTHH:mm' |
| format | string | no | - |
| time-format | string | no | 'H:mm a' |
| locale | string | no | en |
| disable-time | Boolean | no | false |
Expand All @@ -74,6 +74,7 @@ Vue.component('vue-ctk-date-time-picker', VueCtkDateTimePicker);
| no-weekends-days | Boolean | no | false |
| auto-close | Boolean | no | false |
| without-input | Boolean | no | false |
| disabled-dates***** | Boolean | no | [] |

*hint : Is a text that replaces the label/placeholder

Expand All @@ -83,6 +84,8 @@ Vue.component('vue-ctk-date-time-picker', VueCtkDateTimePicker);

****min-date & max-date : Must be 'YYYY-MM-DD' format

*****Disabled-Dates is an Array of dates in 'YYYY-MM-DD' format (ex: `['2018-04-03', '2018-04-07', '2018-04-09'])


## Contribution

Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>vue-ctk-date-time-picker</title><link rel=stylesheet href=./assets/main.css><link href=./static/css/app.b5dd9eebb4a82c2e37351b1c0e6486a9.css rel=stylesheet></head><body><div id=app></div><script src=/build/build.js></script><script type=text/javascript src=./static/js/manifest.3ad1d5771e9b13dbdad2.js></script><script type=text/javascript src=./static/js/vendor.88b4d2f1b6949b36de49.js></script><script type=text/javascript src=./static/js/app.e56a2602d6d3b9ee948e.js></script></body></html>
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>vue-ctk-date-time-picker</title><link rel=stylesheet href=./assets/main.css><link href=./static/css/app.160515f52ccc1fa47230d0f0081c2217.css rel=stylesheet></head><body><div id=app></div><script src=/build/build.js></script><script type=text/javascript src=./static/js/manifest.3ad1d5771e9b13dbdad2.js></script><script type=text/javascript src=./static/js/vendor.88b4d2f1b6949b36de49.js></script><script type=text/javascript src=./static/js/app.91181ebab409053b436e.js></script></body></html>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions demo/static/js/app.91181ebab409053b436e.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions demo/static/js/app.91181ebab409053b436e.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions demo/static/js/app.e56a2602d6d3b9ee948e.js

This file was deleted.

1 change: 0 additions & 1 deletion demo/static/js/app.e56a2602d6d3b9ee948e.js.map

This file was deleted.

2 changes: 1 addition & 1 deletion demo/static/js/manifest.3ad1d5771e9b13dbdad2.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/umd/vue-ctk-date-time-picker.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/umd/vue-ctk-date-time-picker.min.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/umd/vue-ctk-date-time-picker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/umd/vue-ctk-date-time-picker.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-ctk-date-time-picker.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-ctk-date-time-picker.min.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-ctk-date-time-picker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-ctk-date-time-picker.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-ctk-date-time-picker",
"version": "1.1.40",
"version": "1.2.0",
"description": "A vue component for select date & time (by Chronotruck)",
"author": "Louis Mazel <[email protected]>",
"main": "dist/vue-ctk-date-time-picker.min.js",
Expand Down
7 changes: 5 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div id="app">
<div
id="vueCtkDateTimePicker"
class="ctk-date-time-picker"
style="width: 90%; margin: 0 auto;">
<header>
<img
Expand Down Expand Up @@ -56,9 +57,9 @@
tabindex="-1"
style="height: 110px;">
<ctk-date-time-picker
v-model="value2"
format="YYYY-MM-DD"
formatted="ddd D MMM YYYY"
v-model="value2"
label="Choose date"
disable-time
/>
Expand Down Expand Up @@ -131,10 +132,11 @@
</div>
<div class="components-container flex">
<div class="component-container flex-1">
<h3>Inline DateTimePicker</h3>
<h3>Inline DateTimePicker && disabled dates</h3>
<p>v-model = {{ value || 'null' }}</p>
<ctk-date-time-picker
v-model="value"
:disabled-dates="['2018-04-03', '2018-04-07', '2018-04-09', '2018-04-11', '2018-04-13', '2018-04-15', '2018-04-17', '2018-04-19']"
label="Choose date time"
no-weekends-days
without-input
Expand All @@ -146,6 +148,7 @@
style="height: 100px;">
<ctk-date-time-picker
v-model="value"
:disabled-dates="['2018-04-03', '2018-04-07', '2018-04-09', '2018-04-11', '2018-04-13', '2018-04-15', '2018-04-17', '2018-04-19']"
label="Choose date time"
no-weekends-days
without-input
Expand Down
5 changes: 3 additions & 2 deletions src/vue-ctk-date-time-picker/_subs/CtkDatePickerAgenda.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
:color="color"
:min-date="minDate"
:max-date="maxDate"
:disabled-dates="disabledDates"
:value="value"
@change-date="selectDate"
@change-month="changeMonth"
Expand Down Expand Up @@ -155,7 +156,8 @@
noWeekendsDays: { type: Boolean, default: Boolean },
autoClose: { type: Boolean, default: Boolean },
enableButtonValidate: { type: Boolean, default: Boolean },
value: { type: String, default: String }
value: { type: String, default: String },
disabledDates: { type: Array, default: Array }
},
data () {
return {
Expand Down Expand Up @@ -262,7 +264,6 @@
</script>

<style lang="scss" scoped>
@import url('https://fonts.googleapis.com/css?family=Roboto:400,500,700');
@import "../assets/animation.scss";
.datetimepicker {
position: absolute;
Expand Down
28 changes: 19 additions & 9 deletions src/vue-ctk-date-time-picker/_subs/_subs/CtkDatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<button
v-for="day in monthDays"
:key="day.format('D')"
:class="{selected: isSelected(day) && value, disabled: (isDisabled(day) || isWeekEndDay(day)), enable: !(isDisabled(day) || isWeekEndDay(day))}"
:class="{selected: isSelected(day) && value && !isDisabled(day), disabled: (isDisabled(day) || isWeekEndDay(day)), enable: !(isDisabled(day) || isWeekEndDay(day))}"
type="button"
tabindex="-1"
class="datepicker-day flex align-center justify-content-center"
Expand Down Expand Up @@ -119,6 +119,10 @@
value: {
type: String,
default: String
},
disabledDates: {
type: Array,
default: Array
}
},
data () {
Expand Down Expand Up @@ -151,14 +155,20 @@
return this.month.getFormatted()
},
isDisabled (day) {
if (this.minDate && this.maxDate) {
return !moment(day).isBetween(this.minDate, this.maxDate)
} else if (this.minDate) {
return moment(day).isBefore(this.minDate)
} else if (this.maxDate) {
return moment(day).isAfter(this.maxDate)
}
return false
return (
this.isDateDisabled(day) ||
this.isBeforeMinDate(day) ||
this.isAfterEndDate(day)
)
},
isDateDisabled (day) {
return this.disabledDates.indexOf(day.format('YYYY-MM-DD')) > -1
},
isBeforeMinDate (day) {
return moment(day).isBefore(this.minDate)
},
isAfterEndDate (day) {
return moment(day).isAfter(this.maxDate)
},
isSelected (day) {
return moment(moment(this.dateTime).format('YYYY-MM-DD')).isSame(day.format('YYYY-MM-DD'))
Expand Down
72 changes: 37 additions & 35 deletions src/vue-ctk-date-time-picker/vue-ctk-date-time-picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,38 @@
class="ctk-date-time-picker"
>
<div
v-if="!withoutInput"
ref="parent"
:class="{'is-focused': isFocus || isVisible, 'has-value': dateFormatted, 'has-error': errorHint, 'is-disabled': disabled}"
class="field"
@click="showDatePicker"
>
<div v-if="!withoutInput">
<input
ref="CtkDateTimePicker"
:id="id"
:value="dateFormatted"
:placeholder="label"
:disabled="disabled"
:style="getBorderStyle"
type="text"
class="field-input"
readonly
@focus="onFocus"
>

<input
ref="CtkDateTimePicker"
:id="id"
:value="dateFormatted"
:placeholder="label"
:disabled="disabled"
:style="isFocus && !errorHint || isVisible ? borderStyle : ''"
type="text"
class="field-input"
readonly
@focus="onFocus"
>

<label
ref="label"
:for="id"
:class="hint ? (errorHint ? 'text-danger' : 'text-primary') : ''"
:style="isFocus || isVisible ? colorStyle : ''"
class="field-label"
>
{{ hint || label }}
</label>

</div>
<label
ref="label"
:for="id"
:class="hint ? (errorHint ? 'text-danger' : 'text-primary') : null"
:style="getColorStyle"
class="field-label"
>
{{ hint || label }}
</label>
</div>

<div
v-if="overlay && (isVisible && !withoutInput)"
v-if="overlay && isVisible && !withoutInput"
class="time-picker-overlay"
@click.stop="unFocus"
/>
Expand All @@ -63,6 +60,7 @@
:no-weekends-days="noWeekendsDays"
:enable-button-validate="enableButtonValidate"
:auto-close="autoClose"
:disabled-dates="disabledDates"
@change-date="changeDate"
@validate="validate"
/>
Expand Down Expand Up @@ -105,7 +103,8 @@
autoClose: {type: Boolean, default: false},
disabled: {type: Boolean, default: false},
overlay: {type: Boolean, default: true},
enableButtonValidate: {type: Boolean, default: false}
enableButtonValidate: {type: Boolean, default: false},
disabledDates: { type: Array, default: Array }
},
data: function () {
return {
Expand All @@ -117,15 +116,17 @@
}
},
computed: {
colorStyle: function () {
return {
color: this.color
}
getColorStyle: function () {
const cond = this.isFocus || this.isVisible
return cond
? { color: this.color }
: null
},
borderStyle: function () {
return {
borderColor: this.color
}
getBorderStyle: function () {
const cond = (this.isFocus && !this.errorHint) || this.isVisible
return cond
? { borderColor: this.color }
: null
},
dateTime () {
const date = this.disableDate
Expand Down Expand Up @@ -190,6 +191,7 @@
</script>

<style lang="scss">
@import url('https://fonts.googleapis.com/css?family=Roboto:400,500,700');
@import "./assets/main.scss";
.ctk-date-time-picker {
width: 100%;
Expand Down

0 comments on commit 9043a07

Please sign in to comment.