|
| 1 | +<template> |
| 2 | + <s-text-field class="input monospace" label="颜色" v-model="color"> |
| 3 | + <s-popup slot="end" align="right"> |
| 4 | + <s-icon-button |
| 5 | + slot="trigger" |
| 6 | + class="colorpicker-button" |
| 7 | + :style="{ color }" |
| 8 | + > |
| 9 | + <SIconPalette /> |
| 10 | + </s-icon-button> |
| 11 | + <ColorPicker :color="color" sucker-hide @changeColor="changeColor" /> |
| 12 | + </s-popup> |
| 13 | + </s-text-field> |
| 14 | +</template> |
| 15 | + |
| 16 | +<script lang="ts" setup> |
| 17 | +import SIconPalette from "@/ui/icons/palette.vue"; |
| 18 | +import { ColorPicker } from "vue-color-kit"; |
| 19 | +
|
| 20 | +const color = defineModel<string>({ required: true }); |
| 21 | +
|
| 22 | +interface ColorPickerArgs { |
| 23 | + rgba: { r: number; g: number; b: number; a: number }; |
| 24 | + hex: string; |
| 25 | + hsv: { h: number; s: number; v: number }; |
| 26 | +} |
| 27 | +
|
| 28 | +function changeColor(newColor: ColorPickerArgs) { |
| 29 | + let { hex } = newColor; |
| 30 | + if (newColor.rgba.a < 1) { |
| 31 | + hex = |
| 32 | + hex + |
| 33 | + Math.round(newColor.rgba.a * 255) |
| 34 | + .toString(16) |
| 35 | + .toUpperCase() |
| 36 | + .padStart(2, "0"); |
| 37 | + } |
| 38 | + color.value = hex; |
| 39 | +} |
| 40 | +</script> |
| 41 | + |
| 42 | +<style lang="scss"> |
| 43 | +.colorpicker-button { |
| 44 | + margin-right: 4px; |
| 45 | + margin-left: calc( |
| 46 | + var(--text-field-border-radius) - var(--text-field-padding-right) + 4px |
| 47 | + ); |
| 48 | +} |
| 49 | +
|
| 50 | +.hu-color-picker { |
| 51 | + padding: 15px; |
| 52 | + display: flex; |
| 53 | + flex-direction: column; |
| 54 | + gap: 8px; |
| 55 | + --border-radius: 3px; |
| 56 | + font-family: var(--font-base); |
| 57 | + canvas { |
| 58 | + vertical-align: top; |
| 59 | + border-radius: var(--border-radius); |
| 60 | + } |
| 61 | + .color-set { |
| 62 | + display: flex; |
| 63 | + justify-content: space-between; |
| 64 | + } |
| 65 | + .color-show { |
| 66 | + display: flex; |
| 67 | + } |
| 68 | +
|
| 69 | + .saturation { |
| 70 | + position: relative; |
| 71 | + .slide { |
| 72 | + position: absolute; |
| 73 | + left: 100px; |
| 74 | + top: 0; |
| 75 | + width: 10px; |
| 76 | + height: 10px; |
| 77 | + border-radius: 50%; |
| 78 | + border: 1px solid #fff; |
| 79 | + box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.3); |
| 80 | + pointer-events: none; |
| 81 | + } |
| 82 | + } |
| 83 | +
|
| 84 | + .color-type { |
| 85 | + display: flex; |
| 86 | + font-size: 12px; |
| 87 | + .name { |
| 88 | + width: 60px; |
| 89 | + height: 30px; |
| 90 | + display: flex; |
| 91 | + justify-content: center; |
| 92 | + align-items: center; |
| 93 | + color: var(--s-color-on-surface-variant); |
| 94 | + background: var(--s-color-surface-container-highest); |
| 95 | + border-top-left-radius: var(--border-radius); |
| 96 | + border-bottom-left-radius: var(--border-radius); |
| 97 | + } |
| 98 | + .value { |
| 99 | + flex: 1; |
| 100 | + height: 30px; |
| 101 | + min-width: 100px; |
| 102 | + padding: 0 12px; |
| 103 | + border: 0; |
| 104 | + color: var(--s-color-on-surface); |
| 105 | + background: var(--s-color-surface-container-high); |
| 106 | + box-sizing: border-box; |
| 107 | + caret-color: var(--s-color-primary); |
| 108 | + border-top-right-radius: var(--border-radius); |
| 109 | + border-bottom-right-radius: var(--border-radius); |
| 110 | + transition: box-shadow 0.2s; |
| 111 | + &:focus { |
| 112 | + box-shadow: 0 0 0 1.5px var(--s-color-primary) inset; |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | +
|
| 117 | + .color-alpha, |
| 118 | + .hue { |
| 119 | + position: relative; |
| 120 | + .slide { |
| 121 | + position: absolute; |
| 122 | + left: 0; |
| 123 | + top: 100px; |
| 124 | + width: 100%; |
| 125 | + height: 4px; |
| 126 | + background: #fff; |
| 127 | + box-shadow: 0 0 1px 0 rgba(0, 0, 0, 0.3); |
| 128 | + pointer-events: none; |
| 129 | + } |
| 130 | + } |
| 131 | +
|
| 132 | + .colors { |
| 133 | + padding: 0; |
| 134 | + margin: 0; |
| 135 | + display: flex; |
| 136 | + flex-wrap: wrap; |
| 137 | + gap: 10px; |
| 138 | + margin-top: 5px; |
| 139 | + .item { |
| 140 | + position: relative; |
| 141 | + width: 16px; |
| 142 | + height: 16px; |
| 143 | + border-radius: 3px; |
| 144 | + box-sizing: border-box; |
| 145 | + vertical-align: top; |
| 146 | + display: inline-block; |
| 147 | + transition: all 0.1s; |
| 148 | + cursor: pointer; |
| 149 | +
|
| 150 | + &:hover { |
| 151 | + transform: scale(1.2); |
| 152 | + } |
| 153 | + .alpha { |
| 154 | + height: 100%; |
| 155 | + border-radius: 4px; |
| 156 | + } |
| 157 | + .color { |
| 158 | + position: absolute; |
| 159 | + left: 0; |
| 160 | + top: 0; |
| 161 | + width: 100%; |
| 162 | + height: 100%; |
| 163 | + border-radius: 3px; |
| 164 | + } |
| 165 | + } |
| 166 | + } |
| 167 | +} |
| 168 | +</style> |
0 commit comments