260702_01_ENH: 리스트 작업 도중 공용 ui를 적용하기 위한 중간 커밋

This commit is contained in:
2026-07-02 17:02:17 +09:00
parent 6944064377
commit a8ce35f5bf
111 changed files with 2833 additions and 2557 deletions

View File

@@ -1,5 +1,6 @@
'use client'
import type { CSSProperties } from 'react'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
import { cn } from '@/lib/utils'
@@ -9,78 +10,86 @@ export type KriSelectItem = {
}
type KriSelectProps<T> = {
/** options 배열: string[] 혹은 T[] */
items: T[]
/** 현재 선택 값 */
value: string
/** 값 변경 시 호출 */
onChange?: (value: string) => void
/** 옵션 변경시 호출 */
onChangeOption?: (option: T) => void
/** placeholder 텍스트 */
placeholder?: string
/** 기타 클래스 (예: 'w-40') */
className?: string
/** value를 어떻게 뽑을지 (없으면 String(item)) */
heightClassName?: string
triggerTextClassName?: string
contentClassName?: string
itemClassName?: string
getValue?: (item: T) => string
/** label을 어떻게 뽑을지 (없으면 String(item)) */
getLabel?: (item: T) => string
/** 전체 사용 여부 */
useAll?: boolean
}
const HEIGHT_CLASS_VALUE: Record<string, CSSProperties['height']> = {
'h-6': '1.5rem',
'h-7': '1.75rem',
'h-8': '2rem',
'h-9': '2.25rem',
'h-10': '2.5rem',
}
export function KriSelect<T>({
items,
value,
onChange,
onChangeOption,
placeholder,
className,
getValue,
getLabel,
useAll = true,
}: KriSelectProps<T>) {
const extractValue = (item: T) =>
getValue ? getValue(item) : String(item);
const extractLabel = (item: T) =>
getLabel ? getLabel(item) : String(item);
items,
value,
onChange,
onChangeOption,
placeholder,
className,
heightClassName,
triggerTextClassName = 'text-lg',
contentClassName,
itemClassName,
getValue,
getLabel,
useAll = true,
}: KriSelectProps<T>) {
const extractValue = (item: T) => (getValue ? getValue(item) : String(item))
const extractLabel = (item: T) => (getLabel ? getLabel(item) : String(item))
const triggerStyle: CSSProperties | undefined = heightClassName
? { height: HEIGHT_CLASS_VALUE[heightClassName] ?? undefined }
: undefined
return (
<Select
value={value}
onValueChange={(v) => {
onChange?.(v);
<Select
value={value}
onValueChange={(v) => {
onChange?.(v)
const selected = items.find((item) => extractValue(item) === v);
if(selected) {
onChangeOption?.(selected);
}
}}
const selected = items.find((item) => extractValue(item) === v)
if (selected) {
onChangeOption?.(selected)
}
}}
>
<SelectTrigger
className={cn('w-fit whitespace-nowrap bg-white', triggerTextClassName, heightClassName, className)}
style={triggerStyle}
aria-label={placeholder ?? 'select'}
>
<SelectTrigger
className={cn(
'w-fit whitespace-nowrap bg-white content-text-lg', // 폰트 사이즈
className
)}
aria-label={placeholder ?? 'select'}
>
<SelectValue placeholder={placeholder} />
</SelectTrigger>
<SelectContent>
{ useAll? <SelectItem key="ALL" value="ALL">전체</SelectItem> :null }
{items.map((item, idx) => {
const v = extractValue(item);
const label = extractLabel(item);
<SelectValue placeholder={placeholder} />
</SelectTrigger>
<SelectContent className={contentClassName}>
{useAll ? (
<SelectItem key="ALL" value="ALL" className={itemClassName}>
전체
</SelectItem>
) : null}
{items.map((item, idx) => {
const v = extractValue(item)
const label = extractLabel(item)
return (
<SelectItem key={v ?? idx} value={v}>
{label}
</SelectItem>
)
})}
</SelectContent>
</Select>
return (
<SelectItem key={v ?? idx} value={v} className={itemClassName}>
{label}
</SelectItem>
)
})}
</SelectContent>
</Select>
)
}