Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

vue-datetime

mariomka72.4kMIT1.0.0-beta.14TypeScript support: definitely-typed

Mobile friendly datetime picker for Vue. Supports date, datetime and time modes, i18n and disabling dates.

datetime, datetime-picker, picker, date, vue

readme

vue-datetime

Software License Latest Version on NPM npm Vue 2.x Build Coverage

Mobile friendly datetime picker for Vue. Supports date, datetime and time modes, i18n and more.

Demo

Go to demo.

demo

Installation

Bundler (Webpack, Rollup...)

yarn add luxon vue-datetime weekstart

Or

npm install --save luxon vue-datetime weekstart

weekstart is optional, is used to get the first day of the week.

Register

import Vue from 'vue'
import { Datetime } from 'vue-datetime'
// You need a specific loader for CSS files
import 'vue-datetime/dist/vue-datetime.css'

Vue.use(Datetime)

Register manually

Global
import { Datetime } from 'vue-datetime';

Vue.component('datetime', Datetime);
Local
import { Datetime } from 'vue-datetime';

Vue.extend({
  template: '...',
  components: {
    datetime: Datetime
  }
});

Browser

Download vue, luxon, weekstart and vue-datetime or use a CDN like unpkg.

<link rel="stylesheet" href="vue-datetime.css"></link>
<script src="vue.js"></script>
<script src="luxon.js"></script>
<script src="weekstart.js"></script>
<script src="vue-datetime.js"></script>

The component registers itself automatically as <datetime>. If you want to use a different name then register it explicitly:

Vue.component('vue-datetime', window.VueDatetime.Datetime);

weekstart is optional, is used to get the first day of the week.

Usage

Minimal

<datetime v-model="date"></datetime>

Setup

Parameters

Parameter Type Default Description
v-model (required) ISO 8601 String - Datetime.
type String date Picker type: date, datetime or time.
input-id String '' Id for the input.
input-class String, Array or Object '' Class for the input.
input-style String, Array or Object '' Style for the input.
hidden-name String null Name for hidden input with raw value. See #51.
value-zone String UTC Time zone for the value.
zone String local Time zone for the picker.
format Object or String DateTime.DATE_MED, DateTime.DATETIME_MED or DateTime.TIME_24_SIMPLE Input date format. Luxon presets or tokens.
phrases Object {ok: 'Ok', cancel: 'Cancel'} Phrases.
use12-hour Boolean false Display 12 hour (AM/PM) mode
hour-step Number 1 Hour step.
minute-step Number 1 Minute step.
min-datetime ISO 8601 String null Minimum datetime.
max-datetime ISO 8601 String null Maximum datetime.
auto Boolean false Auto continue/close on select.
week-start Number auto from locale if weekstart is available or 1 First day of the week. 1 is Monday and 7 is Sunday.
flow Array Depends of type Customize steps flow, steps available: time, date, month, year. Example: ['year', 'date', 'time']
title String '' Popup title.
hide-backdrop Boolean false Show/Hide backdrop.
backdrop-click Boolean true Enable/Disable backdrop click to cancel (outside click).

Input inherits all props not defined above but style and class will be inherited by root element. See inheritAttrs option

The component is based on Luxon, check out documentation to set time zones and format.

Internationalization

Date internationalization depends on luxon. Set the default locale.

import { Settings } from 'luxon'

Settings.defaultLocale = 'es'

Events

Component emits the input event to work with v-model. More info.

close event is emitted when the popup closes.

Also, input text inherits all component events.

Slots

You can customize the component using named slots.

Available slots: before, after, button-cancel and button-confirm

Button customization example:

<datetime v-model="date" input-id="startDate">
  <label for="startDate" slot="before">Field Label</label>
  <span class="description" slot="after">The field description</span>
  <template slot="button-cancel">
    <fa :icon="['far', 'times']"></fa>
    Cancel
  </template>
  <template slot="button-confirm">
    <fa :icon="['fas', 'check-circle']"></fa>
    Confirm
  </template>
</datetime>

You can also use slot-scope to determine which view is currently active:

<template slot="button-confirm" slot-scope="scope">
  <span v-if='scope.step === "date"'>Next <i class='fas fa-arrow-right' /></span>
  <span v-else><i class='fas fa-check-circle' /> Publish</span>
</template>

Theming

Theming is supported by overwriting CSS classes.

Development

Launch lint and tests

yarn test

Launch visual tests

yarn dev

Build

Bundle the js and css to the dist folder:

yarn build

License

The MIT License

changelog

Changelog

All notable changes to this project will be documented in this file.

Generated by auto-changelog.

v1.0.0-beta.14

21 August 2020

  • Added new props for backdrop-click 8af46c1
  • Added new props for and hide backdrop d6770a1

v1.0.0-beta.13

1 May 2020

  • Revert `rollup-plugin-vue` update. It doesn't output the same files. We should work on it deeper. 91818e5

v1.0.0-beta.12

1 May 2020

v1.0.0-beta.11

13 November 2019

  • add curly brackets export name #178
  • Add type=time to the time example #172
  • Update util.js #164
  • improve pickers scrolling experience on mobile devices #162
  • added a check to see if yearList ref exists #131
  • replaced usage of Array.fill to work on old versions on Chrome #129
  • Fix min/max dates when picker zone isn't UTC 0576c01
  • Expose the popup. ad7d42f
  • Added height to month selection arrows. 55d3ac4

v1.0.0-beta.10

13 January 2019

  • Add title property. Based on #118 0da317c
  • Set `line-height` for popup 04db82b
  • Remove 0.x notice 3ba3ea8

v1.0.0-beta.9

12 January 2019

  • Added new custom slots for Buttons #97
  • fix: docs typo #99
  • Update `yarn.lock` 24830ab
  • months selector 5e093d5
  • specs for DatetimeMonthsPicker 38f96d7
  • Add property to customize the flow 408720a
  • Update readme 1f5accd
  • Revert split date for being compatible with all locales. So, month picker will be shown when clicking on the date. 7892362
  • Add `input-style` property and accept `Object` and `Array` besides to `String` for the property `input-class`. e5653b5
  • Update readme 0b79ce9
  • Add `month` to flow 84589b8
  • Fix disabled months. Month could be enabled even if it first and last day is disabled. 26493f4
  • Code style 8a2a0bb
  • Update DatetimePopup.vue aa89e7f
  • Set cursor pointer to header date 1eb7125
  • Set `inheritAttrs` to prevent apply not recognized props to the root element. a1ff9ee
  • fix disabling dbefc2f
  • fix comma-spacing 9a330e0
  • fix comma-dangle 68c70c2
  • fix comma-spacing 44c69b8
  • Fix demo 395f9db
  • Update DatetimePopup.vue b80f55b

v1.0.0-beta.8

14 October 2018

v1.0.0-beta.7

14 October 2018

v1.0.0-beta.6

9 July 2018

v1.0.0-beta.5

9 July 2018

v1.0.0-beta.4

8 July 2018

  • apply default rounded time when using minute step - resolves #56 #56
  • Generate hidden input with raw value when name is passed 32f8744
  • macro tokens are supported. 5db1a70
  • Add test for macro tokens format d995e02
  • Fix value formatting with `type=date` and specified time zone 522b19d
  • Rename `name` attribute by `hidden-name` f06fc41
  • Update readme 4bcbeef
  • Fix time zone for macro tokens format f868eb6
  • fix format describe c2a3456
  • fix format describe 5f44166
  • Macro tokens are supported. 74deb7d

v1.0.0-beta.3

3 February 2018

  • Add 12/24 hour format option to the time picker. #39
  • Update issue template 4c5de6d
  • Fix demo example code 2a5944f

v1.0.0-beta.2

23 January 2018

  • Add `week-start` parameter 6cb9279
  • Update demo 057f87a
  • Fix issue with value time zone 035d4da
  • Refactoring calendar new date d82d09c
  • Rename `date` by `datetime` in `Datetime.vue` 296f2c0
  • Refactoring 7d40f6f
  • Rename and improve `clearTime` util ccd80f5
  • Fix demo webpack 579096d
  • Add `luxon` in rollup globals config 46551bf
  • Add demo link to readme 44c667f
  • Remove auto-changelog limit f972692

v1.0.0-beta.1

19 January 2018

  • Cancel popup on key down ESC or TAB 47c8fca
  • Close popup on press ESC key 072063f
  • Continue or confirm popup on key down ENTER ff281ca
  • Fix auto on select time 69edaaa
  • On open popup blur input 5155ac7

v1.0.0-alpha.8

18 January 2018

  • Value will be an empty string instead of null when the date is empty or invalid because value type is a string. 3fa3463
  • Update luxon peer dependency version 2dd13b2

v1.0.0-alpha.7

18 January 2018

  • Watch value changes d58b910
  • Update readme and issue template 8adff3d
  • Ignore all vue devtools globals in mocha 7daee98
  • Update issue template b525ff6

v1.0.0-alpha.6

16 January 2018

v1.0.0-alpha.5

15 January 2018

v1.0.0-alpha.4

15 January 2018

  • Reformat code 6391d30
  • Add minimum and maximum datetimes. 5467eec
  • Clear time when type is date 317d0b4
  • Add notice and todo to readme 6a8855b
  • Refactor utils 45a82a3
  • Update readme parameters section 4461ab5
  • Add `VUE_DEVTOOLS_TOAST` to accepted global variables names in mocha. 1b40d2f

v1.0.0-alpha.3

25 December 2017

v1.0.0-alpha.2

25 December 2017

  • Add year picker c7766c8
  • Update `phrases` test c056826
  • Pass time steps from date picker to time picker through the popup. fd2d338
  • Fix tests 539a5cf
  • Refactor flow 7b19f2f
  • Rename `i18n` prop by `phrases` and add it to `Datetime` component 46e10ff
  • Add `auto-changelog` package to auto generate changelog on every version db2b5ea
  • Update readme d882209
  • Remove `wrapper-class` and `input-class` props. Use `class` attribute instead. 5017b63
  • Refactor how years, hours and minutes are generated. e3e5429
  • Update readme 5d60ed3
  • Update readme 63c1c43
  • Fix transition z-index issue 9ac6aa9
  • Remove unused prop c709478
  • Remove duplicated year from header f2ba651
  • Update readme d04236a

v1.0.0-alpha.1

20 December 2017