GithubHelp home page GithubHelp logo

siathalysedi / rome Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bevacqua/rome

0.0 3.0 0.0 932 KB

Dependency free, opt-in UI, customizable date (and time) picker!

Home Page: https://bevacqua.github.io/rome

License: MIT License

rome's Introduction

rome

Dependency free, opt-in UI, customizable date (and time) picker!

Demo!

You can see a live demo here.

screenshot.png

Oh, rome synchronizes in real-time with the input, never steals focus, and its CSS is entirely customizable!

Install

From npm or Bower.

npm install --save rome
bower install --save rome

Note that if you're using the standalone version, the API is published under the rome global. If you're using CJS, then you'll have to require('rome').

API

The API in rome exposes two methods.

rome.find(input)

Finds a previously created Rome calendar. Exactly the same as doing rome(input) after the first time. The difference is that if the first call made on an input is .find you'll get undefined, and if the first call is rome then a Rome calendar will be created and associated to the input. This association can't be undone even by .destroy()ing the rome instance, which can be .restore()d later.

rome(input, options?)

Creates a Rome calendar using a ton of options. These have reasonable defaults that are easy to adjust, too. The options are listed below.

Option Description
autoHideOnClick Hides the calendar when clicking away
appendTo DOM element where the calendar will be appended to. Takes 'parent' as the parent element
autoClose Closes the calendar when picking a day or a time
autoHideOnBlur Hides the calendar when focusing something other than the input field
date The calendar shows days and allows you to navigate between months
dayFormat Format string used to display days on the calendar
inputFormat Format string used for the input field as well as the results of rome
invalidate Ensures the date is valid when the field is blurred
min Disallow dates before min. Takes string, Date, moment
max Disallow dates past max. Takes string, Date, moment
monthFormat Format string used by the calendar to display months and their year
styles CSS classes applied to elements on the calendar
time The calendar shows the current time and allows you to change it using a dropdown
timeFormat Format string used to display the time on the calendar
timeInterval Seconds between each option in the time dropdown

Default Options

If you don't set an option, the default will be used. You can look up the defaults here, or below.

{
  "autoHideOnClick": true,
  "appendTo": document.body,
  "autoClose": true,
  "autoHideOnBlur": true,
  "date": true,
  "dayFormat": "DD",
  "inputFormat": "YYYY-MM-DD HH:mm",
  "invalidate": true,
  "min": null,
  "max": null,
  "monthFormat": "MMMM YYYY",
  "styles": {
    "back": "rd-back",
    "container": "rd-container",
    "date": "rd-date",
    "dayBody": "days-body",
    "dayBodyElem": "day-body",
    "dayDisabled": "day-disabled",
    "dayHead": "days-head",
    "dayHeadElem": "day-head",
    "dayRow": "days-row",
    "dayTable": "rd-days",
    "month": "rd-month",
    "next": "rd-next",
    "selectedDay": "day-selected",
    "selectedTime": "time-selected",
    "time": "rd-time",
    "timeList": "time-list",
    "timeOption": "time-option"
  },
  "time": true,
  "timeFormat": "HH:mm",
  "timeInterval": 1800
}

Rome API

When you create a calendar with rome(input), you'll get a cal instance back. This has a few API methods.

.show()

Shows the calendar by absolutely positioning it right below the input field.

.hide()

Hides the calendar.

.container

The DOM element that contains the calendar.

.input

The input field assigned to this calendar instance.

.getDate()

Returns the current date, as defined by the calendar, in a native Date object.

.getDateString(format?)

Returns the current date, as defined by the calendar, using the provided options.inputFormat format string or a format of your choosing.

.getMoment()

Returns a copy of the moment object underlying the current date in the calendar.

.destroy()

Removes the calendar from the DOM and all of its associated DOM event listeners. The API is reduced to provide only the .restore method described below. After emitting the destroyed event, all event listeners are removed from the instance.

.restore(options?)

Restores the calendar, using the provided options (or the default options). The associated input field can't be changed.

.options(options?)

If an options object is provided, it destroys the calendar and initializes it with the provided options. Effectively the same as calling .restore(options) immediately after calling .destroy().

If no options object is provided, a copy of the current options is returned.

.options.reset()

Resets the options to the factory defaults. Effectively the same as calling .options({}).

Events

Rome calendars also provide a few events you can subscribe to. These events are published through an event emitter created using contra. These events are listed below.

Event Arguments Description
ready [options] The calendar has been .restored
destroyed [] The calendar has been .destroyed
data [value] The date may have been updated by the calendar. Value of .getDateString() is provided
year [year] The year may have been updated by the calendar. Value of moment.year() is provided
month [month] The month may have been updated by the calendar. Value of moment.month() is provided
day [day] The day may have been updated by the calendar. Value of moment.date() is provided
time [time] The time may have been updated by the calendar. Formatted time string is provided

License

MIT

rome's People

Contributors

bevacqua avatar

Watchers

Arnstein Henriksen avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.