Skip to content

Commit

Permalink
Support nudge for color value input
Browse files Browse the repository at this point in the history
  • Loading branch information
599316527 committed Jan 22, 2019
1 parent c7e3fb6 commit 1227e6b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:readonly="readonly"
:format="formatPercentage"
:parse="parsePercentage"
nudge="percentage"
@input="updateAlphaValue"
/>
</div>
Expand Down
3 changes: 3 additions & 0 deletions packages/veui/src/components/ColorPicker/_ColorValueHsl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:readonly="readonly"
:format="formatHue"
:parse="parseHue"
nudge="hue"
@input="handleHueValueInput"
/>
</div>
Expand All @@ -15,6 +16,7 @@
:readonly="readonly"
:format="formatPercentage"
:parse="parsePercentage"
nudge="percentage"
@input="handleSaturationValueInput"
/>
</div>
Expand All @@ -24,6 +26,7 @@
:readonly="readonly"
:format="formatPercentage"
:parse="parsePercentage"
nudge="percentage"
@input="handleLightnessValueInput"
/>
</div>
Expand Down
57 changes: 48 additions & 9 deletions packages/veui/src/components/ColorPicker/_ColorValueInput.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
<template>
<veui-input
type="text"
:value="localValue"
:readonly="readonly"
@input="handleValueInput"
@blur="handleValueBlur"
/>
</template>

<script>
import Input from '../Input'
Expand Down Expand Up @@ -37,6 +28,9 @@ export default {
parse: {
type: Function,
default: identity
},
nudge: {
type: String
}
},
data () {
Expand All @@ -47,6 +41,20 @@ export default {
computed: {
formattedValue () {
return this.format(this.value)
},
directives () {
if (!this.nudge) {
return []
}
return [
{
name: 'nudge',
value: {
update: this.hanleNudgeUpdate
},
modifiers: {}
}
]
}
},
watch: {
Expand All @@ -58,6 +66,27 @@ export default {
}
},
methods: {
hanleNudgeUpdate (increase) {
if (Math.abs(increase) < 1) {
return
}
switch (this.nudge) {
case 'hue':
case 'ff':
break
case 'percentage':
increase /= 100
break
default:
return
}
this.handleValueInput(this.format(this.value + increase))
},
handleValueInput (val) {
this.localValue = val
let realValue
Expand All @@ -73,6 +102,16 @@ export default {
this.localValue = this.formattedValue
}
}
},
render () {
return (<veui-input
type="text"
value={this.localValue}
readonly={this.readonly}
onInput={this.handleValueInput}
onBlur={this.handleValueBlur}
{...{ directives: this.directives }}
/>)
}
}
</script>
3 changes: 3 additions & 0 deletions packages/veui/src/components/ColorPicker/_ColorValueRgb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:value="rgb.r"
:readonly="readonly"
:parse="parseFFValue"
nudge="ff"
@input="handleRedValueInput"
/>
</div>
Expand All @@ -14,6 +15,7 @@
:value="rgb.g"
:readonly="readonly"
:parse="parseFFValue"
nudge="ff"
@input="handleGreenValueInput"
/>
</div>
Expand All @@ -23,6 +25,7 @@
:value="rgb.b"
:readonly="readonly"
:parse="parseFFValue"
nudge="ff"
@input="handleBlueValueInput"
/>
</div>
Expand Down

0 comments on commit 1227e6b

Please sign in to comment.