UNPKG

6.25 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.
122
123Input 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)
124
125The 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).
126
127### Internationalization
128
129Date internationalization depends on luxon. [Set the default locale](https://moment.github.io/luxon/docs/manual/intl.html#setting-the-default).
130
131```js
132import { Settings } from 'luxon'
133
134Settings.defaultLocale = 'es'
135```
136
137### Events
138
139Component emits the `input` event to work with `v-model`. [More info](https://vuejs.org/v2/guide/components.html#Form-Input-Components-using-Custom-Events).
140
141`close` event is emitted when the popup closes.
142
143Also, input text inherits all component events.
144
145### Slots
146
147You can customize the component using named slots.
148
149Available slots: `before`, `after`, `button-cancel` and `button-confirm`
150
151#### Button customization example:
152
153```html
154<datetime v-model="date" input-id="startDate">
155 <label for="startDate" slot="before">Field Label</label>
156 <span class="description" slot="after">The field description</span>
157 <template slot="button-cancel">
158 <fa :icon="['far', 'times']"></fa>
159 Cancel
160 </template>
161 <template slot="button-confirm">
162 <fa :icon="['fas', 'check-circle']"></fa>
163 Confirm
164 </template>
165</datetime>
166```
167
168You can also use `slot-scope` to determine which view is currently active:
169
170```html
171<template slot="button-confirm" slot-scope="scope">
172 <span v-if='scope.step === "date"'>Next <i class='fas fa-arrow-right' /></span>
173 <span v-else><i class='fas fa-check-circle' /> Publish</span>
174</template>
175```
176
177## Theming
178
179Theming is supported by overwriting CSS classes.
180
181## Development
182
183### Launch lint and tests
184
185```bash
186yarn test
187```
188
189### Launch visual tests
190
191```bash
192yarn dev
193```
194
195### Build
196
197Bundle the js and css to the `dist` folder:
198
199```bash
200yarn build
201```
202
203## License
204
205[The MIT License](http://opensource.org/licenses/MIT)