GithubHelp home page GithubHelp logo

diegodevgroup / vuejs-datepicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from charliekassel/vuejs-datepicker

0.0 8.0 0.0 1003 KB

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

License: MIT License

JavaScript 66.40% HTML 0.31% Vue 33.28%

vuejs-datepicker's Introduction

Datepicker

Coverage Status

A datepicker Vue component. Compatible with Vue 1.x and Vue 2.x

Demo

https://www.webpackbin.com/bins/-KhQbtTSVuU6r8VCrIdC

Install

$ npm install vuejs-datepicker --save
import Datepicker from 'vuejs-datepicker';

Vue.component('my-component', {
    components: {
        Datepicker
    }
});

Usage

<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>

Use v-model for two-way binding

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

Emits events

<datepicker v-on:selected="doSomethingInParentComponentFunction" v-on:opened="datepickerOpenedFunction" v-on:closed="datepickerClosedFunction">

Inline always open version

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

Available props

Prop Type Default Description
value Date/String Date value of the datepicker
name String Input name property
id String Input id
format String dd MMM yyyy Date formatting string
language String en Translation for days and months
disabled Object See below for configuration
placeholder String Input placeholder text
inline Boolean To show the datepicker always open
input-class String CSS class applied to the input el
wrapper-class String CSS class applied to the outer div
monday-first Boolean false To start the week on Monday
clear-button Boolean false Show an icon for clearing the date
clear-button-icon String Use icon for button (ex: fa fa-times)
calendar-button Boolean false Show an icon that that can be clicked
calendar-button-icon String Use icon for button (ex: fa fa-calendar)
bootstrapStyling Boolean false Output bootstrap styling classes
initial-view String 'day' If 'month' or 'year', open on that view
disabled-picker Boolean false If true, disable Datepicker on screen
required Boolean false Sets html required attribute on input
allow-input Boolean false Allow keyboard input of standard date formats

Events

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
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

Date formatting

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

Token Desc Example
d day 1
dd 0 prefixed day 01
D abbr day Mon
su date suffix st, nd, rd
M month number (1 based) 1 (for Jan)
MM 0 prefixed month 01
MMM abbreviated month name Jan
MMMM month name January
yy two digit year 16
yyyy four digit year 2016

Disabled Dates

Dates can disabled in a number of ways.

<script>
var state = {
    disabled: {
        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
        dates: [ // Disable an array of dates
            new Date(2016, 9, 16),
            new Date(2016, 9, 17),
            new Date(2016, 9, 18)
        ]
    }
}
</script>
<datepicker :disabled="state.disabled"></datepicker>

Highlight Dates

Dates can be highlighted (e.g. for marking an appointment) in a number of ways. Important: You can only highlight dates, that aren't disabled. Note: Both to and from properties are require 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
        dates: [ // Highlight an array of dates
            new Date(2016, 9, 16),
            new Date(2016, 9, 17),
            new Date(2016, 9, 18)
        ]
    }
}
</script>
<datepicker :highlighted="state.highlighted"></datepicker>

Translations

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

Available languages

Abbr Language
en English Default
es Spanish
fi Finnish
fr French
hu Hungarian
hr Croatian
id Indonesian
it Italian
nl Dutch
de German
da Danish
nb-no Norwegian Bokmål
cs Czech
pt-br Portuguese-Brazil
ro Romanian
vi Vietnamese
zh Chinese
ja Japanese
he Hebrew
ru Russian
sk Slovak
sl-si Slovenian
sv Swedish
th Thai
bg Bulgarian
lt Lithuanian
pl Polish
ar Arabic
ee Estonian
ko Korean
tr Turkish
uk Ukrainian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.