feat: 모달·필드·라디오그룹 공용 컴포넌트 추가
Co-Authored-By: Claude Opus 5
@f29287853d2ead4073a6a8f9908f2b914ae9cc5f
+++ components/ui/field.tsx
... | ... | @@ -0,0 +1,21 @@ |
| 1 | +import type { ReactNode } from "react"; | |
| 2 | + | |
| 3 | +interface FieldProps { | |
| 4 | + label: string; | |
| 5 | + children: ReactNode; | |
| 6 | + /** 배치(레이아웃) 조정용 클래스 패스스루만 허용 — 디자인 값 주입 금지. */ | |
| 7 | + className?: string; | |
| 8 | +} | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 폼 라벨 + 값 배치. `<label>`이 children을 함께 감싸 암시적 라벨 연결(implicit label)을 | |
| 12 | + * 제공한다 — 조회 팝업에서 readOnly `Input`을 감싸는 용도. | |
| 13 | + */ | |
| 14 | +export function Field({ label, children, className }: FieldProps) { | |
| 15 | + return ( | |
| 16 | + <label className={`flex flex-col gap-1 ${className ?? ""}`}> | |
| 17 | + <span className="text-label-md text-foreground-muted">{label}</span> | |
| 18 | + {children} | |
| 19 | + </label> | |
| 20 | + ); | |
| 21 | +} |
+++ components/ui/modal.tsx
... | ... | @@ -0,0 +1,62 @@ |
| 1 | +"use client"; | |
| 2 | + | |
| 3 | +import { useEffect, useId, type ReactNode } from "react"; | |
| 4 | +import { IconButton } from "@/components/ui/icon-button"; | |
| 5 | + | |
| 6 | +interface ModalProps { | |
| 7 | + title: string; | |
| 8 | + children: ReactNode; | |
| 9 | + footer?: ReactNode; | |
| 10 | + /** scrim 클릭·ESC·닫기 버튼에서 호출된다. 실제로 마운트 해제할지는 호출부(feature) 책임. */ | |
| 11 | + onClose: () => void; | |
| 12 | +} | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * 조회/입력 팝업 셸(scrim + 패널). 열림 여부는 호출부가 마운트/언마운트로 제어한다. | |
| 16 | + * alert.tsx(확인 다이얼로그)와 달리 폼 필드를 담는 용도라 ESC 키·scrim 클릭·닫기 버튼에서 | |
| 17 | + * onClose를 호출하는 상호작용을 자체적으로 가진다 — 그래서 이 컴포넌트만 'use client'. | |
| 18 | + * 포커스 트랩은 다루지 않는다(호출부 책임). | |
| 19 | + */ | |
| 20 | +export function Modal({ title, children, footer, onClose }: ModalProps) { | |
| 21 | + const titleId = useId(); | |
| 22 | + | |
| 23 | + useEffect(() => { | |
| 24 | + function handleKeyDown(event: KeyboardEvent) { | |
| 25 | + if (event.key === "Escape") { | |
| 26 | + onClose(); | |
| 27 | + } | |
| 28 | + } | |
| 29 | + document.addEventListener("keydown", handleKeyDown); | |
| 30 | + return () => { | |
| 31 | + document.removeEventListener("keydown", handleKeyDown); | |
| 32 | + }; | |
| 33 | + }, [onClose]); | |
| 34 | + | |
| 35 | + return ( | |
| 36 | + <div | |
| 37 | + className="fixed inset-0 z-50 flex items-center justify-center bg-scrim p-4" | |
| 38 | + onClick={onClose} | |
| 39 | + > | |
| 40 | + <div | |
| 41 | + role="dialog" | |
| 42 | + aria-modal="true" | |
| 43 | + aria-labelledby={titleId} | |
| 44 | + onClick={(event) => event.stopPropagation()} | |
| 45 | + className="w-full max-w-lg animate-dialog-in rounded-xl bg-surface p-6 shadow-dialog" | |
| 46 | + > | |
| 47 | + <div className="flex items-center justify-between gap-4"> | |
| 48 | + <h2 id={titleId} className="text-title-lg text-foreground"> | |
| 49 | + {title} | |
| 50 | + </h2> | |
| 51 | + <IconButton label="닫기" onClick={onClose}> | |
| 52 | + <span aria-hidden="true" className="text-title-md leading-none"> | |
| 53 | + × | |
| 54 | + </span> | |
| 55 | + </IconButton> | |
| 56 | + </div> | |
| 57 | + <div className="mt-4">{children}</div> | |
| 58 | + {footer && <div className="mt-6 flex justify-end gap-2">{footer}</div>} | |
| 59 | + </div> | |
| 60 | + </div> | |
| 61 | + ); | |
| 62 | +} |
+++ components/ui/radio-group.tsx
... | ... | @@ -0,0 +1,40 @@ |
| 1 | +interface RadioGroupOption { | |
| 2 | + value: string; | |
| 3 | + label: string; | |
| 4 | +} | |
| 5 | + | |
| 6 | +interface RadioGroupProps { | |
| 7 | + name: string; | |
| 8 | + options: RadioGroupOption[]; | |
| 9 | + defaultValue?: string; | |
| 10 | + disabled?: boolean; | |
| 11 | +} | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 네이티브 라디오 그룹(비제어) — 폼 제출 시 `name` 필드로 선택값이 함께 전달된다. | |
| 15 | + * React 상태를 가지지 않으므로 `'use client'`가 필요 없다. | |
| 16 | + */ | |
| 17 | +export function RadioGroup({ name, options, defaultValue, disabled = false }: RadioGroupProps) { | |
| 18 | + return ( | |
| 19 | + <div role="radiogroup" className="flex items-center gap-4"> | |
| 20 | + {options.map((option) => ( | |
| 21 | + <label | |
| 22 | + key={option.value} | |
| 23 | + className={`flex items-center gap-2 text-body-md ${ | |
| 24 | + disabled ? "text-foreground-subtle opacity-50" : "text-foreground" | |
| 25 | + }`} | |
| 26 | + > | |
| 27 | + <input | |
| 28 | + type="radio" | |
| 29 | + name={name} | |
| 30 | + value={option.value} | |
| 31 | + defaultChecked={option.value === defaultValue} | |
| 32 | + disabled={disabled} | |
| 33 | + className="size-4 accent-primary" | |
| 34 | + /> | |
| 35 | + {option.label} | |
| 36 | + </label> | |
| 37 | + ))} | |
| 38 | + </div> | |
| 39 | + ); | |
| 40 | +} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?