260713_01_ENH: 테이블 스티키 헤더 수정, KriSelect에 disabled 추가, 타임 피커 시간 내림차순에서 오른 차순으로 변경
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "kri-ui-registry",
|
"name": "kri-ui-registry",
|
||||||
"version": "0.5.1",
|
"version": "0.6.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "KRI internal shadcn UI registry",
|
"description": "KRI internal shadcn UI registry",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export type KriSelectProps<T> = {
|
|||||||
getValue?: (item: T) => string
|
getValue?: (item: T) => string
|
||||||
getLabel?: (item: T) => string
|
getLabel?: (item: T) => string
|
||||||
useAll?: boolean
|
useAll?: boolean
|
||||||
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const HEIGHT_CLASS_VALUE: Record<string, CSSProperties['height']> = {
|
const HEIGHT_CLASS_VALUE: Record<string, CSSProperties['height']> = {
|
||||||
@@ -47,6 +48,7 @@ export function KriSelect<T>({
|
|||||||
getValue,
|
getValue,
|
||||||
getLabel,
|
getLabel,
|
||||||
useAll = true,
|
useAll = true,
|
||||||
|
disabled,
|
||||||
}: KriSelectProps<T>) {
|
}: KriSelectProps<T>) {
|
||||||
const extractValue = (item: T) => (getValue ? getValue(item) : String(item))
|
const extractValue = (item: T) => (getValue ? getValue(item) : String(item))
|
||||||
const extractLabel = (item: T) => (getLabel ? getLabel(item) : String(item))
|
const extractLabel = (item: T) => (getLabel ? getLabel(item) : String(item))
|
||||||
@@ -57,6 +59,7 @@ export function KriSelect<T>({
|
|||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
value={value}
|
value={value}
|
||||||
|
disabled={disabled}
|
||||||
onValueChange={(selectedValue) => {
|
onValueChange={(selectedValue) => {
|
||||||
onChange?.(selectedValue)
|
onChange?.(selectedValue)
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export function KriTimePicker({
|
|||||||
const normalizedMinuteStep = Number.isFinite(minuteStep) && minuteStep > 0
|
const normalizedMinuteStep = Number.isFinite(minuteStep) && minuteStep > 0
|
||||||
? Math.min(Math.floor(minuteStep), 60)
|
? Math.min(Math.floor(minuteStep), 60)
|
||||||
: 5
|
: 5
|
||||||
const hours = Array.from({ length: 24 }, (_, index) => 23 - index)
|
const hours = Array.from({ length: 24 }, (_, index) => index)
|
||||||
const minutes = Array.from(
|
const minutes = Array.from(
|
||||||
{ length: Math.ceil(60 / normalizedMinuteStep) },
|
{ length: Math.ceil(60 / normalizedMinuteStep) },
|
||||||
(_, index) => index * normalizedMinuteStep,
|
(_, index) => index * normalizedMinuteStep,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { flexRender, getCoreRowModel, getPaginationRowModel, getSortedRowModel,
|
|||||||
import { ArrowDown, ArrowUp, ArrowUpDown } from 'lucide-react'
|
import { ArrowDown, ArrowUp, ArrowUpDown } from 'lucide-react'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Checkbox } from '@/components/ui/checkbox'
|
import { Checkbox } from '@/components/ui/checkbox'
|
||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
import { TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import type { DataTableColumn, DataTableProps } from './DataTable.type'
|
import type { DataTableColumn, DataTableProps } from './DataTable.type'
|
||||||
import { DataTablePagination } from './DataTablePagination'
|
import { DataTablePagination } from './DataTablePagination'
|
||||||
@@ -31,6 +31,7 @@ export function DataTable<TData, TValue = unknown>({
|
|||||||
paginationItemsToDisplay = 5,
|
paginationItemsToDisplay = 5,
|
||||||
emptyText = '데이터가 없습니다.',
|
emptyText = '데이터가 없습니다.',
|
||||||
className,
|
className,
|
||||||
|
maxBodyHeight,
|
||||||
}: Readonly<DataTableProps<TData, TValue>>) {
|
}: Readonly<DataTableProps<TData, TValue>>) {
|
||||||
const [internalPagination, setInternalPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: defaultPageSize })
|
const [internalPagination, setInternalPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: defaultPageSize })
|
||||||
const [sorting, setSorting] = useState<SortingState>([])
|
const [sorting, setSorting] = useState<SortingState>([])
|
||||||
@@ -133,57 +134,62 @@ export function DataTable<TData, TValue = unknown>({
|
|||||||
return (
|
return (
|
||||||
<div className={cn('w-full space-y-4', className)}>
|
<div className={cn('w-full space-y-4', className)}>
|
||||||
<div className="rounded-md border">
|
<div className="rounded-md border">
|
||||||
<Table>
|
<div
|
||||||
<TableHeader>
|
className={cn('relative w-full overflow-x-auto', maxBodyHeight && 'overflow-y-auto')}
|
||||||
{table.getHeaderGroups().map((headerGroup) => (
|
style={maxBodyHeight ? { maxHeight: maxBodyHeight } : undefined}
|
||||||
<TableRow key={headerGroup.id} className="hover:bg-transparent">
|
>
|
||||||
{headerGroup.headers.map((header) => {
|
<table className="w-full caption-bottom text-sm">
|
||||||
const column = header.column
|
<TableHeader className={cn(maxBodyHeight && 'sticky top-0 z-10 bg-background')}>
|
||||||
const sorted = column.getIsSorted()
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
const content = header.isPlaceholder ? null : flexRender(column.columnDef.header, header.getContext())
|
<TableRow key={headerGroup.id} className="hover:bg-transparent">
|
||||||
|
{headerGroup.headers.map((header) => {
|
||||||
|
const column = header.column
|
||||||
|
const sorted = column.getIsSorted()
|
||||||
|
const content = header.isPlaceholder ? null : flexRender(column.columnDef.header, header.getContext())
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableHead
|
<TableHead
|
||||||
key={header.id}
|
key={header.id}
|
||||||
className={cn('text-base font-semibold text-foreground', column.id === 'actions' && 'w-[140px] text-center')}
|
className={cn('text-base font-semibold text-foreground', column.id === 'actions' && 'w-[140px] text-center')}
|
||||||
style={{ width: header.getSize() !== 150 ? header.getSize() : undefined }}
|
style={{ width: header.getSize() !== 150 ? header.getSize() : undefined }}
|
||||||
>
|
>
|
||||||
{!header.isPlaceholder && column.getCanSort() ? (
|
{!header.isPlaceholder && column.getCanSort() ? (
|
||||||
<Button type="button" variant="ghost" className="flex gap-1 px-0 text-base font-semibold" onClick={column.getToggleSortingHandler()}>
|
<Button type="button" variant="ghost" className="flex gap-1 px-0 text-base font-semibold" onClick={column.getToggleSortingHandler()}>
|
||||||
<span>{content}</span>
|
<span>{content}</span>
|
||||||
{sorted === 'asc' ? <ArrowUp className="size-3" /> : sorted === 'desc' ? <ArrowDown className="size-3" /> : <ArrowUpDown className="text-muted-foreground size-3" />}
|
{sorted === 'asc' ? <ArrowUp className="size-3" /> : sorted === 'desc' ? <ArrowDown className="size-3" /> : <ArrowUpDown className="text-muted-foreground size-3" />}
|
||||||
</Button>
|
</Button>
|
||||||
) : content}
|
) : content}
|
||||||
</TableHead>
|
</TableHead>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{table.getRowModel().rows.length ? table.getRowModel().rows.map((row) => (
|
{table.getRowModel().rows.length ? table.getRowModel().rows.map((row) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={row.id}
|
key={row.id}
|
||||||
data-state={row.getIsSelected() ? 'selected' : undefined}
|
data-state={row.getIsSelected() ? 'selected' : undefined}
|
||||||
onPointerDown={drag.onPointerDown}
|
onPointerDown={drag.onPointerDown}
|
||||||
onPointerMove={drag.onPointerMove}
|
onPointerMove={drag.onPointerMove}
|
||||||
onPointerUp={drag.onPointerUp}
|
onPointerUp={drag.onPointerUp}
|
||||||
onPointerCancel={drag.onPointerCancel}
|
onPointerCancel={drag.onPointerCancel}
|
||||||
onClick={drag.wrapClick(() => handleRowClick(row))}
|
onClick={drag.wrapClick(() => handleRowClick(row))}
|
||||||
className={cn(
|
className={cn(
|
||||||
'text-sm [&>td]:px-2 [&>td]:py-0',
|
'text-sm [&>td]:px-2 [&>td]:py-0',
|
||||||
selectMode !== 'none' && 'cursor-pointer',
|
selectMode !== 'none' && 'cursor-pointer',
|
||||||
'data-[state=selected]:bg-muted data-[state=selected]:font-semibold',
|
'data-[state=selected]:bg-muted data-[state=selected]:font-semibold',
|
||||||
highlightRowIds?.includes(row.id) && 'bg-emerald-50',
|
highlightRowIds?.includes(row.id) && 'bg-emerald-50',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{row.getVisibleCells().map((cell) => <TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>)}
|
{row.getVisibleCells().map((cell) => <TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>)}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
)) : (
|
)) : (
|
||||||
<TableRow><TableCell colSpan={enhancedColumns.length} className="h-24 text-center">{emptyText}</TableCell></TableRow>
|
<TableRow><TableCell colSpan={enhancedColumns.length} className="h-24 text-center">{emptyText}</TableCell></TableRow>
|
||||||
)}
|
)}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DataTablePagination
|
<DataTablePagination
|
||||||
|
|||||||
@@ -34,4 +34,5 @@ export interface DataTableProps<TData, TValue = unknown> {
|
|||||||
paginationItemsToDisplay?: number
|
paginationItemsToDisplay?: number
|
||||||
emptyText?: string
|
emptyText?: string
|
||||||
className?: string
|
className?: string
|
||||||
|
maxBodyHeight?: string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user