@carbonid1/design-system 5.4.0 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Table/Table.d.ts +3 -0
- package/dist/Table/Table.js +25 -0
- package/dist/Table/Table.types.d.ts +28 -0
- package/dist/Table/Table.types.js +1 -0
- package/dist/Table/defaultCellValue.d.ts +9 -0
- package/dist/Table/defaultCellValue.js +9 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from '../helpers/cn/cn';
|
|
3
|
+
import { cva } from 'class-variance-authority';
|
|
4
|
+
import { defaultCellValue, EM_DASH } from './defaultCellValue';
|
|
5
|
+
/**
|
|
6
|
+
* Presentational, config-driven table for structured/DB data. Renders semantic
|
|
7
|
+
* `<table>` markup (no ARIA grid roles) with zero hooks, state, or handlers, so
|
|
8
|
+
* it can be used directly inside a React Server Component — hence no `'use client'`.
|
|
9
|
+
*
|
|
10
|
+
* v1 is display-only. Sort / filter / pagination / selection / virtualization are
|
|
11
|
+
* intended to land later behind this same API by wrapping an engine (TanStack
|
|
12
|
+
* Table, React Aria), so the column shape mirrors TanStack's `ColumnDef`.
|
|
13
|
+
*/
|
|
14
|
+
// Header and body cells share one alignment axis; keep it in a single cva so a
|
|
15
|
+
// future option (e.g. `center`) is added in exactly one place.
|
|
16
|
+
const cellAlign = cva('', {
|
|
17
|
+
variants: {
|
|
18
|
+
align: { start: 'text-start', end: 'text-end' },
|
|
19
|
+
},
|
|
20
|
+
defaultVariants: { align: 'start' },
|
|
21
|
+
});
|
|
22
|
+
const HEADER_CELL = 'px-3 py-2 text-xs font-medium uppercase tracking-wide text-muted-foreground';
|
|
23
|
+
const BODY_CELL = 'bg-muted/40 px-3 py-2.5 align-middle text-foreground transition-colors first:rounded-l-lg last:rounded-r-lg group-hover:bg-muted/60';
|
|
24
|
+
const Table = ({ columns, rows, rowKey, empty = EM_DASH }) => (_jsxs("table", { className: "w-full border-separate border-spacing-x-0 border-spacing-y-1 text-sm", children: [_jsx("colgroup", { children: columns.map((column, index) => (_jsx("col", { style: column.width ? { width: column.width } : undefined }, `${column.accessorKey}:${index}`))) }), _jsx("thead", { children: _jsx("tr", { children: columns.map((column, index) => (_jsx("th", { scope: "col", className: cn(HEADER_CELL, cellAlign({ align: column.align })), children: column.header }, `${column.accessorKey}:${index}`))) }) }), _jsx("tbody", { children: rows.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: columns.length || 1, className: "bg-muted/40 text-muted-foreground rounded-lg px-3 py-6 text-center", children: empty }) })) : (rows.map(row => (_jsx("tr", { className: "group", children: columns.map((column, index) => (_jsx("td", { className: cn(BODY_CELL, cellAlign({ align: column.align })), children: column.render ? column.render(row) : defaultCellValue(row[column.accessorKey]) }, `${column.accessorKey}:${index}`))) }, rowKey(row))))) })] }));
|
|
25
|
+
export { Table };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Column config, intentionally aligned with TanStack Table's `ColumnDef` shape
|
|
4
|
+
* (`accessorKey` / `header` / cell-style `render`). Keeping this shape means
|
|
5
|
+
* sort / filter / pagination can later be added by wrapping an engine behind
|
|
6
|
+
* the same API without breaking consumers.
|
|
7
|
+
*/
|
|
8
|
+
type Column<Row> = {
|
|
9
|
+
/** Field used for the cell's default text when `render` is omitted. */
|
|
10
|
+
accessorKey: keyof Row & string;
|
|
11
|
+
/** Header content for the column. */
|
|
12
|
+
header: ReactNode;
|
|
13
|
+
/** Horizontal alignment of the header + cells. Defaults to `start`; use `end` for numbers. */
|
|
14
|
+
align?: 'start' | 'end';
|
|
15
|
+
/** Optional fixed column width (any CSS width, e.g. `'8rem'`). Auto-sized when omitted. */
|
|
16
|
+
width?: string;
|
|
17
|
+
/** Custom cell renderer; receives the whole row so a cell can compose fields. */
|
|
18
|
+
render?: (row: Row) => ReactNode;
|
|
19
|
+
};
|
|
20
|
+
type TableProps<Row> = {
|
|
21
|
+
columns: Column<Row>[];
|
|
22
|
+
rows: Row[];
|
|
23
|
+
/** Stable React key per row, e.g. `row => row.id`. */
|
|
24
|
+
rowKey: (row: Row) => string;
|
|
25
|
+
/** Rendered in one cell spanning all columns when `rows` is empty. Defaults to a dash. */
|
|
26
|
+
empty?: ReactNode;
|
|
27
|
+
};
|
|
28
|
+
export type { Column, TableProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The placeholder glyph for a missing cell value and for the default empty state. */
|
|
2
|
+
export declare const EM_DASH = "\u2014";
|
|
3
|
+
/**
|
|
4
|
+
* Default text for a cell that has no custom `render`. Only *nullish*
|
|
5
|
+
* (`null` / `undefined`) collapses to the em dash — every other value is
|
|
6
|
+
* stringified, so a real `0`, `false`, or `''` still renders instead of being
|
|
7
|
+
* mistaken for "missing". (The naive `value ? … : '—'` is a bug for those.)
|
|
8
|
+
*/
|
|
9
|
+
export declare const defaultCellValue: (value: unknown) => string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The placeholder glyph for a missing cell value and for the default empty state. */
|
|
2
|
+
export const EM_DASH = '—';
|
|
3
|
+
/**
|
|
4
|
+
* Default text for a cell that has no custom `render`. Only *nullish*
|
|
5
|
+
* (`null` / `undefined`) collapses to the em dash — every other value is
|
|
6
|
+
* stringified, so a real `0`, `false`, or `''` still renders instead of being
|
|
7
|
+
* mistaken for "missing". (The naive `value ? … : '—'` is a bug for those.)
|
|
8
|
+
*/
|
|
9
|
+
export const defaultCellValue = (value) => value == null ? EM_DASH : String(value);
|
package/dist/index.d.ts
CHANGED
|
@@ -11,12 +11,16 @@ export { Slider } from './Slider/Slider';
|
|
|
11
11
|
export { ContextMenu } from './ContextMenu/ContextMenu';
|
|
12
12
|
export { Select } from './Select/Select';
|
|
13
13
|
export type { SelectOption, SelectGroup, SelectOptionState, SelectProps, } from './Select/Select.types';
|
|
14
|
+
export { Table } from './Table/Table';
|
|
15
|
+
export type { Column, TableProps } from './Table/Table.types';
|
|
14
16
|
export { Tooltip } from './Tooltip/Tooltip';
|
|
15
17
|
export { ThemeProvider } from './ThemeProvider/ThemeProvider';
|
|
16
18
|
export { ThemeCycler } from './ThemeCycler/ThemeCycler';
|
|
17
19
|
export { Toaster } from './Toaster/Toaster';
|
|
18
20
|
export { toast } from 'sonner';
|
|
19
21
|
export { useTheme } from 'next-themes';
|
|
22
|
+
export { useHotkeys, useRecordHotkeys, useHotkeysContext, isHotkeyPressed, HotkeysProvider, } from 'react-hotkeys-hook';
|
|
23
|
+
export type { Options, Keys, HotkeyCallback } from 'react-hotkeys-hook';
|
|
20
24
|
export { cn } from './helpers/cn/cn';
|
|
21
25
|
export { getModKey } from './helpers/getModKey/getModKey';
|
|
22
26
|
export { cva } from 'class-variance-authority';
|
package/dist/index.js
CHANGED
|
@@ -6,12 +6,14 @@ export { ProgressRing } from './ProgressRing/ProgressRing';
|
|
|
6
6
|
export { Slider } from './Slider/Slider';
|
|
7
7
|
export { ContextMenu } from './ContextMenu/ContextMenu';
|
|
8
8
|
export { Select } from './Select/Select';
|
|
9
|
+
export { Table } from './Table/Table';
|
|
9
10
|
export { Tooltip } from './Tooltip/Tooltip';
|
|
10
11
|
export { ThemeProvider } from './ThemeProvider/ThemeProvider';
|
|
11
12
|
export { ThemeCycler } from './ThemeCycler/ThemeCycler';
|
|
12
13
|
export { Toaster } from './Toaster/Toaster';
|
|
13
14
|
export { toast } from 'sonner';
|
|
14
15
|
export { useTheme } from 'next-themes';
|
|
16
|
+
export { useHotkeys, useRecordHotkeys, useHotkeysContext, isHotkeyPressed, HotkeysProvider, } from 'react-hotkeys-hook';
|
|
15
17
|
export { cn } from './helpers/cn/cn';
|
|
16
18
|
export { getModKey } from './helpers/getModKey/getModKey';
|
|
17
19
|
export { cva } from 'class-variance-authority';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbonid1/design-system",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "Shared React UI primitives + design tokens (themes, postcss config)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"build": "tsc",
|
|
80
|
-
"storybook": "storybook dev -p 7006",
|
|
80
|
+
"storybook": "storybook dev -p 7006 --no-open",
|
|
81
81
|
"build-storybook": "storybook build",
|
|
82
82
|
"test": "vitest --run",
|
|
83
83
|
"test:watch": "vitest",
|