Commit d411992d07dd1f193844cf862982152154c92491
Committed by
GitHub
Merge pull request #4353 from icarusion/ColorPicker-add-editable-prop
ColorPicker add editable prop
Showing
3 changed files
with
39 additions
and
148 deletions
Show diff stats
examples/routers/color-picker.vue
| 1 | <template> | 1 | <template> |
| 2 | <div style="margin: 100px;"> | 2 | <div style="margin: 100px;"> |
| 3 | - {{color}} | ||
| 4 | - <!--<Input placeholder="请输入..." size="large" style="width: 50px;"></Input>--> | ||
| 5 | - <color-picker | ||
| 6 | - v-model="color" | ||
| 7 | - placement="bottom-start" | ||
| 8 | - @on-change="c1" | ||
| 9 | - @on-active-change="c2"></color-picker> | ||
| 10 | - <Input value="hello" style="display: inline-block" /> | ||
| 11 | - <Date-picker | ||
| 12 | - type="date" | ||
| 13 | - placeholder="选择日期" | ||
| 14 | - style="width: 200px"></Date-picker> | ||
| 15 | - <color-picker | ||
| 16 | - ref="xxx" | ||
| 17 | - v-model="color" | ||
| 18 | - :recommend="true" | ||
| 19 | - format="rgb" | ||
| 20 | - alpha | ||
| 21 | - @on-change="onChange" | ||
| 22 | - @on-active-change="onActiveChange"></color-picker> | ||
| 23 | - <color-picker | ||
| 24 | - v-model="color2" | ||
| 25 | - :alpha="true" | ||
| 26 | - :recommend="false" | ||
| 27 | - format="hsv"></color-picker> | ||
| 28 | - <!--<Date-picker type="date" placeholder="选择日期" style="width: 200px"></Date-picker>--> | ||
| 29 | - <color-picker | ||
| 30 | - v-model="color" | ||
| 31 | - placement="bottom-start" | ||
| 32 | - ></color-picker> | ||
| 33 | - <Date-picker | ||
| 34 | - type="date" | ||
| 35 | - placeholder="选择日期" | ||
| 36 | - style="width: 200px"></Date-picker> | ||
| 37 | - <color-picker | ||
| 38 | - ref="yyy" | ||
| 39 | - :colors="colors" | ||
| 40 | - v-model="color" | ||
| 41 | - format="rgb" | ||
| 42 | - alpha></color-picker> | ||
| 43 | - <Button @click="setColor">set color</Button> | ||
| 44 | - | ||
| 45 | - <br><br><br><br> | ||
| 46 | - {{openState}} | ||
| 47 | - <ColorPicker | ||
| 48 | - v-model="color7" | ||
| 49 | - :hue="false" | ||
| 50 | - @on-open-change="onOpenChange"></ColorPicker> | ||
| 51 | - <ColorPicker | ||
| 52 | - v-model="color7" | ||
| 53 | - :hue="false" | ||
| 54 | - :hide-drop-down="hideDropDown" | ||
| 55 | - @on-open-change="onOpenChange"></ColorPicker> | ||
| 56 | - | ||
| 57 | - <br><br><br><br> | ||
| 58 | - <ColorPicker | ||
| 59 | - v-model="color7" | ||
| 60 | - disabled></ColorPicker> | 3 | + {{ color1 }} |
| 4 | + <ColorPicker v-model="color1" /> | ||
| 5 | + <ColorPicker v-model="color2" :editable="false"/> | ||
| 61 | </div> | 6 | </div> |
| 62 | </template> | 7 | </template> |
| 63 | - | ||
| 64 | <script> | 8 | <script> |
| 65 | -export default { | ||
| 66 | - props: {}, | ||
| 67 | - | ||
| 68 | - data() { | ||
| 69 | - return { | ||
| 70 | - color: 'rgba(12,34,255,.85)', | ||
| 71 | - color2: '', | ||
| 72 | - color7: '#19be6b', | ||
| 73 | - openState: false, | ||
| 74 | - colors: [ | ||
| 75 | - '#2d8cf0', | ||
| 76 | - '#19be6b', | ||
| 77 | - '#ff9900', | ||
| 78 | - '#ed3f14', | ||
| 79 | - '#00b5ff', | ||
| 80 | - '#19c919', | ||
| 81 | - '#f9e31c', | ||
| 82 | - '#ea1a1a', | ||
| 83 | - '#9b1dea', | ||
| 84 | - '#00c2b1', | ||
| 85 | - '#ac7a33', | ||
| 86 | - '#1d35ea', | ||
| 87 | - '#8bc34a', | ||
| 88 | - '#f16b62', | ||
| 89 | - '#ea4ca3', | ||
| 90 | - '#0d94aa', | ||
| 91 | - '#febd79', | ||
| 92 | - '#5d4037', | ||
| 93 | - '#00bcd4', | ||
| 94 | - '#f06292', | ||
| 95 | - '#cddc39', | ||
| 96 | - '#607d8b', | ||
| 97 | - '#000000', | ||
| 98 | - '#ffffff', | ||
| 99 | - '#2d8cf0', | ||
| 100 | - '#19be6b', | ||
| 101 | - '#ff9900', | ||
| 102 | - '#ed3f14', | ||
| 103 | - '#00b5ff', | ||
| 104 | - '#19c919', | ||
| 105 | - '#f9e31c', | ||
| 106 | - '#ea1a1a', | ||
| 107 | - '#9b1dea', | ||
| 108 | - '#00c2b1', | ||
| 109 | - '#ac7a33', | ||
| 110 | - '#1d35ea', | ||
| 111 | - '#8bc34a', | ||
| 112 | - '#f16b62', | ||
| 113 | - '#ea4ca3', | ||
| 114 | - '#0d94aa', | ||
| 115 | - '#febd79', | ||
| 116 | - '#5d4037', | ||
| 117 | - ], | ||
| 118 | - hideDropDown: false, | ||
| 119 | - }; | ||
| 120 | - }, | ||
| 121 | - | ||
| 122 | - computed: {}, | ||
| 123 | - | ||
| 124 | - mounted() { | ||
| 125 | - setInterval(this.toggleShowHide, 2000); | ||
| 126 | - }, | ||
| 127 | - | ||
| 128 | - methods: { | ||
| 129 | - setColor() { | ||
| 130 | - this.color = '#26bc77'; | ||
| 131 | - }, | ||
| 132 | - c1(d) { | ||
| 133 | - console.log(d); | ||
| 134 | - }, | ||
| 135 | - c2(d) { | ||
| 136 | - console.log(d); | ||
| 137 | - }, | ||
| 138 | - onOpenChange(state) { | ||
| 139 | - this.openState = state; | ||
| 140 | - }, | ||
| 141 | - onChange(d) { | ||
| 142 | - console.log(d); | ||
| 143 | - }, | ||
| 144 | - onActiveChange(d) { | ||
| 145 | - console.log(d); | ||
| 146 | - }, | ||
| 147 | - toggleShowHide() { | ||
| 148 | - this.hideDropDown = !this.hideDropDown; | ||
| 149 | - }, | ||
| 150 | - }, | ||
| 151 | -}; | 9 | + export default { |
| 10 | + data () { | ||
| 11 | + return { | ||
| 12 | + color1: '#19be6b', | ||
| 13 | + color2: '' | ||
| 14 | + }; | ||
| 15 | + } | ||
| 16 | + }; | ||
| 152 | </script> | 17 | </script> |
src/components/color-picker/color-picker.vue
| @@ -82,7 +82,12 @@ | @@ -82,7 +82,12 @@ | ||
| 82 | @picker-color="handleSelectColor"></recommend-colors> | 82 | @picker-color="handleSelectColor"></recommend-colors> |
| 83 | </div> | 83 | </div> |
| 84 | <div :class="[prefixCls + '-confirm']"> | 84 | <div :class="[prefixCls + '-confirm']"> |
| 85 | - <span :class="[prefixCls + '-confirm-color']">{{formatColor}}</span> | 85 | + <span :class="confirmColorClasses"> |
| 86 | + <template v-if="editable"> | ||
| 87 | + <i-input :value="formatColor" size="small" @on-enter="handleEditColor" @on-blur="handleEditColor"></i-input> | ||
| 88 | + </template> | ||
| 89 | + <template v-else>{{formatColor}}</template> | ||
| 90 | + </span> | ||
| 86 | <i-button | 91 | <i-button |
| 87 | ref="clear" | 92 | ref="clear" |
| 88 | :tabindex="0" | 93 | :tabindex="0" |
| @@ -118,6 +123,7 @@ import RecommendColors from './recommend-colors.vue'; | @@ -118,6 +123,7 @@ import RecommendColors from './recommend-colors.vue'; | ||
| 118 | import Saturation from './saturation.vue'; | 123 | import Saturation from './saturation.vue'; |
| 119 | import Hue from './hue.vue'; | 124 | import Hue from './hue.vue'; |
| 120 | import Alpha from './alpha.vue'; | 125 | import Alpha from './alpha.vue'; |
| 126 | +import iInput from '../input/input.vue'; | ||
| 121 | import Locale from '../../mixins/locale'; | 127 | import Locale from '../../mixins/locale'; |
| 122 | import {oneOf} from '../../utils/assist'; | 128 | import {oneOf} from '../../utils/assist'; |
| 123 | import Emitter from '../../mixins/emitter'; | 129 | import Emitter from '../../mixins/emitter'; |
| @@ -127,7 +133,7 @@ import {changeColor, toRGBAString} from './utils'; | @@ -127,7 +133,7 @@ import {changeColor, toRGBAString} from './utils'; | ||
| 127 | export default { | 133 | export default { |
| 128 | name: 'ColorPicker', | 134 | name: 'ColorPicker', |
| 129 | 135 | ||
| 130 | - components: {Drop, RecommendColors, Saturation, Hue, Alpha}, | 136 | + components: {Drop, RecommendColors, Saturation, Hue, Alpha, iInput}, |
| 131 | 137 | ||
| 132 | directives: {clickOutside, TransferDom}, | 138 | directives: {clickOutside, TransferDom}, |
| 133 | 139 | ||
| @@ -209,6 +215,10 @@ export default { | @@ -209,6 +215,10 @@ export default { | ||
| 209 | type: String, | 215 | type: String, |
| 210 | default: undefined, | 216 | default: undefined, |
| 211 | }, | 217 | }, |
| 218 | + editable: { | ||
| 219 | + type: Boolean, | ||
| 220 | + default: true | ||
| 221 | + }, | ||
| 212 | }, | 222 | }, |
| 213 | 223 | ||
| 214 | data() { | 224 | data() { |
| @@ -334,6 +344,14 @@ export default { | @@ -334,6 +344,14 @@ export default { | ||
| 334 | 344 | ||
| 335 | return saturationColors.hex; | 345 | return saturationColors.hex; |
| 336 | }, | 346 | }, |
| 347 | + confirmColorClasses () { | ||
| 348 | + return [ | ||
| 349 | + `${this.prefixCls}-confirm-color`, | ||
| 350 | + { | ||
| 351 | + [`${this.prefixCls}-confirm-color-editable`]: this.editable | ||
| 352 | + } | ||
| 353 | + ]; | ||
| 354 | + } | ||
| 337 | }, | 355 | }, |
| 338 | 356 | ||
| 339 | watch: { | 357 | watch: { |
| @@ -419,6 +437,10 @@ export default { | @@ -419,6 +437,10 @@ export default { | ||
| 419 | this.val = changeColor(color); | 437 | this.val = changeColor(color); |
| 420 | this.$emit('on-active-change', this.formatColor); | 438 | this.$emit('on-active-change', this.formatColor); |
| 421 | }, | 439 | }, |
| 440 | + handleEditColor (event) { | ||
| 441 | + const value = event.target.value; | ||
| 442 | + this.handleSelectColor(value); | ||
| 443 | + }, | ||
| 422 | handleFirstTab(event) { | 444 | handleFirstTab(event) { |
| 423 | if (event.shiftKey) { | 445 | if (event.shiftKey) { |
| 424 | event.preventDefault(); | 446 | event.preventDefault(); |
src/styles/components/color-picker.less