1.0.16 • Published 2 months ago

vue-datetime3 v1.0.16

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Vue-datetime3


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

This is a fork and port of Vue 2 vue-datetime by mariomka to support Vue 3 and typescript. For older versions of Vue refer to aforementioned project.

Demo

Go to demo.

demo

Installation

Bundler

yarn add luxon vue-datetime3 weekstart

Or

npm install --save luxon vue-datetime3 weekstart

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

Register

import createApp from 'vue'
import createDatetime from 'vue-datetime'
// You need a specific loader for CSS files
import 'vue-datetime/dist/style.css'

const app = createApp();

app.use(createDatetime());

Usage

Minimal

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

Setup

Parameters

ParameterTypeDefaultDescription
v-model (required)ISO 8601 String-Datetime.
typeStringdatePicker type: date, datetime or time.
input-idString''Id for the input.
input-classString, Array or Object''Class for the input.
input-styleString, Array or Object''Style for the input.
hidden-nameStringnullName for hidden input with raw value. See #51.
value-zoneStringUTCTime zone for the value.
zoneStringlocalTime zone for the picker.
formatObject or StringDateTime.DATE_MED, DateTime.DATETIME_MED or DateTime.TIME_24_SIMPLEInput date format. Luxon presets or tokens.
phrasesObject{ok: 'Ok', cancel: 'Cancel'}Phrases.
use12-hourBooleanfalseDisplay 12 hour (AM/PM) mode
hour-stepNumber1Hour step.
minute-stepNumber1Minute step.
min-datetimeISO 8601 StringnullMinimum datetime.
max-datetimeISO 8601 StringnullMaximum datetime.
autoBooleanfalseAuto continue/close on select.
week-startNumberauto from locale if weekstart is available or 1First day of the week. 1 is Monday and 7 is Sunday.
flowArrayDepends of typeCustomize steps flow, steps available: time, date, month, year. Example: 'year', 'date', 'time'
titleString''Popup title.
hide-backdropBooleanfalseShow/Hide backdrop.
backdrop-clickBooleantrueEnable/Disable backdrop click to cancel (outside click).
colorString#3f51b5Color theme of the component
fixed-dateBooleanfalseEnables 'datetime' to have fixed date, input acts like a time picker, returns datetime value
fixed-timeBooleanfalseEnables 'datetime' to have fixed time, input acts like a date picker, returns datetime value

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 defining a color in props. color should be a valid css color option, it's default value is #3f51b5.

Development

Launch lint and tests

npm run test

Note: Currently not working. Tests need to be rewritten to ViTest.

Launch visual tests

npm run demo

Build

Bundle the js and css to the dist folder:

npm run build

License

The MIT License

1.0.16

2 months ago

1.0.15

4 months ago

1.0.14

5 months ago

1.0.13

7 months ago

1.0.12

7 months ago

1.0.11

12 months ago

1.0.10

12 months ago

1.0.9

12 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago