UNPKG

6.4 kBMarkdownView Raw
1# vue-datetime
2
3[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
4[![Latest Version on NPM](https://img.shields.io/npm/v/vue-datetime.svg?style=flat-square)](https://npmjs.com/package/vue-datetime)
5[![npm](https://img.shields.io/npm/dt/vue-datetime.svg?style=flat-square)](https://www.npmjs.com/package/vue-datetime)
6[![Vue 2.x](https://img.shields.io/badge/vue-2.x-brightgreen.svg?style=flat-square)](https://vuejs.org)
7[![Build](https://img.shields.io/travis/mariomka/vue-datetime/v1.x.svg?style=flat-square)](https://travis-ci.org/mariomka/vue-datetime)
8[![Coverage](https://img.shields.io/codecov/c/github/mariomka/vue-datetime/v1.x.svg?style=flat-square)](https://codecov.io/gh/mariomka/vue-datetime)
9
10> Mobile friendly datetime picker for Vue. Supports date, datetime and time modes, i18n and more.
11
12## Demo
13
14**[Go to demo](http://mariomka.github.io/vue-datetime)**.
15
16[![demo](https://raw.githubusercontent.com/mariomka/vue-datetime/v1.x/demo/demo.gif)](http://mariomka.github.io/vue-datetime)
17
18## Installation
19
20### Bundler (Webpack, Rollup...)
21
22```bash
23yarn add luxon vue-datetime weekstart
24```
25
26Or
27
28```bash
29npm install --save luxon vue-datetime weekstart
30```
31
32**weekstart** is optional, is used to get the first day of the week.
33
34#### Register
35
36```js
37import Vue from 'vue'
38import { Datetime } from 'vue-datetime'
39// You need a specific loader for CSS files
40import 'vue-datetime/dist/vue-datetime.css'
41
42Vue.use(Datetime)
43```
44
45#### Register manually
46
47##### Global
48
49```js
50import { Datetime } from 'vue-datetime';
51
52Vue.component('datetime', Datetime);
53```
54
55##### Local
56
57```js
58import { Datetime } from 'vue-datetime';
59
60Vue.extend({
61 template: '...',
62 components: {
63 datetime: Datetime
64 }
65});
66```
67
68### Browser
69
70Download vue, luxon, weekstart and vue-datetime or use a CDN like unpkg.
71
72```html
73<link rel="stylesheet" href="vue-datetime.css"></link>
74<script src="vue.js"></script>
75<script src="luxon.js"></script>
76<script src="weekstart.js"></script>
77<script src="vue-datetime.js"></script>
78```
79
80The component registers itself automatically as `<datetime>`. If you want to use a different name then register it explicitly:
81
82```js
83Vue.component('vue-datetime', window.VueDatetime.Datetime);
84```
85
86
87**weekstart** is optional, is used to get the first day of the week.
88
89## Usage
90
91### Minimal
92
93```html
94<datetime v-model="date"></datetime>
95```
96
97## Setup
98
99### Parameters
100
101Parameter | Type | Default | Description
102--------- | ---- | ------- | -----------
103v-model (*required*) | ISO 8601 `String` | - | Datetime.
104type | `String` | `date` | Picker type: date, datetime or time.
105input-id | `String` | `''` | Id for the input.
106input-class | `String`, `Array` or `Object` | `''` | Class for the input.
107input-style | `String`, `Array` or `Object` | `''` | Style for the input.
108hidden-name | `String` | `null` | Name for hidden input with raw value. See #51.
109value-zone | `String` | `UTC` | Time zone for the value.
110zone | `String` | `local` | Time zone for the picker.
111format | `Object` or `String` | `DateTime.DATE_MED`, `DateTime.DATETIME_MED` or `DateTime.TIME_24_SIMPLE` | Input date format. Luxon [presets](https://moment.github.io/luxon/docs/manual/formatting.html#tolocalestring--strings-for-humans-) or [tokens](https://moment.github.io/luxon/docs/manual/formatting.html#formatting-with-tokens--strings-for-cthulhu-).
112phrases | `Object` | `{ok: 'Ok', cancel: 'Cancel'}` | Phrases.
113use12-hour | `Boolean` | `false` | Display 12 hour (AM/PM) mode
114hour-step | `Number` | `1` | Hour step.
115minute-step | `Number` | `1` | Minute step.
116min-datetime | ISO 8601 `String` | `null` | Minimum datetime.
117max-datetime | ISO 8601 `String` | `null` | Maximum datetime.
118auto | `Boolean` | `false` | Auto continue/close on select.
119week-start | `Number` | auto from locale if _weekstart_ is available or `1` | First day of the week. 1 is Monday and 7 is Sunday.
120flow | `Array` | Depends of *type* | Customize steps flow, steps available: time, date, month, year. Example: ['year', 'date', 'time']
121title | `String` | `''` | Popup title.
122hide-backdrop | `Boolean` | `false` | Show/Hide backdrop.
123backdrop-click | `Boolean` | `true` | Enable/Disable backdrop click to cancel (outside click).
124
125Input inherits all props not defined above but `style` and `class` will be inherited by root element. [See inheritAttrs option](https://vuejs.org/v2/api/#inheritAttrs)
126
127The component is based on [Luxon](https://github.com/moment/luxon), check out [documentation](https://moment.github.io/luxon/docs/index.html) to set [time zones](https://moment.github.io/luxon/docs/manual/zones.html) and [format](https://moment.github.io/luxon/docs/manual/formatting.html).
128
129### Internationalization
130
131Date internationalization depends on luxon. [Set the default locale](https://moment.github.io/luxon/docs/manual/intl.html#setting-the-default).
132
133```js
134import { Settings } from 'luxon'
135
136Settings.defaultLocale = 'es'
137```
138
139### Events
140
141Component emits the `input` event to work with `v-model`. [More info](https://vuejs.org/v2/guide/components.html#Form-Input-Components-using-Custom-Events).
142
143`close` event is emitted when the popup closes.
144
145Also, input text inherits all component events.
146
147### Slots
148
149You can customize the component using named slots.
150
151Available slots: `before`, `after`, `button-cancel` and `button-confirm`
152
153#### Button customization example:
154
155```html
156<datetime v-model="date" input-id="startDate">
157 <label for="startDate" slot="before">Field Label</label>
158 <span class="description" slot="after">The field description</span>
159 <template slot="button-cancel">
160 <fa :icon="['far', 'times']"></fa>
161 Cancel
162 </template>
163 <template slot="button-confirm">
164 <fa :icon="['fas', 'check-circle']"></fa>
165 Confirm
166 </template>
167</datetime>
168```
169
170You can also use `slot-scope` to determine which view is currently active:
171
172```html
173<template slot="button-confirm" slot-scope="scope">
174 <span v-if='scope.step === "date"'>Next <i class='fas fa-arrow-right' /></span>
175 <span v-else><i class='fas fa-check-circle' /> Publish</span>
176</template>
177```
178
179## Theming
180
181Theming is supported by overwriting CSS classes.
182
183## Development
184
185### Launch lint and tests
186
187```bash
188yarn test
189```
190
191### Launch visual tests
192
193```bash
194yarn dev
195```
196
197### Build
198
199Bundle the js and css to the `dist` folder:
200
201```bash
202yarn build
203```
204
205## License
206
207[The MIT License](http://opensource.org/licenses/MIT)