npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cevad-tokatli/date-picker

v1.0.3

Published

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

Downloads

61

Readme

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

Option | Type | Default | Description ------ | ---- | ------- | ----------- value | String|Number|Date | null | The picker's initial value. el | String|HTMLElement* | null | Main element which, picker is created below. inputEl | String|HTMLElement* | null | Input element. toggleEl | String|HTMLElement* | null | Toggle element. type | String | "DATE" | Sets picker type. (DATE, HOUR, DATEHOUR) dateType | String | "DD/MM/YYYY" | Sets date type. (DD/MM/YYYY, MM/DD/YYYY) hourType | String | "12" | Sets hour type. (12, 24) allowEmpty | Boolean | true | A boolean value that indicates whether null and empty value are allowed or not. showButtons | Boolean | false | A boolean value that indicates whether the buttons are visible or not. inputToggle | Boolean | true | If sets true, opens the picker when the input is clicked. lang | String | "en" | Changes language of the picker. You have to create a language except “en (English)” before use it. orientation | Boolean | false | If it is set true, up arrow increases value, down arrow decreases. If it is set false, vice versa. showArrowButtons | Boolean | false | Displays increase and decrase buttons instead of arrows.

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

Methods

Method | Params | Return | Description ------ | ------ | ------ | ----------- get | | { value: String, day: Number, month: Number, year: Number, hour: Number, minute: Number, am: Boolean } | Returns the value. set | value: String|Number|Date | void | Sets the value. open | | void | Opens the picker. close | | void | Closes the picker. toggle | | void | Toggles the picker. save | | void | Saves the selection. cancel | | void | Cancels the selection. destroy | | void | Destroys the picker.

Events

Event | Description ----- | ----------- wdp.change | Fires when the value changes. wdp.open | Fires when the picker opens. wdp.close | Fires when the picker closes. wdp.save | Fires when the selection is saved. wdp.cancel | Fires when the picker is closed without being saved. wdp.destroy | Fires 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.