111
jihongshun
8 天以前 0c741cdda7ef9935a20d3090dfea97e1ce8ae754
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<template>
  <div class="ant-color-predefine">
    <div class="ant-color-predefine__colors">
      <div
        v-for="(item, index) in rgbaColors"
        :title="colors[index]"
        :class="{ 'is-alpha': item._alpha < 100 }"
        class="ant-color-predefine__color-selector"
        @click="handleSelect(index)"
      >
        <div :style="{ backgroundColor: item.value }"></div>
      </div>
    </div>
  </div>
</template>
 
<script>
import Color from '../lib/color';
 
export default {
  name: 'PreDefine',
  props: {
    colors: {
      type: Array,
      required: true,
    },
  },
  emits: ['selected'],
  computed: {
    rgbaColors() {
      return this.colors.map((value) => {
        const c = new Color({ enableAlpha: true, format: 'rgba' });
        c.fromString(value);
        return c;
      });
    },
  },
  methods: {
    handleSelect(index) {
      this.$emit('selected', this.colors[index]);
    },
  },
};
</script>
 
<style scoped>
.ant-color-predefine {
  display: flex;
  flex-direction: column;
  width: 280px;
  margin-top: 8px;
  font-size: 12px;
}
.ant-color-predefine__colors {
  margin-top: 8px;
  display: flex;
  flex: 1;
  flex-wrap: wrap;
}
.ant-color-predefine__color-selector {
  width: 20px;
  height: 20px;
  margin: 0 0 8px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.ant-color-predefine__color-selector:nth-child(10n + 1) {
  margin-left: 0;
}
.ant-color-predefine__color-selector > div {
  height: 100%;
  border-radius: 3px;
  border: 1px solid #e8e8e8;
  transition: all 0.2s cubic-bezier(0.38, 0, 0.24, 1);
}
.ant-color-predefine__color-selector > div:hover {
  transform: scale(1.25);
  transform-origin: center;
}
</style>