Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.

Commit d90aea8

Browse files
committed
init
0 parents  commit d90aea8

File tree

13 files changed

+4658
-0
lines changed

13 files changed

+4658
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
*.log

.npmignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
app
2+
dist
3+
*.js
4+
*.lock
5+
*.log
6+
*.yml
7+
.gitignore
8+
.npmignore
9+
tsconfig.json
10+
tslint.json

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"git.ignoreLimitWarning": true
3+
}

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# vue-input-number
2+
3+
> A custom input number component for [Vue.js 2](https://vuejs.org/).
4+
5+
## Install
6+
7+
[Yarn](https://yarnpkg.com/lang/en/)
8+
9+
```sh
10+
yarn add vue-input-number --dev
11+
```
12+
13+
[NPM](https://www.npmjs.com/)
14+
```sh
15+
npm install vue-input-number --save-dev
16+
```
17+
18+
## Prerequisites
19+
20+
- [Vue.js 2](https://vuejs.org/)
21+
22+
## Usage
23+
24+
```html
25+
<template>
26+
27+
<input-number
28+
:step="1"
29+
:min="10"
30+
:max="100"
31+
:maxlength="3"
32+
@onInputNumberChange="onChange"></input-number>
33+
34+
</template>
35+
36+
<script>
37+
export default {
38+
methods: {
39+
onChange (value) {
40+
console.log(value)
41+
}
42+
}
43+
}
44+
</script>
45+
```
46+
47+
In your entry app:
48+
49+
```js
50+
const Vue = require('vue')
51+
52+
Vue.component('vue-input-number', require('vue-input-number'))
53+
54+
const app = new Vue({
55+
el: '#app'
56+
})
57+
```
58+
59+
For more detailed example check out [the app directory](./app).
60+
61+
## Attributes
62+
63+
- __step:__ Step value for increment and decrement the input number value.
64+
- __min:__ Minimum value for input number.
65+
- __max:__ Maximum value for input number.
66+
- __maxlength:__ Maxlength for the input number.
67+
68+
## Events
69+
70+
#### @onInputNumberChange
71+
72+
Event is fired when value is changed.
73+
74+
## License
75+
MIT license
76+
77+
© 2017 [José Luis Quintana](https://git.io/joseluisq)

app/app.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Vue from 'vue'
2+
import InputNumber from '../index.vue'
3+
import App from './app.vue'
4+
5+
Vue.component('input-number', InputNumber)
6+
7+
// tslint:disable-next-line
8+
new Vue({
9+
el: '#app',
10+
render: (h) => h(App)
11+
})

app/app.vue

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<template>
2+
<div>
3+
4+
<h3>Input Number</h3>
5+
6+
<strong>Options:</strong>
7+
8+
<div v-for="opt in getOptions()" :key="opt">
9+
<span style="display:inline-block; width: 100px; text-align:right;">
10+
{{ opt }}:</span> <input type="input" v-model.number="options[opt]">
11+
</div>
12+
13+
<p>
14+
<strong>Try:</strong> <br>
15+
<input-number
16+
:step="options.step"
17+
:min="options.min"
18+
:max="options.max"
19+
:maxlength="options.maxlength"
20+
@onInputNumberChange="inputChange"></input-number>
21+
</p>
22+
23+
<strong>Value:</strong> <span>{{ inputValue }}</span>
24+
25+
</div>
26+
</template>
27+
28+
<script lang="ts">
29+
import Vue from 'vue'
30+
import Component from 'vue-class-component'
31+
32+
interface Options {
33+
step: number,
34+
min: number,
35+
max: number,
36+
maxlength: number
37+
}
38+
39+
@Component
40+
export default class App extends Vue {
41+
options: Options = {
42+
step: 1,
43+
min: 1,
44+
max: 100,
45+
maxlength: 3
46+
}
47+
48+
inputValue: number = 1
49+
50+
getOptions () {
51+
return Object.keys(this.options)
52+
}
53+
54+
inputChange (val: number) {
55+
this.inputValue = val
56+
}
57+
}
58+
</script>
59+
60+
<style>
61+
.v-input-number {
62+
position: relative;
63+
display: block;
64+
overflow: hidden;
65+
width: 175px;
66+
}
67+
.v-input-number * {
68+
box-sizing: border-box;
69+
}
70+
.v-input-number-arrows {
71+
position: absolute;
72+
width: 100%;
73+
top: 0;
74+
right: 0;
75+
}
76+
.v-input-number-arrows > a {
77+
position: absolute;
78+
top: 0;
79+
right: 2px;
80+
background-color: #ccc;
81+
border: 0;
82+
width: 28px;
83+
height: 15px;
84+
line-height: 1;
85+
text-align: center;
86+
cursor: pointer;
87+
}
88+
.v-input-number-arrows > a.v-input-number-up {
89+
top: 2px;
90+
}
91+
.v-input-number-arrows > a.v-input-number-down {
92+
top: 18px;
93+
}
94+
.v-input-number-arrows > a > i {
95+
display: inline-block;
96+
height: 0;
97+
text-indent: -999em;
98+
content: "";
99+
overflow: hidden;
100+
position: relative;
101+
vertical-align: baseline;
102+
width: 0;
103+
border: 4px solid transparent;
104+
}
105+
.v-input-number-arrows > a.v-input-number-up > i {
106+
top: -3px;
107+
border: 4px solid transparent;
108+
border-bottom-color: #333;
109+
}
110+
.v-input-number-arrows > a.v-input-number-down > i {
111+
border-top-color: #333;
112+
}
113+
.v-input-number-input {
114+
display: block;
115+
padding: 5px 25px 5px 0;
116+
font-size: 16px;
117+
background-color: #fff;
118+
border: 1px solid #bbb;
119+
text-align: center;
120+
width: 100%;
121+
height: 35px;
122+
text-align: center;
123+
}
124+
</style>

app/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Vue Input Number</title>
8+
</head>
9+
<body>
10+
</body>
11+
<div id="app"></div>
12+
<script src="bundle.js"></script>
13+
</html>

0 commit comments

Comments
 (0)