Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@wslyhbb/vuejs-datepicker
Advanced tools
Readme
A datepicker Vue component.
this is a fork of https://github.com/charliekassel/vuejs-datepicker, which includes following breaking changes:
To view a demo online:
https://codesandbox.io/s/vue-datepicker-demo-hjktwc
https://stackblitz.com/edit/vitejs-vite-hgm3ct
To view demo examples locally clone the repo and run npm install && npm run serve
Vue version | npm Package |
---|---|
Vue 2 | @wslyhbb/vuejs-datepicker@3 |
Vue 3 | @wslyhbb/vuejs-datepicker@4 |
# Vue 2
npm install @wslyhbb/vuejs-datepicker@3
yarn add @wslyhbb/vuejs-datepicker@3
# Vue 3
npm install @wslyhbb/vuejs-datepicker
yarn add @wslyhbb/vuejs-datepicker
import Datepicker from '@wslyhbb/vuejs-datepicker';
export default {
// ...
components: {
Datepicker
}
// ...
}
To upgrade to version 2+ check:
I have changed the translations from internal to use the date-fns,
therefore you need to change imports
for the "locale" imports e.g.:
import {en, es} from 'vuejs-datepicker/dist/locale'
change to:
import { enUS } from 'date-fns/locale'
Please see Translations section how to set up your language.
change custom date formatting to date-fns date formatting: https://date-fns.org/docs/format Examples:
Old | New (date-fns) | Displays |
---|---|---|
dsu MMM yyyy | do MMM yyyy | 12th Feb 2016 |
D dsu MMM yyyy | eee do MMM yyyy | Sat 12th Feb 2016 |
As this bundle is also useable for SSR rendering, you have to take care of css yourself. (see also https://github.com/vuejs/rollup-plugin-vue/issues/266) I strongly recommend to create a custom component, that wraps the vuejs-datepicker. Then it is easy to add custom css and have a consistent style for the datepicker.
Ensure you have postcss-import up and running. (https://github.com/postcss/postcss-import) E.g.via:
<style lang="scss">
/* purgecss start ignore */
@import "@wslyhbb/vuejs-datepicker/dist/vuejs-datepicker.css"
/* purgecss end ignore */
</style>
If you do not use purgeCSS, you can safely remove the comment lines
add inside nuxt.config:
css: [
{
src: '@wslyhbb/vuejs-datepicker/dist/vuejs-datepicker.css',
lang: 'css'
},
<style lang="scss">
.vdp-datepicker {
overflow: visible;
display: inline-block;
....
}
...
</style>
<datepicker></datepicker>
value prop if passed should be a Date object
<script>
var state = {
date: new Date(2016, 9, 16)
}
</script>
<datepicker :value="state.date"></datepicker>
support name attribute for normal html form submission
<datepicker :value="state.date" name="uniquename"></datepicker>
Using v-model
<datepicker v-model="state.date" name="uniquename"></datepicker>
Emits events
<datepicker @selected="doSomethingInParentComponentFunction" @opened="datepickerOpenedFunction" @closed="datepickerClosedFunction">
Inline always open version
<datepicker :inline="true"></datepicker>
Prop | Type | Default | Description |
---|---|---|---|
autofocus | String | Sets html autofocus attribute on input | |
value | Date|String | Date value of the datepicker | |
name | String | Input name property | |
id | String | Input id | |
format | String|Function | dd MMM yyyy | Date formatting string or function |
full-month-name | Boolean | false | To show the full month name |
language | Object | enUS | Translation for days and months |
maxlength | String | Sets html maxlength attribute on input | |
disabled | Boolean | false | If true, disable Datepicker on screen |
disabled-dates | Object | See below for configuration | |
placeholder | String | Input placeholder text | |
inline | Boolean | To show the datepicker always open | |
calendar-class | String|Object | CSS class applied to the calendar el | |
input-class | String|Object | CSS class applied to the input el | |
wrapper-class | String|Object | CSS class applied to the outer div | |
monday-first | Boolean | false | (Deprecated for first-day-of-week) To start the week |
first-day-of-week | String | sun | Sets the first day of the week. |
two-letter-abbr | false | Show day abbreviations in two letters | |
clear-button | Boolean | false | Show an icon for clearing the date |
clear-button-icon | String | (Deprecated for slot) Use icon for button (ex: fa fa-times) | |
calendar-button | Boolean | false | Show an icon that that can be clicked |
calendar-button-icon | String | (Deprecated for slot) Use icon for button (ex: fa fa-calendar) | |
calendar-button-icon-content | String | (Deprecated for slot) Use for material-icons (ex: event) | |
day-cell-content | Function | Use to render custom content in day cell | |
bootstrap-styling | Boolean | false | Output bootstrap v4 styling classes. |
initial-view | String | minimumView | If set, open on that view |
required | Boolean | false | Sets html required attribute on input |
show-edge-dates | Boolean | false | If false , dates from previous/next months won't show |
tabindex | String|Number | Tabindex for the input | |
typeable | Boolean | false | If true, allow the user to type the date |
use-utc | Boolean | false | use UTC for time calculations |
open-date | Date|String | If set, open on that date | |
pattern | String | Sets html pattern attribute on input | |
minimum-view | String | 'day' | If set, lower-level views won't show |
maximum-view | String | 'year' | If set, higher-level views won't show |
parse-typed-date | Function: Date | Use to parse custom date for typed input | |
highlighted | Object | Dates to be highlighted |
These events are emitted on actions in the datepicker
Event | Output | Description |
---|---|---|
opened | The picker is opened | |
closed | The picker is closed | |
selected | Date|null | A date has been selected |
selectedDisabled | Object | A disabled date has been selected |
input | Date|null | Input value has been modified |
cleared | Selected date has been cleared | |
changedMonth | Object | Month page has been changed |
changedYear | Object | Year page has been changed |
changedDecade | Object | Decade page has been changed |
Uses date-fns for date formatting. See https://date-fns.org/docs/format Examples:
Example | Displays |
---|---|
d MMM yyyy | 12 Feb 2016 |
d MMMM yyyy | 12 February 2016 |
yyyy-MM-dd | 2016-02-12 |
do MMM yyyy | 12th Feb 2016 |
eee do MMM yyyy | Sat 12th Feb 2016 |
Token | Desc | Example | Version <2.0 |
---|---|---|---|
d | day | 1 | d |
dd | 0 prefixed day | 01 | dd |
ccc | abbr day | Mon | D |
do | date of Month | 1st 2nd ... 30th 31st | (su) |
M | month number (1 based) | 1 (for Jan) | M |
MM | 0 prefixed month | 01 | MM |
MMM | abbreviated month name | Jan | MMM |
MMMM | month name | January | MMMM |
yy | two digit year | 16 | yy |
yyyy | four digit year | 2016 | yyyy |
Delegates date formatting to provided function. Function will be called with date and it has to return formated date as a string. This allow us to use date-fns, globalize or any other library to format date.
<script>
methods: {
customFormatter(date) {
return format(date, 'MMMM Do yyyy, h:mm:ss a');
}
}
</script>
<datepicker :format="customFormatter"></datepicker>
Dates can be disabled in a number of ways.
<script>
var state = {
disabledDates: {
to: new Date(2016, 0, 5), // Disable all dates up to specific date
from: new Date(2016, 0, 26), // Disable all dates after specific date
days: [6, 0], // Disable Saturday's and Sunday's
daysOfMonth: [29, 30, 31], // Disable 29th, 30th and 31st of each month
dates: [ // Disable an array of dates
new Date(2016, 9, 16),
new Date(2016, 9, 17),
new Date(2016, 9, 18)
],
ranges: [{ // Disable dates in given ranges (exclusive).
from: new Date(2016, 11, 25),
to: new Date(2016, 11, 30)
}, {
from: new Date(2017, 1, 12),
to: new Date(2017, 2, 25)
}],
// a custom function that returns true if the date is disabled
// this can be used for wiring your own logic to disable a date if none
// of the above conditions serve your purpose
// this function should accept a date and return true if it is disabled
customPredictor: function(date) {
// disables the date if it is a multiple of 5
if(date.getDate() % 5 == 0){
return true
}
}
}
}
</script>
<datepicker :disabledDates="state.disabledDates"></datepicker>
Dates can be highlighted (e.g. for marking an appointment) in a number of ways. Important:
By default disabled dates are ignored, to highlight disabled dates set the includeDisabled
property to true
. Note: Both to
and from
properties are required to define a range of
dates to highlight.
<script>
var state = {
highlighted: {
to: new Date(2016, 0, 5), // Highlight all dates up to specific date
from: new Date(2016, 0, 26), // Highlight all dates after specific date
days: [6, 0], // Highlight Saturday's and Sunday's
daysOfMonth: [15, 20, 31], // Highlight 15th, 20th and 31st of each month
dates: [ // Highlight an array of dates
new Date(2016, 9, 16),
new Date(2016, 9, 17),
new Date(2016, 9, 18)
],
// a custom function that returns true of the date is highlighted
// this can be used for wiring you own logic to highlight a date if none
// of the above conditions serve your purpose
// this function should accept a date and return true if is highlighted
customPredictor: function(date) {
// highlights the date if it is a multiple of 4
if(date.getDate() % 4 == 0){
return true
}
},
includeDisabled: true // Highlight disabled dates
}
}
</script>
<datepicker :highlighted="state.highlighted"></datepicker>
Slots will help you customize content. .
Sometimes you need to show custom content before the calendar header. For such cases you can use the named slot beforeCalendarHeader
.
An example would be to use bootstrap's input-group-prepend
and input-group-append
to show some custom text:
<datepicker :bootstrap-styling="true">
<template v-slot:beforeCalendarHeader">
<div class="calender-header">
Choose a Date
</div>
</template>
</datepicker>
To implement calendar button.
To implement some custom styling on DateInput, you might need to add elemnt before the DateInput. Similar to afterDateInput, just it is before in the html DOM.
To implement clear button.
To implement some custom styling (for instance to add an animated placeholder) on DateInput, you might need to add elements as DateInput siblings. Slot named
afterDateInput
allows you to do that:
<datepicker>
<template v-slot:afterDateInput">
<span class="animated-placeholder">
Choose a Date
</span>
</template>
</datepicker>
See also https://date-fns.org/docs/I18n Especially if you use webpack!
import { de } from 'date-fns/locale';
<datepicker :language="de"></datepicker>
Available languages are all that date-fs supports. See demo file or https://github.com/date-fns/date-fns/tree/main/src/locale for a list of available languages and the correct language code for it.
FAQs
A simple Vue.js datepicker component. Supports disabling of dates, inline mode, translations. Fork of initial vuejs-datepicker which is abandoned.
The npm package @wslyhbb/vuejs-datepicker receives a total of 48 weekly downloads. As such, @wslyhbb/vuejs-datepicker popularity was classified as not popular.
We found that @wslyhbb/vuejs-datepicker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.