Skip to content

Commit

Permalink
refactor: Simplify detecting disabled state
Browse files Browse the repository at this point in the history
  • Loading branch information
rkunev committed Dec 1, 2018
1 parent 84a8aa3 commit b83d1f7
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/ColorPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>

<div class="rcp__rotator"
:style="{ 'pointer-events': isDisabled ? 'none' : null }"
:style="{ 'pointer-events': isPressed || !isKnobIn ? 'none' : null }"
@dblclick.self="rotateToMouse"
ref="rotator">
<div class="rcp__knob" :class="isKnobIn ? 'in' : 'out'" @transitionend="hidePalette"></div>
Expand Down Expand Up @@ -57,7 +57,6 @@
isPressed: false,
isRippling: false,
isDragging: false,
isDisabled: false,
}
},
computed: {
Expand Down Expand Up @@ -98,7 +97,7 @@
},
methods: {
onScroll(ev) {
if (this.isDisabled)
if (this.isPressed || !this.isKnobIn)
return;
ev.preventDefault();
Expand All @@ -112,7 +111,7 @@
this.updateColor(rotator.angle);
},
rotate(ev, isIncrementing) {
if (this.isDisabled)
if (this.isPressed || !this.isKnobIn)
return;
let multiplier = isIncrementing ? 1 : -1;
Expand All @@ -135,7 +134,7 @@
});
},
rotateToMouse(ev) {
if (this.isDisabled)
if (this.isPressed || !this.isKnobIn)
return;
rotator.setAngleFromEvent(ev);
Expand All @@ -146,17 +145,13 @@
if (this.isPaletteIn && this.isKnobIn) {
this.$emit('select', this.value);
this.isRippling = true;
if (this.variant !== 'persistent')
this.isDisabled = true;
} else {
this.isPaletteIn = true;
}
},
togglePicker() {
if (this.variant !== 'persistent') {
if (this.isKnobIn) {
this.isDisabled = true;
this.isKnobIn = false;
} else {
this.isKnobIn = true;
Expand All @@ -168,9 +163,7 @@
this.isPressed = false;
},
hidePalette() {
if (this.isKnobIn) {
this.isDisabled = false;
} else {
if (!this.isKnobIn) {
this.isPaletteIn = false;
}
},
Expand Down

0 comments on commit b83d1f7

Please sign in to comment.