2.1.1 • Published 5 years ago

nuxt-ctk-date-time-picker v2.1.1

Weekly downloads
78
License
MIT
Repository
github
Last release
5 years ago

VueCtkDateTimePicker

A vue component for select dates (range mode available) & time

This documentation is for v2.*. Find v1 documentation here

vue-ctk-date-time-picker

Dark mode

vue-ctk-date-time-picker

Demo

Enjoy

Installation

Yarn

yarn add vue-ctk-date-time-picker

NPM

npm i --save vue-ctk-date-time-picker

Usage

ES6 Modules / CommonJS

import VueCtkDateTimePicker from 'vue-ctk-date-time-picker';
import 'vue-ctk-date-time-picker/dist/vue-ctk-date-time-picker.css';

Vue.component('VueCtkDateTimePicker', VueCtkDateTimePicker);
<VueCtkDateTimePicker v-model="yourValue" />

UMD

<link rel="stylesheet" type="text/css" href="${YOUR_PATH}/vue-ctk-date-time-picker.css">

<div id="app">
  <VueCtkDateTimePicker v-model="yourValue"></VueCtkDateTimePicker>
</div>

<script src="https://unpkg.com/vue" charset="utf-8"></script>
<script src="${YOUR_PATH}/vue-ctk-date-time-picker.umd.min.js" charset="utf-8"></script>

<script type="text/javascript">
  Vue.component('vue-ctk-date-time-picker', window['vue-ctk-date-time-picker']);
  new Vue({
    el: '#app',
    data () {
      return {
        yourValue: null
      }
    }
  });
</script>

Here is an example of UMD implementation: https://codepen.io/louismazel/pen/jQWNzQ

Use custom element to trigger the component

<VueCtkDateTimePicker :no-value-to-custom-elem="(true|false)" />
  ...
  <input type="text" />
  ... or
  <button type="button">Label</button>
  ...
</VueCtkDateTimePicker>

Props API

PropsTypeRequiredDefault
v-modelStringyes-
idStringnoDateTimePicker
formatStringno'YYYY-MM-DD hh:mm a'
formattedStringno'llll' (momentjs format)
labelStringnoSelect date & time
disabledBooleannofalse
hint (1)Stringno-
error (2)Booleannofalse
color (3)String (hex)nododgerblue
button-color (4)String (hex)no#00C853
positionStringnonull
locale (5)StringnoBrowser Locale
persistentBooleannofalse
minute-intervalIntegerno1
output-formatStringnonull
only-timeBooleannofalse
only-dateBooleannofalse
no-labelBooleannofalse
no-headerBooleannofalse
no-value-to-custom-elem (6)Booleannofalse
min-date (7)Stringno-
max-date (7)Stringno-
no-weekends-daysBooleannofalse
auto-closeBooleannofalse
inlineBooleannofalse
overlayBooleannofalse
rangeBooleannofalse
darkBooleannofalse
no-shortcutsBooleannofalse
no-buttonBooleannofalse
input-sizeString (sm or lg)nonull
button-now-translationStringno'Now'
no-button-nowBooleannofalse
first-day-of-weekInt (0 to 7)no-
disabled-dates (8)Array<string>no[]
disabled-hours (9)Array<string>no-
custom-shortcuts (10)Array<object>no-
disabled-weekly (11)Array<integer>no[]
no-keyboard (12)Booleannofalse
right (13)Booleannofalse
noClearButtonBooleannofalse

(1) hint : Is a text that replaces the label/placeholder (Ex : Error designation)

(2) error : When is true --> Input border & label are red

(3) color: Replace color for the hint, the borders & picker color

(4) button-color: Replace color for the buttons on bottom (validation & 'now')

(5) locale : Default value is the locale of the browser - Ex : Set locale="fr" to force to French language

(6) no-value-to-custom-elem : No value will set to your elem (you can get the formatted value with @formatted-value event)

(7) min-date && max-date should be in the same format as property format specified. If format not set - it is set to 'YYYY-MM-DD hh:mm a' by default

(8) Disabled-Dates is an Array of dates in 'YYYY-MM-DD' format (ex: ['2018-04-03', '2018-04-07', '2018-04-09'])

(9) disabled-hours : Must be an Array of hours in 24h format ('00' to '23') : ['00','01','02','03','04','05','06','07','19','20','21','22','23']

(10) custom-shortcuts - It's an Array of Objects like this :

[
  { label: `Aujourd'hui`, value: 'day', isSelected: false },
  { label: 'Yesterday', value: '-day', isSelected: false },
  { label: 'This Week', value: 'week', isSelected: true },
  { label: 'Last Week', value: '-week', isSelected: false },
  { label: 'This iso Week', value: 'isoWeek', isSelected: true },
  { label: 'Last iso Week', value: '-isoWeek', isSelected: false },
  { label: 'This Month', value: 'month', isSelected: false },
  { label: 'Last Month', value: '-month', isSelected: false },
  { label: 'This Month', value: 'year', isSelected: false },
  { label: 'Last Month', value: '-year', isSelected: false },
  { label: 'Last 5 days', value: 5, isSelected: false }
]

Shortcut types allowed : ['day', '-day', 'isoWeek', '-isoWeek', 'month', '-month', 'year', '-year', 'week', '-week']

If the value of shortcut is a number (Integer), this number correspond to number of day (for 5 --> Last 5 days)

You can use this feature for translate the shortcuts

When you set isSelected to true, the shortcut is selected by default

(11) disabled-weekly : Days of the week which are disabled every week, in Array format with day index, Sunday as 0 and Saturday as 6: [0,4,6]

(12) no-keyboard : Disable keyboard accessibility & navigation

(13) right : add this attribute to align the picker on right

Events API

EventReturn
inputvalue (formatted with 'format' props)
formatted-valuevalue (formatted with 'formatted' props)
is-shownComponent is shown
is-hiddenComponent is hidden
validateClick on validate button (so component is closed)
destroyComponent is destroy

Keyboard Accessible

KeyAction
Arrow RightNext Day
Arrow LeftPrevious Day
Arrow DownSame day on next week
Arrow UpSame day on previous week
Page DownSame day on previous month
Page UpSame day on next month
Enter or SpaceSelect day
EscapeClose component

Upcoming features (Todo)

  • Double Calendar on RangeDatePicker (issue : #33)
  • Inputs Text to choose values (issue #30)
  • TimePicker seconds support (issue : #79)

Contribution

Project setup

npm install

Compiles and hot-reloads for development

npm run serve

Lints and fixes files

npm run lint

Tests

Work in progress

License

This project is licensed under MIT License

Credit

Open source time proudly sponsored by Chronotruck