├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .gitignore ├── LICENSE ├── README.md ├── bower.json ├── example ├── dist │ ├── .gitignore │ ├── bundle.js │ ├── common.js │ ├── example.css │ ├── example.js │ └── index.html └── src │ ├── .gitignore │ ├── example.js │ ├── example.less │ └── index.html ├── gulpfile.js ├── package.json └── src └── TimePicker.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs 2 | # editorconfig.org 3 | root = true 4 | 5 | [*] 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = false 9 | insert_final_newline = true 10 | indent_style = tab 11 | 12 | [*.json] 13 | indent_style = space 14 | indent_size = 2 15 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | .publish/* 2 | dist/* 3 | example/dist/* 4 | lib/* 5 | node_modules/* 6 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "env": { 4 | "browser": true, 5 | "node": true 6 | }, 7 | "plugins": [ 8 | "react" 9 | ], 10 | "rules": { 11 | "curly": [2, "multi-line"], 12 | "quotes": [2, "single", "avoid-escape"], 13 | "react/display-name": 0, 14 | "react/jsx-boolean-value": 1, 15 | "react/jsx-quotes": 1, 16 | "react/jsx-no-undef": 1, 17 | "react/jsx-sort-props": 0, 18 | "react/jsx-sort-prop-types": 1, 19 | "react/jsx-uses-react": 1, 20 | "react/jsx-uses-vars": 1, 21 | "react/no-did-mount-set-state": 1, 22 | "react/no-did-update-set-state": 1, 23 | "react/no-multi-comp": 1, 24 | "react/no-unknown-property": 1, 25 | "react/prop-types": 1, 26 | "react/react-in-jsx-scope": 1, 27 | "react/self-closing-comp": 1, 28 | "react/wrap-multilines": 1, 29 | "semi": 2, 30 | "strict": 0 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # nyc test coverage 19 | .nyc_output 20 | 21 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 22 | .grunt 23 | 24 | # node-waf configuration 25 | .lock-wscript 26 | 27 | # Compiled binary addons (http://nodejs.org/api/addons.html) 28 | build/Release 29 | 30 | # Dependency directories 31 | node_modules 32 | jspm_packages 33 | 34 | # Optional npm cache directory 35 | .npm 36 | 37 | # Optional REPL history 38 | .node_repl_history 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Luke Wilson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TimePicker 2 | 3 | ## THIS PACKAGE IS DEPRECATED AND NO LONGER MAINTAINED.# 4 | 5 | A really simple TimePicker dropdown component that lets you set the gap (step) between times, set earliest and latest limits for your range, attach a change handler and set a default value. 6 | 7 | ## Demo & Examples 8 | 9 | ![](http://g.recordit.co/hD6wmPCfOu.gif) 10 | 11 | Live demo: [luke-wilson.github.io/basic-react-timepicker](http://luke-wilson.github.io/basic-react-timepicker/) 12 | 13 | To build the examples locally, run: 14 | 15 | ``` 16 | npm install 17 | npm start 18 | ``` 19 | 20 | Then open [`localhost:8000`](http://localhost:8000) in a browser. 21 | 22 | ## Installation 23 | 24 | The easiest way to use basic-react-timepicker is to install it from NPM and include it in your own React build process (using [Browserify](http://browserify.org), [Webpack](http://webpack.github.io/), etc). 25 | 26 | You can also use the standalone build by including `dist/basic-react-timepicker.js` in your page. If you use this, make sure you have already included React, and it is available as a global variable. 27 | 28 | ``` 29 | npm install basic-react-timepicker --save 30 | ``` 31 | 32 | ## Usage 33 | 34 | _Prop Types:_ 35 | **defaultValue** Passing a time value as a string here (e.g. "2:30PM") will make that the default selected value 36 | 37 | **onChange** This is the callback that fires when the user selects a time 38 | 39 | **name** The name of the select element 40 | 41 | **beginLimit** This sets the earliest time in the dropdown. Default value is "12:00AM"- string 42 | 43 | **endLimit** This sets the latest time in the dropdown. Default value is "11:45PM" - string 44 | 45 | **step** Number - this sets the time between steps. Default value is 15 minutes. 46 | 47 | #Examples 48 | 49 | ``` 50 | var TimePicker = require('basic-react-timepicker'); 51 | 52 | //Default: 53 | 54 | //or 55 | 56 | 57 | //With a default value selected (2:30PM) 58 | 59 | 60 | //With a 60 min step between times 61 | 62 | 63 | //With change handler 64 | 65 | 66 | //With beginning and ending limits (3:00PM to 6:00PM) 67 | 68 | 69 | ``` 70 | 71 | ## Development (`src`, `lib` and the build process) 72 | 73 | **NOTE:** The source code for the component is in `src`. A transpiled CommonJS version (generated with Babel) is available in `lib` for use with node.js, browserify and webpack. A UMD bundle is also built to `dist`, which can be included without the need for any build system. 74 | 75 | To build, watch and serve the examples (which will also watch the component source), run `npm start`. If you just want to watch changes to `src` and rebuild `lib`, run `npm run watch` (this is useful if you are working with `npm link`). 76 | 77 | ## License 78 | 79 | MIT License 80 | 81 | Copyright (c) 2017 Luke Wilson. 82 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "basic-react-timepicker", 3 | "version": "0.0.0", 4 | "description": "TimePicker", 5 | "main": "dist/basic-react-timepicker.min.js", 6 | "homepage": "https://github.com/luke-wilson/basic-react-timepicker", 7 | "authors": [ 8 | "Luke Wilson" 9 | ], 10 | "moduleType": [ 11 | "amd", 12 | "globals", 13 | "node" 14 | ], 15 | "keywords": [ 16 | "react", 17 | "react-component" 18 | ], 19 | "license": "MIT", 20 | "ignore": [ 21 | ".editorconfig", 22 | ".gitignore", 23 | "package.json", 24 | "src", 25 | "node_modules", 26 | "example", 27 | "test" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /example/dist/.gitignore: -------------------------------------------------------------------------------- 1 | ## This file is here to ensure it is included in the gh-pages branch, 2 | ## when `gulp deploy` is used to push updates to the demo site. 3 | 4 | # Dependency directory 5 | node_modules 6 | -------------------------------------------------------------------------------- /example/dist/example.css: -------------------------------------------------------------------------------- 1 | /* 2 | // Examples Stylesheet 3 | // ------------------- 4 | */ 5 | body { 6 | font-family: Helvetica Neue, Helvetica, Arial, sans-serif; 7 | font-size: 14px; 8 | color: #333; 9 | margin: 0; 10 | padding: 0; 11 | } 12 | a { 13 | color: #08c; 14 | text-decoration: none; 15 | } 16 | a:hover { 17 | text-decoration: underline; 18 | } 19 | .container { 20 | margin-left: auto; 21 | margin-right: auto; 22 | max-width: 720px; 23 | padding: 1em; 24 | } 25 | .footer { 26 | margin-top: 50px; 27 | border-top: 1px solid #eee; 28 | padding: 20px 0; 29 | font-size: 12px; 30 | color: #999; 31 | } 32 | h1, 33 | h2, 34 | h3, 35 | h4, 36 | h5, 37 | h6 { 38 | color: #222; 39 | font-weight: 100; 40 | margin: 0.5em 0; 41 | } 42 | label { 43 | color: #999; 44 | display: inline-block; 45 | font-size: 0.85em; 46 | font-weight: bold; 47 | margin: 1em 0; 48 | text-transform: uppercase; 49 | } 50 | .hint { 51 | margin: 15px 0; 52 | font-style: italic; 53 | color: #999; 54 | } 55 | -------------------------------------------------------------------------------- /example/dist/example.js: -------------------------------------------------------------------------------- 1 | require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 2 | 3 | TimePicker 4 | 5 | 6 | 7 |
8 |

TimePicker

9 |

View project on GitHub

10 | 11 |
12 |
13 | 14 |
15 | 18 |
19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /example/src/.gitignore: -------------------------------------------------------------------------------- 1 | ## This file is here to ensure it is included in the gh-pages branch, 2 | ## when `gulp deploy` is used to push updates to the demo site. 3 | 4 | # Dependency directory 5 | node_modules 6 | -------------------------------------------------------------------------------- /example/src/example.js: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | var ReactDOM = require('react-dom'); 3 | var TimePicker = require('basic-react-timepicker'); 4 | 5 | var App = React.createClass({ 6 | render () { 7 | return ( 8 |
9 |
10 |

Default

11 | 12 |
13 |
14 |

With a default value selected (2:30PM)

15 | 16 |
17 |
18 |

With 60 min step

19 | 20 |
21 |
22 |

With change handler

23 | alert('a change was made!')} /> 24 |
25 |
26 |

With beginning and ending limits (3:00PM to 6:00PM)

27 | 28 |
29 |
30 | ); 31 | } 32 | }); 33 | 34 | ReactDOM.render(, document.getElementById('app')); 35 | -------------------------------------------------------------------------------- /example/src/example.less: -------------------------------------------------------------------------------- 1 | /* 2 | // Examples Stylesheet 3 | // ------------------- 4 | */ 5 | 6 | body { 7 | font-family: Helvetica Neue, Helvetica, Arial, sans-serif; 8 | font-size: 14px; 9 | color: #333; 10 | margin: 0; 11 | padding: 0; 12 | } 13 | 14 | a { 15 | color: #08c; 16 | text-decoration: none; 17 | } 18 | 19 | a:hover { 20 | text-decoration: underline; 21 | } 22 | 23 | .container { 24 | margin-left: auto; 25 | margin-right: auto; 26 | max-width: 720px; 27 | padding: 1em; 28 | } 29 | 30 | .footer { 31 | margin-top: 50px; 32 | border-top: 1px solid #eee; 33 | padding: 20px 0; 34 | font-size: 12px; 35 | color: #999; 36 | } 37 | 38 | h1, h2, h3, h4, h5, h6 { 39 | color: #222; 40 | font-weight: 100; 41 | margin: 0.5em 0; 42 | } 43 | 44 | label { 45 | color: #999; 46 | display: inline-block; 47 | font-size: 0.85em; 48 | font-weight: bold; 49 | margin: 1em 0; 50 | text-transform: uppercase; 51 | } 52 | 53 | .hint { 54 | margin: 15px 0; 55 | font-style: italic; 56 | color: #999; 57 | } 58 | -------------------------------------------------------------------------------- /example/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | TimePicker 4 | 5 | 6 | 7 |
8 |

TimePicker

9 |

View project on GitHub

10 | 11 |
12 |
13 | 14 |
15 | 18 |
19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var initGulpTasks = require('react-component-gulp-tasks'); 3 | 4 | /** 5 | * Tasks are added by the react-component-gulp-tasks package 6 | * 7 | * See https://github.com/JedWatson/react-component-gulp-tasks 8 | * for documentation. 9 | * 10 | * You can also add your own additional gulp tasks if you like. 11 | */ 12 | 13 | var taskConfig = { 14 | 15 | component: { 16 | name: 'TimePicker', 17 | dependencies: [ 18 | 'classnames', 19 | 'react', 20 | 'react-dom' 21 | ], 22 | lib: 'lib' 23 | }, 24 | 25 | example: { 26 | src: 'example/src', 27 | dist: 'example/dist', 28 | files: [ 29 | 'index.html', 30 | '.gitignore' 31 | ], 32 | scripts: [ 33 | 'example.js' 34 | ], 35 | less: [ 36 | 'example.less' 37 | ] 38 | } 39 | 40 | }; 41 | 42 | initGulpTasks(gulp, taskConfig); 43 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "basic-react-timepicker", 3 | "version": "1.0.0", 4 | "description": "TimePicker", 5 | "main": "lib/TimePicker.js", 6 | "author": "Luke Wilson", 7 | "homepage": "https://github.com/luke-wilson/basic-react-timepicker", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/luke-wilson/basic-react-timepicker.git" 11 | }, 12 | "bugs": { 13 | "url": "https://github.com/luke-wilson/basic-react-timepicker/issues" 14 | }, 15 | "dependencies": { 16 | "classnames": "^2.1.2", 17 | "moment": "^2.18.1" 18 | }, 19 | "devDependencies": { 20 | "babel-eslint": "^4.1.3", 21 | "eslint": "^1.6.0", 22 | "eslint-plugin-react": "^3.5.1", 23 | "gulp": "^3.9.0", 24 | "react": "^0.14.0", 25 | "react-component-gulp-tasks": "^0.7.6", 26 | "react-dom": "^0.14.0" 27 | }, 28 | "peerDependencies": { 29 | "react": "^0.14.0" 30 | }, 31 | "browserify-shim": { 32 | "react": "global:React" 33 | }, 34 | "scripts": { 35 | "build": "gulp clean && NODE_ENV=production gulp build", 36 | "examples": "gulp dev:server", 37 | "lint": "eslint ./; true", 38 | "publish:site": "NODE_ENV=production gulp publish:examples", 39 | "release": "NODE_ENV=production gulp release", 40 | "start": "gulp dev", 41 | "test": "echo \"no tests yet\" && exit 0", 42 | "watch": "gulp watch:lib" 43 | }, 44 | "keywords": [ 45 | "react", 46 | "react-component" 47 | ] 48 | } 49 | -------------------------------------------------------------------------------- /src/TimePicker.js: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | var moment = require('moment'); 3 | 4 | var TimePicker = React.createClass({ 5 | propTypes: { 6 | defaultValue: React.PropTypes.string, 7 | onChange: React.PropTypes.func, 8 | name: React.PropTypes.string, 9 | beginLimit: React.PropTypes.string, 10 | endLimit: React.PropTypes.string, 11 | step: React.PropTypes.number 12 | }, 13 | 14 | isEarlierThanEndLimit: function(timeValue, endLimit, lastValue) { 15 | var timeValueIsEarlier = moment(timeValue, 'h:mmA').diff(moment(endLimit, 'h:mmA')) < 0 16 | var timeValueIsLaterThanLastValue = lastValue === undefined ? true : moment(lastValue, 'h:mmA').diff(moment(timeValue, 'h:mmA')) < 0 17 | return timeValueIsEarlier && timeValueIsLaterThanLastValue; 18 | }, 19 | 20 | render () { 21 | var timeValue = this.props.beginLimit || "12:00AM"; 22 | var lastValue; 23 | var endLimit = this.props.endLimit || "11:59PM"; 24 | var step = this.props.step || 15; 25 | 26 | var options = []; 27 | options.push(); 28 | 29 | while ( this.isEarlierThanEndLimit(timeValue, endLimit, lastValue) ) { 30 | lastValue = timeValue; 31 | console.log(timeValue, moment(timeValue, 'h:mmA').diff(moment(endLimit, 'h:mmA'), 'minutes')); 32 | timeValue = moment(timeValue, 'h:mmA').add(step, 'minutes').format('h:mmA'); 33 | options.push() 34 | } 35 | return( 36 | 39 | ) 40 | } 41 | }); 42 | 43 | export default TimePicker; 44 | --------------------------------------------------------------------------------