Components
SortableTable
Sortable data table with generic type safety
Overview
SortableTable is a sortable data table. It provides complete type safety with TypeScript generics.
- Generic — Define data and field types with
<T, F> - Sortable — Supports string (localeCompare), number, date, and null
- Controlled/Uncontrolled —
sortStateordefaultSort - Accessible —
aria-sortattribute, keyboard sorting support
Basic Usage
Controlled Sorting
Empty State
Column Definition
export type SortableTableColumn<T, F extends string> = {
field: F
header: ReactNode
render: (item: T, rowIndex: number) => ReactNode
sortable?: boolean
getSortValue?: (item: T) => string | number | Date | null | undefined
headerAlign?: 'left' | 'center' | 'right'
cellAlign?: 'left' | 'center' | 'right'
width?: string | number
}Table Props
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
data | T[] | - | Yes | Rows |
columns | SortableTableColumn<T, F>[] | - | Yes | Column definitions (field, header, render, sortable, getSortValue, alignment, width) |
getRowId | (item: T, index: number) => string | - | No | Row key. Falls back to item.id, then the index |
defaultSort | SortState<F> | - | No | First sort (uncontrolled) |
sortState | SortState<F> | - | No | Current sort (controlled) |
onSortChange | (nextSort: SortState<F>) => void | - | No | Called when a header is pressed |
emptyState | ReactNode | - | No | Replaces the whole empty state |
emptyMessage | ReactNode | 'No data found' | No | Text shown when data is empty |
className | string | - | No | Extra class |
Sort Behavior
- Clicking the same column: toggles
asc↔desc - Clicking a different column: starts with
desc - Null values are always sorted last
- Keyboard: toggle sort with Enter/Space
Specification
base
| 상태 | 요소 | 속성 | 값 |
|---|---|---|---|
| enabled | table | backgroundColor | $color.background.default.default |
| enabled | table | borderRadius | $size.radius.200 |
| enabled | table | borderWidth | $size.stroke.border |
| enabled | table | borderColor | $color.border.default.default |
| enabled | headerCell | backgroundColor | $color.background.default.secondary |
| enabled | headerCell | padding | $size.space.300 |
| enabled | headerCell | borderBottomWidth | $size.stroke.border |
| enabled | headerCell | borderBottomColor | $color.border.default.default |
| enabled | headerCell | typography | $text.bodySmallStrong |
| enabled | cell | padding | $size.space.300 |
| enabled | cell | borderBottomWidth | $size.stroke.border |
| enabled | cell | borderBottomColor | $color.border.default.default |
| focusVisible | headerCell | outlineWidth | $size.stroke.focus |
| focusVisible | headerCell | outlineStyle | solid토큰 아님 — no line style token |
| focusVisible | headerCell | outlineColor | $color.border.focus.default |
| focusVisible | headerCell | outlineOffset | -2px토큰 아님 — inside ring; no ring offset token |
Guidelines
- Without
getSortValue, sorting cannot be applied based on raw data instead ofrenderoutput - Always specify
getSortValuefor date columns - Use
sortable: falseto exclude columns where sorting is meaningless (e.g., action buttons)