Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sketch) : display a checkboard if the color alpha equals 0 #148

Merged
merged 1 commit into from
Aug 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 47 additions & 13 deletions src/components/Sketch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="vc-sketch-controls">
<div class="vc-sketch-sliders">
<div class="vc-sketch-hue-wrap">
<hue v-model="colors" @change="childChange"></hue>
<hue v-model="colors" @change="childChange"></hue>
</div>
<div class="vc-sketch-alpha-wrap" v-if="!disableAlpha">
<alpha v-model="colors" @change="childChange"></alpha>
Expand All @@ -20,7 +20,7 @@
<div class="vc-sketch-field" v-if="!disableFields">
<!-- rgba -->
<div class="vc-sketch-field--double">
<ed-in label="hex" :value="hex" @change="inputChange"></ed-in>
<ed-in label="hex" :value="hex" @change="inputChange"></ed-in>
</div>
<div class="vc-sketch-field--single">
<ed-in label="r" :value="colors.rgba.r" @change="inputChange"></ed-in>
Expand All @@ -36,13 +36,22 @@
</div>
</div>
<div class="vc-sketch-presets">
<div class="vc-sketch-presets-color"
:aria-label="'color:'+c"
v-for="c in presetColors"
:key="c"
:style="{background: c}"
@click="handlePreset(c)">
</div>
<template v-for="c in presetColors">
<div
class="vc-sketch-presets-color"
v-if="!colorIsTransparent(c)"
:aria-label="'color:'+c"
:key="c"
:style="{background: c}"
@click="handlePreset(c)">
</div>
<div
class="vc-sketch-presets-color"
v-else
@click="handlePreset(c)">
<checkboard/>
</div>
</template>
</div>
</div>
</template>
Expand All @@ -54,11 +63,13 @@ import saturation from './common/Saturation.vue'
import hue from './common/Hue.vue'
import alpha from './common/Alpha.vue'
import checkboard from './common/Checkboard.vue'
import tinycolor from 'tinycolor2'

const presetColors = [
'#D0021B', '#F5A623', '#F8E71C', '#8B572A', '#7ED321',
'#417505', '#BD10E0', '#9013FE', '#4A90E2', '#50E3C2',
'#B8E986', '#000000', '#4A4A4A', '#9B9B9B', '#FFFFFF'
'#B8E986', '#000000', '#4A4A4A', '#9B9B9B', '#FFFFFF',
'rgba(0,0,0,0)'
]

export default {
Expand Down Expand Up @@ -103,6 +114,9 @@ export default {
source: 'hex'
})
},
colorIsTransparent (c) {
return tinycolor(c).getAlpha() === 0;
},
childChange (data) {
this.colorChange(data)
},
Expand Down Expand Up @@ -137,35 +151,42 @@ export default {
box-sizing: initial;
background: #fff;
border-radius: 4px;
box-shadow: 0 0 0 1px rgba(0,0,0,.15), 0 8px 16px rgba(0,0,0,.15);
box-shadow: 0 0 0 1px rgba(0, 0, 0, .15), 0 8px 16px rgba(0, 0, 0, .15);
}

.vc-sketch-saturation-wrap {
width: 100%;
padding-bottom: 75%;
position: relative;
overflow: hidden;
}

.vc-sketch-controls {
display: flex;
}

.vc-sketch-sliders {
padding: 4px 0;
flex: 1;
}

.vc-sketch-sliders .vc-hue,
.vc-sketch-sliders .vc-alpha-gradient {
border-radius: 2px;
}

.vc-sketch-hue-wrap {
position: relative;
height: 10px;
}

.vc-sketch-alpha-wrap {
position: relative;
height: 10px;
margin-top: 4px;
overflow: hidden;
}

.vc-sketch-color-wrap {
width: 24px;
height: 24px;
Expand All @@ -174,16 +195,18 @@ export default {
margin-left: 4px;
border-radius: 3px;
}

.vc-sketch-active-color {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0,0,0,.15), inset 0 0 4px rgba(0,0,0,.25);
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15), inset 0 0 4px rgba(0, 0, 0, .25);
z-index: 2;
}

.vc-sketch-color-wrap .vc-checkerboard {
background-size: auto;
}
Expand All @@ -192,13 +215,15 @@ export default {
display: flex;
padding-top: 4px;
}

.vc-sketch-field .vc-input__input {
width: 80%;
padding: 4px 10% 3px;
border: none;
box-shadow: inset 0 0 0 1px #ccc;
font-size: 11px;
}

.vc-sketch-field .vc-input__label {
display: block;
text-align: center;
Expand All @@ -208,20 +233,24 @@ export default {
padding-bottom: 4px;
text-transform: capitalize;
}

.vc-sketch-field--single {
flex: 1;
padding-left: 6px;
}

.vc-sketch-field--double {
flex: 2;
}

.vc-sketch-presets {
margin-right: -10px;
margin-left: -10px;
padding-left: 10px;
padding-top: 10px;
border-top: 1px solid #eee;
}

.vc-sketch-presets-color {
border-radius: 3px;
overflow: hidden;
Expand All @@ -232,7 +261,12 @@ export default {
cursor: pointer;
width: 16px;
height: 16px;
box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15);
}

.vc-sketch-presets-color .vc-checkerboard {
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15);
border-radius: 3px;
}

.vc-sketch__disable-alpha .vc-sketch-color-wrap {
Expand Down