[feat] negodata/front: 프론트 초기 구축 (Vite+React, orval API 클라이언트, 견적/상품/협력사 페이지)

- 라우팅 react-router v7, 서버상태 TanStack Query
- orval 자동 생성 API 클라이언트(src/api/generated)
- 견적/상품/협력사/견적설정 페이지, shadcn UI, 토큰(tokens.css)
- 실행: 루트 docker compose (front :3001), README 그에 맞게 정리
- AI Studio 스캐폴드 잔재 제거(metadata.json, 중복 DESIGN_TOKENS.md), 타이틀 NegoData, vite.config 죽은코드 제거

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
minaChoiandClaude Opus 4.8 committed 2026-06-16 17:18:08 +09:00
1 parent a6731dcb07
commit 87524bf6e8
288 files changed
+26363 -1

No files matched your search

@@ -0,0 +1,168 @@
import React, { useState, useRef, DragEvent, ChangeEvent } from 'react';
import { Upload, Image as ImageIcon, X, AlertCircle } from 'lucide-react';
interface ImageDropzoneProps {
value: string;
onChange: (base64Url: string) => void;
onClear: () => void;
label?: string;
className?: string;
}
export default function ImageDropzone({
value,
onChange,
onClear,
label = '상품 대표 이미지 업로드',
className = ''
}: ImageDropzoneProps) {
const [isDragActive, setIsDragActive] = useState(false);
const [error, setError] = useState<string | null>(null);
const fileInputRef = useRef<HTMLInputElement>(null);
const processFile = (file: File) => {
setError(null);
// Validate file type
if (!file.type.startsWith('image/')) {
setError('이미지 파일(*.png, *.jpg, *.jpeg, *.gif)만 업로드할 수 있습니다.');
return;
}
// Validate size (e.g., max 4MB for high-fidelity base64 storage)
const maxSize = 4 * 1024 * 1024;
if (file.size > maxSize) {
setError('이미지 최댓값은 4MB입니다. 더 작고 최적화된 이미지를 권장합니다.');
return;
}
const reader = new FileReader();
reader.onload = (e) => {
if (e.target?.result && typeof e.target.result === 'string') {
onChange(e.target.result);
} else {
setError('이미지 해독 과정에 이상이 발생했습니다.');
}
};
reader.onerror = () => {
setError('파일을 수집하지 못했습니다.');
};
reader.readAsDataURL(file);
};
const handleDragOver = (e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
e.stopPropagation();
setIsDragActive(true);
};
const handleDragLeave = (e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
e.stopPropagation();
setIsDragActive(false);
};
const handleDrop = (e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
e.stopPropagation();
setIsDragActive(false);
if (e.dataTransfer.files && e.dataTransfer.files[0]) {
processFile(e.dataTransfer.files[0]);
}
};
const handleFileChange = (e: ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files[0]) {
processFile(e.target.files[0]);
}
};
const handleButtonClick = () => {
fileInputRef.current?.click();
};
return (
<div className={`space-y-1.5 font-mono text-xs ${className}`}>
<label className="font-semibold text-foreground flex items-center gap-1.5">
<span className="h-1.5 w-1.5 rounded-full bg-primary" />
{label}
</label>
{value ? (
// Preview Mode with image loaded
<div className="relative group border border-border rounded-lg overflow-hidden bg-background h-44 flex items-center justify-center">
<img
src={value}
alt="Uploaded preview"
referrerPolicy="no-referrer"
className="h-full w-full object-contain"
/>
{/* Hover overlay control */}
<div className="absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex flex-col items-center justify-center gap-2">
<button
type="button"
onClick={handleButtonClick}
className="px-3 py-1.5 bg-background text-foreground hover:bg-muted font-bold rounded text-[11px] cursor-pointer"
>
다른 이미지로 교체
</button>
<button
type="button"
onClick={onClear}
className="px-3 py-1.5 bg-destructive text-destructive-foreground hover:opacity-90 font-bold rounded text-[11px] cursor-pointer flex items-center gap-1"
>
<X size={12} />
이미지 제거
</button>
</div>
</div>
) : (
// Active Dropzone Area
<div
onDragOver={handleDragOver}
onDragLeave={handleDragLeave}
onDrop={handleDrop}
onClick={handleButtonClick}
className={`border-2 border-dashed rounded-lg p-6 flex flex-col items-center justify-center text-center cursor-pointer min-h-44 transition-all ${
isDragActive
? 'border-primary bg-primary/5'
: 'border-border hover:border-foreground/30 bg-muted/20'
}`}
>
<input
type="file"
ref={fileInputRef}
onChange={handleFileChange}
accept="image/*"
className="hidden"
/>
<div className="p-2.5 bg-background border border-border rounded-full shadow-xs mb-3 text-muted-foreground">
{isDragActive ? (
<Upload size={22} className="animate-bounce text-primary" />
) : (
<ImageIcon size={22} />
)}
</div>
<div className="space-y-1">
<p className="font-semibold text-foreground text-xs">
{isDragActive ? '여기에 드롭하여 업로드' : '이지지 드래그 앤 드롭 또는 파일 탐색'}
</p>
<p className="text-[10px] text-muted-foreground max-w-[280px] leading-relaxed">
PNG, JPG, JPEG, GIF 파일 지원 (최대 4MB)
</p>
</div>
</div>
)}
{error && (
<div className="flex items-center gap-1.5 text-[10px] text-destructive mt-1">
<AlertCircle size={12} />
<span>{error}</span>
</div>
)}
</div>
);
}
@@ -0,0 +1,127 @@
import React from 'react';
interface SlateLeaf {
text: string;
bold?: boolean;
italic?: boolean;
color?: 'primary' | 'success' | 'warning' | 'destructive';
}
interface SlateNode {
type?: 'paragraph' | 'block-quote' | 'heading-one' | 'heading-two' | 'list-item';
children: (SlateLeaf | SlateNode)[];
}
interface SlateRendererProps {
nodes?: any[];
variables?: Record<string, string | number>;
}
export default function SlateRenderer({ nodes, variables = {} }: SlateRendererProps) {
if (!nodes || !Array.isArray(nodes)) {
return null;
}
// Helper to replace variable strings like {target_price} or {partner_type}
const replaceVariables = (text: string): string => {
let result = text;
Object.entries(variables).forEach(([key, val]) => {
const placeholder = `{${key}}`;
if (result.includes(placeholder)) {
if (typeof val === 'number') {
result = result.replace(new RegExp(placeholder, 'g'), val.toLocaleString('ko-KR'));
} else {
result = result.replace(new RegExp(placeholder, 'g'), String(val));
}
}
});
return result;
};
const renderLeaf = (leaf: SlateLeaf, key: string) => {
const text = replaceVariables(leaf.text);
let classes = '';
if (leaf.bold) {
classes += ' font-bold ';
}
if (leaf.italic) {
classes += ' italic ';
}
if (leaf.color === 'primary') {
return (
<span key={key} className={`${classes} text-primary font-bold underline decoration-2 decoration-gray-400 dark:decoration-gray-600`}>
{text}
</span>
);
}
if (leaf.color === 'success') {
return (
<span key={key} className={`${classes} text-success font-semibold px-1 py-0.5 rounded bg-emerald-50 dark:bg-emerald-950/40 border border-emerald-200/50 dark:border-emerald-900/40`}>
{text}
</span>
);
}
if (leaf.color === 'warning') {
return (
<span key={key} className={`${classes} text-warning font-semibold px-1 py-0.5 rounded bg-amber-50 dark:bg-amber-950/40 border border-amber-200/50`}>
{text}
</span>
);
}
if (leaf.color === 'destructive') {
return (
<span key={key} className={`${classes} text-destructive font-semibold`}>
{text}
</span>
);
}
return (
<span key={key} className={classes || undefined}>
{text}
</span>
);
};
const renderNode = (node: any, index: number): React.ReactNode => {
const key = `node-${index}`;
// If it's pure leaf structure (contains no children arrays, but has text attribute)
if (node.text !== undefined) {
return renderLeaf(node as SlateLeaf, key);
}
const childrenElements = (node.children || []).map((child: any, childIdx: number) => {
if (child.text !== undefined) {
return renderLeaf(child as SlateLeaf, `${key}-${childIdx}`);
}
return renderNode(child, childIdx);
});
switch (node.type) {
case 'heading-one':
return <h1 key={key} className="text-xl font-bold tracking-tight text-foreground my-2">{childrenElements}</h1>;
case 'heading-two':
return <h2 key={key} className="text-lg font-semibold tracking-tight text-foreground my-1.5">{childrenElements}</h2>;
case 'block-quote':
return (
<blockquote key={key} className="border-l-4 border-foreground/50 bg-muted/60 px-4 py-2.5 my-3 rounded-r text-sm text-foreground/90 font-mono">
{childrenElements}
</blockquote>
);
case 'list-item':
return <li key={key} className="list-disc ml-5 my-1 text-sm text-foreground/80">{childrenElements}</li>;
case 'paragraph':
default:
return <p key={key} className="text-sm leading-relaxed text-foreground/85 my-1 whitespace-pre-line">{childrenElements}</p>;
}
};
return (
<div className="space-y-2">
{nodes.map((node, i) => renderNode(node, i))}
</div>
);
}
@@ -0,0 +1,46 @@
import {Outlet, useNavigate, useLocation} from 'react-router';
import Layout from './Layout';
import {PageType} from '@/types';
import {useAuth} from '@/features/auth/useAuth';
import {showToast} from '@/lib/notify';
const PAGE_TO_PATH: Record<PageType, string> = {
PRODUCTS: '/products',
PARTNERS: '/partners',
QUOTATION: '/quotation',
CARDS: '/cards',
};
export default function AuthenticatedLayout() {
const {user, logout} = useAuth();
const navigate = useNavigate();
const {pathname} = useLocation();
const currentPage =
(Object.keys(PAGE_TO_PATH) as PageType[]).find((page) =>
pathname.startsWith(PAGE_TO_PATH[page]),
) ?? 'PRODUCTS';
const setPage = (page: PageType) => {
navigate(PAGE_TO_PATH[page]);
};
const handleLogout = async () => {
// logout()이 상태를 비우므로 메시지에 쓸 유저 정보를 미리 잡아둔다.
const who = `${user?.company ? user.company + ' ' : ''}${user?.name ?? ''}`.trim();
// 로그아웃 완료(상태 초기화) 후 이동 — 안 그러면 /login 가드가 다시 튕겨낼 수 있다.
await logout();
showToast(who ? `${who}님, 로그아웃되었습니다.` : '로그아웃되었습니다.', 'info');
navigate('/login');
};
return (
<Layout
currentPage={currentPage}
setPage={setPage}
onLogout={handleLogout}
>
<Outlet />
</Layout>
);
}
@@ -0,0 +1,287 @@
import { useState, type ReactNode, type ElementType } from 'react';
import { PageType } from '@/types';
import { useAuth } from '@/features/auth/useAuth';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { Typography } from '@/components/ui/typography';
import { cn } from '@/lib/utils';
import {
Briefcase,
Users,
FileSpreadsheet,
Layers,
LogOut,
Sun,
Moon,
Building,
ChevronRight,
} from 'lucide-react';
interface LayoutProps {
children: ReactNode;
currentPage: PageType;
setPage: (page: PageType) => void;
onLogout: () => void;
}
type SidebarUser = ReturnType<typeof useAuth>['user'];
const menuItems = [
{ type: 'PRODUCTS' as PageType, label: '상품관리', icon: Briefcase, id: 'sidebar-products' },
{ type: 'PARTNERS' as PageType, label: '협력사관리', icon: Users, id: 'sidebar-partners' },
{ type: 'QUOTATION' as PageType, label: '견적관리', icon: FileSpreadsheet, id: 'sidebar-quotation' },
{ type: 'CARDS' as PageType, label: '협상카드관리', icon: Layers, id: 'sidebar-cards' },
];
const pageLabelMap: Record<PageType, string> = {
PRODUCTS: '상품관리',
PARTNERS: '협력사관리',
QUOTATION: '견적관리',
CARDS: '협상카드관리',
};
export default function Layout({ children, currentPage, setPage, onLogout }: LayoutProps) {
const { user } = useAuth();
// 기준일시(오늘) — 로컬 타임존 기준 YYYY-MM-DD
const today = new Date().toLocaleDateString('sv-SE');
const [isDark, setIsDark] = useState(false);
const [isSidebarOpen, setIsSidebarOpen] = useState(true);
const toggleDarkMode = () => {
setIsDark(!isDark);
if (!isDark) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
};
return (
<div className="min-h-screen bg-background text-foreground flex">
{/* 토스트는 sonner <Toaster/>(main.tsx)가 전역으로 처리한다 */}
{/* Main Sidebar */}
<aside
className={cn(
'bg-card border-r border-border flex flex-col justify-between transition-all duration-300 z-30 fixed h-full',
isSidebarOpen ? 'w-60' : 'w-16'
)}
>
<div>
{/* Sidebar Brand Header */}
<div className="h-14 flex items-center justify-between px-4 border-b border-border">
{isSidebarOpen ? (
<>
<Typography as="div" variant="body" className="text-primary font-extrabold tracking-tighter">
NegoData
</Typography>
<Button
variant="ghost"
onClick={() => setIsSidebarOpen(false)}
className="p-1 h-auto rounded text-muted-foreground"
title="메뉴 접기"
>
<ChevronRight size={14} className="rotate-180 size-3.5" />
</Button>
</>
) : (
<Button
variant="ghost"
onClick={() => setIsSidebarOpen(true)}
className="mx-auto p-1.5 h-auto rounded bg-muted/65 text-muted-foreground"
title="메뉴 열기"
>
<ChevronRight size={14} className="size-3.5" />
</Button>
)}
</div>
{/* Nav User Profile Card */}
{isSidebarOpen && <SidebarProfileCard user={user} />}
{/* Nav Items */}
<nav className="mt-2 px-3 space-y-1">
{menuItems.map((item) => (
<NavItem
key={item.type}
item={item}
isActive={currentPage === item.type}
isOpen={isSidebarOpen}
onClick={() => setPage(item.type)}
/>
))}
</nav>
</div>
{/* Sidebar Footer Controls */}
<div className="p-2 border-t border-border space-y-1">
{/* Theme switcher */}
<Button
variant="ghost"
onClick={toggleDarkMode}
className="w-full justify-start gap-3 py-1.5 px-3 h-auto rounded text-[11px] font-semibold text-muted-foreground"
>
{isDark ? <Sun size={14} className="text-warning size-3.5" /> : <Moon size={14} className="size-3.5" />}
{isSidebarOpen && <span>{isDark ? '라이트 모드' : '다크 모드'}</span>}
</Button>
{/* Logout btn */}
<Button
id="header-logout-button"
variant="ghost"
onClick={onLogout}
className="w-full justify-start gap-3 py-1.5 px-3 h-auto rounded text-[11px] font-semibold text-destructive hover:bg-destructive/10 hover:text-destructive"
>
<LogOut size={14} className="size-3.5" />
{isSidebarOpen && <span>시스템 로그아웃</span>}
</Button>
</div>
</aside>
{/* Main Container Wrapper */}
<div
className="flex-1 flex flex-col transition-all duration-300"
style={{ paddingLeft: isSidebarOpen ? '15rem' : '4rem' }}
>
{/* Global Header */}
<header className="h-14 bg-card border-b border-border flex items-center justify-between px-8 sticky top-0 z-20 shadow-xs backdrop-blur-md bg-opacity-95">
<div className="flex items-center gap-4">
<Typography as="div" variant="small" className="font-bold">
{pageLabelMap[currentPage]}
</Typography>
<Badge variant="outline">B2B 시스템</Badge>
</div>
<HeaderMeta user={user} today={today} />
</header>
{/* Content Body Area */}
<main className="flex-1 p-8 overflow-y-auto bg-background">
<div className="max-w-7xl mx-auto space-y-6">{children}</div>
</main>
{/* Compact Admin footer info */}
<footer className="h-10 border-t border-border/60 bg-card flex items-center justify-between px-8">
<Typography variant="mono">Copyright &copy; O2O Inc. All rights reserved</Typography>
</footer>
</div>
</div>
);
}
/** 라벨:값 한 줄 (사이드바 프로필 카드용) */
function InfoRow({
label,
value,
valueClassName,
title,
}: {
label: string;
value?: string;
valueClassName?: string;
title?: string;
}) {
return (
<div className="flex justify-between items-center">
<Typography variant="caption">{label}</Typography>
<Typography variant="caption" title={title} className={cn('font-bold text-foreground', valueClassName)}>
{value}
</Typography>
</div>
);
}
/** 사이드바 사용자 프로필 카드 */
function SidebarProfileCard({ user }: { user: SidebarUser }) {
return (
<div className="p-3.5 mx-4 my-4 rounded-lg bg-muted/80 border border-border flex flex-col gap-1.5 shadow-2xs">
<div className="flex items-center gap-2 pb-1.5 border-b border-border/50">
<Building size={13} className="text-primary" />
<Typography variant="caption" className="font-bold text-foreground truncate max-w-[140px]" title="소속 고객사">
{user?.company}
</Typography>
</div>
<div className="space-y-1">
<InfoRow label="사용자명:" value={user?.name} />
<InfoRow label="로그인 ID:" value={user?.loginId} valueClassName="font-mono" />
<InfoRow
label="이메일:"
value={user?.email}
title={user?.email}
valueClassName="font-mono text-foreground/90 truncate max-w-[80px]"
/>
<InfoRow label="연락처:" value={user?.contact} valueClassName="font-mono" />
<div className="flex justify-between items-center pt-1 border-t border-border/20">
<Typography variant="caption">권한등급:</Typography>
<Badge variant="secondary" className="text-[10px]">{user?.role}</Badge>
</div>
</div>
</div>
);
}
/** 사이드바 메뉴 항목 */
function NavItem({
item,
isActive,
isOpen,
onClick,
}: {
item: { type: PageType; label: string; icon: ElementType; id: string };
isActive: boolean;
isOpen: boolean;
onClick: () => void;
}) {
const Icon = item.icon;
return (
<Button
id={item.id}
variant="ghost"
onClick={onClick}
className={cn(
'w-full justify-start gap-3 py-2 px-3 h-auto rounded text-xs font-semibold tracking-tight',
isActive
? 'bg-secondary text-foreground border-l-2 border-primary pl-2 hover:bg-secondary hover:text-foreground'
: 'text-muted-foreground hover:bg-muted/80'
)}
>
<Icon size={16} className={cn('size-4', isActive ? 'text-foreground' : 'text-muted-foreground/85')} />
{isOpen && <span className="truncate">{item.label}</span>}
</Button>
);
}
/** 글로벌 헤더 우측 메타 정보 */
function HeaderMeta({ user, today }: { user: SidebarUser; today: string }) {
return (
<div className="flex items-center gap-4">
<Typography as="div" variant="caption" className="hidden md:block">
기준일시: <span className="font-semibold text-foreground">{today}</span>
</Typography>
<div className="h-4 w-px bg-border hidden md:block" />
<div className="flex items-center gap-2">
<span className="inline-block h-2 w-2 rounded-full bg-success animate-pulse" />
<Typography as="span" variant="caption">회사:</Typography>
<Typography
as="span"
variant="caption"
id="header-company-name"
className="font-bold text-foreground underline decoration-1"
>
{user?.company}
</Typography>
</div>
<div className="h-4 w-px bg-border" />
<div className="flex items-center gap-2">
<Typography as="span" variant="caption">관리자:</Typography>
<Typography as="span" variant="caption" className="font-semibold text-foreground">
{user?.name} ({user?.loginId})
</Typography>
<Badge variant="secondary" className="text-[9px]">{user?.role}</Badge>
</div>
</div>
);
}
@@ -0,0 +1,14 @@
import type { ReactNode } from 'react';
import { cn } from '@/lib/utils';
// 라우트 페이지 최상위 래퍼. 페이지 간 세로 리듬(섹션 간격)을 단일 출처로 통일한다.
// 페이지마다 <div className="space-y-6">를 복붙하지 말고 이걸 쓴다.
export function PageContainer({
className,
children,
}: {
className?: string;
children: ReactNode;
}) {
return <div className={cn('space-y-6', className)}>{children}</div>;
}
@@ -0,0 +1,44 @@
import type { ComponentProps, ReactNode } from 'react';
import { Search } from 'lucide-react';
import { cn } from '@/lib/utils';
// 페이지 상단의 "검색/액션 바". card 외피 + 좌측(검색·필터) / 우측(액션 버튼) 레이아웃.
// products/partners/quotation에서 동일하게 반복되던 구조를 단일 출처로 통일.
export function PageToolbar({
children,
actions,
className,
}: {
children: ReactNode; // 좌측: 검색 + 필터
actions?: ReactNode; // 우측: 액션 버튼들
className?: string;
}) {
return (
<div
className={cn(
'flex flex-col md:flex-row md:items-center justify-between gap-4 p-4 rounded-lg border border-border bg-card',
className
)}
>
<div className="flex flex-1 flex-col sm:flex-row gap-3">{children}</div>
{actions && <div className="flex items-center gap-2">{actions}</div>}
</div>
);
}
// 돋보기 아이콘 + 검색 input. 매 페이지 복붙하던 동일 마크업을 컴포넌트화.
export function SearchInput({ className, ...props }: ComponentProps<'input'>) {
return (
<div className="relative flex-1">
<Search className="absolute left-3 top-2.5 h-4 w-4 text-muted-foreground" />
<input
type="text"
className={cn(
'w-full pl-9 pr-3 py-2 text-xs bg-background border border-border rounded focus:outline-none focus:border-foreground/40 text-foreground transition-colors font-mono',
className
)}
{...props}
/>
</div>
);
}
@@ -0,0 +1,52 @@
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const badgeVariants = cva(
"group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
secondary:
"bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
destructive:
"bg-destructive/10 text-destructive focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:bg-destructive/20",
outline:
"border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
ghost:
"hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
link: "text-primary underline-offset-4 hover:underline",
},
},
defaultVariants: {
variant: "default",
},
}
)
function Badge({
className,
variant = "default",
render,
...props
}: useRender.ComponentProps<"span"> & VariantProps<typeof badgeVariants>) {
return useRender({
defaultTagName: "span",
props: mergeProps<"span">(
{
className: cn(badgeVariants({ variant }), className),
},
props
),
render,
state: {
slot: "badge",
variant,
},
})
}
export { Badge, badgeVariants }
@@ -0,0 +1,58 @@
import { Button as ButtonPrimitive } from "@base-ui/react/button"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const buttonVariants = cva(
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none cursor-pointer focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/80",
outline:
"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
secondary:
"bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
ghost:
"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
destructive:
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/30 dark:bg-destructive/80 dark:hover:bg-destructive/70",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default:
"h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
icon: "size-8",
"icon-xs":
"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
"icon-sm":
"size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
"icon-lg": "size-9",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
function Button({
className,
variant = "default",
size = "default",
...props
}: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>) {
return (
<ButtonPrimitive
data-slot="button"
className={cn(buttonVariants({ variant, size, className }))}
{...props}
/>
)
}
export { Button, buttonVariants }
+92
View File
@@ -0,0 +1,92 @@
import * as React from "react"
import { cn } from "@/lib/utils"
function Card({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card"
className={cn(
"flex flex-col gap-6 rounded-lg border border-border bg-card py-6 text-card-foreground shadow-sm",
className
)}
{...props}
/>
)
}
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-header"
className={cn(
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
className
)}
{...props}
/>
)
}
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-title"
className={cn("font-semibold leading-none", className)}
{...props}
/>
)
}
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-description"
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
)
}
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-action"
className={cn(
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
className
)}
{...props}
/>
)
}
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-content"
className={cn("px-6", className)}
{...props}
/>
)
}
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-footer"
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
{...props}
/>
)
}
export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardAction,
CardDescription,
CardContent,
}
@@ -0,0 +1,171 @@
import type { ReactNode, MouseEvent } from "react"
import { cn } from "@/lib/utils"
import {
Table,
TableHeader,
TableBody,
TableRow,
TableHead,
TableCell,
} from "@/components/ui/table"
// 컬럼 설정형 데이터 테이블. 래퍼/헤더/행/빈상태/정렬·패딩, 그리고 행 선택(체크박스)까지
// 여기서 책임지고, 페이지는 컬럼 정의(header/cell)와 선택 상태만 넘긴다. 표 룩의 단일 출처.
export type Column<T> = {
id?: string
header: ReactNode
cell: (row: T) => ReactNode
align?: "left" | "right" | "center"
headClassName?: string
cellClassName?: string
// 셀 단위 클릭 핸들러 (예: 행 클릭 전파 차단)
onCellClick?: (row: T, e: MouseEvent) => void
}
// 행 선택 기능. 넘기면 맨 앞에 체크박스 컬럼(전체선택 헤더 포함)이 자동으로 붙는다.
export type RowSelection = {
selectedKeys: string[]
onSelectionChange: (keys: string[]) => void
}
type DataTableProps<T> = {
columns: Column<T>[]
data: T[]
rowKey: (row: T) => string
onRowClick?: (row: T) => void
rowClassName?: (row: T) => string
selection?: RowSelection
empty?: ReactNode
// 같은 카드 안에 들어가는 하단 영역 (예: 페이지네이션 푸터)
footer?: ReactNode
className?: string
}
const alignClass = {
left: "text-left",
right: "text-right",
center: "text-center",
} as const
const checkboxClass =
"h-3.5 w-3.5 rounded border-border text-primary focus:ring-primary cursor-pointer accent-primary"
export function DataTable<T>({
columns,
data,
rowKey,
onRowClick,
rowClassName,
selection,
empty = "데이터가 없습니다.",
footer,
className,
}: DataTableProps<T>) {
const pageKeys = data.map(rowKey)
const isAllSelected =
!!selection && data.length > 0 && pageKeys.every((k) => selection.selectedKeys.includes(k))
const toggleAll = (checked: boolean) => {
if (!selection) return
const set = new Set(selection.selectedKeys)
pageKeys.forEach((k) => (checked ? set.add(k) : set.delete(k)))
selection.onSelectionChange([...set])
}
const toggleOne = (key: string, checked: boolean) => {
if (!selection) return
selection.onSelectionChange(
checked
? [...selection.selectedKeys, key]
: selection.selectedKeys.filter((k) => k !== key)
)
}
const colCount = columns.length + (selection ? 1 : 0)
return (
<div className={cn("border border-border rounded-lg bg-card overflow-hidden", className)}>
<Table className="w-full text-xs">
<TableHeader>
<TableRow className="bg-muted/50 border-b border-border hover:bg-transparent">
{selection && (
<TableHead className="p-4 w-12 text-center">
<input
type="checkbox"
checked={isAllSelected}
onChange={(e) => toggleAll(e.target.checked)}
className={checkboxClass}
/>
</TableHead>
)}
{columns.map((c, i) => (
<TableHead
key={c.id ?? i}
className={cn(
"p-4 font-semibold text-foreground",
c.align && alignClass[c.align],
c.headClassName
)}
>
{c.header}
</TableHead>
))}
</TableRow>
</TableHeader>
<TableBody>
{data.length > 0 ? (
data.map((row) => {
const key = rowKey(row)
const selected = !!selection && selection.selectedKeys.includes(key)
return (
<TableRow
key={key}
className={cn(
"border-b border-border/50 transition-colors",
onRowClick && "cursor-pointer hover:bg-muted/35",
selected && "bg-primary/5 hover:bg-primary/10",
rowClassName?.(row)
)}
onClick={onRowClick ? () => onRowClick(row) : undefined}
>
{selection && (
<TableCell
className="p-4 text-center w-12"
onClick={(e) => e.stopPropagation()}
>
<input
type="checkbox"
checked={selected}
onChange={(e) => toggleOne(key, e.target.checked)}
className={checkboxClass}
/>
</TableCell>
)}
{columns.map((c, i) => (
<TableCell
key={c.id ?? i}
className={cn("p-4", c.align && alignClass[c.align], c.cellClassName)}
onClick={c.onCellClick ? (e) => c.onCellClick!(row, e) : undefined}
>
{c.cell(row)}
</TableCell>
))}
</TableRow>
)
})
) : (
<TableRow>
<TableCell
colSpan={colCount}
className="p-12 text-center text-muted-foreground font-mono"
>
{empty}
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
{footer}
</div>
)
}
+160
View File
@@ -0,0 +1,160 @@
"use client"
import * as React from "react"
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
import { XIcon } from "lucide-react"
function Dialog({ ...props }: DialogPrimitive.Root.Props) {
return <DialogPrimitive.Root data-slot="dialog" {...props} />
}
function DialogTrigger({ ...props }: DialogPrimitive.Trigger.Props) {
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
}
function DialogPortal({ ...props }: DialogPrimitive.Portal.Props) {
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
}
function DialogClose({ ...props }: DialogPrimitive.Close.Props) {
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
}
function DialogOverlay({
className,
...props
}: DialogPrimitive.Backdrop.Props) {
return (
<DialogPrimitive.Backdrop
data-slot="dialog-overlay"
className={cn(
"fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
className
)}
{...props}
/>
)
}
function DialogContent({
className,
children,
showCloseButton = true,
...props
}: DialogPrimitive.Popup.Props & {
showCloseButton?: boolean
}) {
return (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Popup
data-slot="dialog-content"
className={cn(
"fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
className
)}
{...props}
>
{children}
{showCloseButton && (
<DialogPrimitive.Close
data-slot="dialog-close"
render={
<Button
variant="ghost"
className="absolute top-2 right-2"
size="icon-sm"
/>
}
>
<XIcon
/>
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
)}
</DialogPrimitive.Popup>
</DialogPortal>
)
}
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="dialog-header"
className={cn("flex flex-col gap-2", className)}
{...props}
/>
)
}
function DialogFooter({
className,
showCloseButton = false,
children,
...props
}: React.ComponentProps<"div"> & {
showCloseButton?: boolean
}) {
return (
<div
data-slot="dialog-footer"
className={cn(
"-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t bg-muted/50 p-4 sm:flex-row sm:justify-end",
className
)}
{...props}
>
{children}
{showCloseButton && (
<DialogPrimitive.Close render={<Button variant="outline" />}>
Close
</DialogPrimitive.Close>
)}
</div>
)
}
function DialogTitle({ className, ...props }: DialogPrimitive.Title.Props) {
return (
<DialogPrimitive.Title
data-slot="dialog-title"
className={cn(
"font-heading text-base leading-none font-medium",
className
)}
{...props}
/>
)
}
function DialogDescription({
className,
...props
}: DialogPrimitive.Description.Props) {
return (
<DialogPrimitive.Description
data-slot="dialog-description"
className={cn(
"text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
className
)}
{...props}
/>
)
}
export {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogOverlay,
DialogPortal,
DialogTitle,
DialogTrigger,
}
+132
View File
@@ -0,0 +1,132 @@
import * as React from "react"
import { Drawer as DrawerPrimitive } from "vaul"
import { cn } from "@/lib/utils"
function Drawer({
...props
}: React.ComponentProps<typeof DrawerPrimitive.Root>) {
return <DrawerPrimitive.Root data-slot="drawer" {...props} />
}
function DrawerTrigger({
...props
}: React.ComponentProps<typeof DrawerPrimitive.Trigger>) {
return <DrawerPrimitive.Trigger data-slot="drawer-trigger" {...props} />
}
function DrawerPortal({
...props
}: React.ComponentProps<typeof DrawerPrimitive.Portal>) {
return <DrawerPrimitive.Portal data-slot="drawer-portal" {...props} />
}
function DrawerClose({
...props
}: React.ComponentProps<typeof DrawerPrimitive.Close>) {
return <DrawerPrimitive.Close data-slot="drawer-close" {...props} />
}
function DrawerOverlay({
className,
...props
}: React.ComponentProps<typeof DrawerPrimitive.Overlay>) {
return (
<DrawerPrimitive.Overlay
data-slot="drawer-overlay"
className={cn(
"fixed inset-0 z-50 bg-black/10 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
className
)}
{...props}
/>
)
}
function DrawerContent({
className,
children,
...props
}: React.ComponentProps<typeof DrawerPrimitive.Content>) {
return (
<DrawerPortal data-slot="drawer-portal">
<DrawerOverlay />
<DrawerPrimitive.Content
data-slot="drawer-content"
className={cn(
"group/drawer-content fixed z-50 flex h-auto flex-col bg-popover text-sm text-popover-foreground data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=bottom]:rounded-t-xl data-[vaul-drawer-direction=bottom]:border-t data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:rounded-r-xl data-[vaul-drawer-direction=left]:border-r data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:rounded-l-xl data-[vaul-drawer-direction=right]:border-l data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=top]:rounded-b-xl data-[vaul-drawer-direction=top]:border-b data-[vaul-drawer-direction=left]:sm:max-w-sm data-[vaul-drawer-direction=right]:sm:max-w-sm",
className
)}
{...props}
>
<div className="mx-auto mt-4 hidden h-1 w-[100px] shrink-0 rounded-full bg-muted group-data-[vaul-drawer-direction=bottom]/drawer-content:block" />
{children}
</DrawerPrimitive.Content>
</DrawerPortal>
)
}
function DrawerHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="drawer-header"
className={cn(
"flex flex-col gap-0.5 p-4 group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center group-data-[vaul-drawer-direction=top]/drawer-content:text-center md:gap-0.5 md:text-left",
className
)}
{...props}
/>
)
}
function DrawerFooter({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="drawer-footer"
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
{...props}
/>
)
}
function DrawerTitle({
className,
...props
}: React.ComponentProps<typeof DrawerPrimitive.Title>) {
return (
<DrawerPrimitive.Title
data-slot="drawer-title"
className={cn(
"font-heading text-base font-medium text-foreground",
className
)}
{...props}
/>
)
}
function DrawerDescription({
className,
...props
}: React.ComponentProps<typeof DrawerPrimitive.Description>) {
return (
<DrawerPrimitive.Description
data-slot="drawer-description"
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
)
}
export {
Drawer,
DrawerPortal,
DrawerOverlay,
DrawerTrigger,
DrawerClose,
DrawerContent,
DrawerHeader,
DrawerFooter,
DrawerTitle,
DrawerDescription,
}
@@ -0,0 +1,20 @@
import { Input as InputPrimitive } from "@base-ui/react/input"
import { cn } from "@/lib/utils"
function Input({ className, ...props }: InputPrimitive.Props) {
return (
<InputPrimitive
data-slot="input"
className={cn(
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground border-input flex h-8 w-full min-w-0 rounded-lg border bg-transparent px-2.5 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-3",
"aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",
className
)}
{...props}
/>
)
}
export { Input }
@@ -0,0 +1,87 @@
"use client"
import { Select as SelectPrimitive } from "@base-ui/react/select"
import { CheckIcon, ChevronDownIcon } from "lucide-react"
import { cn } from "@/lib/utils"
// 기존 네이티브 <select> 필터를 대체하는 shadcn 스타일 Select(@base-ui 기반).
// 사용: <Select value onValueChange><SelectTrigger><SelectValue/></SelectTrigger>
// <SelectContent><SelectItem value>...</SelectItem></SelectContent></Select>
function Select<Value>(props: SelectPrimitive.Root.Props<Value>) {
return <SelectPrimitive.Root data-slot="select" {...props} />
}
function SelectValue(props: SelectPrimitive.Value.Props) {
return <SelectPrimitive.Value data-slot="select-value" {...props} />
}
function SelectTrigger({
className,
children,
...props
}: SelectPrimitive.Trigger.Props) {
return (
<SelectPrimitive.Trigger
data-slot="select-trigger"
className={cn(
"border-border bg-background text-foreground flex h-auto w-full items-center justify-between gap-2 rounded border px-3 py-2 text-xs whitespace-nowrap transition-colors outline-none cursor-pointer focus-visible:border-foreground/40 disabled:cursor-not-allowed disabled:opacity-50 data-[popup-open]:border-foreground/40 [&_svg]:pointer-events-none [&_svg]:shrink-0",
className
)}
{...props}
>
{children}
<SelectPrimitive.Icon className="text-muted-foreground">
<ChevronDownIcon size={14} />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
)
}
function SelectContent({
className,
children,
...props
}: SelectPrimitive.Popup.Props) {
return (
<SelectPrimitive.Portal>
<SelectPrimitive.Positioner className="z-50 outline-none" sideOffset={4}>
<SelectPrimitive.Popup
data-slot="select-content"
className={cn(
"bg-popover text-popover-foreground relative z-50 max-h-[min(var(--available-height),20rem)] min-w-[var(--anchor-width)] overflow-y-auto rounded-lg border border-border p-1 text-xs shadow-md outline-none data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
className
)}
{...props}
>
{children}
</SelectPrimitive.Popup>
</SelectPrimitive.Positioner>
</SelectPrimitive.Portal>
)
}
function SelectItem({
className,
children,
...props
}: SelectPrimitive.Item.Props) {
return (
<SelectPrimitive.Item
data-slot="select-item"
className={cn(
"relative flex w-full cursor-pointer items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-xs outline-none select-none data-highlighted:bg-muted data-highlighted:text-foreground data-disabled:pointer-events-none data-disabled:opacity-50",
className
)}
{...props}
>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
<SelectPrimitive.ItemIndicator className="absolute right-2 flex items-center justify-center text-muted-foreground">
<CheckIcon size={14} />
</SelectPrimitive.ItemIndicator>
</SelectPrimitive.Item>
)
}
export { Select, SelectValue, SelectTrigger, SelectContent, SelectItem }
@@ -0,0 +1,45 @@
import type { ReactNode } from 'react';
import { X } from 'lucide-react';
import { Typography } from '@/components/ui/typography';
type SheetProps = {
open: boolean;
title: string;
onClose: () => void;
children: ReactNode;
};
// 우측 슬라이드 드로어 껍데기. 백드롭 + 패널 + 헤더(액센트바·타이틀·닫기)만 담당하고
// 폼/내용은 children으로 받는다. ProductFormSheet·PartnerFormSheet 공통 셸.
// 백드롭 클릭 시 닫힘(기존 FormSheet 동작 유지).
export function Sheet({ open, title, onClose, children }: SheetProps) {
if (!open) return null;
return (
<div className="fixed inset-0 z-50 flex justify-end bg-black/40 backdrop-blur-xs animate-fade-in">
{/* 백드롭 */}
<div className="flex-1 cursor-pointer" onClick={onClose} />
{/* 우측 드로어 패널 */}
<div className="w-full max-w-lg bg-card border-l border-border h-full flex flex-col justify-between shadow-2xl p-6 overflow-y-auto animate-slide-left">
<div>
{/* 헤더 */}
<div className="flex items-center justify-between pb-4 border-b border-border">
<div className="flex items-center gap-2">
<div className="h-6 w-2 bg-primary rounded" />
<Typography variant="h3">{title}</Typography>
</div>
<button
onClick={onClose}
className="p-1 rounded text-muted-foreground hover:bg-muted cursor-pointer"
>
<X size={18} />
</button>
</div>
{children}
</div>
</div>
</div>
);
}
@@ -0,0 +1,37 @@
import * as React from "react"
import { cn } from "@/lib/utils"
// products 등에서 매번 직접 그리던 role="switch" 패턴을 단일 프리미티브로.
type SwitchProps = Omit<React.ComponentProps<"button">, "onChange"> & {
checked?: boolean
onCheckedChange?: (checked: boolean) => void
}
function Switch({ checked = false, onCheckedChange, disabled, className, ...props }: SwitchProps) {
return (
<button
type="button"
role="switch"
aria-checked={checked}
disabled={disabled}
onClick={() => onCheckedChange?.(!checked)}
data-slot="switch"
className={cn(
"relative inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-all duration-200 outline-none focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50",
checked ? "bg-primary" : "bg-input dark:bg-zinc-700",
className
)}
{...props}
>
<span
className={cn(
"pointer-events-none block h-4 w-4 rounded-full bg-white shadow transition-all duration-200",
checked ? "translate-x-4" : "translate-x-0"
)}
/>
</button>
)
}
export { Switch }
@@ -0,0 +1,104 @@
import { ChevronLeft, ChevronRight } from "lucide-react"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
// 리스트(테이블) 하단 페이지네이션 푸터 단일 출처.
// 수동 페이지네이션(useState page/size) 앱이라 props 기반으로 동작한다.
type TablePaginationProps = {
page: number // 1-based 현재 페이지
totalPages: number
totalCount: number // 필터링된 전체 행 수
pageSize: number
onPageChange: (page: number) => void
label?: string // 카운터 앞 명사 (예: "검색 결과", "연동 파트너사")
unit?: string // 수량 단위 (예: "건", "개사")
className?: string
}
// 페이지가 많을 때 1 … 현재±1 … 끝 형태로 줄인다(버튼 20개 방지).
function getPageWindow(page: number, totalPages: number): (number | "ellipsis")[] {
if (totalPages <= 7) {
return Array.from({ length: totalPages }, (_, i) => i + 1)
}
const pages: (number | "ellipsis")[] = [1]
const start = Math.max(2, page - 1)
const end = Math.min(totalPages - 1, page + 1)
if (start > 2) pages.push("ellipsis")
for (let i = start; i <= end; i++) pages.push(i)
if (end < totalPages - 1) pages.push("ellipsis")
pages.push(totalPages)
return pages
}
export function TablePagination({
page,
totalPages,
totalCount,
pageSize,
onPageChange,
label = "전체",
unit = "건",
className,
}: TablePaginationProps) {
const start = totalCount === 0 ? 0 : (page - 1) * pageSize + 1
const end = Math.min(page * pageSize, totalCount)
return (
<div
className={cn(
"flex flex-col gap-3 border-t border-border bg-muted/40 p-3 text-sm sm:flex-row sm:items-center sm:justify-between",
className
)}
>
<span className="text-muted-foreground">
{label}{" "}
<span className="font-semibold text-foreground">
{totalCount.toLocaleString()}
{unit}
</span>{" "}
중 {start.toLocaleString()}–{end.toLocaleString()}
</span>
<div className="flex items-center gap-1">
<Button
variant="outline"
size="icon-sm"
onClick={() => onPageChange(Math.max(page - 1, 1))}
disabled={page === 1}
aria-label="이전 페이지"
>
<ChevronLeft />
</Button>
{getPageWindow(page, totalPages).map((p, i) =>
p === "ellipsis" ? (
<span key={`ellipsis-${i}`} className="px-1.5 text-muted-foreground select-none">
…
</span>
) : (
<Button
key={p}
variant={p === page ? "default" : "ghost"}
size="icon-sm"
onClick={() => onPageChange(p)}
aria-current={p === page ? "page" : undefined}
>
{p}
</Button>
)
)}
<Button
variant="outline"
size="icon-sm"
onClick={() => onPageChange(Math.min(page + 1, totalPages))}
disabled={page === totalPages}
aria-label="다음 페이지"
>
<ChevronRight />
</Button>
</div>
</div>
)
}
+116
View File
@@ -0,0 +1,116 @@
"use client"
import * as React from "react"
import { cn } from "@/lib/utils"
function Table({ className, ...props }: React.ComponentProps<"table">) {
return (
<div
data-slot="table-container"
className="relative w-full overflow-x-auto"
>
<table
data-slot="table"
className={cn("w-full caption-bottom text-sm", className)}
{...props}
/>
</div>
)
}
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
return (
<thead
data-slot="table-header"
className={cn("[&_tr]:border-b", className)}
{...props}
/>
)
}
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
return (
<tbody
data-slot="table-body"
className={cn("[&_tr:last-child]:border-0", className)}
{...props}
/>
)
}
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
return (
<tfoot
data-slot="table-footer"
className={cn(
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
className
)}
{...props}
/>
)
}
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
return (
<tr
data-slot="table-row"
className={cn(
"border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted",
className
)}
{...props}
/>
)
}
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
return (
<th
data-slot="table-head"
className={cn(
"h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0",
className
)}
{...props}
/>
)
}
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
return (
<td
data-slot="table-cell"
className={cn(
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0",
className
)}
{...props}
/>
)
}
function TableCaption({
className,
...props
}: React.ComponentProps<"caption">) {
return (
<caption
data-slot="table-caption"
className={cn("mt-4 text-sm text-muted-foreground", className)}
{...props}
/>
)
}
export {
Table,
TableHeader,
TableBody,
TableFooter,
TableHead,
TableRow,
TableCell,
TableCaption,
}
+80
View File
@@ -0,0 +1,80 @@
import { Tabs as TabsPrimitive } from "@base-ui/react/tabs"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
function Tabs({
className,
orientation = "horizontal",
...props
}: TabsPrimitive.Root.Props) {
return (
<TabsPrimitive.Root
data-slot="tabs"
data-orientation={orientation}
className={cn(
"group/tabs flex gap-2 data-horizontal:flex-col",
className
)}
{...props}
/>
)
}
const tabsListVariants = cva(
"group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-8 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none",
{
variants: {
variant: {
default: "bg-muted",
line: "gap-1 bg-transparent",
},
},
defaultVariants: {
variant: "default",
},
}
)
function TabsList({
className,
variant = "default",
...props
}: TabsPrimitive.List.Props & VariantProps<typeof tabsListVariants>) {
return (
<TabsPrimitive.List
data-slot="tabs-list"
data-variant={variant}
className={cn(tabsListVariants({ variant }), className)}
{...props}
/>
)
}
function TabsTrigger({ className, ...props }: TabsPrimitive.Tab.Props) {
return (
<TabsPrimitive.Tab
data-slot="tabs-trigger"
className={cn(
"relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 aria-disabled:pointer-events-none aria-disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
"group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent",
"data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground",
"after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100",
className
)}
{...props}
/>
)
}
function TabsContent({ className, ...props }: TabsPrimitive.Panel.Props) {
return (
<TabsPrimitive.Panel
data-slot="tabs-content"
className={cn("flex-1 text-sm outline-none", className)}
{...props}
/>
)
}
export { Tabs, TabsList, TabsTrigger, TabsContent, tabsListVariants }
@@ -0,0 +1,61 @@
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
// 디자인시스템 텍스트 토큰. 페이지마다 text-2xl/font-bold/tracking-...를
// 직접 박지 말고 variant로 통일한다. 실제로 코드에 흩어져 있던 조합을 그대로 토큰화함.
const typographyVariants = cva("", {
variants: {
variant: {
h1: "text-4xl font-bold tracking-tight text-foreground",
h2: "text-2xl font-bold tracking-tight text-foreground",
h3: "text-xl font-bold text-foreground",
h4: "text-lg font-semibold text-foreground",
body: "text-base text-foreground",
small: "text-sm text-foreground",
muted: "text-sm text-muted-foreground leading-relaxed",
// 폼 라벨: 대문자 트래킹 (login의 label 패턴)
label: "text-xs font-semibold uppercase tracking-wider text-foreground",
// 모노 캡션: 콘솔/메타 텍스트 (login 서브타이틀, 푸터 등)
mono: "text-xs font-mono uppercase tracking-wider text-muted-foreground",
// 사이드바/헤더 등 chrome 메타텍스트: type scale 최소(text-xs=12px)보다 작은 11px 캡션
caption: "text-[11px] text-muted-foreground leading-normal",
},
},
defaultVariants: { variant: "body" },
})
const defaultTag: Record<NonNullable<VariantProps<typeof typographyVariants>["variant"]>, React.ElementType> = {
h1: "h1",
h2: "h2",
h3: "h3",
h4: "h4",
body: "p",
small: "p",
muted: "p",
label: "span",
mono: "span",
caption: "span",
}
type TypographyProps = React.HTMLAttributes<HTMLElement> &
VariantProps<typeof typographyVariants> & {
/** 의미상 태그를 강제로 바꾸고 싶을 때 (예: label variant를 <label>로) */
as?: React.ElementType
/** as="label"일 때 폼 연결용 (label 전용 속성이라 따로 허용) */
htmlFor?: string
}
function Typography({ className, variant, as, ...props }: TypographyProps) {
const Comp = as ?? defaultTag[variant ?? "body"]
return (
<Comp
data-slot="typography"
className={cn(typographyVariants({ variant }), className)}
{...props}
/>
)
}
export { Typography, typographyVariants }