Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@reciprocity/date-picker

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reciprocity/date-picker

A date picker / datetime picker component

  • 0.6.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
147
decreased by-9.82%
Maintainers
3
Weekly downloads
 
Created
Source

Date Picker

A datepicker / datetimepicker component. This this basically a wrapper of vue2-datepicker

Installation

npm install @reciprocity/date-picker

or

yarn add @reciprocity/date-picker

Usage

This component is meant to be used as an ES module, so you can import it using the ES6 import syntax.

After importing you can just register it with Vue. Eg:

app.vue

<template>
  <date-picker v-model="time" valueType="format"></date-picker>
</template>
<script>
import DatePicker from '@reciprocity/date-picker';

export default Vue.extend({
  name: 'My App',
  data: {
    time: null
  },
  components: {
    DatePicker
  }
};
</script>

Props

PropDescriptionTypeDefault
typeselect the type of pickerdate |datetime|year|month|time|week'date'
rangeif true, pick the range datebooleanfalse
formatto set the date format. similar to moment.jstoken'YYYY-MM-DD'
value-typedata type of the binding valuevalue-type'format'
default-valuedefault date of the calendarDatenew Date()
langoverride the default localeobjecthere
placeholderinput placeholder textstring''
editablewhether the input is editablebooleantrue
clearableif false, don't show the clear iconbooleantrue
confirmif true, need click the button to change valuebooleanfalse
confirm-textthe text of confirm buttonstring'OK'
disableddisable the componentbooleanfalse
disabled-datespecify the date that cannot be selected(date) => boolean-
disabled-timespecify the time that cannot be selected(date) => boolean-
append-to-bodyappend the popup to bodybooleantrue
inlinewithout inputbooleanfalse
input-classinput classnamestring'mx-input'
input-attrinput attrs(eg: { name: 'date', id: 'foo'})object
openopen state of pickerboolean-
popup-stylepopup styleobject
popup-classpopup classes
shortcutsset shortcuts to selectArray<{text, onClick}>-
title-formatformat of the tooltip in calendar celltoken'YYYY-MM-DD'
partial-updatewhether update date when select year or monthbooleanfalse
range-separatortext of range separatorstring' ~ '
show-week-numberdetermine whether show week numberbooleanfalse
hour-stepinterval between hours in time picker1 - 601
minute-stepinterval between minutes in time picker1 - 601
second-stepinterval between seconds in time picker1 - 601
hour-optionscustom hour columnArray<number>-
minute-optionscustom minute columnArray<number>-
second-optionscustom second columnArray<number>-
show-hourwhether show hour columnbooleanbase on format
show-minutewhether show minute columnbooleanbase on format
show-secondwhether show second columnbooleanbase on format
use12hwhether show ampm columnbooleanbase on format
show-time-headerwhether show header of time pickerbooleanfalse
time-title-formatformat of the time headertoken'YYYY-MM-DD'
time-picker-optionsset fixed time list to selecttime-picker-optionsnull
altInputflag to print the date in altFormatbooleantrue
altFormatto be used in the input and placeholdersstring'MM/DD/YYYY'
Token
UintTokenoutput
YearYY70 71 ... 10 11
YYYY1970 1971 ... 2010 2011
Y-1000 ...20 ... 1970 ... 9999 +10000
MonthM1 2 ... 11 12
MM01 02 ... 11 12
MMMJan Feb ... Nov Dec
MMMMJanuary February ... November December
Day of MonthD1 2 ... 30 31
DD01 02 ... 30 31
Day of Weekd0 1 ... 5 6
ddSu Mo ... Fr Sa
dddSun Mon ... Fri Sat
ddddSunday Monday ... Friday Saturday
AM/PMAAM PM
aam pm
HourH0 1 ... 22 23
HH00 01 ... 22 23
h1 2 ... 12
hh01 02 ... 12
Minutem0 1 ... 58 59
mm00 01 ... 58 59
Seconds0 1 ... 58 59
ss00 01 ... 58 59
Fractional SecondS0 1 ... 8 9
SS00 01 ... 98 99
SSS000 001 ... 998 999
Time ZoneZ-07:00 -06:00 ... +06:00 +07:00
ZZ-0700 -0600 ... +0600 +0700
Week of Yearw1 2 ... 52 53
ww01 02 ... 52 53
Unix TimestampX1360013296
Unix Millisecond Timestampx1360013296123
custom format

The format accepts an object to customize formatting.

<date-picker :format="formatter" />
import { format, parse as dateParse } from 'date-fns';
// ...
data() {
  return {
    // Use date-fns instead of the default
    formatter: {
      // Date to String
      stringify: date => {
        return date ? format(date, this.currentFormat) : '';
      },
      // String to Date
      parse: value => {
        return value ? dateParse(value) : null;
      },
    }
  }
}

value-type

set the format of binding value

ValueDescription
'date'return a Date object
'timestamp'return a timestamp number
'format'returns a string formatted using pattern of format
token(MM/DD/YYYY)returns a string formatted using this pattern
shortcuts

The shortcuts for the range picker

[
  { text: 'today', onClick: () => new Date() },
  {
    text: 'Yesterday',
    onClick: () => {
      const date = new Date();
      date.setTime(date.getTime() - 3600 * 1000 * 24);
      return date;
    },
  },
];
AttributeDescription
texttitle of the shortcut
onClickcallback function , need to return a Date
time-picker-options

Set fixed time list to select;

{start: '00:00', step:'00:30' , end: '23:30', format: 'HH:mm' }
AttributeDescription
startstart time
stepstep time
endend time
formatthe default is same as prop format
Default Locale
{
  // the locale of formatting and parsing function
  formatLocale: {
    // MMMM
    months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
    // MMM
    monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
    // dddd
    weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
    // ddd
    weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
    // dd
    weekdaysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
    // first day of week
    firstDayOfWeek: 0,
    // first week contains January 1st.
    firstWeekContainsDate: 1,
    // format 'a', 'A'
    meridiem: (h: number, _: number, isLowercase: boolean) {
      const word = h < 12 ? 'AM' : 'PM';
      return isLowercase ? word.toLocaleLowerCase() : word;
    },
    // parse ampm
    meridiemParse: /[ap]\.?m?\.?/i;
    // parse ampm
    isPM: (input: string) {
      return `${input}`.toLowerCase().charAt(0) === 'p';
    }
  },
  // the calendar header, default formatLocale.weekdaysMin
  days: [],
  // the calendar months, default formatLocale.monthsShort
  months: [],
  // the calendar title of year
  yearFormat: 'YYYY',
  // the calendar title of month
  monthFormat: 'MMMM',
  // the calendar title of month before year
  monthBeforeYear: false,
}

Events

NameDescriptionCallback Arguments
inputWhen the value change(v-model event)date
changeWhen the value change(same as input)date, type(date, hour, minute, second, ampm)
openWhen panel opening
closeWhen panel closing
confirmWhen click 'confirm' buttondate
clearWhen click 'clear' button
input-errorWhen user type a invalid Datethe input text
focusWhen input focus
blurWhen input blur
pickwhen select datedate
calendar-changewhen change the calendardate, oldDate

Slots

NameDescription
icon-calendarcustom the calender icon
icon-clearcustom the clear icon
inputreplace input
headerpopup header
footerpopup footer
sidebarpopup sidebar

FAQs

Package last updated on 26 May 2020

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