项目作者: mariomka

项目描述 :
Mobile friendly datetime picker for Vue. Supports date and datetime modes, i18n and more.
高级语言: JavaScript
项目地址: git://github.com/mariomka/vue-datetime.git
创建时间: 2017-09-25T17:40:40Z
项目社区:https://github.com/mariomka/vue-datetime

开源协议:MIT License

下载


🚨 THIS PROJECT IS NO LONGER MAINTAINED 🚨 read more

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

  1. yarn add luxon vue-datetime weekstart

Or

  1. npm install --save luxon vue-datetime weekstart

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

Register

  1. import Vue from 'vue'
  2. import { Datetime } from 'vue-datetime'
  3. // You need a specific loader for CSS files
  4. import 'vue-datetime/dist/vue-datetime.css'
  5. Vue.use(Datetime)

Register manually

Global
  1. import { Datetime } from 'vue-datetime';
  2. Vue.component('datetime', Datetime);
Local
  1. import { Datetime } from 'vue-datetime';
  2. Vue.extend({
  3. template: '...',
  4. components: {
  5. datetime: Datetime
  6. }
  7. });

Browser

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

  1. <link rel="stylesheet" href="vue-datetime.css"></link>
  2. <script src="vue.js"></script>
  3. <script src="luxon.js"></script>
  4. <script src="weekstart.js"></script>
  5. <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:

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

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

Usage

Minimal

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

  1. import { Settings } from 'luxon'
  2. 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:

  1. <datetime v-model="date" input-id="startDate">
  2. <label for="startDate" slot="before">Field Label</label>
  3. <span class="description" slot="after">The field description</span>
  4. <template slot="button-cancel">
  5. <fa :icon="['far', 'times']"></fa>
  6. Cancel
  7. </template>
  8. <template slot="button-confirm">
  9. <fa :icon="['fas', 'check-circle']"></fa>
  10. Confirm
  11. </template>
  12. </datetime>

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

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

Theming

Theming is supported by overwriting CSS classes.

Development

Launch lint and tests

  1. yarn test

Launch visual tests

  1. yarn dev

Build

Bundle the js and css to the dist folder:

  1. yarn build

License

The MIT License