Socket
Socket
Sign inDemoInstall

@cevad-tokatli/date-picker

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @cevad-tokatli/date-picker

Date Picker is a JavaScript library for setting and choosing date and hour.


Version published
Maintainers
1
Install size
272 kB
Created

Readme

Source

Date Picker

Date Picker is a JavaScript library for setting and choosing date and hour.

NPM

npm install --save @cevad-tokatli/date-picker

Yarn

yarn add @cevad-tokatli/date-picker

Installation

import DatePicker from '@cevad-tokatli/date-picker';

const picker = new DatePicker({
    el: '#picker',
    toggleEl: '#toggle',
    inputEl: '#input'
});

Add the css file.

<link rel="stylesheet" href="/node_modules/@cevad-tokatli/date-picker/css/date-picker.min.css" />

Settings

OptionTypeDefaultDescription
valueString|Number|DatenullThe picker's initial value.
elString|HTMLElement*nullMain element which, picker is created below.
inputElString|HTMLElement*nullInput element.
toggleElString|HTMLElement*nullToggle element.
typeString"DATE"Sets picker type. (DATE, HOUR, DATEHOUR)
dateTypeString"DD/MM/YYYY"Sets date type. (DD/MM/YYYY, MM/DD/YYYY)
hourTypeString"12"Sets hour type. (12, 24)
allowEmptyBooleantrueA boolean value that indicates whether null and empty value are allowed or not.
showButtonsBooleanfalseA boolean value that indicates whether the buttons are visible or not.
inputToggleBooleantrueIf sets true, opens the picker when the input is clicked.
langString"en"Changes language of the picker. You have to create a language except “en (English)” before use it.
orientationBooleanfalseIf it is set true, up arrow increases value, down arrow decreases. If it is set false, vice versa.
showArrowButtonsBooleanfalseDisplays increase and decrase buttons instead of arrows.

*: You can give an HTML element or a CSS selector (like #carousel, .container > div:first-child)

Methods

MethodParamsReturnDescription
get{ value: String, day: Number, month: Number, year: Number, hour: Number, minute: Number, am: Boolean }Returns the value.
setvalue: String|Number|DatevoidSets the value.
openvoidOpens the picker.
closevoidCloses the picker.
togglevoidToggles the picker.
savevoidSaves the selection.
cancelvoidCancels the selection.
destroyvoidDestroys the picker.

Events

EventDescription
wdp.changeFires when the value changes.
wdp.openFires when the picker opens.
wdp.closeFires when the picker closes.
wdp.saveFires when the selection is saved.
wdp.cancelFires when the picker is closed without being saved.
wdp.destroyFires when the picker is destroyed.
import DatePicker from '@cevad-tokatli/date-picker';

const picker = new DatePicker({
  el: '#picker'
});

picker.el.addEventListener('wdp.open', () => {
  console.log('open');
});

picker.el.addEventListener('wdp.close', () => {
  console.log('close');
});

Set Position

When window is scrolled or resized and triggers scroll or resize event, Date Picker repositions the picker. If you use third party scroll or resize library that don't trigger window resize or scroll event, you can manually call method setPosition to reposition the picker.

var picker = new DatePicker({
  el: '#picker'
});

...
...
...
...
picker.setPosition();

Language

You can create a language to use with lang attribute.

import DatePicker from '@cevad-tokatli/date-picker';

DatePicker.createLanguage('tr', {
    DAYS_ABBR: ['', 'Pzt', 'Sal', 'Çar', 'Per', 'Cum', 'Cmt', 'Paz'],
    MONTHS: ['', 'Ocak', 'Şubat', 'Mart', 'Nisan', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', 'Eylül', 'Ekim', 'Kasım', 'Aralık'],
    MONTHS_ABBR: ['', 'Oca', 'Şub', 'Mar', 'Nis', 'May', 'Haz', 'Tem', 'Ağu', 'Eyl', 'Eki', 'Kas', 'Ara'],
    AM_PM: ['ÖÖ', 'ÖS'],
    BUTTONS: ['İPTAL', 'TAMAM'],
    INVALID_DATE: 'Geçersiz Tarih'
});

new DatePicker({
  el: '#picker',
  lang: 'tr'
});

Theme

You can change colors of the picker by adding a css class to main element.

<div id="picker"></div>
<div id="blue-picker" class="wdp-blue"></div>
<div id="cyan-picker" class="wdp-cyan"></div>
<div id="dark-picker" class="wdp-dark"></div>
<div id="gray-picker" class="wdp-gray"></div>
<div id="green-picker" class="wdp-green"></div>
<div id="light-picker" class="wdp-light"></div>
<div id="purple-picker" class="wdp-purple"></div>
<div id="red-picker" class="wdp-red"></div>
<div id="yellow-picker" class="wdp-yellow"></div>

You can also create your own theme for your picker.

Create a new file under theme folder.

// theme/_my_theme.scss

$color: #EEA55B;
$color-dark: #000;
$header-background: $color;
$header-text-color: $color-dark;
$header-icon-color: darken($color, 10%);
$list-el-text-active: $color-dark;
$list-el-background-active: $color;
$hour-input-text: $color-dark;
$button-text: $color-dark;

.wdp.wdp-my-theme {
    @include insert-theme();
}

Import your theme to _theme.scss file`.

// _theme.scss
...
@import 'theme/purple';
@import 'theme/red';
@import 'theme/yellow';
@import 'theme/my_theme';

Bundle css code.

$ gulp css
$ gulp minify-css

You are ready to use your theme.

<div id="picker" class="wdp-my-theme"></div>

License

Date Picker is provided under the MIT License.

Keywords

FAQs

Last updated on 06 Jan 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc