2.2.1 • Published 4 months ago

tzolkin v2.2.1

Weekly downloads
170
License
(MIT OR Apache-2....
Repository
github
Last release
4 months ago

Tzolkin

React DateTime picker for Real Geeks' LeadManager and beyond!

About the Name

Tzolk'in (Mayan pronunciation: t͡sol ˈkʼin, formerly and commonly tzolkin) is the name bestowed by Mayanists on the 260-day Mesoamerican calendar originated by the Maya civilization of pre-Columbian Mesoamerica.

read more

Install

  npm install tzolkin --save

React/JSX Usage

  { Tzolkin } = require('tzolkin')

  render: => {
    return (
      <div>
        <Tzolkin type="datetime">
          <input defaultValue="3/09/2018" type="input" />
        </Tzolkin>
      </div>
    )
  }

Standard JavaScript or jQuery Usage

HTML:

  <input type='text' name='date' class='select-datetime' />

To prevent any browser Date/Time picker UI, use a standard text input vs date, time or datetime.

TzolkinPlugin v1.x.x JS:

  { TzolkinPlugin } = require('tzolkin');

  TzolkinPlugin.create({
    type: 'datetime',
    input: '.select-datetime'
  })

TzolkinPlugin v2.x.x JS:

  { TzolkinPlugin } = require('tzolkin');

  tz = new TzolkinPlugin().create({
    type: 'datetime',
    input: '.select-datetime'
  })

  // if you need to:
  tz.close()

Multiple Instances

  <label>Date</label>
  <input type='text' name='date' class='select-datetime' />

  <label>Time</label>
  <input type='text' name='time' class='select-datetime' />

If there are multiple inputs which need to use Tzolkin then set input key equal to a JavaScript selected element or have different classes for each and pass just the CSS class as a string.

  { TzolkinPlugin } = require('tzolkin');

  dt_input = document.querySelectorAll('.select-datetime')[0];
  // or $('.select-datetime')[0]
  tm_input = document.querySelectorAll('.select-datetime')[1];
  // or $('.select-datetime')[1]

  TzolkinPlugin.create({ type: 'date', input:  dt_input});
  TzolkinPlugin.create({ type: 'time', input:  tm_input});

Options

OptionData TypeDescriptionAcceptable options
input *DOM element, String<input> to trigger date picker and receive selected date/timedocument.querySelector('.select-date') or '.select-date'
typeStringpicker has date, time or both'date', 'time', 'datetime'
dateStringDate/time for Tzolkin to start with"03/12/2018"
formatStringDate/time format desired using moment.js formating"MM/DD/YYYY h:mm a"
triggerDOM element, Stringlink, span, button, etc to trigger date pickerdocument.querySelector('a.select-date-trigger') or 'a.select-date-trigger'
stepIntegerFor time picker, minutes increments between hours15, 30, etc
minDateStringdisable any dates earlier than this date"01/01/2001"
maxDateStringdisable any dates later than this date"12/31/2025"
disableObjectsee below
onOpencallbacksee below
onSelectcallbacksee below
onClosecallbacksee below

* non-React only

Defaults

All options, minus input are optional and most have a default value that they fall back on if no value is passed in the configurations.

OptionDefaultMore...
type'date'
formatdepends on typedate: "MM/DD/YYYY" datetime: "MM/DD/YYYY h:mm a" time: "h:mm a"
minDate-2 yearsJan 1st of 2 years ago
maxDate+2 yearsDec 31st of 2 years in future

Disabling Dates and Times

Tzolkin allows selected days of week, months, dates, hours and/or years to disable from user selection. This option expects a JavaScript object with one or more of the following keys.

keydescription
yearsa list of years where every day will be disabled
monthsa list of months where every day will be disabled
datesa list of individual dates to be disabled across all months
daysall dates that fall under selected days (Monday, Tuesday, etc)
hoursa list of hours to be disable from selection

Example:

  let disable = {
    years: [2010, 2012, 2014],
    months: ["February", "May"],
    dates: [1, 5, 24],
    days: ["Sunday", "Saturday"],
    hours: ["11am", "12am", "1pm"]
  }

  <Tzolkin type="datetime" disable={disable}>
    <input defaultValue="3/09/2018 9:30 am" type="input"/>
  </Tzolkin>

Callbacks

Tzolkin allows for 3 callbacks occurring at different points in the lifecycle of the date/time picker.

callbackwhen
onOpenduring componentDidMount called on picker component
onSelectcalled immediately after a date or time has been clicked
onCloseduring componentWillUnmount called on picker component

Example:

  Tzolkin.create({
    type: 'datetime',
    input: '.select-datetime',

    onOpen: (date, picker_el, input_el) => {
      console.log("Opening date/time picker");
      console.log(date);
      // ... do something cool ...
    },

    onSelect: (date, picker_el, input_el) => {
      alert("You picked" + date);
      // ... do something EVEN cooler ...
    },

    onClose: (date, picker_el, input_el) => {
      console.log("Closing date/time picker")
      // ... do something mildly entertaining ...
    }
  })
2.2.1

4 months ago

2.2.0

4 months ago

2.2.0-0

4 months ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago