diff --git a/examples/routers/color-picker.vue b/examples/routers/color-picker.vue
index c5ee5b0..b538fc1 100644
--- a/examples/routers/color-picker.vue
+++ b/examples/routers/color-picker.vue
@@ -4,11 +4,12 @@
-
+
+
\ No newline at end of file
diff --git a/src/components/color-picker/color-picker.vue b/src/components/color-picker/color-picker.vue
index 63b3085..ad4b96f 100644
--- a/src/components/color-picker/color-picker.vue
+++ b/src/components/color-picker/color-picker.vue
@@ -1,9 +1,11 @@
-
+
@@ -19,7 +21,7 @@
-
+
@@ -94,7 +96,7 @@
components: { Dropdown, DropdownMenu, Confirm, RecommendColors, Saturation, Hue, Alpha },
props: {
value: {
- type: Object
+ type: String
},
alpha: {
type: Boolean,
@@ -139,6 +141,7 @@
return {
val: _colorChange(this.value),
prefixCls: prefixCls,
+ visible: false,
recommendedColor: [
'#2d8cf0',
'#19be6b',
@@ -170,7 +173,6 @@
},
set (newVal) {
this.val = newVal;
- this.$emit('input', newVal);
}
},
wrapClasses () {
@@ -190,14 +192,70 @@
[`${inputPrefixCls}-disabled`]: this.disabled
}
];
+ },
+ displayedColor () {
+ let color;
+ if (this.visible) {
+ const rgba = this.saturationColors.rgba;
+ color = {
+ r: rgba.r,
+ g: rgba.g,
+ b: rgba.b,
+ a: rgba.a
+ };
+ } else {
+ color = tinycolor(this.value).toRgb();
+ }
+ return `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a})`;
}
},
watch: {
value (newVal) {
this.val = _colorChange(newVal);
+ },
+ visible () {
+ this.val = _colorChange(this.value);
}
},
methods: {
+ formatColor () {
+ const defaultColor = {
+ hex: '#ff0000',
+ hsl: {
+ h: 0,
+ s: 1,
+ l: 0.5,
+ a: 1
+ },
+ hsv: {
+ h: 0,
+ s: 1,
+ v: 1,
+ a: 1
+ },
+ rgba: {
+ r: 255,
+ g: 0,
+ b: 0,
+ a: 1
+ },
+ a: 1
+ };
+ if (this.value) {
+ const color = tinycolor(this.value);
+ const hex = color.toHex();
+ const hsl = color.toHsl();
+ const hsv = color.toHsv();
+ const rgba = color.toRgb();
+
+ defaultColor.hex = hex;
+ defaultColor.hsl = hsl;
+ defaultColor.hsv = hsv;
+ defaultColor.rgba = rgba;
+ defaultColor.a = rgba.a;
+ }
+ return defaultColor;
+ },
childChange (data) {
this.colorChange(data);
},
@@ -226,6 +284,16 @@
if (checked === passed) {
return data;
}
+ },
+ handleToggleVisible (visible) {
+ this.visible = visible;
+ },
+ handleSuccess () {
+ this.$emit('input', this.val);
+ },
+ handleClear () {
+ this.$emit('input', '');
+ // todo
}
}
};
diff --git a/src/styles/components/color-picker.less b/src/styles/components/color-picker.less
index 86240c8..240f7be 100644
--- a/src/styles/components/color-picker.less
+++ b/src/styles/components/color-picker.less
@@ -7,10 +7,16 @@
&-color{
width: 18px;
height: 18px;
- box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAIAAADZF8uwAAAAGUlEQVQYV2M4gwH+YwCGIasIUwhT25BVBADtzYNYrHvv4gAAAABJRU5ErkJggg==);
border-radius: 2px;
position: relative;
top: 2px;
+ div{
+ width: 100%;
+ height: 100%;
+ box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
+ border-radius: 2px;
+ }
}
&-large &-color{
width: 20px;
--
libgit2 0.21.4