Skip to content

Commit e97f726

Browse files
committed
Support nudge for color value input
1 parent 9e40957 commit e97f726

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

packages/veui/src/components/ColorPicker/_ColorValueAlpha.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
:readonly="readonly"
77
:format="formatPercentage"
88
:parse="parsePercentage"
9+
nudge="percentage"
910
@input="updateAlphaValue"
1011
/>
1112
</div>

packages/veui/src/components/ColorPicker/_ColorValueHsl.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
:readonly="readonly"
77
:format="formatHue"
88
:parse="parseHue"
9+
nudge="hue"
910
@input="handleHueValueInput"
1011
/>
1112
</div>
@@ -15,6 +16,7 @@
1516
:readonly="readonly"
1617
:format="formatPercentage"
1718
:parse="parsePercentage"
19+
nudge="percentage"
1820
@input="handleSaturationValueInput"
1921
/>
2022
</div>
@@ -24,6 +26,7 @@
2426
:readonly="readonly"
2527
:format="formatPercentage"
2628
:parse="parsePercentage"
29+
nudge="percentage"
2730
@input="handleLightnessValueInput"
2831
/>
2932
</div>

packages/veui/src/components/ColorPicker/_ColorValueInput.vue

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
<template>
2-
<veui-input
3-
type="text"
4-
:value="localValue"
5-
:readonly="readonly"
6-
@input="handleValueInput"
7-
@blur="handleValueBlur"
8-
/>
9-
</template>
101

112
<script>
123
import Input from '../Input'
@@ -37,6 +28,9 @@ export default {
3728
parse: {
3829
type: Function,
3930
default: identity
31+
},
32+
nudge: {
33+
type: String
4034
}
4135
},
4236
data () {
@@ -47,6 +41,20 @@ export default {
4741
computed: {
4842
formattedValue () {
4943
return this.format(this.value)
44+
},
45+
directives () {
46+
if (!this.nudge) {
47+
return []
48+
}
49+
return [
50+
{
51+
name: 'nudge',
52+
value: {
53+
update: this.hanleNudgeUpdate
54+
},
55+
modifiers: {}
56+
}
57+
]
5058
}
5159
},
5260
watch: {
@@ -58,6 +66,27 @@ export default {
5866
}
5967
},
6068
methods: {
69+
hanleNudgeUpdate (increase) {
70+
if (Math.abs(increase) < 1) {
71+
return
72+
}
73+
74+
switch (this.nudge) {
75+
case 'hue':
76+
case 'ff':
77+
break
78+
79+
case 'percentage':
80+
increase /= 100
81+
break
82+
83+
default:
84+
return
85+
}
86+
87+
this.handleValueInput(this.format(this.value + increase))
88+
},
89+
6190
handleValueInput (val) {
6291
this.localValue = val
6392
let realValue
@@ -73,6 +102,16 @@ export default {
73102
this.localValue = this.formattedValue
74103
}
75104
}
105+
},
106+
render () {
107+
return (<veui-input
108+
type="text"
109+
value={this.localValue}
110+
readonly={this.readonly}
111+
onInput={this.handleValueInput}
112+
onBlur={this.handleValueBlur}
113+
{...{ directives: this.directives }}
114+
/>)
76115
}
77116
}
78117
</script>

packages/veui/src/components/ColorPicker/_ColorValueRgb.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
:value="rgb.r"
66
:readonly="readonly"
77
:parse="parseFFValue"
8+
nudge="ff"
89
@input="handleRedValueInput"
910
/>
1011
</div>
@@ -14,6 +15,7 @@
1415
:value="rgb.g"
1516
:readonly="readonly"
1617
:parse="parseFFValue"
18+
nudge="ff"
1719
@input="handleGreenValueInput"
1820
/>
1921
</div>
@@ -23,6 +25,7 @@
2325
:value="rgb.b"
2426
:readonly="readonly"
2527
:parse="parseFFValue"
28+
nudge="ff"
2629
@input="handleBlueValueInput"
2730
/>
2831
</div>

0 commit comments

Comments
 (0)