261117_01_ENH: KriColorPalette를 KriUiRegistry(kri-color-palette) 설치본으로 교체

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 08:49:12 +09:00
parent 623615a287
commit f955dbaeea
7 changed files with 6 additions and 6 deletions

View File

@@ -4,11 +4,11 @@ import { useState, type CSSProperties, type KeyboardEvent } from 'react'
import { Check } from 'lucide-react'
import { Slider as SliderPrimitive } from 'radix-ui'
import { Button } from '@/components/ui/button'
import { ColorPicker, ColorPickerArea, ColorPickerHueSlider } from '@/components/ui/color-picker'
import { ColorPicker, ColorPickerArea, ColorPickerHueSlider } from '@/components/common/color-palette/color-picker'
import { Input } from '@/components/ui/input'
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
import { cn } from '@/lib/utils'
import { formatHexColor, isLightHexColor, normalizeHexColor, parseHexColor } from '@/utils/color'
import { formatHexColor, isLightHexColor, normalizeHexColor, parseHexColor } from '@/components/common/color-palette/color'
export const KRI_COLOR_PALETTE_DEFAULT_COLORS = [
'#111827', '#4B5563', '#9CA3AF', '#E5E7EB', '#EF4444', '#F97316', '#F59E0B', '#EAB308',

View File

@@ -13,9 +13,9 @@ import {
import { useComposedRefs, useLayoutEffect } from "radix-ui/internal";
import * as React from "react";
import { VisuallyHiddenInput } from "@/components/visually-hidden-input";
import { useRefWithInit } from "@/hooks/use-ref-with-init";
import { useValueAsRef } from "@/hooks/use-value-as-ref";
import { VisuallyHiddenInput } from "./visually-hidden-input";
import { useRefWithInit } from "./use-ref-with-init";
import { useValueAsRef } from "./use-value-as-ref";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import {

View File

@@ -0,0 +1,42 @@
export type ParsedHexColor = {
/** `#RRGGBB` (대문자) */
rgb: string
/** 0~255. 투명도가 없는 값은 255 */
alpha: number
}
const HEX_COLOR_PATTERN = /^#?([0-9A-F]{6})([0-9A-F]{2})?$/
/** `#RRGGBB` 또는 `#RRGGBBAA`(대소문자 무관, `#` 생략 가능)를 해석한다. 형식이 다르면 null. */
export const parseHexColor = (value: string | null | undefined): ParsedHexColor | null => {
if (!value) return null
const match = HEX_COLOR_PATTERN.exec(value.trim().toUpperCase())
if (!match) return null
return {
rgb: `#${match[1]}`,
alpha: match[2] ? Number.parseInt(match[2], 16) : 255,
}
}
/** 투명도가 255이면 `#RRGGBB`, 아니면 `#RRGGBBAA`로 만든다. */
export const formatHexColor = (rgb: string, alpha = 255): string => {
const clamped = Math.max(0, Math.min(255, Math.round(alpha)))
if (clamped === 255) return rgb.toUpperCase()
return `${rgb.toUpperCase()}${clamped.toString(16).padStart(2, '0').toUpperCase()}`
}
/** 정규화된 hex 문자열. 형식이 다르면 null. */
export const normalizeHexColor = (value: string | null | undefined): string | null => {
const parsed = parseHexColor(value)
return parsed ? formatHexColor(parsed.rgb, parsed.alpha) : null
}
/** 흰 배경 위에 그렸을 때 밝은 색인지 판단한다(투명도 반영). 글자색 대비 결정에 쓴다. */
export const isLightHexColor = (value: string): boolean => {
const parsed = parseHexColor(value)
if (!parsed) return true
const ratio = parsed.alpha / 255
const channel = (offset: number) => Number.parseInt(parsed.rgb.slice(offset, offset + 2), 16) * ratio + 255 * (1 - ratio)
const luminance = (channel(1) * 299 + channel(3) * 587 + channel(5) * 114) / 1000
return luminance > 150
}

View File

@@ -0,0 +1,8 @@
import * as React from "react";
function useRefWithInit<T>(init: () => T): React.RefObject<T> {
const [ref] = React.useState(() => ({ current: init() }));
return ref;
}
export { useRefWithInit };

View File

@@ -0,0 +1,14 @@
import { useLayoutEffect } from "radix-ui/internal";
import * as React from "react";
function useValueAsRef<T>(value: T) {
const ref = React.useRef<T>(value);
useLayoutEffect(() => {
ref.current = value;
});
return ref;
}
export { useValueAsRef };

View File

@@ -17,7 +17,7 @@ import { formatKst } from '@kri/common'
import { isListFieldEditableForContact, isListFieldVisibleForContact } from '@/utils/listAccess'
import { substituteVariables } from '@/lib/variableSubstitution'
import { formatKoreanPhoneNumber } from '@/utils/phone'
import { isLightHexColor, normalizeHexColor } from '@/utils/color'
import { isLightHexColor, normalizeHexColor } from '@/components/common/color-palette/color'
import SurveyQrDialog from '@/components/dialog/SurveyQrDialog'
import SingleMessageSendDialog from '@/components/dialog/SingleMessageSendDialog'
import { ctiClient } from '@/lib/cti/ctiClient'