import { React, ReactNative } from "@vendetta/metro/common"; import { isValidHex, resolveSemanticColorSafe } from "../lib/color"; const { View, Text, TextInput, TouchableOpacity } = ReactNative; const PRESETS = [ "#F23F42", "#F0B232", "#FEE75C", "#23A55A", "#1ABC9C", "#5865F2", "#9B59B6", "#EB459E", "#99AAB5", "#FFFFFF" ]; interface ColorInputProps { title: string; value?: string; placeholder?: string; onChange: (value: string) => void; } // Hex color field with a live swatch preview and tap-to-pick presets. Built entirely from RN // primitives, so it doesn't carry the same "might silently stop rendering after a Discord update" // risk as the plugins' UI patches do. export default function ColorInput({ title, value, placeholder, onChange }: ColorInputProps) { const valid = !value || isValidHex(value); const swatchColor = isValidHex(value) ? value : (isValidHex(placeholder) ? placeholder : "#5865F2"); const textColor = resolveSemanticColorSafe(["TEXT_NORMAL", "TEXT_DEFAULT"], "#dbdee1"); return ( {title} {PRESETS.map((preset) => { const active = value?.toLowerCase() === preset.toLowerCase(); return ( onChange(preset)} style={{ width: 24, height: 24, borderRadius: 6, backgroundColor: preset, marginRight: 8, marginBottom: 8, borderWidth: active ? 2 : 1, borderColor: active ? "#ffffff" : "rgba(128,128,128,0.35)" }} /> ); })} {!valid && ( Invalid hex color, e.g. #5865F2 )} ); }