Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A simple Vue.js datepicker component. Supports disabling of dates, inline mode, translations

License

NotificationsYou must be signed in to change notification settings

charliekassel/vuejs-datepicker

Repository files navigation

Travis BuildVersionCoveralls githubDownloads

A datepicker Vue component. Compatible with Vue 2.x

NB. Vue 1.x was supported up to version v0.9.9. If you want to use this component with Vue 1.x you can install withnpm install vuejs-datepicker@0.9.9

Demo

To view a demo online:https://codesandbox.io/s/mpklq49wp

To view demo examples locally clone the repo and runnpm install && npm run serve

Install

npm install vuejs-datepicker --save
importDatepickerfrom'vuejs-datepicker';exportdefault{// ...components:{    Datepicker}// ...}

Or use directly from a CDN

<divid="app"><vuejs-datepicker></vuejs-datepicker></div><scriptsrc="https://unpkg.com/vue"></script><scriptsrc="https://unpkg.com/vuejs-datepicker"></script><script>constapp=newVue({el:'#app',components:{  vuejsDatepicker}})</script><!-- French language example --><divid="app"><vuejs-datepicker:language="fr"></vuejs-datepicker></div><scriptsrc="https://unpkg.com/vue"></script><scriptsrc="https://unpkg.com/vuejs-datepicker"></script><scriptsrc="https://unpkg.com/vuejs-datepicker/dist/locale/translations/fr.js"></script><script>constapp=newVue({el:'#app',data(){return{fr:vdp_translation_fr.js}},components:{  vuejsDatepicker}})</script>

Usage

<datepicker></datepicker>

value prop if passed should be a Date object

<script>varstate={date:newDate(2016,9,16)}</script><datepicker:value="state.date"></datepicker>

support name attribute for normal html form submission

<datepicker:value="state.date"name="uniquename"></datepicker>

Usingv-model

<datepickerv-model="state.date"name="uniquename"></datepicker>

Emits events

<datepicker@selected="doSomethingInParentComponentFunction"@opened="datepickerOpenedFunction"@closed="datepickerClosedFunction">

Inline always open version

<datepicker:inline="true"></datepicker>

Available props

PropTypeDefaultDescription
valueDate|StringDate value of the datepicker
nameStringInput name property
idStringInput id
formatString|Functiondd MMM yyyyDate formatting string or function
full-month-nameBooleanfalseTo show the full month name
languageObjectenTranslation for days and months
disabled-datesObjectSee below for configuration
placeholderStringInput placeholder text
inlineBooleanTo show the datepicker always open
calendar-classString|ObjectCSS class applied to the calendar el
input-classString|ObjectCSS class applied to the input el
wrapper-classString|ObjectCSS class applied to the outer div
monday-firstBooleanfalseTo start the week on Monday
clear-buttonBooleanfalseShow an icon for clearing the date
clear-button-iconStringUse icon for button (ex: fa fa-times)
calendar-buttonBooleanfalseShow an icon that that can be clicked
calendar-button-iconStringUse icon for button (ex: fa fa-calendar)
calendar-button-icon-contentStringUse for material-icons (ex: event)
day-cell-contentFunctionUse to render custom content in day cell
bootstrap-stylingBooleanfalseOutput bootstrap v4 styling classes.
initial-viewStringminimumViewIf set, open on that view
disabledBooleanfalseIf true, disable Datepicker on screen
requiredBooleanfalseSets html required attribute on input
typeableBooleanfalseIf true, allow the user to type the date
use-utcBooleanfalseuse UTC for time calculations
open-dateDate|StringIf set, open on that date
minimum-viewString'day'If set, lower-level views won't show
maximum-viewString'year'If set, higher-level views won't show

Events

These events are emitted on actions in the datepicker

EventOutputDescription
openedThe picker is opened
closedThe picker is closed
selectedDate|nullA date has been selected
selectedDisabledObjectA disabled date has been selected
inputDate|nullInput value has been modified
clearedSelected date has been cleared
changedMonthObjectMonth page has been changed
changedYearObjectYear page has been changed
changedDecadeObjectDecade page has been changed

Date formatting

String formatter

NB. This is not very robust at all - use at your own risk! Needs a better implementation.

TokenDescExample
dday1
dd0 prefixed day01
Dabbr dayMon
sudate suffixst, nd, rd
Mmonth number (1 based)1 (for Jan)
MM0 prefixed month01
MMMabbreviated month nameJan
MMMMmonth nameJanuary
yytwo digit year16
yyyyfour digit year2016

Function formatter

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 moment, date-fns, globalize or any other library to format date.

<script>  methods:{customFormatter(date){returnmoment(date).format('MMMM Do YYYY, h:mm:ss a');}}</script><datepicker:format="customFormatter"></datepicker>

Disabled Dates

Dates can be disabled in a number of ways.

<script>varstate={disabledDates:{to:newDate(2016,0,5),// Disable all dates up to specific datefrom:newDate(2016,0,26),// Disable all dates after specific datedays:[6,0],// Disable Saturday's and Sunday'sdaysOfMonth:[29,30,31],// Disable 29th, 30th and 31st of each monthdates:[// Disable an array of datesnewDate(2016,9,16),newDate(2016,9,17),newDate(2016,9,18)],ranges:[{// Disable dates in given ranges (exclusive).from:newDate(2016,11,25),to:newDate(2016,11,30)},{from:newDate(2017,1,12),to:newDate(2017,2,25)}],// a custom function that returns true if the date is disabled// this can be used for wiring you 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 is disabledcustomPredictor:function(date){// disables the date if it is a multiple of 5if(date.getDate()%5==0){returntrue}}}}</script><datepicker:disabled-dates="state.disabledDates"></datepicker>

Highlighted Dates

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 theincludeDisabledproperty totrue. Note: Bothto andfrom properties are required to define a range ofdates to highlight.

<script>varstate={highlighted:{to:newDate(2016,0,5),// Highlight all dates up to specific datefrom:newDate(2016,0,26),// Highlight all dates after specific datedays:[6,0],// Highlight Saturday's and Sunday'sdaysOfMonth:[15,20,31],// Highlight 15th, 20th and 31st of each monthdates:[// Highlight an array of datesnewDate(2016,9,16),newDate(2016,9,17),newDate(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 highlightedcustomPredictor:function(date){// highlights the date if it is a multiple of 4if(date.getDate()%4==0){returntrue}},includeDisabled:true// Highlight disabled dates}}</script><datepicker:highlighted="state.highlighted"></datepicker>

Slots

Slots will help you customize content. .

beforeCalendarHeader

Sometimes you need to show custom content before the calendar header. For such cases you can use the named slotbeforeCalendarHeader.

An example would be to use bootstrap'sinput-group-prepend andinput-group-appendto show some custom text:

<datepicker:bootstrap-styling="true"><divslot="beforeCalendarHeader"class="calender-header">    Choose a Date</div></datepicker>

afterDateInput

To implement some custom styling (for instance to add an animated placeholder) on DateInput, you might need to add elements as DateInput siblings. Slot namedafterDateInput allows you to do that:

<datepicker><spanslot="afterDateInput"class="animated-placeholder">    Choose a Date</span></datepicker>

Translations

Contributing guide - please use appropriate code from thislist as the translation property.

  • Add your language as a module in thesrc/locale/translations dir.
  • Import and export it in thesrc/locale/index file
  • Add the Language to the available languages in the readme file.
  • Runnpm run lint to make sure your code formatting is in line with the required code style.

How to apply language

Below script tag in component.

import{en,es}from'vuejs-datepicker/dist/locale'

In component data.

data(){return{en:en,es:es}}

html.

<datepicker :language="es"></datepicker>

Available languages

AbbrLanguage
afAfrikaans
arArabic
bgBulgarian
bsBosnian
caCatalan
csCzech
daDanish
deGerman
eeEstonian
elGreek
enEnglishDefault
esSpanish
faPersian (Farsi)
fiFinnish
foFaroese
frFrench
geGeorgia
glGalician
heHebrew
huHungarian
hrCroatian
idIndonesian
isIcelandic
itItalian
jaJapanese
kkKazakh
koKorean
lbLuxembourgish
ltLithuanian
lvLatvian
mkMacedonian
mnMongolian
nbNONorwegian Bokmål
nlDutch
plPolish
ptBRPortuguese-Brazil
roRomanian
ruRussian
skSlovak
slSISlovenian
svSwedish
srSerbian (Latin)
srCyrlSerbian (Cyrl)
thThai
trTurkish
ukUkrainian
urUrdu
viVietnamese
zhChinese
zhHKChinese_HK

About

A simple Vue.js datepicker component. Supports disabling of dates, inline mode, translations

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp