Skip to content
This repository was archived by the owner on Jan 27, 2023. It is now read-only.

Commit 76315b4

Browse files
committed
Init repo
0 parents  commit 76315b4

30 files changed

+2660
-0
lines changed

.babelrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": ["es2015", "stage-2"],
3+
"plugins": ["transform-runtime"],
4+
"comments": false
5+
}

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/*.js
2+
config/*.js

.eslintrc.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
root: true,
3+
parser: 'babel-eslint',
4+
parserOptions: {
5+
sourceType: 'module'
6+
},
7+
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
8+
extends: 'standard',
9+
// required to lint *.vue files
10+
plugins: [
11+
'html'
12+
],
13+
// add your custom rules here
14+
'rules': {
15+
// allow paren-less arrow functions
16+
'arrow-parens': 0,
17+
// allow async-await
18+
'generator-star-spacing': 0,
19+
// allow debugger during development
20+
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
21+
}
22+
}

.gitignore

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Compiled source #
2+
###################
3+
*.com
4+
*.class
5+
*.dll
6+
*.exe
7+
*.o
8+
*.so
9+
10+
# Packages #
11+
############
12+
*.7z
13+
*.dmg
14+
*.gz
15+
*.iso
16+
*.jar
17+
*.rar
18+
*.tar
19+
*.zip
20+
21+
# Cache and logs #
22+
##################
23+
Application/Runtime/Cache/
24+
Application/Runtime/Logs/
25+
Application/Runtime/Temp/
26+
*.log
27+
28+
# OS generated files #
29+
######################
30+
.DS_Store
31+
.DS_Store?
32+
._*
33+
.Spotlight-V100
34+
.Trashes
35+
ehthumbs.db
36+
Thumbs.db
37+
~$*
38+
.editorconfig
39+
40+
# NodeJS Packages #
41+
###################
42+
node_modules
43+
44+
# Bower Packages #
45+
###################
46+
bower
47+
bower_components
48+
49+
50+
# Test and Logs #
51+
###################
52+
npm-debug.log
53+
selenium-debug.log
54+
test/unit/coverage
55+
test/e2e/reports

README.md

+235
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
# Vue2 Time Picker
2+
3+
A dropdown time picker (hour|minute|second) for **Vue 2.x**, with flexible time format support.
4+
5+
> Looking for the Vue 1.x version? Please check the [vue-timepicker](https://github.com/phoenixwong/vue-timepicker) *(Vue 1.x supported)*
6+
7+
## Demo
8+
9+
You can see the **Vue2 Timepicker** in action in the [Demo Page](https://phoenixwong.github.io/vue2-timepicker/)
10+
11+
## Dependencies
12+
13+
[Vue.js](http://vuejs.org/) v2.0+
14+
15+
## Get Started
16+
17+
**Step 1:** Import VueTimepicker
18+
19+
```javascript
20+
// import
21+
import VueTimepicker from 'vue2-timepicker'
22+
23+
// Or, require
24+
var VueTimepicker = require('vue2-timepicker')
25+
26+
```
27+
28+
**Step 2**: Include VueTimepicker in your component
29+
30+
```javascript
31+
var yourComponent = new Vue({
32+
components: { VueTimepicker },
33+
...
34+
})
35+
```
36+
37+
**Step 3**: Then, you can introduce the `vue-timepicker` tag anywhere you like in your component's template
38+
39+
```html
40+
<vue-timepicker></vue-timepicker>
41+
```
42+
43+
## Usage
44+
45+
### Basic Usage
46+
47+
```html
48+
<!-- Default to 24-Hour format HH:mm -->
49+
<vue-timepicker></vue-timepicker>
50+
```
51+
52+
### Customized Time Format
53+
54+
```html
55+
<!-- Show seconds picker -->
56+
<vue-timepicker format="HH:mm:ss"></vue-timepicker>
57+
58+
<!-- 12-hour format, with AM/PM picker -->
59+
<vue-timepicker format="hh:mm A"></vue-timepicker>
60+
61+
<!-- 12-hour format, with seconds picker and am/pm picker -->
62+
<vue-timepicker format="hh:mm:ss a"></vue-timepicker>
63+
```
64+
65+
VueTimepicker will recognizes the following tokens in the format string
66+
67+
Section | Token | Output
68+
---------- | ----- | ---------------
69+
**AM/PM** | A | AM PM
70+
| a | am pm
71+
**Hour** | H | 0 1 ... 22 23
72+
| HH | 00 01 ... 22 23
73+
| h | 1 2 ... 11 12
74+
| hh | 01 02 ... 11 12
75+
| k | 1 2 ... 23 24
76+
| kk | 01 02 ... 23 24
77+
**Minute** | m | 0 1 ... 58 59
78+
| mm | 00 01 ... 58 59
79+
**Second** | s | 0 1 ... 58 59
80+
| ss | 00 01 ... 58 59
81+
82+
> If not set, `format` string will be default to "HH:mm"
83+
84+
### Customized Picker interval
85+
86+
```html
87+
<!-- Show minute picker's value in the form of 0, 5, 10, ... 55, 60 -->
88+
<vue-timepicker :minute-interval="5"></vue-timepicker>
89+
90+
<!-- Show second picker's value in the form of 0, 10, 20, ... 50, 60 -->
91+
<vue-timepicker :second-interval="10"></vue-timepicker>
92+
93+
<!-- Bind interval config with your own data variable -->
94+
<vue-timepicker :minute-interval="yourMinuteInterval"></vue-timepicker>
95+
```
96+
97+
**Note:** Please do remember to add the `:` or `v-bind:` sign before the interval properties
98+
99+
### Hide Clear Button
100+
101+
```html
102+
<vue-timepicker hide-clear-button></vue-timepicker>
103+
```
104+
105+
### Bind Value with `v-model`
106+
107+
```javascript
108+
// e.g. If you want to assign "10:05:00" as the initial value of vue-timepicker
109+
var yourComponent = new Vue({
110+
components: { VueTimepicker },
111+
data: function () {
112+
return {
113+
yourTimeValue: {
114+
HH: "10",
115+
mm: "05",
116+
ss: "00"
117+
},
118+
...
119+
}
120+
},
121+
...
122+
})
123+
```
124+
125+
```html
126+
<!-- HTML -->
127+
<vue-timepicker v-model="yourTimeValue" format="HH:mm:ss"></vue-timepicker>
128+
```
129+
130+
### Get Time Picker's Current Value
131+
132+
**Method 1:** Read value from `v-model`
133+
134+
```html
135+
<!-- In the last section, we've set the initial value (yourTimeValue) to "10:05:00" -->
136+
<vue-timepicker v-model="yourTimeValue" format="HH:mm:ss"></vue-timepicker>
137+
```
138+
139+
```javascript
140+
// Then, open the dropdown picker and pick a new time.
141+
// Like setting to "14:30:15" for example
142+
// Check the value after that
143+
console.log(this.yourTimeValue)
144+
// outputs -> {HH: "14", mm: "30", ss: "15"}
145+
```
146+
147+
**Method 2:** Add `@change` event handler
148+
149+
```html
150+
<!-- A: No argument -->
151+
<vue-timepicker :time-value.sync="yourTimeValue" @change="changeHandler"></vue-timepicker>
152+
153+
<!-- B: Custom arguments -->
154+
<vue-timepicker :time-value.sync="yourTimeValue" @change="otherChangeHandler($event, 'foo', 'bar')"></vue-timepicker>
155+
```
156+
157+
```javascript
158+
// A: No argument
159+
changeHandler (eventData) {
160+
console.log(eventData)
161+
// -> {data: {HH:..., mm:... }}
162+
}
163+
164+
// B: Custom arguments
165+
otherChangeHandler (eventData, yourArg1, yourArg2) {
166+
console.log(eventData)
167+
// -> {data: {HH:..., mm:... }}
168+
console.log(yourArg1)
169+
// -> 'foo'
170+
console.log(yourArg2)
171+
// -> 'bar'
172+
}
173+
```
174+
175+
Unlike `v-model`, which only returns the defined time tokens you provided in the binding variable, the `change` event will return **all** supported formats.
176+
177+
In the example above, when picker is set to "14:30:15" in HH:mm:ss format, `change` event will return the following data:
178+
179+
```javascript
180+
// `@change` event data
181+
{
182+
HH: "14",
183+
H: "14",
184+
hh: "14",
185+
a: "am",
186+
A: "AM",
187+
h: "14",
188+
kk: "14",
189+
k: "14",
190+
m: "30",
191+
mm: "30",
192+
s: "15",
193+
ss: "15"
194+
}
195+
```
196+
197+
Whereas the `v-model` will only return the data with defined tokens
198+
199+
```javascript
200+
// Previously defined variable (`yourTimeValue` in this case) as {HH:..., mm:..., ss:...}
201+
// Hence, the `v-model` returns:
202+
{
203+
HH: "14",
204+
mm: "30",
205+
ss: "15"
206+
}
207+
```
208+
209+
## Props API
210+
211+
Prop | Type | Required | Default Value
212+
--------------------- | --------- | -------- | -------------
213+
**v-model** | _Object_ | no | _undefined_
214+
**format** | _String_ | no | "HH:mm"
215+
**minute-interval** | _Number_ | no | _undefined_
216+
**second-interval** | _Number_ | no | _undefined_
217+
**hide-clear-button** | _Boolean_ | no | false
218+
219+
## Contribution
220+
221+
Please feel free to fork and help developing.
222+
223+
```bash
224+
# install dependencies
225+
npm install
226+
227+
# serve with hot reload at localhost:8080
228+
npm run dev
229+
```
230+
231+
For detailed explanation on how things work, checkout the [webpack guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
232+
233+
## License
234+
235+
[MIT](http://opensource.org/licenses/MIT)

bower.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "vue2-timepicker",
3+
"description": "A dropdown time picker (hour|minute|second) for Vue 2.x, with flexible time format support",
4+
"main": "index.js",
5+
"version": "0.1.0",
6+
"authors": [
7+
"Phoenix Wong <[email protected]>"
8+
],
9+
"license": "MIT",
10+
"keywords": [
11+
"vue",
12+
"vue2",
13+
"time",
14+
"picker",
15+
"dropdown",
16+
"input",
17+
"UI"
18+
],
19+
"homepage": "https://github.com/phoenixwong/vue2-timepicker",
20+
"moduleType": [
21+
"es6",
22+
"node"
23+
],
24+
"ignore": [
25+
"**/.*",
26+
"node_modules",
27+
"bower_components",
28+
"test",
29+
"tests"
30+
]
31+
}

build/demo.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// https://github.com/shelljs/shelljs
2+
require('shelljs/global')
3+
env.NODE_ENV = 'demo'
4+
5+
var path = require('path')
6+
var config = require('../config')
7+
var ora = require('ora')
8+
var webpack = require('webpack')
9+
var webpackConfig = require('./webpack.prod.conf')
10+
11+
console.log(
12+
' Tip:\n' +
13+
' Built files are meant to be served over an HTTP server.\n' +
14+
' Opening index.html over file:// won\'t work.\n'
15+
)
16+
17+
var spinner = ora('building for demo...')
18+
spinner.start()
19+
20+
var assetsPath = path.join(config.demo.assetsRoot, config.demo.assetsSubDirectory)
21+
22+
rm('-rf', assetsPath)
23+
mkdir('-p', assetsPath)
24+
cp('-R', 'static/', assetsPath)
25+
26+
webpack(webpackConfig, function (err, stats) {
27+
spinner.stop()
28+
if (err) throw err
29+
process.stdout.write(stats.toString({
30+
colors: true,
31+
modules: false,
32+
children: false,
33+
chunks: false,
34+
chunkModules: false
35+
}) + '\n')
36+
})

0 commit comments

Comments
 (0)