diff --git a/src/components/common/KriColorPalette.tsx b/src/components/common/KriColorPalette.tsx new file mode 100644 index 0000000..9b6c931 --- /dev/null +++ b/src/components/common/KriColorPalette.tsx @@ -0,0 +1,248 @@ +'use client' + +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 { 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' + +export const KRI_COLOR_PALETTE_DEFAULT_COLORS = [ + '#111827', '#4B5563', '#9CA3AF', '#E5E7EB', '#EF4444', '#F97316', '#F59E0B', '#EAB308', + '#84CC16', '#22C55E', '#14B8A6', '#06B6D4', '#3B82F6', '#6366F1', '#A855F7', '#EC4899', +] as const + +const CUSTOM_PICKER_FALLBACK = '#3B82F6' +const CHECKERBOARD = 'repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 0% 50% / 8px 8px' + +export type KriColorPaletteProps = { + /** `#RRGGBB` 또는 `#RRGGBBAA` 형식의 색상. 지정되지 않았으면 null */ + value: string | null + onChange: (value: string | null) => void + colors?: readonly string[] + /** 색상 영역·색조 슬라이더·HEX 입력 노출 여부 */ + allowCustom?: boolean + /** + * 투명도 슬라이더 노출 및 `#RRGGBBAA` 입력 허용 여부. + * false여도 전달받은 값의 투명도는 표시·보존하며, 사용자가 색을 바꾸면 불투명(`#RRGGBB`)으로 바뀐다. + */ + allowAlpha?: boolean + allowClear?: boolean + disabled?: boolean + placeholder?: string + className?: string + 'aria-label'?: string +} + +const swatchStyle = (color: string): CSSProperties => ({ + background: `linear-gradient(${color}, ${color}), ${CHECKERBOARD}`, +}) + +export function KriColorPalette({ + value, + onChange, + colors = KRI_COLOR_PALETTE_DEFAULT_COLORS, + allowCustom = true, + allowAlpha = false, + allowClear = true, + disabled = false, + placeholder = '색상 없음', + className, + 'aria-label': ariaLabel = '색상 선택', +}: KriColorPaletteProps) { + const normalizedValue = normalizeHexColor(value) + const parsedValue = parseHexColor(normalizedValue) + const currentAlpha = parsedValue?.alpha ?? 255 + const [open, setOpen] = useState(false) + // 프리셋·HEX 입력·제거로 값이 바뀌면 색상 영역을 새 값으로 다시 초기화한다. + const [pickerKey, setPickerKey] = useState(0) + const [hexDraft, setHexDraft] = useState(normalizedValue ?? '') + const [hexDraftSource, setHexDraftSource] = useState(normalizedValue) + const [hexInvalid, setHexInvalid] = useState(false) + + if (hexDraftSource !== normalizedValue) { + setHexDraftSource(normalizedValue) + setHexDraft(normalizedValue ?? '') + setHexInvalid(false) + } + + const withAlpha = (rgb: string) => formatHexColor(rgb, allowAlpha ? currentAlpha : 255) + + const selectDiscrete = (next: string | null) => { + onChange(next) + setPickerKey((key) => key + 1) + } + + const handlePickerChange = (next: string) => { + const parsed = parseHexColor(next) + if (!parsed) return + const nextValue = withAlpha(parsed.rgb) + if (nextValue === normalizedValue) return + onChange(nextValue) + } + + const handleAlphaChange = (values: number[]) => { + const percent = values[0] ?? 100 + const nextValue = formatHexColor(parsedValue?.rgb ?? CUSTOM_PICKER_FALLBACK, (percent / 100) * 255) + if (nextValue === normalizedValue) return + onChange(nextValue) + } + + const commitHexDraft = () => { + if (hexDraft.trim() === '') { + setHexDraft(normalizedValue ?? '') + setHexInvalid(false) + return + } + // 전달받은 값을 그대로 두고 포커스만 이동한 경우(투명도 포함 값 포함)는 변경으로 보지 않는다. + if (normalizeHexColor(hexDraft) === normalizedValue) { + setHexDraft(normalizedValue ?? '') + setHexInvalid(false) + return + } + const parsed = parseHexColor(hexDraft) + if (!parsed || (!allowAlpha && parsed.alpha !== 255)) { + setHexInvalid(true) + return + } + const nextValue = formatHexColor(parsed.rgb, parsed.alpha) + setHexInvalid(false) + setHexDraft(nextValue) + if (nextValue !== normalizedValue) selectDiscrete(nextValue) + } + + const handleHexKeyDown = (event: KeyboardEvent) => { + if (event.key !== 'Enter') return + event.preventDefault() + commitHexDraft() + } + + const hexFormatLabel = allowAlpha ? '#RRGGBB 또는 #RRGGBBAA' : '#RRGGBB' + const alphaPercent = Math.round((currentAlpha / 255) * 100) + + // disabled이면 트리거 상태와 무관하게 팝오버가 열리지 않도록 한다(이미 열린 상태에서 disabled로 바뀐 경우 포함). + const resolvedOpen = open && !disabled + + return ( + setOpen(nextOpen && !disabled)}> + + + + +
+ {colors.map((color) => { + const parsedColor = parseHexColor(color) + if (!parsedColor) return null + const selected = parsedColor.rgb === parsedValue?.rgb + return ( + + ) + })} +
+ + {allowCustom ? ( +
+ + + + + {allowAlpha ? ( +
+ + +
+ + + + {alphaPercent}% +
+ ) : null} +
+ { + setHexDraft(event.target.value) + setHexInvalid(false) + }} + onBlur={commitHexDraft} + onKeyDown={handleHexKeyDown} + placeholder={allowAlpha ? '#RRGGBBAA' : '#RRGGBB'} + maxLength={allowAlpha ? 9 : 7} + aria-label="HEX 색상 코드" + aria-invalid={hexInvalid} + className="h-8 font-mono text-sm" + /> + {hexInvalid ?

{hexFormatLabel} 형식으로 입력해 주세요.

: null} +
+
+ ) : null} + + {allowClear ? ( +
+ +
+ ) : null} + + + ) +} diff --git a/src/components/dialog/ListHeaderManageDialog.tsx b/src/components/dialog/ListHeaderManageDialog.tsx index 54e1efc..549e768 100644 --- a/src/components/dialog/ListHeaderManageDialog.tsx +++ b/src/components/dialog/ListHeaderManageDialog.tsx @@ -20,6 +20,7 @@ import { } from '@dnd-kit/sortable' import { CSS } from '@dnd-kit/utilities' import { GripVertical, Plus, Trash2 } from 'lucide-react' +import { KriColorPalette } from '@/components/common/KriColorPalette' import { KriDialog } from '@/components/common/KriDialog' import { Button } from '@/components/ui/button' import { Checkbox } from '@/components/ui/checkbox' @@ -44,6 +45,7 @@ export type ListHeaderManageDialogProps = { type ListHeaderRowProps = { row: listHeader activeId: number | null + onHeaderColorChange: (id: number, color: string | null) => void onHeaderNameChange: (id: number, listHderNm: string) => void onHeaderTypeChange: (id: number, listHderTy: ListHeaderType) => void onFlagChange: (id: number, field: 'useColView' | 'useFilter' | 'useIntrvwerView' | 'useIntrvwerEdit', checked: boolean) => void @@ -62,13 +64,23 @@ const isInterviewerEditDisabled = (row: listHeader) => row.listHderTy === ListHeaderConst.CONTACT_INTERVIEWER || row.listHderTy === ListHeaderConst.FIELD_INTERVIEWER -const ListHeaderRow = ({ row, activeId, onHeaderNameChange, onHeaderTypeChange, onFlagChange, onDelete }: ListHeaderRowProps) => { +const ListHeaderRow = ({ + row, + activeId, + onHeaderColorChange, + onHeaderNameChange, + onHeaderTypeChange, + onFlagChange, + onDelete, +}: ListHeaderRowProps) => { const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: row.listHderId }) const canEditName = isCommonGrade(row.listHderGrad) const canEditType = isCommonGrade(row.listHderGrad) const canDelete = isCommonGrade(row.listHderGrad) const canEditFlags = !isImmutableGrade(row.listHderGrad) const canSort = isCommonGrade(row.listHderGrad) + // IMMUTABLE 헤더의 색상은 서버가 저장하지 않으므로 선택을 막는다. + const canEditColor = !isImmutableGrade(row.listHderGrad) const style: CSSProperties = { transform: CSS.Transform.toString(transform), @@ -86,7 +98,7 @@ const ListHeaderRow = ({ row, activeId, onHeaderNameChange, onHeaderTypeChange, ref={setNodeRef} style={style} className={cn( - 'h-12 px-4 border-b last:border-b-0 grid grid-cols-[56px_1fr_150px_96px_96px_110px_110px_88px] items-center gap-2', + 'h-12 px-4 border-b last:border-b-0 grid grid-cols-[56px_1fr_150px_120px_96px_96px_110px_110px_88px] items-center gap-2', (activeId === row.listHderId || isDragging) && 'bg-muted', )} > @@ -131,6 +143,12 @@ const ListHeaderRow = ({ row, activeId, onHeaderNameChange, onHeaderTypeChange, ))} + onHeaderColorChange(row.listHderId, color)} + disabled={!canEditColor} + aria-label={`${row.listHderNm} 헤더 색상`} + />
{ + setLocalRows((prev) => + prev.map((row) => { + if (row.listHderId !== id) return row + if (isImmutableGrade(row.listHderGrad)) return row + return { ...row, listHderColor } + }), + ) + } + const handleHeaderNameChange = (id: number, listHderNm: string) => { setLocalRows((prev) => prev.map((row) => { @@ -302,6 +330,7 @@ const ListHeaderManageDialog = ({ useColView: true, useIntrvwerView: false, useIntrvwerEdit: false, + listHderColor: null, } return [...prev, nextRow] @@ -388,10 +417,11 @@ const ListHeaderManageDialog = ({
-
+
순서 헤더명 헤더 타입 + 헤더 색상 헤더 노출 필터 사용 면접원 노출 @@ -413,6 +443,7 @@ const ListHeaderManageDialog = ({ key={row.listHderId} row={row} activeId={activeId} + onHeaderColorChange={handleHeaderColorChange} onHeaderNameChange={handleHeaderNameChange} onHeaderTypeChange={handleHeaderTypeChange} onFlagChange={handleFlagChange} diff --git a/src/components/list-contact/ListContactInfoPanel.tsx b/src/components/list-contact/ListContactInfoPanel.tsx index edebfd5..1792b87 100644 --- a/src/components/list-contact/ListContactInfoPanel.tsx +++ b/src/components/list-contact/ListContactInfoPanel.tsx @@ -17,6 +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 SurveyQrDialog from '@/components/dialog/SurveyQrDialog' import SingleMessageSendDialog from '@/components/dialog/SingleMessageSendDialog' import { ctiClient } from '@/lib/cti/ctiClient' @@ -52,12 +53,20 @@ export const buildInitialValues = (listHeaders: listHeader[], detail?: ListSearc for (const header of listHeaders) { if (header.listHderTy === ListHeaderConst.SID) continue if (!isListFieldVisibleForContact(header)) continue + // 사용 허용은 저장 시 코드("0"/"1"/"9")로 보내야 하므로 폼 값은 코드로 둔다. + // 문자·알림톡 변수 치환은 resolveListHeaderValue의 라벨을 그대로 사용한다. + if (header.listHderTy === ListHeaderConst.IS_USE) { + values[header.listHderId] = detail?.use != null ? String(detail.use) : '' + continue + } values[header.listHderId] = resolveListHeaderValue(header, detail) } return values } +const IS_USE_OPTIONS = Object.entries(LIST_IS_USE_LABEL).map(([value, label]) => ({ value, label })) + const disabledContrastClass = 'bg-white disabled:opacity-100 disabled:text-foreground disabled:bg-muted/60' // Input/textarea는 수정 불가 상태에서도 드래그 선택/복사가 가능해야 해서 disabled 대신 readOnly를 쓴다. // disabled는 공용 Input 컴포넌트의 disabled:pointer-events-none 때문에 마우스 이벤트 자체를 못 받는다. @@ -77,19 +86,27 @@ const getCallButtonTitle = (isCtiReady: boolean, isDialing: boolean, isEnding: b return undefined } -const FieldRow = ({ label, editable, children }: { label: string; editable?: boolean; children: ReactNode }) => ( -
- -
{children}
-
-) +const FieldRow = ({ label, color, children }: { label: string; color?: string | null; children: ReactNode }) => { + // 헤더에 지정한 색상(투명도 포함)이 기본색보다 우선한다. 형식이 잘못된 값은 기본색으로 표시한다. + const headerColor = normalizeHexColor(color) + const isDarkHeaderColor = headerColor !== null && !isLightHexColor(headerColor) + + return ( +
+ +
{children}
+
+ ) +} const ListContactInfoPanel = ({ prjctIdx, @@ -202,9 +219,9 @@ const ListContactInfoPanel = ({ const value = formValues[header.listHderId] ?? '' const onChange = (next: string) => onFieldChange(header.listHderId, next) - if (header.listHderTy === ListHeaderConst.MEMO) { + if (header.listHderTy === ListHeaderConst.MEMO || header.listHderTy === ListHeaderConst.MULTILINE_TEXT) { return ( - +