Datepickers
Datepickers in Shards Vue are wrappers over the vuejs-datepicker
component. You can learn more about the component in the official component's GitHub repository, or follow the short guide below for an overview of how to use datepickers in Shards Vue.
Basic Example
Creating a datepicker can be easily achieved using the <d-datepicker>
component.
<template>
<div>
<div>Opened: <span :class="[opened ? 'text-success' : 'text-danger']">{{ opened }}</span></div>
<div>📅 Date: <span>{{ date }}</span></div>
<d-datepicker
v-model="date"
@opened="handleOpened"
@closed="handleClosed"
typeable />
</div>
</template>
<script>
export default {
data() {
return {
opened: false,
date: new Date(2018, 8, 23)
}
},
methods: {
handleOpened() {
this.opened = true
},
handleClosed() {
this.opened = false
}
}
}
</script>
<!-- datepicker-1.vue -->
Disabled Dates
There are multiple ways that you can follow in order to display disabled dates.
<template>
<div>
<div>📅 Date: <span>{{ date }}</span></div>
<d-datepicker
v-model="date"
:disabled-dates="disabledDates"
typeable />
</div>
</template>
<script>
export default {
data() {
return {
date: new Date(2018, 8, 23),
disabledDates: {
// Disable all the dates up to specific date.
to: new Date(2016, 0, 5),
// Disable all dates after specific date.
from: new Date(2016, 0, 26),
// Disable only Saturdays and Sundays.
days: [6, 0],
// Disable 29th, 30th and 31st of each month.
daysOfMonth: [29, 30, 31],
// Disable an array of dates.
dates: [
new Date(2016, 9, 16),
new Date(2016, 9, 17),
new Date(2016, 9, 18)
],
// Disable dates in given ranges (exclusive).
ranges: [{
from: new Date(2016, 11, 25),
to: new Date(2016, 11, 30)
}, {
from: new Date(2017, 1, 12),
to: new Date(2017, 2, 25)
}],
/**
* You can also use a custom predictor function that returns true if
* the date is disabled or false if it's not. You can use this callback
* validator to provide your own date checking logic in case the options
* above are not sufficient for your own use case.
*/
customPredictor: function(date) {
// Disables the date if it is a multiple of 5.
if(date.getDate() % 5 == 0){
return true
}
}
}
}
}
}
</script>
<!-- datepicker-2.vue -->
Highlighted Dates
<template>
<div>
<div>📅 Date: <span>{{ date }}</span></div>
<d-datepicker
v-model="date"
:highlighted="highlightedDates"
typeable />
</div>
</template>
<script>
export default {
data() {
return {
date: new Date(2018, 8, 23),
highlightedDates: {
// Highlight all dates up to specific date.
to: new Date(2016, 0, 5),
// Highlight all dates after specific date.
from: new Date(2016, 0, 26),
// Highlight Saturdays and Sundays.
days: [6, 0],
// Highlight 15th, 20th and 31st of each month.
daysOfMonth: [15, 20, 31],
// Highlight an array of dates.
dates: [
new Date(2016, 9, 16),
new Date(2016, 9, 17),
new Date(2016, 9, 18)
],
/**
* You can also use a custom predictor function that returns true if
* the date is highlighted or false if it's not. You can use this callback
* validator to provide your own date checking logic in case the options
* above are not sufficient for your own use case.
*/
customPredictor: function(date) {
// Highlights the date if it is a multiple of 4.
if(date.getDate() % 4 == 0){
return true
}
},
// Highlight disabled dates
includeDisabled: true
}
}
}
}
</script>
<!-- datepicker-3.vue -->
Props
Prop | Description | Type | Default | Required |
---|---|---|---|---|
:value | The datepicker's value. | Undefined | False | |
:name | The name. | String | null | False |
:id | The component's ID. | String | null | False |
:format | The date format. | String | Func | "dd MMM yyyy" | False |
:language | The language. | Object | False | |
:open-date | If set, the datepicker will open on this date. | Undefined | False | |
:day-cell-content | Function used to render custom content inside the day cell. | Func | False | |
:full-month-name | Whether to show the full month name, or not. | Boolean | False | |
:disabled-dates | Configure disabled dates. | Object | False | |
:highlighted | Highlight dates. | Object | False | |
:placeholder | The placeholder. | String | False | |
:inline | Show the datepicker always open. | Boolean | False | |
:calendar-class | The CSS class applied to the calendar element. | String | Object | Array | False | |
:input-class | The CSS Class applied to the input element. | String | Object | Array | "form-control" | False |
:wrapper-class | The CSS class applied to the wrapper element. | String | Object | Array | False | |
:monday-first | Whether Monday is the first day, or not. | Boolean | False | |
:clear-button | Display a button for clearing the dates. | Boolean | False | |
:clear-button-icon | Use an icon for the clear button. | String | False | |
:calendar-button | Dislay a calendar button. | Boolean | False | |
:calendar-button-icon | The calendar button's icon. | String | False | |
:calendar-button-icon-content | The calendar button's icon content. | String | False | |
:initial-view | If set, the datepicker is opened on that specific view. | String | False | |
:disabled | The disabled state. | Boolean | False | |
:required | The required state. | Boolean | False | |
:typeable | Whether to allow users to type the date, or not. | Boolean | False | |
:use-utc | Use UTC for time calculations. | Boolean | False | |
:minimum-view | If set, the lower-level views will not be shown. | String | "day" | False |
:maximum-view | If set, the higher-level views will not be shown. | String | "year" | False |