All Projects → jannicz → appointment-picker

jannicz / appointment-picker

Licence: MIT License
Appointment Picker - a tiny JavaScript timepicker that helps you pick appointments

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to appointment-picker

Easyappointments
Easy!Appointments is a highly customizable web application that allows customers to book appointments with you via a sophisticated web interface. Moreover, it provides the ability to sync your data with Google Calendar so you can use them with other services. It is an open source project that you can download and install even for commercial use. Easy!Appointments will run smoothly with your existing website as it can be installed in a single folder of the server and of course share an existing database.
Stars: ✭ 2,013 (+4008.16%)
Mutual labels:  time, appointments
Yort.Ntp
A cross platform NTP client library for .Net platforms. Allows you to easily retrieve an accurate, current date & time from internet NTP servers.
Stars: ✭ 35 (-28.57%)
Mutual labels:  time
react-time-ago
Localized relative date/time formatting in React
Stars: ✭ 88 (+79.59%)
Mutual labels:  time
kick-off-web-scraping-python-selenium-beautifulsoup
A tutorial-based introduction to web scraping with Python.
Stars: ✭ 18 (-63.27%)
Mutual labels:  time
TASNET
Time-domain Audio Separation Network (IN PYTORCH)
Stars: ✭ 18 (-63.27%)
Mutual labels:  time
rktree.cljc
Trees where leaves are located both in time and space
Stars: ✭ 15 (-69.39%)
Mutual labels:  time
Language Time
A library that converts Time to its equivalent local languages starting with some basic Nigeria languages(Yoruba, Hausa, Igbo, Efik and English)
Stars: ✭ 51 (+4.08%)
Mutual labels:  time
dogma
Things and stuffs.
Stars: ✭ 22 (-55.1%)
Mutual labels:  time
vue-timeselector
🕒 Simply customizable powerful time picker for Vue.js
Stars: ✭ 41 (-16.33%)
Mutual labels:  time
cftime
Time-handling functionality from netcdf4-python.
Stars: ✭ 53 (+8.16%)
Mutual labels:  time
moment-cache
⏱ Simple utility to cache moment.js results and speed up moment calls.
Stars: ✭ 29 (-40.82%)
Mutual labels:  time
react-picky-date-time
A react component for date time picker. Online demo examples
Stars: ✭ 41 (-16.33%)
Mutual labels:  time
MD DS3231
DS3231 Real Time Clock Library
Stars: ✭ 29 (-40.82%)
Mutual labels:  time
hast-util-reading-time
utility to estimate the reading time
Stars: ✭ 55 (+12.24%)
Mutual labels:  time
macos-receiver
A MacOS TabBar (StatusBar) application that securely receives one-time passwords (OTPs) that you tapped in Raivo for iOS.
Stars: ✭ 44 (-10.2%)
Mutual labels:  time
ad-alexatalkingclock
Alexa (or other Smart Speakers) tell you the time without asking every hour. Please ⭐️if you like my app :)
Stars: ✭ 30 (-38.78%)
Mutual labels:  time
canon-generator
Create and visualize temporal canons a'la Conlon Nancarrow
Stars: ✭ 31 (-36.73%)
Mutual labels:  time
time-api
Nodejs API for Wobbly Time Tracker for the Teams
Stars: ✭ 24 (-51.02%)
Mutual labels:  time
native-app
🍿 🕐 🎞 React Native App for the PCT environment
Stars: ✭ 39 (-20.41%)
Mutual labels:  time
humanize time
Adds the humanize method to reports the approximate distance in time between two Time. humanize supports i18n translations too so it can be used in internationalized apps.
Stars: ✭ 20 (-59.18%)
Mutual labels:  time

Appointment Picker

A lightweight, accessible and customizable javascript timepicker widget

Yet another timepicker? - Advantages

  • no dependencies
  • tiny (6KB minified, 2KB gzipped)
  • only the listed times can be picked or entered, no validation necessary

See Appointment-Picker Demo and Examples

Installation

npm i -S appointment-picker

Setup

When using inside a static HTML file, add both the stylesheet and the script

<link rel="stylesheet" href="css/appointment-picker.css">
<script src="js/appointment-picker.min.js"></script>

<script type="text/javascript">
    new AppointmentPicker(...);
</script>

Import

When using with a module loader, import the node-module

// Webpack (React, Angular, ES6)
import AppointmentPicker from 'appointment-picker';

// CommonJS (Node, Browserify)
const AppointmentPicker = require('appointment-picker');

Initialize the picker using the new keyword

<input id="time" type="text" value="10:00">
var picker = new AppointmentPicker(document.getElementById('time'), {});

Options

The appointment-picker can be configured with options

  • interval sets the interval between appointments in minutes (1-60), if this number gets lower (more possible appointments) the picker will get longer
  • mode the picker can be used in standard 24h hour mode or in 12h mode - the latter uses am/pm postfix
  • minTime sets the minimum hour that can be picked, default is 0 what is eqivalent to 12am
  • maxTime sets the maximum hour that can be picked, default is 24
  • startTime hides all appointments below this hour, default is 0
  • endTime hides all appointments above this hour, default is 24
  • disabled array of disabled appointments, i.e. ['10:30', '1:15pm', ...] - these times cannot be selected or entered and will be skipped using the keyboard arrows
  • large increases the size of the picker and the appointments by setting a is-large modifier
  • leadingZero adds leading zero to single-digit hour if true (i.e. 07:15)
  • allowReset whether a time can be reset once entered
  • title defines the picker's heading
  • templateOuter HTML template that renders the picker's outer frame (usually containing a wrapper and title), must contain {{innerHtml}} placeholder (example)
  • templateInner template for repeated list items (time inputs), must contain at least an input tag, {{time}} and optional {{disabled}} placeholder, i.e. <input type="button" value="{{time}}" {{disabled}}>
  • timeFormat24 custom time format for 24h mode (use placeholder H for hour, M for minute), i.e. H/M could evaluate to 13/45 (example)
  • timeFormat12 custom time format for am/pm mode (use placeholder apm for postfix - the algorithm will remove either the a or the p from the pattern), i.e. H.M AP.M. could evaluate to 1.30 A.M

Note: with startTime and endTime appointments below and above can be visually removed. If startTime is greater than minTime a lower time can still be manually set via the keyboard. On the other hand the picker does not accept lower hours than minTime and higher than maxTime. Manually entered times outside of the defined bounds will be rejected by the picker, no extra validation is therefore needed. Entering an empty string into the input resets the time.

Now you can pass your options into the the AppointmentPicker invocation

var picker = new AppointmentPicker(document.getElementById('time-2'), {
  interval: 30,
  mode: '12h',
  minTime: 09,
  maxTime: 22,
  startTime: 08,
  endTime: 24,
  disabled: ['16:30', '17:00'],
  templateInner: '<li class="appo-picker-list-item {{disabled}}"><input type="button" tabindex="-1" value="{{time}}" {{disabled}}></li>',
  templateOuter: '<span class="appo-picker-title">{{title}}</span><ul class="appo-picker-list">{{innerHtml}}</ul>'
});

Methods

The appointment-picker exposes several functions to change its behaviour from outside (example).

Method Desc.
picker.open() open the picker popup
picker.getTime() get the current time programmatically from a picker instance, returns an object like { h: 14, m: 30, displayTime: '2:30 pm' }
picker.setTime('10:30') set a time of a picker instance (empty string resets the time)
picker.close() close the picker popup
picker.destroy() destroy the picker instance and remove both the markup and all event listeners

Events

Appointment-picker exposes events for hooking into the functionality:

  • change.appo.picker triggered on each successful value change (event example)
  • open.appo.picker is fired each time the picker is opened
  • close.appo.picker is fired each time the picker is closed

Each event contains 2 properties time and displayTime, i.e. event.time: {'h':14,'m':30} and event.displayTime: '2:30 pm'

document.body.addEventListener('change.appo.picker', function(e) { var time = e.time; }, false);

Styling

All appointment-picker styles are namespaced with .appo-picker, i.e. .appo-picker-list-item. You can either copy and modify the provided CSS, or import it using

/* Using sass/scss */
@import '~appointment-picker/css/appointment-picker';

or in your javascript file

// Using a css-loader inside JS (relative path to your node_modules folder)
import '../node_modules/appointment-picker/css/appointment-picker.css';

Accessibility

For screen reader support add both a aria-label and aria-live properties on the input field

<input id="time-1" type="text" aria-live="assertive" aria-label="Use up or down arrow keys to change time">

Browser Support

  • Chrome
  • Firefox
  • Safari (macOS 10 & iOS 9)
  • Edge
  • IE11 / IE10
  • IE9 (with classList polyfill)

Legacy browser support (IE9)

Add the element.classList polyfill by either importing it with a module loader or simply add the polyfill from a CDN in your html head.

Integration

Use as jQuery plugin

If you would like to use the appointment-picker as a jQuery plugin add following code before initializing

$.fn.appointmentPicker = function(options) {
  this.appointmentPicker = new AppointmentPicker(this[0], options);
  return this;
};

Now you can initialize the picker on any text input field using $

<input id="time-1" type="text">
var $picker = $('#time-1').appointmentPicker();

// Or pass in options
$('#time-1').appointmentPicker({
  interval: 15
});

// And access all exposed methods using jQuery
$picker.appointmentPicker.getTime(); // i.e. { h: 15, m: 30, displayTime: '3:30 pm' }

Use with React

Appointment Picker can be easily integrated into a React component. Simply import the node module and use React.createRef() to pass the DOM element when calling new AppointmentPicker (see example)

import AppointmentPicker from 'appointment-picker';

class AppoPicker extends React.Component {

  constructor(props) {
    super(props);
    this.pickerRef = React.createRef();
    this.onTimeSelect = this.onTimeSelect.bind(this);
  }
  
  render() {
    return <input type="text" ref={ this.pickerRef }></input>;
  }

  onTimeSelect(event) {
    console.log(event.time);
  }
  
  componentDidMount() {
    this.picker = new AppointmentPicker(this.pickerRef.current, {});
    this.pickerRef.current.addEventListener('change.appo.picker', this.onTimeSelect);
  }
  
  componentWillUnmount() {
    this.pickerRef.current.removeEventListener('change.appo.picker', this.onTimeSelect);
    this.picker.destroy();
  }
}

Use with Angular

To integrate AppointmentPicker into an Angular component, import it's CSS, create a @ViewChild reference (#pickerInput) and pass it's nativeElement when calling new AppointmentPicker.

/* CSS, SCSS */
@import '~appointment-picker/css/appointment-picker';
<!-- HTML -->
<input #pickerInput type="text">
import AppointmentPicker from 'appointment-picker';

@Component({
  selector: 'xyz-picker',
  templateUrl: './picker.component.html',
  styleUrls: ['./picker.component.scss'],
  // Disable View Encapsulation to pass down the picker's CSS styles
  encapsulation: ViewEncapsulation.None
})
export class PickerComponent implements OnInit, OnDestroy {

  @ViewChild('pickerInput') input: ElementRef;

  picker: AppointmentPicker;

  @HostListener('change.appo.picker', ['$event'])
  onChangeTime(event: any) {
    console.log('change.appo.picker', event.time);
  }

  ngOnInit() {
    this.picker = new AppointmentPicker(this.input.nativeElement, {});
  }

  ngOnDestroy() { this.picker.destroy(); }
}

Author & License

  • Jan Suwart | MIT License
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].