Commit c0fa72ca6df0de8a772b45d30084f608c4421528
1 parent
93a5f34f
update ColorPicker
Showing
3 changed files
with
19 additions
and
43 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.rgba }} | 3 | + {{ color }} |
4 | <!--<Input placeholder="请输入..." size="large" style="width: 50px;"></Input>--> | 4 | <!--<Input placeholder="请输入..." size="large" style="width: 50px;"></Input>--> |
5 | <!--<color-picker placement="bottom-start" size="large"></color-picker>--> | 5 | <!--<color-picker placement="bottom-start" size="large"></color-picker>--> |
6 | <!--<Date-picker type="date" placeholder="选择日期" size="large" style="width: 200px"></Date-picker>--> | 6 | <!--<Date-picker type="date" placeholder="选择日期" size="large" style="width: 200px"></Date-picker>--> |
7 | <color-picker ref="xxx" v-model="color" alpha :recommend="true"></color-picker> | 7 | <color-picker ref="xxx" v-model="color" alpha :recommend="true"></color-picker> |
8 | - <color-picker v-model="color" :alpha="false" :recommend="false"></color-picker> | 8 | + <color-picker v-model="color2" :alpha="false" :recommend="false"></color-picker> |
9 | <!--<Date-picker type="date" placeholder="选择日期" style="width: 200px"></Date-picker>--> | 9 | <!--<Date-picker type="date" placeholder="选择日期" style="width: 200px"></Date-picker>--> |
10 | <!--<color-picker placement="bottom-start" size="small"></color-picker>--> | 10 | <!--<color-picker placement="bottom-start" size="small"></color-picker>--> |
11 | <!--<Date-picker type="date" placeholder="选择日期" size="small" style="width: 200px"></Date-picker>--> | 11 | <!--<Date-picker type="date" placeholder="选择日期" size="small" style="width: 200px"></Date-picker>--> |
@@ -17,7 +17,8 @@ | @@ -17,7 +17,8 @@ | ||
17 | props: {}, | 17 | props: {}, |
18 | data () { | 18 | data () { |
19 | return { | 19 | return { |
20 | - color: 'rgba(245,5,78,.8)' | 20 | + color: 'rgba(124,24,24,.5)', |
21 | + color2: '' | ||
21 | }; | 22 | }; |
22 | }, | 23 | }, |
23 | computed: {}, | 24 | computed: {}, |
src/components/color-picker/color-picker.vue
@@ -4,7 +4,10 @@ | @@ -4,7 +4,10 @@ | ||
4 | <i class="ivu-icon ivu-icon-arrow-down-b ivu-input-icon ivu-input-icon-normal"></i> | 4 | <i class="ivu-icon ivu-icon-arrow-down-b ivu-input-icon ivu-input-icon-normal"></i> |
5 | <div :class="inputClasses"> | 5 | <div :class="inputClasses"> |
6 | <div :class="[prefixCls + '-color']"> | 6 | <div :class="[prefixCls + '-color']"> |
7 | - <div :style="{backgroundColor: displayedColor}"></div> | 7 | + <div :class="[prefixCls + '-color-empty']" v-if="value === '' && !visible"> |
8 | + <Icon type="ios-close-empty"></Icon> | ||
9 | + </div> | ||
10 | + <div v-else :style="{backgroundColor: displayedColor}"></div> | ||
8 | </div> | 11 | </div> |
9 | </div> | 12 | </div> |
10 | </div> | 13 | </div> |
@@ -29,6 +32,7 @@ | @@ -29,6 +32,7 @@ | ||
29 | <script> | 32 | <script> |
30 | import tinycolor from 'tinycolor2'; | 33 | import tinycolor from 'tinycolor2'; |
31 | 34 | ||
35 | + import Icon from '../icon/icon.vue'; | ||
32 | import Dropdown from '../dropdown/dropdown.vue'; | 36 | import Dropdown from '../dropdown/dropdown.vue'; |
33 | import DropdownMenu from '../dropdown/dropdown-menu.vue'; | 37 | import DropdownMenu from '../dropdown/dropdown-menu.vue'; |
34 | import RecommendColors from './recommend-colors.vue'; | 38 | import RecommendColors from './recommend-colors.vue'; |
@@ -44,6 +48,7 @@ | @@ -44,6 +48,7 @@ | ||
44 | const inputPrefixCls = 'ivu-input'; | 48 | const inputPrefixCls = 'ivu-input'; |
45 | 49 | ||
46 | function _colorChange (data, oldHue) { | 50 | function _colorChange (data, oldHue) { |
51 | + data = data === '' ? '#ff0000' : data; | ||
47 | const alpha = data && data.a; | 52 | const alpha = data && data.a; |
48 | let color; | 53 | let color; |
49 | 54 | ||
@@ -93,7 +98,7 @@ | @@ -93,7 +98,7 @@ | ||
93 | 98 | ||
94 | export default { | 99 | export default { |
95 | name: 'ColorPicker', | 100 | name: 'ColorPicker', |
96 | - components: { Dropdown, DropdownMenu, Confirm, RecommendColors, Saturation, Hue, Alpha }, | 101 | + components: { Icon, Dropdown, DropdownMenu, Confirm, RecommendColors, Saturation, Hue, Alpha }, |
97 | props: { | 102 | props: { |
98 | value: { | 103 | value: { |
99 | type: String | 104 | type: String |
@@ -218,44 +223,6 @@ | @@ -218,44 +223,6 @@ | ||
218 | } | 223 | } |
219 | }, | 224 | }, |
220 | methods: { | 225 | methods: { |
221 | - formatColor () { | ||
222 | - const defaultColor = { | ||
223 | - hex: '#ff0000', | ||
224 | - hsl: { | ||
225 | - h: 0, | ||
226 | - s: 1, | ||
227 | - l: 0.5, | ||
228 | - a: 1 | ||
229 | - }, | ||
230 | - hsv: { | ||
231 | - h: 0, | ||
232 | - s: 1, | ||
233 | - v: 1, | ||
234 | - a: 1 | ||
235 | - }, | ||
236 | - rgba: { | ||
237 | - r: 255, | ||
238 | - g: 0, | ||
239 | - b: 0, | ||
240 | - a: 1 | ||
241 | - }, | ||
242 | - a: 1 | ||
243 | - }; | ||
244 | - if (this.value) { | ||
245 | - const color = tinycolor(this.value); | ||
246 | - const hex = color.toHex(); | ||
247 | - const hsl = color.toHsl(); | ||
248 | - const hsv = color.toHsv(); | ||
249 | - const rgba = color.toRgb(); | ||
250 | - | ||
251 | - defaultColor.hex = hex; | ||
252 | - defaultColor.hsl = hsl; | ||
253 | - defaultColor.hsv = hsv; | ||
254 | - defaultColor.rgba = rgba; | ||
255 | - defaultColor.a = rgba.a; | ||
256 | - } | ||
257 | - return defaultColor; | ||
258 | - }, | ||
259 | childChange (data) { | 226 | childChange (data) { |
260 | this.colorChange(data); | 227 | this.colorChange(data); |
261 | }, | 228 | }, |
src/styles/components/color-picker.less
@@ -17,6 +17,14 @@ | @@ -17,6 +17,14 @@ | ||
17 | box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); | 17 | box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); |
18 | border-radius: 2px; | 18 | border-radius: 2px; |
19 | } | 19 | } |
20 | + &-empty{ | ||
21 | + background: #fff; | ||
22 | + overflow: hidden; | ||
23 | + text-align: center; | ||
24 | + i{ | ||
25 | + font-size: 20px; | ||
26 | + } | ||
27 | + } | ||
20 | } | 28 | } |
21 | &-large &-color{ | 29 | &-large &-color{ |
22 | width: 20px; | 30 | width: 20px; |