260123_ENH : Layout가지 완성된 최초 commit

This commit is contained in:
2026-01-23 11:58:39 +09:00
parent cd4e47ce22
commit 649e7f4b26
81 changed files with 5608 additions and 343 deletions

View File

@@ -0,0 +1,147 @@
"use client";
import { CategoryTargetData, CategoryTargetType } from "@/config/filter.types";
import {categoryTarget, categoryTargetType} from "@/config/filter.data";
import { ChevronRight } from "lucide-react";
import { useMemo } from "react";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
const PRODUCTS = [
{ value: "냉장고", label: "냉장고" },
{ value: "세탁기", label: "세탁기" },
{ value: "식기세척기", label: "식기세척기" },
{ value: "건조기", label: "건조기" },
{ value: "에어컨", label: "에어컨" },
] as const;
export type CategoryTypeValue = {
label: string;
value: CategoryTargetType;
};
export type CategoryFilterValue = {
product: string;
type: CategoryTypeValue
target: CategoryTargetData;
};
type CategoryFilterProps = {
value: CategoryFilterValue;
onChange: (next: CategoryFilterValue) => void;
className?: string;
};
const CategoryFilter = ({ value, onChange, className }: CategoryFilterProps) => {
const currentTargetItem = useMemo(() => {
return categoryTarget.find((item) => item.type === value.type.value);
}, [value.type]);
const handlePick = (
key: keyof CategoryFilterValue,
v: string | CategoryTypeValue | CategoryTargetData
) => {
if (value[key] === v) return;
const next: CategoryFilterValue = { ...value, [key]: v } as CategoryFilterValue;
if (key === "type") {
const nextItem = categoryTarget.find((item) => item.type === v);
const firstTarget = nextItem?.children?.[0]?.target;
if (firstTarget) next.target = firstTarget;
}
onChange(next);
};
return (
<div className={cn("w-full border border-gray-300 bg-white/70 backdrop-blur-sm", className)}>
{/* 제품 (1줄 나열) */}
<div className="flex min-w-0 border-b border-gray-200">
<div className="flex w-[140px] shrink-0 items-center gap-2 px-3 py-2">
<ChevronRight className="h-4 w-4 text-gray-700" />
<span className="text-sm font-semibold text-gray-900 content-text-sm">제품</span>
</div>
<div className="min-w-0 flex-1 overflow-x-auto px-2 py-2">
<div className="flex w-max items-center gap-1 whitespace-nowrap">
{PRODUCTS.map((p) => {
const active = value.product === p.value;
return (
<Button
key={p.value}
type="button"
variant={active ? "default" : "secondary"}
onClick={() => handlePick("product", p.value)}
className="h-6 shrink-0 rounded-sm px-3 text-sm font-semibold content-text-sm"
>
{p.label}
</Button>
);
})}
</div>
</div>
</div>
{/* 기준 (1줄 나열) */}
<div className="flex min-w-0 border-b border-gray-200">
<div className="flex w-[140px] shrink-0 items-center gap-2 px-3 py-2">
<ChevronRight className="h-4 w-4 text-gray-700" />
<span className="text-sm font-semibold text-gray-900 content-text-sm">기준</span>
</div>
<div className="min-w-0 flex-1 overflow-x-auto px-2 py-2">
<div className="flex w-max items-center gap-1 whitespace-nowrap">
{categoryTargetType.map((item) => {
const active = value.type.label === item.label;
return (
<Button
key={item.label}
type="button"
variant={active ? "default" : "secondary"}
onClick={() => {
handlePick("type", {label:item.label, value:item.value});
}}
className="h-6 shrink-0 rounded-sm px-3 text-sm font-semibold content-text-sm"
>
{item.label}
</Button>
);
})}
</div>
</div>
</div>
{/* 데이터 (1줄 나열) */}
<div className="flex min-w-0">
<div className="flex w-[140px] shrink-0 items-center gap-2 px-3 py-2">
<ChevronRight className="h-4 w-4 text-gray-700" />
<span className="text-sm font-semibold text-gray-900 content-text-sm">데이터</span>
</div>
<div className="min-w-0 flex-1 overflow-x-auto px-2 py-2">
<div className="flex w-max items-center gap-1 whitespace-nowrap">
{currentTargetItem?.children?.map((child) => {
const active = value.target === child.target;
return (
<Button
key={child.target}
type="button"
variant={active ? "default" : "secondary"}
onClick={() => handlePick("target", child.target)}
className="h-6 shrink-0 rounded-sm px-3 text-sm font-semibold content-text-sm"
>
{child.label}
</Button>
);
})}
</div>
</div>
</div>
</div>
);
};
export default CategoryFilter;

View File

@@ -0,0 +1,98 @@
import {useAuth} from "@/hooks/useAuth";
import {useEffect, useState} from "react";
import {LoginUser} from "@/types/auth";
import Image from "next/image";
import {topMenus} from "@/config/menu.data";
import {Button} from "@/components/ui/button";
import {LogOut} from "lucide-react";
import {DASHBOARD_YEAR} from "@/const/commonConst";
import {cn} from "@/lib/utils";
interface HeaderProps {
activeTopId: string;
onNavigate: (path: string) => void;
}
const Header = ({
activeTopId,
onNavigate,
}: HeaderProps) => {
const { auth } = useAuth();
const [userInfo, setUserInfo] = useState<LoginUser|undefined>(undefined);
useEffect(() => {
if(auth.user){
setUserInfo(auth.user);
}
else{
window.location.replace("/logout");
}
}, [auth.user])
return (
<header className="bg-white border-b border-gray-200 sticky top-0 z-40">
<div className="flex items-center justify-between px-4 h-16">
<div className="flex items-center gap-4">
{/* 로고 */}
<div className="flex items-center gap-2 cursor-pointer w-30 h-15 justify-center">
<Image
src="/logo.png" // public/logo.png
alt="브랜드 로고"
width={200}
height={80}
className="object-contain"
onClick={() => onNavigate("/total/penetration")}
priority
/>
</div>
{/* 상단 메뉴 */}
<nav className="flex items-center gap-1 ml-5">
{topMenus.map((m) => {
const active = activeTopId === m.id;
return (
<button
key={m.id}
type="button"
onClick={() => onNavigate(m.path)}
className={cn(
"relative h-10 inline-flex items-center font-semibold transition-colors cursor-pointer",
"content-text-base bg-transparent px-1",
active
? "text-primary"
: "text-secondary-hover"
)}
>
{m.label}
{/* 선택 표시(밑줄) */}
{active && (
<span className="absolute left-0 right-0 -bottom-[2px] h-[2px] bg-primary" />
)}
</button>
);
})}
</nav>
</div>
<div className="flex justify-between items-center">
<h1 className="font-bold content-text-2xl">{DASHBOARD_YEAR}년도 가전보급률 Dashboard</h1>
</div>
{/* 우측 컨트롤 */}
<div className="flex items-center gap-4">
<span className="text-sm text-gray-600 hidden sm:inline font-bold">{userInfo?.userName || ""}</span>
<Button
variant="ghost"
size="sm"
className="gap-2"
onClick={() => onNavigate("/logout")}
>
<LogOut className="w-4 h-4" />
<span className="hidden sm:inline">로그아웃</span>
</Button>
</div>
</div>
</header>
);
}
export default Header;

View File

@@ -0,0 +1,127 @@
"use client";
import {ReactNode, useState} from "react";
import { usePathname, useRouter } from "next/navigation";
import {topMenus, totalSubMenus, categorySubMenus} from "@/config/menu.data";
import Header from "./Header";
import SubMenu from "./SubMenu";
import TotalFilter from "@/components/layout/TotalFilter";
import CategoryFilter, {CategoryFilterValue} from "@/components/layout/CategoryFilter";
import {cn} from "@/lib/utils";
import {Button} from "@/components/ui/button";
import {SelectedMap} from "@/types/common";
import {categoryTarget, totalFilters} from "@/config/filter.data";
import {CategoryTargetData, CategoryTargetType} from "@/config/filter.types";
type MainLayoutProps = {
children: ReactNode;
};
const buildDefaultTotalValue = (): SelectedMap => {
const init: SelectedMap = {};
totalFilters.forEach((f) => {
// "전체"가 있으면 그 value, 없으면 첫 번째 값
const all = f.children.find((c) => c.label === "전체");
init[f.variable] = all?.value ?? f.children[0]?.value ?? "";
});
return init;
};
export const buildDefaultCategoryValue = (): CategoryFilterValue => {
const initType = {label:"보유", value:CategoryTargetType.PENETRATION}
const firstTarget = categoryTarget.find((x) => x.type === initType.value)?.children?.[0]?.target;
return {
product: "냉장고",
type: initType,
target: firstTarget ?? CategoryTargetData.PROFILE,
};
};
const MainLayout = ({ children }: MainLayoutProps) => {
const router = useRouter();
const pathname = usePathname();
const isTotal = pathname.startsWith("/total");
const activeTop = topMenus.find((m) => m.match?.(pathname)) ?? topMenus[0];
const subMenus = isTotal ? totalSubMenus : categorySubMenus;
const activeSub = subMenus.find((m) => m.path.startsWith(pathname)) ?? subMenus[0];
const [isTotalFilterOpen, setIsTotalFilterOpen] = useState(true);
const [isCategoryFilterOpen, setIsCategoryFilterOpen] = useState(true);
const isFilterOpen = isTotal ? isTotalFilterOpen : isCategoryFilterOpen;
const [totalValue, setTotalValue] = useState<SelectedMap>(() => buildDefaultTotalValue());
const [categoryValue, setCategoryValue] = useState<CategoryFilterValue>(() => buildDefaultCategoryValue());
const movePage = (path: string) => {
router.push(path);
};
const toggleFilter = () => {
if (isTotal) setIsTotalFilterOpen((v) => !v);
else setIsCategoryFilterOpen((v) => !v);
};
const handleExcelDownload = async () => {
// TODO: 다운로드 구현 필요
console.log("Excel download:", { pathname, top: activeTop.id, sub: activeSub.id });
};
return (
<div className="min-h-screen flex flex-col bg-transparent">
<Header
activeTopId={activeTop.id}
onNavigate={movePage}
/>
<div className="flex-1 min-h-0 flex flex-col bg-lg-main-body p-1 pl-6">
<SubMenu
subMenu={subMenus}
activeSubId={activeSub.id}
onNavigate={movePage}
/>
<div className="flex-1 min-h-0 flex flex-col pr-4">
<div className="bg-card lg-tab-content flex-1 min-h-0">
<div className="shrink-0 flex items-center justify-between px-2 py-1">
<button
type="button"
onClick={toggleFilter}
className={cn(
"inline-flex items-center gap-2 font-semibold text-gray-900 content-text-sm",
"select-none"
)}
>
필터 <span className="text-sm leading-none">{isFilterOpen ? "▲" : "▼"}</span>
</button>
<Button
variant="excel"
className="h-8 px-3 text-sm font-semibold content-text-sm"
onClick={handleExcelDownload}>
Excel 다운로드
</Button>
</div>
{isFilterOpen && (
<div className="shrink-0">
{isTotal ? (
<TotalFilter filters={totalFilters} value={totalValue} onChange={setTotalValue} />
) : (
<CategoryFilter value={categoryValue} onChange={setCategoryValue} />
)}
</div>
)}
{/* ✅ 실제 콘텐츠만 스크롤 */}
<div className="flex-1 min-h-0 overflow-auto">
<div className="p-3">{children}</div>
</div>
</div>
</div>
</div>
</div>
);
}
export default MainLayout;

View File

@@ -0,0 +1,48 @@
import {SubMenuItem} from "@/config/menu.types";
import {cn} from "@/lib/utils";
interface SubMenuProps {
subMenu: SubMenuItem[];
activeSubId: string;
onNavigate: (path: string) => void;
}
const SubMenu = ({
subMenu,
activeSubId,
onNavigate,
}: SubMenuProps) => {
return (
<div className="flex items-center justify-between pt-3">
<nav className="flex items-center gap-1">
{subMenu.map((m, idx) => {
const active = activeSubId === m.id;
return (
<button
key={m.id}
type="button"
onClick={() => onNavigate(m.path)}
className={cn(
"h-10 px-5 content-text-sm font-semibold transition-colors -mb-0.75",
"border border-gray-200",
"-ml-px first:ml-0 rounded-tl-lg rounded-tr-lg cursor-pointer", // 탭이 서로 '붙어' 보이게
active
? "bg-primary text-primary-foreground z-40"
: "bg-white-hover text-secondary"
)}
style={active ? {
boxShadow: '0 4px 6px -1px rgba(165, 0, 52, 0.15), 0 2px 4px -1px rgba(165, 0, 52, 0.1)'
} : undefined}
>
{m.label}
</button>
);
})}
</nav>
</div>
);
}
export default SubMenu;

View File

@@ -0,0 +1,100 @@
import {TotalFilterItem} from "@/config/filter.types";
import {SelectedMap} from "@/types/common";
import {useMemo} from "react";
import {cn} from "@/lib/utils";
import {Button} from "@/components/ui/button";
import {ChevronRight} from "lucide-react";
type TotalFilterProps = {
filters: TotalFilterItem[];
value: SelectedMap;
onChange: (next: SelectedMap) => void;
className?: string;
};
const TotalFilter = ({
filters,
value,
onChange,
className
}: TotalFilterProps) => {
const handlePick = (variable: string, v: string) => {
if (value[variable] === v) return;
onChange({ ...value, [variable]: v });
};
const arranged = useMemo(() => {
const rows = filters ?? [];
/**
* 현재 적용: 1 5 / 2 6 / 3 7 / 4 8
* 1 2 / 3 4 / 5 6 / 7 8 으로 반환하려면 그냥 rows를 반환하면 됨
* - 렌더링은 [1,5,2,6,3,7,4,8] 순서로 생성
*/
const half = Math.ceil(rows.length / 2);
const out: TotalFilterItem[] = [];
for (let i = 0; i < half; i++) {
if (rows[i]) out.push(rows[i]);
if (rows[i + half]) out.push(rows[i + half]);
}
return out;
}, [filters]);
const rowCount = Math.ceil(arranged.length / 2);
return (
<div className={cn("w-full border border-gray-300 bg-white/70 backdrop-blur-sm", className)}>
<div className="grid grid-cols-2">
{arranged.map((row, idx) => {
const current = value[row.variable] ?? "";
const col = idx % 2; // 0: left, 1: right
const r = Math.floor(idx / 2);
const isLastRow = r === rowCount - 1;
return (
<div
key={row.variable}
className={cn(
"flex min-w-0",
!isLastRow && "border-b border-gray-200",
col === 1 && "border-l-4 border-gray-300"
)}
>
{/* 좌측 라벨 */}
<div className="flex w-[140px] shrink-0 items-center gap-2 px-3 py-2">
<ChevronRight className="h-4 w-4 text-gray-700" />
<span className="text-sm font-semibold text-gray-900 content-text-sm">
{row.variableName}
</span>
</div>
{/* 우측 옵션 */}
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-1 px-2 py-2">
{row.children.map((c) => {
const active = current === c.value;
return (
<Button
key={`${row.variable}_${c.value}`}
type="button"
variant={active ? "default" : "secondary"}
onClick={() => handlePick(row.variable, c.value)}
className="h-6 rounded-sm px-3 text-sm font-semibold content-text-sm"
>
{c.label}
</Button>
);
})}
</div>
</div>
);
})}
</div>
</div>
);
}
export default TotalFilter;

View File

@@ -0,0 +1,46 @@
import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const badgeVariants = cva(
"inline-flex items-center justify-center rounded-full border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
{
variants: {
variant: {
default:
"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
secondary:
"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
destructive:
"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
outline:
"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
},
},
defaultVariants: {
variant: "default",
},
}
)
function Badge({
className,
variant,
asChild = false,
...props
}: React.ComponentProps<"span"> &
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
const Comp = asChild ? Slot : "span"
return (
<Comp
data-slot="badge"
className={cn(badgeVariants({ variant }), className)}
{...props}
/>
)
}
export { Badge, badgeVariants }

View File

@@ -0,0 +1,66 @@
import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const buttonVariants = cva(
"cursor-pointer inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:opacity-90",
destructive:
"bg-destructive text-white hover:opacity-90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:hover:opacity-60",
outline:
"border bg-background shadow-xs hover:bg-secondary hover:text-secondary-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
secondary:
"bg-secondary text-secondary-foreground hover:opacity-80",
excel:
"bg-excel text-excel-foreground hover:opacity-80",
accent:
"bg-accent text-accent-foreground hover:opacity-60",
ghost:
"hover:bg-primary hover:text-primary-foreground dark:hover:opacity-50",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-9 px-4 py-2 has-[>svg]:px-3",
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
icon: "size-9",
"icon-sm": "size-8",
"icon-lg": "size-10",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
function Button({
className,
variant = "default",
size = "default",
asChild = false,
...props
}: React.ComponentProps<"button"> &
VariantProps<typeof buttonVariants> & {
asChild?: boolean
}) {
const Comp = asChild ? Slot : "button"
return (
<Comp
data-slot="button"
data-variant={variant}
data-size={size}
className={cn(buttonVariants({ variant, size, className }))}
{...props}
/>
)
}
export { Button, buttonVariants }

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(
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 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-2 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("leading-none font-semibold", className)}
{...props}
/>
)
}
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-description"
className={cn("text-muted-foreground text-sm", 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,
}

View File

@@ -0,0 +1,143 @@
"use client"
import * as React from "react"
import * as DialogPrimitive from "@radix-ui/react-dialog"
import { XIcon } from "lucide-react"
import { cn } from "@/lib/utils"
function Dialog({
...props
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
return <DialogPrimitive.Root data-slot="dialog" {...props} />
}
function DialogTrigger({
...props
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
}
function DialogPortal({
...props
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
}
function DialogClose({
...props
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
}
function DialogOverlay({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
return (
<DialogPrimitive.Overlay
data-slot="dialog-overlay"
className={cn(
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
className
)}
{...props}
/>
)
}
function DialogContent({
className,
children,
showCloseButton = true,
...props
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
showCloseButton?: boolean
}) {
return (
<DialogPortal data-slot="dialog-portal">
<DialogOverlay />
<DialogPrimitive.Content
data-slot="dialog-content"
className={cn(
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg",
className
)}
{...props}
>
{children}
{showCloseButton && (
<DialogPrimitive.Close
data-slot="dialog-close"
className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
>
<XIcon />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
)}
</DialogPrimitive.Content>
</DialogPortal>
)
}
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="dialog-header"
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
{...props}
/>
)
}
function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="dialog-footer"
className={cn(
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
className
)}
{...props}
/>
)
}
function DialogTitle({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
return (
<DialogPrimitive.Title
data-slot="dialog-title"
className={cn("text-lg leading-none font-semibold", className)}
{...props}
/>
)
}
function DialogDescription({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
return (
<DialogPrimitive.Description
data-slot="dialog-description"
className={cn("text-muted-foreground text-sm", className)}
{...props}
/>
)
}
export {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogOverlay,
DialogPortal,
DialogTitle,
DialogTrigger,
}

View File

@@ -0,0 +1,257 @@
"use client"
import * as React from "react"
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
import { cn } from "@/lib/utils"
function DropdownMenu({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />
}
function DropdownMenuPortal({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
return (
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
)
}
function DropdownMenuTrigger({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
return (
<DropdownMenuPrimitive.Trigger
data-slot="dropdown-menu-trigger"
{...props}
/>
)
}
function DropdownMenuContent({
className,
sideOffset = 4,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
return (
<DropdownMenuPrimitive.Portal>
<DropdownMenuPrimitive.Content
data-slot="dropdown-menu-content"
sideOffset={sideOffset}
className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
className
)}
{...props}
/>
</DropdownMenuPrimitive.Portal>
)
}
function DropdownMenuGroup({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
return (
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
)
}
function DropdownMenuItem({
className,
inset,
variant = "default",
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
inset?: boolean
variant?: "default" | "destructive"
}) {
return (
<DropdownMenuPrimitive.Item
data-slot="dropdown-menu-item"
data-inset={inset}
data-variant={variant}
className={cn(
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
/>
)
}
function DropdownMenuCheckboxItem({
className,
children,
checked,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
return (
<DropdownMenuPrimitive.CheckboxItem
data-slot="dropdown-menu-checkbox-item"
className={cn(
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
checked={checked}
{...props}
>
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
<DropdownMenuPrimitive.ItemIndicator>
<CheckIcon className="size-4" />
</DropdownMenuPrimitive.ItemIndicator>
</span>
{children}
</DropdownMenuPrimitive.CheckboxItem>
)
}
function DropdownMenuRadioGroup({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
return (
<DropdownMenuPrimitive.RadioGroup
data-slot="dropdown-menu-radio-group"
{...props}
/>
)
}
function DropdownMenuRadioItem({
className,
children,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
return (
<DropdownMenuPrimitive.RadioItem
data-slot="dropdown-menu-radio-item"
className={cn(
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
>
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
<DropdownMenuPrimitive.ItemIndicator>
<CircleIcon className="size-2 fill-current" />
</DropdownMenuPrimitive.ItemIndicator>
</span>
{children}
</DropdownMenuPrimitive.RadioItem>
)
}
function DropdownMenuLabel({
className,
inset,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
inset?: boolean
}) {
return (
<DropdownMenuPrimitive.Label
data-slot="dropdown-menu-label"
data-inset={inset}
className={cn(
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
className
)}
{...props}
/>
)
}
function DropdownMenuSeparator({
className,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
return (
<DropdownMenuPrimitive.Separator
data-slot="dropdown-menu-separator"
className={cn("bg-border -mx-1 my-1 h-px", className)}
{...props}
/>
)
}
function DropdownMenuShortcut({
className,
...props
}: React.ComponentProps<"span">) {
return (
<span
data-slot="dropdown-menu-shortcut"
className={cn(
"text-muted-foreground ml-auto text-xs tracking-widest",
className
)}
{...props}
/>
)
}
function DropdownMenuSub({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />
}
function DropdownMenuSubTrigger({
className,
inset,
children,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
inset?: boolean
}) {
return (
<DropdownMenuPrimitive.SubTrigger
data-slot="dropdown-menu-sub-trigger"
data-inset={inset}
className={cn(
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
>
{children}
<ChevronRightIcon className="ml-auto size-4" />
</DropdownMenuPrimitive.SubTrigger>
)
}
function DropdownMenuSubContent({
className,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
return (
<DropdownMenuPrimitive.SubContent
data-slot="dropdown-menu-sub-content"
className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
className
)}
{...props}
/>
)
}
export {
DropdownMenu,
DropdownMenuPortal,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuLabel,
DropdownMenuItem,
DropdownMenuCheckboxItem,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuShortcut,
DropdownMenuSub,
DropdownMenuSubTrigger,
DropdownMenuSubContent,
}

View File

@@ -0,0 +1,21 @@
import * as React from "react"
import { cn } from "@/lib/utils"
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
return (
<input
type={type}
data-slot="input"
className={cn(
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
className
)}
{...props}
/>
)
}
export { Input }

View File

@@ -0,0 +1,24 @@
"use client"
import * as React from "react"
import * as LabelPrimitive from "@radix-ui/react-label"
import { cn } from "@/lib/utils"
function Label({
className,
...props
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
return (
<LabelPrimitive.Root
data-slot="label"
className={cn(
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
className
)}
{...props}
/>
)
}
export { Label }

View File

@@ -0,0 +1,190 @@
"use client"
import * as React from "react"
import * as SelectPrimitive from "@radix-ui/react-select"
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
import { cn } from "@/lib/utils"
function Select({
...props
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
return <SelectPrimitive.Root data-slot="select" {...props} />
}
function SelectGroup({
...props
}: React.ComponentProps<typeof SelectPrimitive.Group>) {
return <SelectPrimitive.Group data-slot="select-group" {...props} />
}
function SelectValue({
...props
}: React.ComponentProps<typeof SelectPrimitive.Value>) {
return <SelectPrimitive.Value data-slot="select-value" {...props} />
}
function SelectTrigger({
className,
size = "default",
children,
...props
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
size?: "sm" | "default"
}) {
return (
<SelectPrimitive.Trigger
data-slot="select-trigger"
data-size={size}
className={cn(
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
>
{children}
<SelectPrimitive.Icon asChild>
<ChevronDownIcon className="size-4 opacity-50" />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
)
}
function SelectContent({
className,
children,
position = "item-aligned",
align = "center",
...props
}: React.ComponentProps<typeof SelectPrimitive.Content>) {
return (
<SelectPrimitive.Portal>
<SelectPrimitive.Content
data-slot="select-content"
className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",
position === "popper" &&
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
className
)}
position={position}
align={align}
{...props}
>
<SelectScrollUpButton />
<SelectPrimitive.Viewport
className={cn(
"p-1",
position === "popper" &&
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"
)}
>
{children}
</SelectPrimitive.Viewport>
<SelectScrollDownButton />
</SelectPrimitive.Content>
</SelectPrimitive.Portal>
)
}
function SelectLabel({
className,
...props
}: React.ComponentProps<typeof SelectPrimitive.Label>) {
return (
<SelectPrimitive.Label
data-slot="select-label"
className={cn("text-muted-foreground px-2 py-1.5 text-xs", className)}
{...props}
/>
)
}
function SelectItem({
className,
children,
...props
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
return (
<SelectPrimitive.Item
data-slot="select-item"
className={cn(
"focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
className
)}
{...props}
>
<span
data-slot="select-item-indicator"
className="absolute right-2 flex size-3.5 items-center justify-center"
>
<SelectPrimitive.ItemIndicator>
<CheckIcon className="size-4" />
</SelectPrimitive.ItemIndicator>
</span>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
</SelectPrimitive.Item>
)
}
function SelectSeparator({
className,
...props
}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
return (
<SelectPrimitive.Separator
data-slot="select-separator"
className={cn("bg-border pointer-events-none -mx-1 my-1 h-px", className)}
{...props}
/>
)
}
function SelectScrollUpButton({
className,
...props
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
return (
<SelectPrimitive.ScrollUpButton
data-slot="select-scroll-up-button"
className={cn(
"flex cursor-default items-center justify-center py-1",
className
)}
{...props}
>
<ChevronUpIcon className="size-4" />
</SelectPrimitive.ScrollUpButton>
)
}
function SelectScrollDownButton({
className,
...props
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
return (
<SelectPrimitive.ScrollDownButton
data-slot="select-scroll-down-button"
className={cn(
"flex cursor-default items-center justify-center py-1",
className
)}
{...props}
>
<ChevronDownIcon className="size-4" />
</SelectPrimitive.ScrollDownButton>
)
}
export {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectScrollDownButton,
SelectScrollUpButton,
SelectSeparator,
SelectTrigger,
SelectValue,
}

View File

@@ -0,0 +1,28 @@
"use client"
import * as React from "react"
import * as SeparatorPrimitive from "@radix-ui/react-separator"
import { cn } from "@/lib/utils"
function Separator({
className,
orientation = "horizontal",
decorative = true,
...props
}: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
return (
<SeparatorPrimitive.Root
data-slot="separator"
decorative={decorative}
orientation={orientation}
className={cn(
"bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
className
)}
{...props}
/>
)
}
export { Separator }

View File

@@ -0,0 +1,40 @@
"use client"
import {
CircleCheckIcon,
InfoIcon,
Loader2Icon,
OctagonXIcon,
TriangleAlertIcon,
} from "lucide-react"
import { useTheme } from "next-themes"
import { Toaster as Sonner, type ToasterProps } from "sonner"
const Toaster = ({ ...props }: ToasterProps) => {
const { theme = "system" } = useTheme()
return (
<Sonner
theme={theme as ToasterProps["theme"]}
className="toaster group"
icons={{
success: <CircleCheckIcon className="size-4" />,
info: <InfoIcon className="size-4" />,
warning: <TriangleAlertIcon className="size-4" />,
error: <OctagonXIcon className="size-4" />,
loading: <Loader2Icon className="size-4 animate-spin" />,
}}
style={
{
"--normal-bg": "var(--popover)",
"--normal-text": "var(--popover-foreground)",
"--normal-border": "var(--border)",
"--border-radius": "var(--radius)",
} as React.CSSProperties
}
{...props}
/>
)
}
export { Toaster }

116
src/components/ui/table.tsx Normal file
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(
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
className
)}
{...props}
/>
)
}
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
return (
<tr
data-slot="table-row"
className={cn(
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
className
)}
{...props}
/>
)
}
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
return (
<th
data-slot="table-head"
className={cn(
"text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
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 [&>[role=checkbox]]:translate-y-[2px]",
className
)}
{...props}
/>
)
}
function TableCaption({
className,
...props
}: React.ComponentProps<"caption">) {
return (
<caption
data-slot="table-caption"
className={cn("text-muted-foreground mt-4 text-sm", className)}
{...props}
/>
)
}
export {
Table,
TableHeader,
TableBody,
TableFooter,
TableHead,
TableRow,
TableCell,
TableCaption,
}

View File

@@ -0,0 +1,66 @@
"use client"
import * as React from "react"
import * as TabsPrimitive from "@radix-ui/react-tabs"
import { cn } from "@/lib/utils"
function Tabs({
className,
...props
}: React.ComponentProps<typeof TabsPrimitive.Root>) {
return (
<TabsPrimitive.Root
data-slot="tabs"
className={cn("flex flex-col gap-2", className)}
{...props}
/>
)
}
function TabsList({
className,
...props
}: React.ComponentProps<typeof TabsPrimitive.List>) {
return (
<TabsPrimitive.List
data-slot="tabs-list"
className={cn(
"bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
className
)}
{...props}
/>
)
}
function TabsTrigger({
className,
...props
}: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
return (
<TabsPrimitive.Trigger
data-slot="tabs-trigger"
className={cn(
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
/>
)
}
function TabsContent({
className,
...props
}: React.ComponentProps<typeof TabsPrimitive.Content>) {
return (
<TabsPrimitive.Content
data-slot="tabs-content"
className={cn("flex-1 outline-none", className)}
{...props}
/>
)
}
export { Tabs, TabsList, TabsTrigger, TabsContent }

View File

@@ -0,0 +1,18 @@
import * as React from "react"
import { cn } from "@/lib/utils"
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
return (
<textarea
data-slot="textarea"
className={cn(
"border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
className
)}
{...props}
/>
)
}
export { Textarea }