All Projects → pglejzer → timepicker-ui

pglejzer / timepicker-ui

Licence: MIT License
timepicker-ui is an easy library with timepicker. Fully wrote with TypeScript. This library is based on Material Design from Google.

Programming Languages

typescript
32286 projects
SCSS
7915 projects
HTML
75241 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to timepicker-ui

Material Discord
Material design theme for Discord
Stars: ✭ 127 (+605.56%)
Mutual labels:  design, material
Material Apex
A Material Design Theme for Oracle APEX
Stars: ✭ 161 (+794.44%)
Mutual labels:  design, material
Arclayout
With Arc Layout explore new styles and approaches on material design
Stars: ✭ 1,662 (+9133.33%)
Mutual labels:  design, material
Materialdesigndemo
A beautiful app designed with Material Design.
Stars: ✭ 1,391 (+7627.78%)
Mutual labels:  design, material
Dialogsheet
An Android library to create fully material designed bottom dialogs similar to the Android Pay app.
Stars: ✭ 236 (+1211.11%)
Mutual labels:  design, material
Materialize
Materialize, a CSS Framework based on Material Design
Stars: ✭ 38,630 (+214511.11%)
Mutual labels:  design, material
Material
A UI/UX framework for creating beautiful applications.
Stars: ✭ 11,870 (+65844.44%)
Mutual labels:  design, material
Materialdesigncolor
This project shows the color in material design
Stars: ✭ 55 (+205.56%)
Mutual labels:  design, material
Shrine Materialdesign2
implementation of Material Design 2 Shrine project
Stars: ✭ 215 (+1094.44%)
Mutual labels:  design, material
React Mdc Web
Material Design Components for React
Stars: ✭ 175 (+872.22%)
Mutual labels:  design, material
Material Design For Bootstrap
Important! A new UI Kit version for Bootstrap 5 is available. Access the latest free version via the link below.
Stars: ✭ 9,463 (+52472.22%)
Mutual labels:  design, material
React Materialui Notifications
Spec compliant notifications for react and material ui users
Stars: ✭ 252 (+1300%)
Mutual labels:  design, material
Vue Mdc
Material web components for Vue.js
Stars: ✭ 1,217 (+6661.11%)
Mutual labels:  design, material
Materialdesigninxamltoolkit
Google's Material Design in XAML & WPF, for C# & VB.Net.
Stars: ✭ 11,603 (+64361.11%)
Mutual labels:  design, material
Fiftyshadesof
An elegant context-care loading placeholder for Android
Stars: ✭ 1,110 (+6066.67%)
Mutual labels:  design, material
Motion
A library used to create beautiful animations and transitions for iOS.
Stars: ✭ 1,726 (+9488.89%)
Mutual labels:  design, material
Material Bottom Nav
A bottom navigation bar adhering to the Material Design specification.
Stars: ✭ 41 (+127.78%)
Mutual labels:  design, material
Material Design Theme
🎨 A ex-theme for Discord according to Google's Material design Guidelines. Now moved to https://github.com/rauenzi/Nox
Stars: ✭ 50 (+177.78%)
Mutual labels:  design, material
Materialdesign2
A beautiful app designed with Material Design 2 using Android X.
Stars: ✭ 170 (+844.44%)
Mutual labels:  design, material
Material Colors Native
Material Colors - A React Native App to Select Material Colors for macOS.
Stars: ✭ 246 (+1266.67%)
Mutual labels:  design, material

timepicker-ui

downloads npm version License

timepicker-ui is an easy library with timepicker. Fully wrote with TypeScript. This library is based on Material Design from Google.

  • Free
  • Easy to use
  • Easy to customize

Click here to see a demo and examples


Desktop version

desktop-version

24h version

desktop-24h


Landspace version

desktop-version


Mobile version

mobile-version

Themes

There is two available version of theme ( radius and straight). Examples show radius version.

Desktop

desktop-crane-radius-version

Landspace

desktop-crane-radius-version-mobile

Mobile

desktop-crane-radius-version-mobile


Installation

Install timepicker-ui in your project.

Yarn

$ yarn add timepicker-ui

NPM

$ npm install timepicker-ui

This library is using font Roboto and material-design icons. Basic options for all icons have been taken from material-icons. If you want to use material-icons you have to add dependencies to your project.

You can alawys change icons to another package if you change options iconClass and iconClassMobile which contains templates for icons. iconClass and iconClassMobile requiare default class timepicker-ui-keyboard-icon.


Usage

Styles

We provide CSS styles built-in but sometimes if you don't use some normalize/reset CSS styles you have to add box-sizing: border-box to your app to display the correct layout.

*,
::after,
::before {
    box-sizing: border-box;
}

ES Modules

In your project you have to import timepicker from package to your JavaScript file.

import { TimepickerUI } from 'timepicker-ui';

UMD

In your html file you have put script tag with path to timepicker-ui.js file. After installing by npm/yarn you can copy the file from node_modules or add a path to this file.

<script src="timepicker-ui.js"></script>
<script src="node_modules/path/timepicker-ui.js"></script>
<script src="/path/timepicker-ui.js"></script>
Information

timepicker-ui has to have a wrapper that has an input inside this wrapper. If you will not add class timepicker-ui to your wrapper, it will be automatically added during initialization.

HTML

<div class="timepicker-ui">
  <input type="text" class="timepicker-ui-input" value="12:00 AM" />
</div>

timepicker-ui has to be created with a new instance with key new. This instance accepts two parameters which first is the wrapper element for timepicker and the second is options that allow customization.

JavaScript

const DOMElement = document.querySelector('.timepicker-ui');
const options = {};
const newTimepicker = new TimepickerUI(DOMElement, options);

By default initialization of timepicker is started when you click on input. If you want to change it you have to add data-open attribute with selector inside and this element has to be inside wrapper.

HTML

<div class="default-class">
  <input type="text" class="timepicker-ui-input" value="12:00 AM" />
  <button class="timepicker-ui-button" data-open="default-class">Open</button>
</div>

JavaScript

const timepicker = document.querySelector('.default-class');
const initTimepicker = new TimepickerUI(timepicker);

timepicker.create();

Options

You can set options by JavaScript or by data-attribute which attribute is a key option. Data-attributes will be overridden by JavaScript options.

HTML

<div
  class="default-class"
  data-am-label="test"
  data-backdrop="false"
  data-ok-label="fine"
>
  <input type="text" class="timepicker-ui-input" value="12:00 AM" />
  <button class="timepicker-ui-button" data-open="default-class">Open</button>
</div>

JavaScript

const timepicker = document.querySelector('.default-class');
const options = { okLabel: 'test', amLabel: 'test1', backdrop: false };
const initTimepicker = new TimepickerUI(timepicker, options);

timepicker.create();

React integration

It is possible to use this library on the React application. It's necessary to use the useRef hook to attach a dom element and add a custom event handler to this ref.

Link to an example with React Hooks.
Link to an example with React Class Component.

import React, { useRef, useEffect, useState, useCallback } from 'react';
import { TimepickerUI } from 'timepicker-ui';

function App(): JSX.Element {
  const tmRef = useRef(null);
  const [inputValue, setInputValue] = useState('12:00 PM');

  const testHandler = useCallback((e: CustomEvent) => {
    setInputValue(`${e.detail.hour}:${e.detail.minutes} ${e.detail.type}`);
  }, []);

  useEffect(() => {
    if (inputValue === "10:00 PM") {
      alert("You selected 10:00 PM");
    }
  }, [inputValue]);

  useEffect(() => {
    const tm = (tmRef.current as unknown) as HTMLDivElement;

    const newPicker = new TimepickerUI(tm, {});
    newPicker.create();

    //@ts-ignore
    tm.addEventListener('accept', testHandler);

    return () => {
      //@ts-ignore
      tm.removeEventListener('accept', testHandler);
    };
  }, [testHandler]);

  return (
    <div className='timepicker-ui' ref={tmRef}>
      <input
        type='test'
        className='timepicker-ui-input'
        defaultValue={inputValue}
      />
    </div>
  );
}

export default App;

Vue integration

This library can be used on Vue too. You have to use this.$refs to attach elements on DOM and add a custom event listener to this element.

Link to an example with Vue 2
Link to an example with Vue 3

<template>
  <div class="hello">
    <div class="timepicker-ui" ref="tm">
      <input v-model="inputValue" type="text" class="timepicker-ui-input" />
    </div>
    {{ inputValue }}
  </div>
</template>

<script>
import { TimepickerUI } from "timepicker-ui";

export default {
  name: "HelloWorld",
  data() {
    return {
      inputValue: "10:10 PM",
    };
  },
  mounted() {
    const test = new TimepickerUI(this.$refs.tm, { enableSwitchIcon: true });
    test.create();

    this.$refs.tm.addEventListener("accept", ({ detail }) => {
      this.inputValue = `${detail.hour}:${detail.minutes} ${detail.type}`;
    });
  },
};
</script>

Table with options

Name Default Type Description
animated true boolean Turn on/off animations on picker on start/close
amLabel AM string You can set custom text to am label
appendModalSelector '' string You can set default selector to append timepicker inside it. Timepicker default append to body
backdrop true boolean Turn on/off backdrop
cancelLabel CANCEL string You can set custom text to cancel button
clockType 12 string You can set type of clock, it contains 2 versions: 12h and 24h
editable false boolean Edit hour/minutes on the web mode. You have set option preventDefault to false.
enableScrollbar false boolean Turn on/off scroll if timepicker is open
enableSwitchIcon false boolean Turn on/off icon to switch desktop/mobile
focusInputAfterCloseModal false boolean Turn on/off focus to input after close modal
hourMobileLabel Hour string You can set custom text to hour label on mobile version
incrementHours 1 nubmer Increment hour by 1, 2, 3 hour
incrementMinutes 1 nubmer Increment minutes by 1, 5, 10, 15 minutes
minuteMobileLabel Minute string You can set custom text to minute label on mobile version
mobile false boolean Turn on mobile version
okLabel OK string You can set custom text to ok label
pmLabel PM string You can set custom text to pm label
preventDefault true boolean You can set on/off defaults events to clock face events
selectTimeLabel Select Time string You can set custom text to select time label on desktop version
switchToMinutesAfterSelectHour true boolean Turn on/off switch to minutes by select hour
iconClass <i class="material-icons timepicker-ui-keyboard-icon"> keyboard </i> string You can set default template to switch desktop.This options is using by default material design icon
iconClassMobile <i class="material-icons timepicker-ui-keyboard-icon"> schedule </i> string You can set default template to switch mobile. This options is using by default material design icon
theme basic string You can set theme to timepicker. Available options: basic, crane-straight, crane-radius

Methods

Methods are custom function what can be used to manually change the behavior of timepicker.

HTML

<div class="timepicker-ui-test">
  <input type="text" class="timepicker-ui-input" value="12:00 AM">
</div>

JavaScript

const timepicker = document.querySelector('timepicker-ui-test');
const init = new TimepickerUI(timepicker);

timepicker.create();

Table with methods

Name Description
create The create method init timepicker
open The open method opens immediately timepicker after init
close Closure method closes the timepicker

Events

Events are custom events triggered when you add some event listeners to your timepicker element. If you want to have a property timepicker/input values you have to use detail to the event object.

HTML

<div class="timepicker-ui-test">
  <input type="text" class="timepicker-ui-input" value="12:00 AM">
</div>

JavaScript

const timepicker = document.querySelector('timepicker-ui-test');
const init = new TimepickerUI(timepicker);

timepicker.create();

timepicker.addEventListener('show', (event) => console.log(event.detail));

Table with events

Name Description
show The event starts if timepicker is showing up
cancel The event starts if timepicker is closing
accept The event starts if timepicker button OK is accepted
update The event starts if mouse/touch events are triggered on a clock face (multiple events)
selectminutemode The event starts if timepicker minute box is clicked
selecthourmode The event starts if timepicker hour box is clicked
selectamtypemode The event starts if timepicker am box is clicked
selectpmtypemode The event starts if timepicker pm box is clicked
geterror The event start if value in the input is wrong

Future Plans

  • validation
  • keyboard accesibilty
  • max/min time options
  • 24h time mode clock face

If you have more good ideas please let me know in issue. I will try to add more useful features. This project is still develop, if you find some bugs please report on the issue page.


License

MIT

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].