Интегрировать кастомный ColorPicker в настройки

Заменить нативный input[type=color] на кастомный компонент
ColorPicker.vue в стиле liquid glass (HSV-пикер с SB-квадратом,
слайдером оттенка и hex-полем). Удалить устаревшие CSS-классы
из SettingsView.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
vodyanoysh 2026-03-31 22:34:20 +07:00
parent 7f52ab3e27
commit eb52528dac
2 changed files with 385 additions and 102 deletions

View file

@ -0,0 +1,383 @@
<script setup lang="ts">
import { ref, watch, onMounted, onUnmounted, nextTick } from 'vue'
const props = defineProps<{ modelValue: string }>()
const emit = defineEmits<{ 'update:modelValue': [string] }>()
// ── Color math ────────────────────────────────────────────────
function hexToRgb(hex: string): [number,number,number] | null {
const m = /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex)
return m ? [parseInt(m[1],16), parseInt(m[2],16), parseInt(m[3],16)] : null
}
function rgbToHex(r: number, g: number, b: number): string {
return '#' + [r,g,b].map(v =>
Math.round(Math.max(0, Math.min(255, v))).toString(16).padStart(2,'0')
).join('')
}
function hexToHsv(hex: string): [number,number,number] | null {
const rgb = hexToRgb(hex)
if (!rgb) return null
const [r,g,b] = rgb.map(x => x/255) as [number,number,number]
const max=Math.max(r,g,b), min=Math.min(r,g,b), d=max-min
const v=max, s=max===0?0:d/max
let h=0
if (d!==0) {
if (max===r) h=((g-b)/d+(g<b?6:0))/6
else if (max===g) h=((b-r)/d+2)/6
else h=((r-g)/d+4)/6
}
return [h*360, s, v]
}
function hsvToHex(h: number, s: number, v: number): string {
const c=v*s, x=c*(1-Math.abs((h/60)%2-1)), m=v-c
let r=0,g=0,b=0
if(h<60){r=c;g=x} else if(h<120){r=x;g=c} else if(h<180){g=c;b=x}
else if(h<240){g=x;b=c} else if(h<300){r=x;b=c} else{r=c;b=x}
return rgbToHex((r+m)*255,(g+m)*255,(b+m)*255)
}
// ── State ─────────────────────────────────────────────────────
const open = ref(false)
const hue = ref(0)
const sat = ref(1)
const bri = ref(1)
const hexInput = ref('')
let syncing = false
function loadHex(hex: string) {
const hsv = hexToHsv(hex)
if (!hsv) return
syncing = true
;[hue.value, sat.value, bri.value] = hsv
hexInput.value = hex.toUpperCase()
syncing = false
}
loadHex(props.modelValue)
watch(() => props.modelValue, hex => { if (!syncing) loadHex(hex) })
function pushColor() {
if (syncing) return
const hex = hsvToHex(hue.value, sat.value, bri.value)
syncing = true
hexInput.value = hex.toUpperCase()
syncing = false
emit('update:modelValue', hex)
}
// ── SB picker ─────────────────────────────────────────────────
const sbRef = ref<HTMLElement>()
let sbActive = false
function onSbDown(e: PointerEvent) {
sbActive = true
;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
moveSb(e)
}
function onSbMove(e: PointerEvent) { if (sbActive) moveSb(e) }
function onSbUp() { sbActive = false }
function moveSb(e: PointerEvent) {
if (!sbRef.value) return
const r = sbRef.value.getBoundingClientRect()
sat.value = Math.max(0, Math.min(1, (e.clientX - r.left) / r.width))
bri.value = Math.max(0, Math.min(1, 1 - (e.clientY - r.top) / r.height))
pushColor()
}
// ── Hue slider ────────────────────────────────────────────────
const hueRef = ref<HTMLElement>()
let hueActive = false
function onHueDown(e: PointerEvent) {
hueActive = true
;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
moveHue(e)
}
function onHueMov(e: PointerEvent) { if (hueActive) moveHue(e) }
function onHueUp() { hueActive = false }
function moveHue(e: PointerEvent) {
if (!hueRef.value) return
const r = hueRef.value.getBoundingClientRect()
hue.value = Math.max(0, Math.min(360, ((e.clientX - r.left) / r.width) * 360))
pushColor()
}
// ── Hex input ─────────────────────────────────────────────────
function onHexInput(e: Event) {
hexInput.value = (e.target as HTMLInputElement).value.toUpperCase()
}
function commitHex() {
const raw = hexInput.value.trim()
const hex = raw.startsWith('#') ? raw : '#' + raw
const hsv = hexToHsv(hex)
if (hsv) {
;[hue.value, sat.value, bri.value] = hsv
pushColor()
} else {
hexInput.value = props.modelValue.toUpperCase()
}
}
// ── Panel positioning ─────────────────────────────────────────
const triggerRef = ref<HTMLElement>()
const panelRef = ref<HTMLElement>()
const panelStyle = ref<Record<string,string>>({})
async function toggle() {
open.value = !open.value
if (!open.value) return
await nextTick()
const r = triggerRef.value?.getBoundingClientRect()
if (!r) return
const W=240, H=296
const top = window.innerHeight - r.bottom > H + 8 ? r.bottom + 6 : r.top - H - 6
panelStyle.value = {
position: 'fixed',
top: `${top}px`,
left: `${Math.min(r.left, window.innerWidth - W - 8)}px`,
width:`${W}px`,
zIndex: '9999',
}
}
function onDocClick(e: MouseEvent) {
const t = e.target as Node
if (!triggerRef.value?.contains(t) && !panelRef.value?.contains(t)) open.value = false
}
onMounted(() => document.addEventListener('mousedown', onDocClick))
onUnmounted(() => document.removeEventListener('mousedown', onDocClick))
</script>
<template>
<!-- Trigger -->
<button ref="triggerRef" class="cp-trigger" :class="{ open }" type="button" @click="toggle">
<span class="cp-swatch" :style="{ background: modelValue }" />
<span class="cp-hex-label">{{ modelValue.toUpperCase() }}</span>
<svg class="cp-chevron" :class="{ rotated: open }" viewBox="0 0 16 16" width="12" height="12"
fill="none" stroke="currentColor" stroke-width="1.75"
stroke-linecap="round" stroke-linejoin="round">
<polyline points="4,6 8,10 12,6"/>
</svg>
</button>
<!-- Floating panel -->
<Teleport to="body">
<div v-if="open" ref="panelRef" class="cp-panel" :style="panelStyle">
<!-- Saturation / Brightness square -->
<div ref="sbRef" class="cp-sb" :style="{ background: `hsl(${hue},100%,50%)` }"
@pointerdown="onSbDown" @pointermove="onSbMove" @pointerup="onSbUp">
<div class="cp-sb-sat" />
<div class="cp-sb-bri" />
<div class="cp-sb-thumb" :style="{
left: `${sat * 100}%`,
top: `${(1 - bri) * 100}%`,
}" />
</div>
<!-- Hue slider -->
<div ref="hueRef" class="cp-hue"
@pointerdown="onHueDown" @pointermove="onHueMov" @pointerup="onHueUp">
<div class="cp-hue-thumb" :style="{ left: `${(hue / 360) * 100}%` }" />
</div>
<!-- Preview + hex input -->
<div class="cp-footer">
<div class="cp-preview" :style="{ background: modelValue }" />
<input
class="cp-hex-input"
:value="hexInput"
maxlength="7"
spellcheck="false"
@input="onHexInput"
@blur="commitHex"
@keydown.enter.prevent="commitHex"
/>
</div>
</div>
</Teleport>
</template>
<style scoped>
.cp-trigger {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 14px;
border-radius: var(--radius-lg);
background: rgba(255, 255, 255, 0.06);
border: 1px solid rgba(255, 255, 255, 0.11);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.09),
0 2px 8px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(16px) saturate(1.5);
-webkit-backdrop-filter: blur(16px) saturate(1.5);
cursor: pointer;
transition:
background var(--transition-fast),
border-color var(--transition-fast),
box-shadow var(--transition-fast);
}
.cp-trigger:hover {
background: rgba(255, 255, 255, 0.09);
border-color: rgba(255, 255, 255, 0.17);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.12),
0 3px 12px rgba(0, 0, 0, 0.25);
}
.cp-trigger.open {
border-color: color-mix(in srgb, var(--accent) 45%, transparent);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.1),
0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}
.cp-swatch {
width: 22px;
height: 22px;
border-radius: 50%;
flex-shrink: 0;
border: 1.5px solid rgba(255, 255, 255, 0.22);
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255,255,255,0.2);
}
.cp-hex-label {
font-family: var(--font-mono);
font-size: 13px;
font-weight: 600;
color: var(--text-primary);
letter-spacing: 0.4px;
flex: 1;
text-align: left;
}
.cp-chevron {
color: var(--text-muted);
flex-shrink: 0;
transition: transform var(--transition-fast);
}
.cp-chevron.rotated { transform: rotate(180deg); }
</style>
<!-- Panel телепортируется в body — нужны глобальные стили -->
<style>
.cp-panel {
background: rgba(11, 11, 19, 0.92);
backdrop-filter: blur(48px) saturate(2.2);
-webkit-backdrop-filter: blur(48px) saturate(2.2);
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 14px;
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.1),
0 28px 72px rgba(0, 0, 0, 0.8),
0 6px 20px rgba(0, 0, 0, 0.4);
padding: 12px;
display: flex;
flex-direction: column;
gap: 10px;
}
/* SB square */
.cp-sb {
width: 100%;
height: 160px;
border-radius: 8px;
position: relative;
cursor: crosshair;
overflow: hidden;
touch-action: none;
flex-shrink: 0;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.3);
}
.cp-sb-sat {
position: absolute;
inset: 0;
background: linear-gradient(to right, #fff, transparent);
pointer-events: none;
}
.cp-sb-bri {
position: absolute;
inset: 0;
background: linear-gradient(to bottom, transparent, #000);
pointer-events: none;
}
.cp-sb-thumb {
position: absolute;
width: 16px;
height: 16px;
border-radius: 50%;
border: 2.5px solid #fff;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(0,0,0,0.2);
transform: translate(-50%, -50%);
pointer-events: none;
z-index: 3;
}
/* Hue slider */
.cp-hue {
width: 100%;
height: 14px;
border-radius: 7px;
position: relative;
cursor: crosshair;
touch-action: none;
flex-shrink: 0;
background: linear-gradient(to right,
#f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
box-shadow:
0 1px 4px rgba(0, 0, 0, 0.4),
inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.cp-hue-thumb {
position: absolute;
top: 50%;
width: 20px;
height: 20px;
border-radius: 50%;
border: 2.5px solid #fff;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
transform: translate(-50%, -50%);
pointer-events: none;
}
/* Footer */
.cp-footer {
display: flex;
align-items: center;
gap: 10px;
}
.cp-preview {
width: 32px;
height: 32px;
border-radius: 50%;
flex-shrink: 0;
border: 1.5px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255,255,255,0.15);
}
.cp-hex-input {
flex: 1;
background: rgba(255, 255, 255, 0.07);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
padding: 6px 10px;
font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
font-size: 13px;
font-weight: 600;
color: rgba(255, 255, 255, 0.92);
text-transform: uppercase;
letter-spacing: 0.5px;
outline: none;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
transition: border-color 0.15s ease, box-shadow 0.15s ease;
backdrop-filter: blur(8px);
}
.cp-hex-input:focus {
border-color: color-mix(in srgb, var(--accent) 55%, transparent);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.08),
0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}
</style>

View file

@ -3,6 +3,7 @@ import { useRouter } from 'vue-router'
import { useAccountsStore } from '../stores/accounts.store'
import { useSettingsStore, SWIPE_ACTION_LABELS, ACCENT_QUICK_PICKS, type SwipeAction } from '../stores/settings.store'
import CustomSelect from '../components/CustomSelect.vue'
import ColorPicker from '../components/ColorPicker.vue'
const router = useRouter()
const accountsStore = useAccountsStore()
@ -43,23 +44,7 @@ const swipeOptions: { value: SwipeAction; label: string }[] = (
<h2>Акцентный цвет</h2>
<p class="section-desc">Выберите любой оттенок или используйте быстрый выбор</p>
<div class="color-picker-row">
<label class="color-input-wrap" title="Выбрать цвет">
<span class="color-preview" :style="{ background: settingsStore.accentColor }" />
<span class="color-label">
<span class="color-label-text">Акцентный цвет</span>
<span class="color-hex">{{ settingsStore.accentColor.toUpperCase() }}</span>
</span>
<svg class="color-chevron" viewBox="0 0 16 16" width="14" height="14" fill="none"
stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
<polyline points="4,6 8,10 12,6" />
</svg>
<input
type="color"
:value="settingsStore.accentColor"
class="color-native"
@input="(e) => settingsStore.accentColor = (e.target as HTMLInputElement).value"
/>
</label>
<ColorPicker v-model="settingsStore.accentColor" />
<div class="quick-picks">
<button
v-for="hex in ACCENT_QUICK_PICKS"
@ -295,91 +280,6 @@ const swipeOptions: { value: SwipeAction; label: string }[] = (
gap: 10px;
}
/* Основная кнопка выбора цвета */
.color-input-wrap {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 16px;
border-radius: var(--radius-lg);
background: rgba(255, 255, 255, 0.06);
backdrop-filter: blur(16px) saturate(1.5);
-webkit-backdrop-filter: blur(16px) saturate(1.5);
border: 1px solid rgba(255, 255, 255, 0.11);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.09),
0 2px 10px rgba(0, 0, 0, 0.2);
cursor: pointer;
position: relative;
transition:
background var(--transition-fast),
border-color var(--transition-fast),
box-shadow var(--transition-fast);
}
.color-input-wrap:hover {
background: rgba(255, 255, 255, 0.09);
border-color: rgba(255, 255, 255, 0.17);
box-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.12),
0 3px 14px rgba(0, 0, 0, 0.25);
}
.color-preview {
width: 28px;
height: 28px;
border-radius: 50%;
flex-shrink: 0;
border: 1.5px solid rgba(255, 255, 255, 0.2);
box-shadow:
0 2px 10px rgba(0,0,0,0.4),
0 0 0 1px rgba(0,0,0,0.2);
transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}
.color-input-wrap:hover .color-preview {
transform: scale(1.08);
}
.color-label {
display: flex;
flex-direction: column;
gap: 1px;
flex: 1;
}
.color-label-text {
font-size: 11px;
font-weight: 500;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.5px;
}
.color-hex {
font-family: var(--font-mono);
font-size: 13px;
font-weight: 600;
color: var(--text-primary);
letter-spacing: 0.5px;
}
.color-chevron {
color: var(--text-muted);
flex-shrink: 0;
}
.color-native {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
border: none;
padding: 0;
background: none;
border-radius: inherit;
}
/* Быстрый выбор цвета */
.quick-picks {
display: flex;