260703_01_FST: First Commit
This commit is contained in:
78
registry/components/layout/KriHeader.tsx
Normal file
78
registry/components/layout/KriHeader.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
'use client'
|
||||
|
||||
import type { ReactNode } from 'react'
|
||||
import { Menu, X } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { cn } from '@/lib/utils'
|
||||
import type { KriNavigationItem } from './types'
|
||||
|
||||
export interface KriHeaderProps {
|
||||
logo?: ReactNode
|
||||
homePath?: string
|
||||
menus?: KriNavigationItem[]
|
||||
activeMenuId?: string
|
||||
menuOpen?: boolean
|
||||
showMenuButton?: boolean
|
||||
onToggleMenu?: () => void
|
||||
onNavigate?: (path: string, item?: KriNavigationItem) => void
|
||||
center?: ReactNode
|
||||
right?: ReactNode
|
||||
sticky?: boolean
|
||||
className?: string
|
||||
innerClassName?: string
|
||||
}
|
||||
|
||||
export function KriHeader({
|
||||
logo,
|
||||
homePath = '/',
|
||||
menus = [],
|
||||
activeMenuId,
|
||||
menuOpen = false,
|
||||
showMenuButton = true,
|
||||
onToggleMenu,
|
||||
onNavigate,
|
||||
center,
|
||||
right,
|
||||
sticky = true,
|
||||
className,
|
||||
innerClassName,
|
||||
}: KriHeaderProps) {
|
||||
return (
|
||||
<header className={cn('border-b bg-background', sticky && 'sticky top-0 z-40', className)}>
|
||||
<div className={cn('flex h-16 items-center justify-between gap-4 px-4', innerClassName)}>
|
||||
<div className="flex min-w-0 items-center gap-4">
|
||||
{showMenuButton && onToggleMenu ? (
|
||||
<Button type="button" variant="ghost" size="icon" onClick={onToggleMenu} aria-label={menuOpen ? '메뉴 닫기' : '메뉴 열기'}>
|
||||
{menuOpen ? <X className="size-5" /> : <Menu className="size-5" />}
|
||||
</Button>
|
||||
) : null}
|
||||
|
||||
{logo ? (
|
||||
<button type="button" className="flex shrink-0 items-center" onClick={() => onNavigate?.(homePath)}>
|
||||
{logo}
|
||||
</button>
|
||||
) : null}
|
||||
|
||||
{menus.length ? (
|
||||
<nav className="hidden items-center gap-1 md:flex">
|
||||
{menus.map((item) => (
|
||||
<Button
|
||||
key={item.id}
|
||||
type="button"
|
||||
variant={activeMenuId === item.id ? 'default' : 'ghost'}
|
||||
disabled={item.disabled || !item.path}
|
||||
onClick={() => item.path && onNavigate?.(item.path, item)}
|
||||
>
|
||||
{item.label}
|
||||
</Button>
|
||||
))}
|
||||
</nav>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="min-w-0 flex-1 text-center">{center}</div>
|
||||
<div className="flex shrink-0 items-center gap-2">{right}</div>
|
||||
</div>
|
||||
</header>
|
||||
)
|
||||
}
|
||||
50
registry/components/layout/KriMainLayout.tsx
Normal file
50
registry/components/layout/KriMainLayout.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
'use client'
|
||||
|
||||
import type { CSSProperties, ReactNode } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
export interface KriMainLayoutProps {
|
||||
children: ReactNode
|
||||
header?: ReactNode
|
||||
sidebar?: ReactNode
|
||||
sidebarOpen?: boolean
|
||||
onSidebarOpenChange?: (open: boolean) => void
|
||||
fullHeight?: boolean
|
||||
className?: string
|
||||
bodyClassName?: string
|
||||
mainClassName?: string
|
||||
mainStyle?: CSSProperties
|
||||
}
|
||||
|
||||
export function KriMainLayout({
|
||||
children,
|
||||
header,
|
||||
sidebar,
|
||||
sidebarOpen = false,
|
||||
onSidebarOpenChange,
|
||||
fullHeight = true,
|
||||
className,
|
||||
bodyClassName,
|
||||
mainClassName,
|
||||
mainStyle,
|
||||
}: KriMainLayoutProps) {
|
||||
return (
|
||||
<div className={cn('flex flex-col bg-muted/30', fullHeight && 'min-h-screen', className)}>
|
||||
{header}
|
||||
<div className={cn('flex min-h-0 flex-1', bodyClassName)}>
|
||||
{sidebar}
|
||||
<main className={cn('min-w-0 flex-1 overflow-y-auto p-4', mainClassName)} style={mainStyle}>
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
{sidebar && sidebarOpen ? (
|
||||
<button
|
||||
type="button"
|
||||
aria-label="사이드바 닫기"
|
||||
className="fixed inset-0 z-20 bg-black/20 lg:hidden"
|
||||
onClick={() => onSidebarOpenChange?.(false)}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
22
registry/components/layout/KriPageTitle.tsx
Normal file
22
registry/components/layout/KriPageTitle.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
export interface KriPageTitleProps {
|
||||
title: ReactNode
|
||||
description?: ReactNode
|
||||
actions?: ReactNode
|
||||
className?: string
|
||||
titleClassName?: string
|
||||
}
|
||||
|
||||
export function KriPageTitle({ title, description, actions, className, titleClassName }: KriPageTitleProps) {
|
||||
return (
|
||||
<div className={cn('flex items-start justify-between gap-4', className)}>
|
||||
<div className="min-w-0">
|
||||
<h1 className={cn('text-2xl font-bold tracking-tight', titleClassName)}>{title}</h1>
|
||||
{description ? <div className="text-muted-foreground mt-1 text-sm">{description}</div> : null}
|
||||
</div>
|
||||
{actions ? <div className="flex shrink-0 items-center gap-2">{actions}</div> : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
129
registry/components/layout/KriSidebar.tsx
Normal file
129
registry/components/layout/KriSidebar.tsx
Normal file
@@ -0,0 +1,129 @@
|
||||
'use client'
|
||||
|
||||
import * as React from 'react'
|
||||
import { ChevronDown } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { cn } from '@/lib/utils'
|
||||
import type { KriNavigationItem } from './types'
|
||||
|
||||
export interface KriSidebarProps {
|
||||
items: KriNavigationItem[]
|
||||
isOpen: boolean
|
||||
pathname?: string
|
||||
header?: React.ReactNode
|
||||
openItemIds?: string[]
|
||||
defaultOpenItemIds?: string[]
|
||||
onOpenItemIdsChange?: (ids: string[]) => void
|
||||
onNavigate?: (path: string, item: KriNavigationItem) => void
|
||||
className?: string
|
||||
contentClassName?: string
|
||||
}
|
||||
|
||||
function isActive(item: KriNavigationItem, pathname: string): boolean {
|
||||
if (item.match) return item.match(pathname)
|
||||
if (item.path && (pathname === item.path || pathname.startsWith(`${item.path}/`))) return true
|
||||
return item.children?.some((child) => isActive(child, pathname)) ?? false
|
||||
}
|
||||
|
||||
export function KriSidebar({
|
||||
items,
|
||||
isOpen,
|
||||
pathname = '',
|
||||
header,
|
||||
openItemIds,
|
||||
defaultOpenItemIds = [],
|
||||
onOpenItemIdsChange,
|
||||
onNavigate,
|
||||
className,
|
||||
contentClassName,
|
||||
}: KriSidebarProps) {
|
||||
const [internalOpenIds, setInternalOpenIds] = React.useState(defaultOpenItemIds)
|
||||
const currentOpenIds = openItemIds ?? internalOpenIds
|
||||
|
||||
const setOpenIds = (next: string[]) => {
|
||||
if (openItemIds === undefined) setInternalOpenIds(next)
|
||||
onOpenItemIdsChange?.(next)
|
||||
}
|
||||
|
||||
const toggleItem = (id: string) => {
|
||||
setOpenIds(currentOpenIds.includes(id) ? currentOpenIds.filter((value) => value !== id) : [...currentOpenIds, id])
|
||||
}
|
||||
|
||||
return (
|
||||
<aside
|
||||
className={cn(
|
||||
'fixed top-16 left-0 z-30 h-[calc(100vh-4rem)] overflow-y-auto border-r bg-background transition-all duration-300 lg:static lg:top-0 lg:h-auto lg:translate-x-0',
|
||||
isOpen ? 'w-64 translate-x-0' : 'w-64 -translate-x-full lg:w-0 lg:border-r-0',
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<div className={cn('h-full space-y-4 overflow-y-auto p-4', contentClassName)}>
|
||||
{header}
|
||||
<nav className="space-y-1">
|
||||
{items.map((item) => {
|
||||
const active = isActive(item, pathname)
|
||||
const hasChildren = Boolean(item.children?.length)
|
||||
const opened = currentOpenIds.includes(item.id)
|
||||
const Icon = item.icon
|
||||
|
||||
if (!hasChildren) {
|
||||
return (
|
||||
<Button
|
||||
key={item.id}
|
||||
type="button"
|
||||
variant={active ? 'secondary' : 'ghost'}
|
||||
className="w-full justify-start"
|
||||
disabled={item.disabled || !item.path}
|
||||
onClick={() => item.path && onNavigate?.(item.path, item)}
|
||||
>
|
||||
{Icon ? <Icon className="size-4" /> : null}
|
||||
<span>{item.label}</span>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div key={item.id} className="space-y-1">
|
||||
<Button
|
||||
type="button"
|
||||
variant={active ? 'secondary' : 'ghost'}
|
||||
className="w-full justify-between"
|
||||
disabled={item.disabled}
|
||||
onClick={() => toggleItem(item.id)}
|
||||
>
|
||||
<span className="flex items-center gap-2">
|
||||
{Icon ? <Icon className="size-4" /> : null}
|
||||
<span>{item.label}</span>
|
||||
</span>
|
||||
<ChevronDown className={cn('size-4 transition-transform', opened && 'rotate-180')} />
|
||||
</Button>
|
||||
|
||||
{opened ? (
|
||||
<div className="ml-6 space-y-1">
|
||||
{item.children?.map((child) => {
|
||||
const childActive = isActive(child, pathname)
|
||||
const ChildIcon = child.icon
|
||||
return (
|
||||
<Button
|
||||
key={child.id}
|
||||
type="button"
|
||||
variant={childActive ? 'secondary' : 'ghost'}
|
||||
className="w-full justify-start"
|
||||
disabled={child.disabled || !child.path}
|
||||
onClick={() => child.path && onNavigate?.(child.path, child)}
|
||||
>
|
||||
{ChildIcon ? <ChildIcon className="size-4" /> : null}
|
||||
<span>{child.label}</span>
|
||||
</Button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
</aside>
|
||||
)
|
||||
}
|
||||
9
registry/components/layout/index.ts
Normal file
9
registry/components/layout/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export { KriHeader } from './KriHeader'
|
||||
export { KriMainLayout } from './KriMainLayout'
|
||||
export { KriPageTitle } from './KriPageTitle'
|
||||
export { KriSidebar } from './KriSidebar'
|
||||
export type { KriNavigationItem } from './types'
|
||||
export type { KriHeaderProps } from './KriHeader'
|
||||
export type { KriMainLayoutProps } from './KriMainLayout'
|
||||
export type { KriPageTitleProps } from './KriPageTitle'
|
||||
export type { KriSidebarProps } from './KriSidebar'
|
||||
11
registry/components/layout/types.ts
Normal file
11
registry/components/layout/types.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { ComponentType, ReactNode } from 'react'
|
||||
|
||||
export interface KriNavigationItem {
|
||||
id: string
|
||||
label: ReactNode
|
||||
path?: string
|
||||
icon?: ComponentType<{ className?: string }>
|
||||
children?: KriNavigationItem[]
|
||||
disabled?: boolean
|
||||
match?: (pathname: string) => boolean
|
||||
}
|
||||
Reference in New Issue
Block a user