New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mathieustan/vue-datepicker

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mathieustan/vue-datepicker

A clean datepicker made with VueJs

  • 0.1.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

vue-datepicker

Codacy Badge Codacy Badge

A datepicker Vue component. Compatible with Vue 2.x

Demo

To view a demo online: https://vue-datepicker.netlify.com/

Install

npm install @mathieustan/vue-datepicker --save

or

yarn add @mathieustan/vue-datepicker
import { VueDatePicker } from '@mathieustan/vue-datepicker';

export default {
  // ...
  components: {
    VueDatePicker
  }
  // ...
}

or

import VueDatePicker from '@mathieustan/vue-datepicker';

Vue.use(VueDatePicker);

Usage

<VueDatePicker v-model="currentDate" />

value prop if passed should be a Date object

<template>
    <VueDatePicker :value="date"></VueDatePicker>
</template>
<script>
export default {
  // ...
  components: {
    VueDatePicker
  },
  data: () => ({
      date: new Date([2019, 5, 16]),
  }),,
  // ...
}
</script>

support name attribute for normal html form submission

<VueDatePicker :value="state.date" name="uniquename"></VueDatePicker>

Using v-model

<VueDatePicker v-model="state.date" name="uniquename"></VueDatePicker>

Available props

PropTypeDefaultDescription
idString'datepicker'Input id
valueDate|String|NumberDate value of the datepicker
nameString'datepicker'Input name property & datepicker title in fullscreenMobile
validateBooleanfalseShow validations button to select date
buttonValidateString'Ok'Text for validation button
buttonCancelString'Cancel'Text for cancel button
formatStringDD MMMM YYYYDate formatting for input
formatHeaderStringdddd DD MMMAllows you to customize the format of the month string that appears in the header of the calendar.
formatOutputStringYYYY-MM-DDAllows you to customize the format of date when selected
placeholderString'YYYY-MM-DD'Allow you to change input placeholder
visibleBooleanfalseAllow you to trigger datepicker
disabledBooleanfalseDatepicker disabled or not
colorString#4f88ffApplies specified color
noHeaderBooleanAllow to hide header
noInputBooleanHide input to show a button instead (better when width needs to be dynamic)
noCalendarIconBooleanAllow to hide calendar icon
fullscreenMobileBooleanfalseDatepicker will appear in a bottom sheet in mobile view
minDateString|Number|DateDate are available FROM this date
maxDateString|Number|DateDate are disabled AFTER this date
localeObject{lang: 'en'}More informations here Translations
inlineBooleanfalseInline datepicker
fixedBooleanfalseSet datepicker popup to fixed position => More informations here Best Practices
attachToString|DOM Element'#app'It will mount datepicker popup into this element as a child ( /!\ Important /!\ If datepicker is inside a fixed parent, you should set attachTo this parent) More informations here Best Practices
typeString'date'Determines the type of the picker - date/month/quarter
rangeBooleanfalseEnable/disable Date range (actually only available for date )
rangeInputTextString'%d ~ %d'When range is enabled, Allow to customize date text in input
rangeHeaderTextString'From %d To %d 'When range is enabled, set text before date in datepicker header
rangePresetsArrayAllow to add custom range presets to range datepicker. (Max custom presets = 6) Example: [{ name: 'This year', dates: { start: ..., end: ... } }]
tabindexString|Number'0'Specify input tabindex
rtlBooleanfalseAllow to use datepicker with rtl mode
zIndexNumberSpecify a z-index to datepicker & overlay

Events

EventOutputDescription
onOpendatepicker opened
onClosedatepicker closed
onChangedatepicker changed
onDestroydatepicker destroyed

Date Formatting

You can use this with format props.

Example :

<VueDatePicker v-model="currentDate" format="YYYY-MM-DD" />
FormatOutputDescription
YY18Two-digit year
YYYY2018Four-digit year
M1-12Month, beginning at 1
MM01-12Month, 2-digits
MMMJan-DecThe abbreviated month name
MMMMJanuary-DecemberThe full month name
D1-31Day of month
DD01-31Day of month, 2-digits
H0-23Hours
HH00-23Hours, 2-digits
h1-12Hours, 12-hour clock
hh01-12Hours, 12-hour clock, 2-digits
m0-59Minutes
mm00-59Minutes, 2-digits
s0-59Seconds
ss00-59Seconds, 2-digits
S0-9Hundreds of milliseconds, 1-digit
SS00-99Tens of milliseconds, 2-digits
SSS000-999Milliseconds, 3-digits
Z-5:00Offset from UTC
ZZ-0500Compact offset from UTC, 2-digits
AAM PMPost or ante meridiem, upper-case
aam pmPost or ante meridiem, lower-case
Do1st... 31stDay of Month with ordinal

Translations

By default, locale will be set from your navigator language. But it's possible to set it from locale props. Actually, there are some locale inside project ('en', 'fr, 'es', 'de');

exemple:

<template>
    <VueDatePicker :value="date" :locale="locale"></VueDatePicker>
</template>
<script>
export default {
  // ...
  components: {
    VueDatePicker
  },
  data: () => ({
      date: new Date([2019, 5, 16]),
      locale: {
        lang: 'fr' // or 'en', 'es', 'de',
        weekDays: ['L', 'M', 'M', 'J', 'V', 'S', 'D'], // you can surcharge weekDays too
      },
  }),,
  // ...
}
</script>

:rocket: Now, you can use your own language object

Below, an exemple for it language : You should have those properties to make it works :

'name', 'weekdays', 'weekdaysShort', 'weekdaysMin', 'weekStart', 'months', 'monthsShort', 'ordinal', 'formats', 'buttonCancel', 'buttonValidate', 'rangeHeaderText'
<template>
    <VueDatePicker :value="date" :locale="locale"></VueDatePicker>
</template>
<script>
const locale = {
  lang: {
    name: 'it',
    weekdays: 'domenica_lunedì_martedì_mercoledì_giovedì_venerdì_sabato'.split('_'),
    weekdaysShort: 'dom_lun_mar_mer_gio_ven_sab'.split('_'),
    weekStart: 1,
    months: 'gennaio_febbraio_marzo_aprile_maggio_giugno_luglio_agosto_settembre_ottobre_novembre_dicembre'.split('_'),
    monthsShort: 'gen_feb_mar_apr_mag_giu_lug_ago_set_ott_nov_dic'.split('_'),
    formats: {
      LT: 'HH:mm',
      LTS: 'HH:mm:ss',
      L: 'DD/MM/YYYY',
      LL: 'D MMMM YYYY',
      LLL: 'D MMMM YYYY HH:mm',
      LLLL: 'dddd D MMMM YYYY HH:mm',
    },
    ordinal: n => `${n}º`,
    buttonCancel: 'Annulla',
    buttonValidate: 'Ok',
    rangeHeaderText: 'Dalle %d Alle 13',
  },
};

export default {
  // ...
  components: {
    VueDatePicker
  },
  data: () => ({
    date: new Date([2019, 5, 16]),
    locale,
  }),
  // ...
};
</script>

If you need more exemples, you can go to this link to find your language : -> locales

Best Practices

When should you use attachTo or fixed props :

AttachTo

is great when you have a fixed element in your page like a panel, a dialog or a fixed fullscreen container. The datepicker position will not take care of scroll page position and it'll be absolutely positionned into your fixed container. (if you scroll, datepicker popup will scroll too).

On the other hand, when using attachTo, the component will check if there is enough space around to position it correctly, and therefore if the container hasn't enough space it will be positioned oddly. This is where the prop fixed comes in.

Fixed

is great to use it in a fixed toolbar because page can scroll or move, datepicker will always show at same point.

On the other hand, if you use it in a fixed container which allow scroll, you'll have a fixed datepicker even if you scroll. So, you should use attachTo :)

Keywords

FAQs

Package last updated on 16 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc