Skip to content

Commit 95adc0f

Browse files
committed
[Fix] cant disable negative
1 parent a7bd35d commit 95adc0f

File tree

13 files changed

+281
-252
lines changed

13 files changed

+281
-252
lines changed

.eslintrc.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
module.exports = {
2-
"env": {
3-
"browser": true,
4-
"es2021": true,
5-
"node": true
6-
},
7-
"extends": [
8-
"eslint:recommended",
9-
"plugin:vue/essential"
10-
],
11-
"parserOptions": {
12-
"ecmaVersion": 12,
13-
"sourceType": "module"
14-
},
15-
"plugins": [
16-
"vue"
17-
],
18-
"rules": {
19-
}
20-
};
2+
env: {
3+
node: true,
4+
},
5+
extends: [
6+
'eslint:recommended',
7+
'plugin:vue/vue3-recommended',
8+
'prettier'
9+
],
10+
parserOptions: {
11+
ecmaVersion: 12,
12+
sourceType: 'module',
13+
},
14+
plugins: ['vue'],
15+
rules: {},
16+
}

docs/.vuepress/clientAppEnhance.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import number from "../../src";
2-
import { defineClientAppEnhance } from "@vuepress/client";
3-
import "virtual:windi.css";
1+
import number from '../../src'
2+
import { defineClientAppEnhance } from '@vuepress/client'
3+
import 'virtual:windi.css'
44

55
export default defineClientAppEnhance(({ app }) => {
6-
app.use(number);
7-
});
6+
app.use(number)
7+
})

docs/.vuepress/components/BaseLabel.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<script>
1212
export default {
13-
name: "BaseLabel",
13+
name: 'BaseLabel',
1414
props: {
1515
label: {
1616
type: String,
@@ -21,7 +21,7 @@ export default {
2121
default: undefined,
2222
},
2323
},
24-
};
24+
}
2525
</script>
2626

2727
<style scoped></style>

docs/.vuepress/components/BaseSelect.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<script>
1313
export default {
14-
name: "BaseInput",
14+
name: 'BaseInput',
1515
props: {
1616
modelValue: {
1717
default: undefined,
@@ -21,8 +21,8 @@ export default {
2121
required: false,
2222
},
2323
},
24-
emits: ["update:modelValue"],
25-
};
24+
emits: ['update:modelValue'],
25+
}
2626
</script>
2727

2828
<style scoped></style>

docs/.vuepress/components/Checkbox.vue

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<template>
2-
<label class="flex items-center" :class="{ 'text-gray-300 cursor-not-allowed': disabled, 'cursor-pointer': !disabled }">
2+
<label
3+
class="flex items-center"
4+
:class="{
5+
'text-gray-300 cursor-not-allowed': disabled,
6+
'cursor-pointer': !disabled,
7+
}"
8+
>
39
<input
410
:checked="modelValue"
511
:disabled="disabled"
@@ -18,14 +24,14 @@ export default {
1824
modelValue: Boolean,
1925
disabled: {
2026
type: Boolean,
21-
default: false
27+
default: false,
2228
},
2329
label: {
2430
type: String,
25-
required: true
26-
}
31+
required: true,
32+
},
2733
},
28-
emits: ['update:modelValue']
34+
emits: ['update:modelValue'],
2935
}
3036
</script>
3137

docs/.vuepress/components/Dialog.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<template>
2-
<div v-if="modelValue" class="w-screen h-screen fixed z-50 inset-0 flex bg-gray-600 bg-opacity-50" @click.self="$emit('update:modelValue', false)">
3-
<div class="max-w-md md:relative m-auto p-8 bg-white rounded w-full h-auto shadow">
2+
<div
3+
v-if="modelValue"
4+
class="w-screen h-screen fixed z-50 inset-0 flex bg-gray-600 bg-opacity-50"
5+
@click.self="$emit('update:modelValue', false)"
6+
>
7+
<div
8+
class="max-w-md md:relative m-auto p-8 bg-white rounded w-full h-auto shadow"
9+
>
410
<slot />
511
</div>
612
</div>
@@ -10,8 +16,8 @@
1016
export default {
1117
name: 'Dialog',
1218
props: {
13-
modelValue: Boolean
19+
modelValue: Boolean,
1420
},
15-
emits: ['update:modelValue']
21+
emits: ['update:modelValue'],
1622
}
1723
</script>

docs/.vuepress/styles/index.scss

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
[type="text"],
2-
[type="email"],
3-
[type="url"],
4-
[type="password"],
5-
[type="number"],
6-
[type="date"],
7-
[type="datetime-local"],
8-
[type="month"],
9-
[type="search"],
10-
[type="tel"],
11-
[type="time"],
12-
[type="week"],
1+
[type='text'],
2+
[type='email'],
3+
[type='url'],
4+
[type='password'],
5+
[type='number'],
6+
[type='date'],
7+
[type='datetime-local'],
8+
[type='month'],
9+
[type='search'],
10+
[type='tel'],
11+
[type='time'],
12+
[type='week'],
1313
[multiple],
1414
textarea,
1515
select {

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@
6161
"babel-eslint": "^10.1.0",
6262
"babel-jest": "^27.2.0",
6363
"core-js": "^3.6.5",
64-
"eslint": "^7.32.0",
64+
"eslint": "^8.33.0",
6565
"eslint-plugin-import": "^2.24.2",
66-
"eslint-plugin-vue": "^7.18.0",
66+
"eslint-plugin-vue": "^9.9.0",
6767
"jest": "^27.2.0",
68-
"prettier-config-vuepress": "^1.4.0",
68+
"prettier": "2.8.3",
69+
"prettier-config-vuepress": "^4.0.0",
6970
"rollup": "^2.79.0",
7071
"rollup-plugin-filesize": "^9.1.1",
7172
"rollup-plugin-vue": "^6.0.0",

src/directive.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ export default {
4040
const { target } = e
4141
const regExp = new RegExp(`${config.prefix}|${config.suffix}`, 'g')
4242
let newValue = target.value.replace(regExp, '')
43+
const canNegativeInput = config.min && config.min < 0
4344
if (
4445
([110, 190].includes(e.keyCode) || e.key === config.decimal) &&
4546
newValue.includes(config.decimal)
4647
) {
4748
e.preventDefault()
49+
} else if ([109].includes(e.keyCode) && !canNegativeInput) {
50+
e.preventDefault()
4851
} else if ([8].includes(e.keyCode)) {
4952
// check current cursor position is after separator when backspace key down
5053
const character = el.value.slice(el.selectionEnd - 1, el.selectionEnd)
5154
const replace = el.value.slice(el.selectionEnd - 2, el.selectionEnd)
5255
if (character === config.separator) {
5356
e.preventDefault()
54-
5557
let positionFromEnd = el.value.length - el.selectionEnd
5658
// remove separator and before character
5759
el.value = el.value.replace(replace, '')

src/number-format.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ export default function NumberFormat(config = options) {
3030
}
3131

3232
this.sign = () => {
33+
const hasMinus = this.input.toString().indexOf('-') >= 0
3334
if (this.isClean) {
34-
return this.input.toString().indexOf('-') >= 0 && this.realNumber() > 0
35-
? '-'
36-
: ''
35+
return hasMinus && this.realNumber() > 0 ? '-' : ''
3736
}
38-
return this.input.toString().indexOf('-') >= 0 ? '-' : ''
37+
return hasMinus ? '-' : ''
3938
}
4039

4140
function between(min, n, max) {
@@ -132,12 +131,12 @@ export default function NumberFormat(config = options) {
132131
this.input = input
133132
if (this.isNull() && !this.options.reverseFill)
134133
return this.options.nullValue
135-
return (
136-
this.sign() +
137-
this.options.prefix +
138-
this.addSeparator() +
139-
this.options.suffix
140-
)
134+
return [
135+
this.sign(),
136+
this.options.prefix,
137+
this.addSeparator(),
138+
this.options.suffix,
139+
].join
141140
}
142141

143142
/**

0 commit comments

Comments
 (0)