├── static
└── .gitkeep
├── .eslintignore
├── src
├── index.js
├── main.js
├── constValues.js
├── App.vue
└── components
│ ├── OutsideClickHandler.vue
│ ├── PickerPoints.vue
│ ├── TimePickerGenerator.vue
│ ├── TimePicker.vue
│ └── TimePickerModal.vue
├── config
├── prod.env.js
├── test.env.js
├── dev.env.js
└── index.js
├── intro_src
├── 24M.gif
└── 24M.png
├── .babelrc
├── .gitignore
├── test
└── unit
│ ├── .eslintrc
│ ├── specs
│ └── TimePicker.spec.js
│ ├── index.js
│ └── karma.conf.js
├── .editorconfig
├── index.html
├── LICENSE
├── package.json
└── README.md
/static/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | build/*.js
2 | config/*.js
3 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./components/TimePicker.vue')
2 |
--------------------------------------------------------------------------------
/config/prod.env.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | NODE_ENV: '"production"'
3 | }
4 |
--------------------------------------------------------------------------------
/intro_src/24M.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DomonJi/vue-clock-picker/HEAD/intro_src/24M.gif
--------------------------------------------------------------------------------
/intro_src/24M.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DomonJi/vue-clock-picker/HEAD/intro_src/24M.png
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015", "stage-2"],
3 | "plugins": ["transform-runtime"],
4 | "comments": false
5 | }
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | dist/
4 | npm-debug.log
5 | selenium-debug.log
6 | test/unit/coverage
7 | test/e2e/reports
8 |
--------------------------------------------------------------------------------
/config/test.env.js:
--------------------------------------------------------------------------------
1 | var merge = require('webpack-merge')
2 | var devEnv = require('./dev.env')
3 |
4 | module.exports = merge(devEnv, {NODE_ENV: '"testing"'})
5 |
--------------------------------------------------------------------------------
/src/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import App from './App'
3 |
4 | /* eslint-disable no-new */
5 | new Vue({el: '#app', components: {
6 | App
7 | }})
8 |
--------------------------------------------------------------------------------
/test/unit/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "mocha": true
4 | },
5 | "globals": {
6 | "expect": true,
7 | "sinon": true
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/config/dev.env.js:
--------------------------------------------------------------------------------
1 | var merge = require('webpack-merge')
2 | var prodEnv = require('./prod.env')
3 |
4 | module.exports = merge(prodEnv, {NODE_ENV: '"development"'})
5 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/src/constValues.js:
--------------------------------------------------------------------------------
1 | module.exports.HOUR = new Array(24 + 1).join('0').split('')
2 | module.exports.TWELVE_HOURS = new Array(12 + 1).join('0').split('')
3 | module.exports.MINUTES = new Array(60 + 1).join('0').split('')
4 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | vue-time-picker
7 |
8 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/test/unit/specs/TimePicker.spec.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import TimePicker from '../../../src/components/TimePicker.vue'
3 |
4 | describe('TimePicker.vue', () => {
5 | it('hour and minute has lengthOf 2', () => {
6 | const timePicker = Vue.extend(TimePicker)
7 | const vm = new timePicker().$mount()
8 | expect(vm.hourString).to.have.lengthOf(2)
9 | expect(vm.minuteString).to.have.lengthOf(2)
10 | })
11 | }})
12 |
--------------------------------------------------------------------------------
/test/unit/index.js:
--------------------------------------------------------------------------------
1 | // Polyfill fn.bind() for PhantomJS
2 | /* eslint-disable no-extend-native */
3 | Function.prototype.bind = require('function-bind')
4 |
5 | // require all test files (files that ends with .spec.js)
6 | var testsContext = require.context('./specs', true, /\.spec$/)
7 | testsContext.keys().forEach(testsContext)
8 |
9 | // require all src files except main.js for coverage.
10 | // you can also change this to match only the subset of files that
11 | // you want coverage for.
12 | var srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/)
13 | srcContext.keys().forEach(srcContext)
14 |
--------------------------------------------------------------------------------
/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | div(id="app")
4 | time-picker
5 |
6 |
7 |
8 |
16 |
17 |
42 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Domon
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 |
--------------------------------------------------------------------------------
/src/components/OutsideClickHandler.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | div(ref="childnode" class="outside-click-container" @mouseover="overModal=true" @mouseout="overModal=false")
4 | slot(name="modal")
5 |
6 |
7 |
8 |
40 |
41 |
52 |
--------------------------------------------------------------------------------
/config/index.js:
--------------------------------------------------------------------------------
1 | // see http://vuejs-templates.github.io/webpack for documentation.
2 | var path = require('path')
3 |
4 | module.exports = {
5 | build: {
6 | env: require('./prod.env'),
7 | index: path.resolve(__dirname, '../dist/index.html'),
8 | assetsRoot: path.resolve(__dirname, '../dist'),
9 | assetsSubDirectory: 'static',
10 | assetsPublicPath: '/',
11 | productionSourceMap: true,
12 | // Gzip off by default as many popular static hosts such as
13 | // Surge or Netlify already gzip all static assets for you.
14 | // Before setting to `true`, make sure to:
15 | // npm install --save-dev compression-webpack-plugin
16 | productionGzip: false,
17 | productionGzipExtensions: ['js', 'css']
18 | },
19 | dev: {
20 | env: require('./dev.env'),
21 | port: 8080,
22 | assetsSubDirectory: 'static',
23 | assetsPublicPath: '/',
24 | proxyTable: {},
25 | // CSS Sourcemaps off by default because relative paths are "buggy"
26 | // with this option, according to the CSS-Loader README
27 | // (https://github.com/webpack/css-loader#sourcemaps)
28 | // In our experience, they generally work as expected,
29 | // just be aware of this issue when enabling this option.
30 | cssSourceMap: false
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/components/PickerPoints.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | div(':style'="inlineStyle" '@click'="handleTimeChange(index,angle)" class="picker-point" ':class'="[pointClass,{current:picked}]")
4 | div(class="pointer-wrapper" ':style'="wrapperStyle") {{index}}
5 |
6 |
7 |
8 |
53 |
54 |
82 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-clock-picker",
3 | "version": "0.4.1",
4 | "description": "A lite time picker based on Vue2.0",
5 | "author": "domon ",
6 | "scripts": {
7 | "dev": "node build/dev-server.js",
8 | "build": "node build/build.js",
9 | "unit": "karma start test/unit/karma.conf.js --single-run",
10 | "test": "npm run unit"
11 | },
12 | "main": "./src/index.js",
13 | "dependencies": {
14 | "babel-preset-es2015": "^6.22.0",
15 | "babel-runtime": "^6.0.0",
16 | "pug": "^2.0.0-beta6",
17 | "vue": "^2.0.0-rc.6",
18 | "vue-loader": "^9.4.0"
19 | },
20 | "devDependencies": {
21 | "babel-core": "^6.0.0",
22 | "babel-loader": "^6.0.0",
23 | "babel-plugin-transform-runtime": "^6.0.0",
24 | "babel-preset-stage-2": "^6.0.0",
25 | "babel-register": "^6.0.0",
26 | "chai": "^3.5.0",
27 | "connect-history-api-fallback": "^1.1.0",
28 | "css-loader": "^0.23.0",
29 | "eventsource-polyfill": "^0.9.6",
30 | "express": "^4.13.3",
31 | "extract-text-webpack-plugin": "^1.0.1",
32 | "file-loader": "^0.8.4",
33 | "function-bind": "^1.0.2",
34 | "html-webpack-plugin": "^2.8.1",
35 | "http-proxy-middleware": "^0.12.0",
36 | "inject-loader": "^2.0.1",
37 | "isparta-loader": "^2.0.0",
38 | "json-loader": "^0.5.4",
39 | "karma": "^0.13.15",
40 | "karma-coverage": "^0.5.5",
41 | "karma-mocha": "^0.2.2",
42 | "karma-phantomjs-launcher": "^1.0.0",
43 | "karma-sinon-chai": "^1.2.0",
44 | "karma-sourcemap-loader": "^0.3.7",
45 | "karma-spec-reporter": "0.0.24",
46 | "karma-webpack": "^1.7.0",
47 | "lolex": "^1.4.0",
48 | "mocha": "^3.0.2",
49 | "node-sass": "^3.10.0",
50 | "ora": "^0.2.0",
51 | "phantomjs-prebuilt": "^2.1.3",
52 | "sass-loader": "^4.0.2",
53 | "shelljs": "^0.6.0",
54 | "sinon": "^1.17.3",
55 | "sinon-chai": "^2.8.0",
56 | "url-loader": "^0.5.7",
57 | "vue-hot-reload-api": "^1.2.0",
58 | "vue-html-loader": "^1.0.0",
59 | "vue-loader": "^9.4.0",
60 | "vue-style-loader": "^1.0.0",
61 | "webpack": "^1.13.2",
62 | "webpack-dev-middleware": "^1.8.1",
63 | "webpack-hot-middleware": "^2.6.0",
64 | "webpack-merge": "^0.8.3"
65 | },
66 | "license": "MIT",
67 | "repository": "https://github.com/domonji/vue-clock-picker"
68 | }
69 |
--------------------------------------------------------------------------------
/test/unit/karma.conf.js:
--------------------------------------------------------------------------------
1 | // This is a karma config file. For more details see
2 | // http://karma-runner.github.io/0.13/config/configuration-file.html
3 | // we are also using it with karma-webpack
4 | // https://github.com/webpack/karma-webpack
5 |
6 | var path = require('path')
7 | var merge = require('webpack-merge')
8 | var baseConfig = require('../../build/webpack.base.conf')
9 | var utils = require('../../build/utils')
10 | var webpack = require('webpack')
11 | var projectRoot = path.resolve(__dirname, '../../')
12 |
13 | var webpackConfig = merge(baseConfig, {
14 | // use inline sourcemap for karma-sourcemap-loader
15 | module: {
16 | loaders: utils.styleLoaders()
17 | },
18 | devtool: '#inline-source-map',
19 | vue: {
20 | loaders: {
21 | js: 'isparta'
22 | }
23 | },
24 | plugins: [
25 | new webpack.DefinePlugin({
26 | 'process.env': require('../../config/test.env')
27 | })
28 | ]
29 | })
30 |
31 | // no need for app entry during tests
32 | delete webpackConfig.entry
33 |
34 | // make sure isparta loader is applied before eslint
35 | webpackConfig.module.preLoaders = webpackConfig.module.preLoaders || []
36 | webpackConfig.module.preLoaders.unshift({
37 | test: /\.js$/,
38 | loader: 'isparta',
39 | include: path.resolve(projectRoot, 'src')
40 | })
41 |
42 | // only apply babel for test files when using isparta
43 | webpackConfig.module.loaders.some(function (loader, i) {
44 | if (loader.loader === 'babel') {
45 | loader.include = path.resolve(projectRoot, 'test/unit')
46 | return true
47 | }
48 | })
49 |
50 | module.exports = function (config) {
51 | config.set({
52 | // to run in additional browsers:
53 | // 1. install corresponding karma launcher
54 | // http://karma-runner.github.io/0.13/config/browsers.html
55 | // 2. add it to the `browsers` array below.
56 | browsers: ['PhantomJS'],
57 | frameworks: ['mocha', 'sinon-chai'],
58 | reporters: ['spec', 'coverage'],
59 | files: ['./index.js'],
60 | preprocessors: {
61 | './index.js': ['webpack', 'sourcemap']
62 | },
63 | webpack: webpackConfig,
64 | webpackMiddleware: {
65 | noInfo: true
66 | },
67 | coverageReporter: {
68 | dir: './coverage',
69 | reporters: [
70 | { type: 'lcov', subdir: '.' },
71 | { type: 'text-summary' }
72 | ]
73 | }
74 | })
75 | }
76 |
--------------------------------------------------------------------------------
/src/components/TimePickerGenerator.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | div
4 | div(v-if="type=='minute'" id="picker-pointer-container")
5 | picker-points(v-for="(m,i) in MINUTES" v-if="i%5==0" ':index'="i" ':key'="i" ':angle'="6*i" ':handle-time-change'="handleTimePointerClick" ':picked'="i==minute")
6 | div(v-else id="picker_pointer_container")
7 | picker-points(v-for="(h,i) in TWELVE_HOURS" ':index'="interval=='AM'?i:i+12" ':key'="interval=='AM'?i:i+12" ':angle'="30*i" ':handle-time-change'="handleTimePointerClick" ':picked'="interval=='AM'?i==hour:(i+12)==hour")
8 | div(class="interval-container")
9 | span(@click="handleIntervalChange('AM')" class="time-picker-interval" ':class'="{active:interval=='AM'}") AM
10 | | |
11 | span(@click="handleIntervalChange('PM')" class="time-picker-interval" ':class'="{active:interval=='PM'}") PM
12 |
13 |
14 |
15 |
64 |
65 |
92 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Vue-Clock-Picker
2 |
3 | [](https://badge.fury.io/js/vue-clock-picker) [](http://standardjs.com) [](https://github.com/DomonJi/vue-clock-picker/blob/master/LICENSE)
4 |
5 | [](https://nodei.co/npm/vue-clock-picker/)
6 |
7 | > A lite time picker vue-component, writing in es6 standrad style.
8 |
9 | ## SHOW
10 |
11 | > 24 Hours Mode, with Material Design. Try the [Live Demo](https://domonji.github.io/vue-clock-picker)
12 |
13 |  
14 |
15 | Until now, this component has only one theme -- The Material Theme. I'll working on more themes later.
16 |
17 | ## HAVE A TRY
18 |
19 | ```bash
20 | $ git clone https://github.com/DomonJi/vue-clock-picker.git
21 |
22 | $ npm install
23 |
24 | $ npm run dev
25 | ```
26 |
27 | ## INSTALL
28 |
29 | ```bash
30 | $ npm install vue-clock-picker
31 | ```
32 |
33 | dependencies:
34 |
35 | - [`vue@^2.0.0`](https://github.com/vuejs/vue)
36 | - [`pug@^2.0.0`](https://github.com/pugjs/pug)
37 | - [`vue-loader@^9.4.0`](https://github.com/vuejs/vue-loader)
38 |
39 | ## USAGE
40 |
41 | ```html
42 |
43 |
44 |
45 |
46 |
51 |
52 |
53 |
54 |
55 |
58 | ```
59 |
60 | ```javascript
61 |
80 | ```
81 |
82 | > For more detail, you can see the source code.
83 |
84 | ## APIS
85 |
86 | ### Props
87 |
88 | - `defaultHour`
89 | - `defaultMinute`
90 |
91 | `String or Number`
92 |
93 | ```javascript
94 | defaultHour="12"
95 | ```
96 |
97 | - `defaultFocused`
98 |
99 | `Boolean`
100 |
101 | Whether the picker pannel is focused or not when it did mount. Default `false`
102 |
103 | ```javascript
104 | defaultFocused="false"
105 | ```
106 |
107 | - `onFocusChange`
108 |
109 | `Function`
110 |
111 | The callback func when component `focused` state is changed.
112 |
113 | - `onHourChange`
114 |
115 | `Function`
116 |
117 | The callback func when component `hour` state is changed.
118 |
119 | ```javascript
120 | onHourChange(hour) {
121 | // ...
122 | }
123 | ```
124 |
125 | - `onMinuteChange`
126 |
127 | `Function`
128 |
129 | The callback func when component `minute` state is changed.
130 |
131 | ```javascript
132 | onMinuteChange(minute) {
133 | // ...
134 | }
135 | ```
136 |
137 | - `onTimeChange`
138 |
139 | `Function`
140 |
141 | The callback func when component `hour` or `minute` is changed.
142 |
143 | ```javascript
144 | onTimeChange(time) {
145 | let { hour, minute } = time
146 | // ...
147 | }
148 | ```
149 |
150 | ## TODOS
151 |
152 | - Test
153 |
154 | - [x] TimePicker Component
155 | - [x] PickerPointGenerator Component
156 | - [x] TimePickerModal Component
157 | - [x] PickerPoint Component
158 | - [ ] OutsideClickHandler Component
159 |
160 | - Themes
161 |
162 | - [x] Material Theme
163 | - [ ] Classical Theme
164 |
165 | - Mode
166 |
167 | - [ ] 12h mode
168 | - [x] 24h mode
169 |
170 | - Animations
171 |
172 | - [x] Panel Animations
173 | - [ ] PickerModal Animations
174 |
175 | ## THANK
176 |
177 | Thanks to the Ecmadao's open source project: [react-times](https://github.com/ecmadao/react-times), I have learn a lot from that. Thanks.
178 |
--------------------------------------------------------------------------------
/src/components/TimePicker.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {{hourString}}:{{minuteString}}
6 |
7 |
8 |
9 |
14 |
15 |
16 |
17 |
18 |
117 |
118 |
156 |
--------------------------------------------------------------------------------
/src/components/TimePickerModal.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 | div(class="time-picker-modal-container")
4 | div(class="time-picker-modal-header")
5 | span(@click="handleStepChange(0)" class="time-picker-header" ':class'="{active:!step}") {{hourString}}
6 | | :
7 | span(@click="handleStepChange(1)" class="time-picker-header" ':class'="{active:step}") {{minuteString}}
8 | div(class="picker-container")
9 | time-picker-generator(':handle-time-pointer-click'="handleTimePointerClick" ':type'="timeType" ':hour'="hour" ':minute'="minute")
10 |
11 |
12 |
13 |
110 |
111 |
179 |
--------------------------------------------------------------------------------