@surreal-ui/catalog 0.13.0 → 0.14.1

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.
@@ -2518,6 +2518,127 @@ var CATALOG = {
2518
2518
  }
2519
2519
  ]
2520
2520
  },
2521
+ {
2522
+ "id": "table",
2523
+ "name": "Table",
2524
+ "description": "Rows and columns of data with a caption, column headings and optional row headings; numbers line up on the right.",
2525
+ "tags": [
2526
+ "display",
2527
+ "data"
2528
+ ],
2529
+ "group": "baseline",
2530
+ "contract": {
2531
+ "props": {
2532
+ "type": "object",
2533
+ "properties": {
2534
+ "caption": {
2535
+ "type": "string",
2536
+ "description": "What the table shows; also its accessible name."
2537
+ },
2538
+ "columns": {
2539
+ "type": "array",
2540
+ "items": {
2541
+ "type": "string"
2542
+ },
2543
+ "minItems": 1,
2544
+ "description": "Column headings, in order."
2545
+ },
2546
+ "rows": {
2547
+ "type": "array",
2548
+ "items": {
2549
+ "type": "array",
2550
+ "items": {
2551
+ "type": [
2552
+ "string",
2553
+ "number",
2554
+ "null"
2555
+ ]
2556
+ }
2557
+ },
2558
+ "description": "Rows of cells, one per column; null for an empty cell."
2559
+ },
2560
+ "rowHeaders": {
2561
+ "type": "boolean",
2562
+ "description": "The first cell of each row names the row."
2563
+ }
2564
+ },
2565
+ "required": [
2566
+ "columns",
2567
+ "rows"
2568
+ ],
2569
+ "additionalProperties": false
2570
+ },
2571
+ "state": [],
2572
+ "events": [],
2573
+ "a11y": {
2574
+ "role": "table",
2575
+ "keyboard": {},
2576
+ "labelFrom": "prop"
2577
+ },
2578
+ "colorRoles": [
2579
+ "surface-raised",
2580
+ "border",
2581
+ "ink",
2582
+ "ink-muted"
2583
+ ],
2584
+ "motion": false,
2585
+ "sizing": {
2586
+ "mode": "fill",
2587
+ "minWidth": 200
2588
+ }
2589
+ },
2590
+ "examples": [
2591
+ {
2592
+ "name": "revenue",
2593
+ "props": {
2594
+ "caption": "Quarterly revenue (k)",
2595
+ "columns": [
2596
+ "Quarter",
2597
+ "2025",
2598
+ "2026"
2599
+ ],
2600
+ "rows": [
2601
+ [
2602
+ "Q1",
2603
+ 120,
2604
+ 140
2605
+ ],
2606
+ [
2607
+ "Q2",
2608
+ 135,
2609
+ 152
2610
+ ],
2611
+ [
2612
+ "Q3",
2613
+ 128,
2614
+ null
2615
+ ],
2616
+ [
2617
+ "Q4",
2618
+ 160,
2619
+ 181
2620
+ ]
2621
+ ],
2622
+ "rowHeaders": true
2623
+ }
2624
+ }
2625
+ ],
2626
+ "source": {
2627
+ "provider": "manual"
2628
+ },
2629
+ "category": "display",
2630
+ "runtime": "code",
2631
+ "platforms": [
2632
+ "react",
2633
+ "svelte",
2634
+ "web"
2635
+ ],
2636
+ "entry": "@surreal-ui/catalog/react",
2637
+ "export": "Table",
2638
+ "contentHash": "a03aa01420e3c6b9925bcf8286364b10bd396c4323909ab328e1baa383a32231",
2639
+ "path": "components/table",
2640
+ "alternatives": []
2641
+ },
2521
2642
  {
2522
2643
  "id": "textarea",
2523
2644
  "name": "Textarea",
@@ -0,0 +1,41 @@
1
+ // ../../components/table/react.tsx
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ function numericColumns(columns, rows) {
4
+ return columns.map(
5
+ (_, c) => rows.some((r) => typeof r[c] === "number") && rows.every((r) => r[c] === null || r[c] === void 0 || typeof r[c] === "number")
6
+ );
7
+ }
8
+ function Table({ caption, columns, rows, rowHeaders, className, ...props }) {
9
+ const numeric = numericColumns(columns, rows);
10
+ return /* @__PURE__ */ jsx("div", { className: "sui-table", children: /* @__PURE__ */ jsxs("table", { className: ["sui-table__table", className].filter(Boolean).join(" "), ...props, children: [
11
+ caption && /* @__PURE__ */ jsx("caption", { className: "sui-table__caption", children: caption }),
12
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: columns.map((column, i) => /* @__PURE__ */ jsx(
13
+ "th",
14
+ {
15
+ scope: "col",
16
+ className: "sui-table__heading",
17
+ "data-numeric": numeric[i] || void 0,
18
+ children: column
19
+ },
20
+ i
21
+ )) }) }),
22
+ /* @__PURE__ */ jsx("tbody", { children: rows.map((row, r) => /* @__PURE__ */ jsx("tr", { children: columns.map((_, c) => {
23
+ const cell = row[c] ?? null;
24
+ const text = cell === null ? "" : String(cell);
25
+ return rowHeaders && c === 0 ? /* @__PURE__ */ jsx("th", { scope: "row", className: "sui-table__row-heading", children: text }, c) : /* @__PURE__ */ jsx(
26
+ "td",
27
+ {
28
+ className: "sui-table__cell",
29
+ "data-numeric": typeof cell === "number" || void 0,
30
+ children: text
31
+ },
32
+ c
33
+ );
34
+ }) }, r)) })
35
+ ] }) });
36
+ }
37
+
38
+ export {
39
+ numericColumns,
40
+ Table
41
+ };
@@ -441,6 +441,56 @@
441
441
  }
442
442
 
443
443
 
444
+ /* table */
445
+ /* A data table: wide tables scroll sideways inside their box rather than the page. */
446
+ .sui-table {
447
+ max-width: 100%;
448
+ overflow-x: auto;
449
+ background: var(--sui-surface-raised);
450
+ border: var(--sui-border-width, 1px) solid var(--sui-border);
451
+ border-radius: var(--sui-radius, 6px);
452
+ }
453
+ .sui-table__table {
454
+ width: 100%;
455
+ border-collapse: collapse;
456
+ color: var(--sui-ink);
457
+ font: 400 14px/1.45 var(--sui-font, system-ui, sans-serif);
458
+ font-variant-numeric: tabular-nums;
459
+ }
460
+ .sui-table__caption {
461
+ caption-side: top;
462
+ padding: 12px 14px 4px;
463
+ text-align: left;
464
+ color: var(--sui-ink);
465
+ font-weight: 600;
466
+ }
467
+ .sui-table__heading,
468
+ .sui-table__row-heading,
469
+ .sui-table__cell {
470
+ padding: 8px 14px;
471
+ text-align: left;
472
+ vertical-align: top;
473
+ }
474
+ .sui-table__heading {
475
+ color: var(--sui-ink-muted);
476
+ font-size: 12px;
477
+ font-weight: 600;
478
+ letter-spacing: 0.02em;
479
+ border-bottom: var(--sui-border-width, 1px) solid var(--sui-border);
480
+ }
481
+ .sui-table__row-heading {
482
+ font-weight: 600;
483
+ }
484
+ .sui-table__cell[data-numeric] {
485
+ text-align: right;
486
+ }
487
+ .sui-table__heading[data-numeric] {
488
+ text-align: right;
489
+ }
490
+ .sui-table__table tbody tr + tr > * {
491
+ border-top: var(--sui-border-width, 1px) solid var(--sui-border);
492
+ }
493
+
444
494
  /* textarea */
445
495
  .sui-textarea {
446
496
  display: flex;
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  getComponent,
17
17
  replacementFor,
18
18
  resolveRole
19
- } from "./chunk-BV22DQWK.js";
19
+ } from "./chunk-K6AAK2NB.js";
20
20
  import {
21
21
  mapDeprecatedProps,
22
22
  resolveStructure
package/dist/lazy.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  getAesthetic,
12
12
  getComponent,
13
13
  replacementFor
14
- } from "./chunk-BV22DQWK.js";
14
+ } from "./chunk-K6AAK2NB.js";
15
15
  import "./chunk-HMNTTISG.js";
16
16
 
17
17
  // src/lazy.generated.ts
@@ -28,6 +28,7 @@ var REACT_LOADERS = {
28
28
  "skeleton": () => import("./react-DXQG3CE5.js").then((m) => m.Skeleton),
29
29
  "spinner": () => import("./react-NUMFK32C.js").then((m) => m.Spinner),
30
30
  "switch": () => import("./react-AGH5W4PH.js").then((m) => m.Switch),
31
+ "table": () => import("./react-FUBLM3VE.js").then((m) => m.Table),
31
32
  "textarea": () => import("./react-XUETU4ES.js").then((m) => m.Textarea)
32
33
  };
33
34
 
package/dist/node.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AESTHETICS,
3
3
  getAesthetic
4
- } from "./chunk-BV22DQWK.js";
4
+ } from "./chunk-K6AAK2NB.js";
5
5
  import "./chunk-HMNTTISG.js";
6
6
 
7
7
  // src/skills.ts
@@ -135,6 +135,20 @@ interface SwitchProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>
135
135
  }
136
136
  declare const Switch: React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLButtonElement>>;
137
137
 
138
+ type TableCell = string | number | null;
139
+ interface TableProps extends Omit<React.TableHTMLAttributes<HTMLTableElement>, 'children'> {
140
+ /** What the table shows; also its accessible name. */
141
+ caption?: string;
142
+ /** Column headings, in order. */
143
+ columns: string[];
144
+ /** Rows of cells, one per column; null for an empty cell. */
145
+ rows: TableCell[][];
146
+ /** The first cell of each row names the row. */
147
+ rowHeaders?: boolean;
148
+ }
149
+ /** A data table: a caption, column headings and rows; numbers line up on the right. */
150
+ declare function Table({ caption, columns, rows, rowHeaders, className, ...props }: TableProps): React.JSX.Element;
151
+
138
152
  interface TextareaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'onChange'> {
139
153
  label?: string;
140
154
  onValueChange?: (value: string) => void;
@@ -142,4 +156,4 @@ interface TextareaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaEl
142
156
  }
143
157
  declare const Textarea: React.ForwardRefExoticComponent<TextareaProps & React.RefAttributes<HTMLTextAreaElement>>;
144
158
 
145
- export { Badge, type BadgeProps, Button, type ButtonProps, Card, type CardProps, Checkbox, type CheckboxProps, DeprecatedSpec, Input, type InputProps, Kbd, type KbdProps, Label, type LabelProps, Progress, type ProgressProps, type Rgb, type RoleColors, Separator, type SeparatorProps, Skeleton, type SkeletonProps, Spinner, type SpinnerProps, SurrealTheme, type SurrealThemeProps, Switch, type SwitchProps, Textarea, type TextareaProps, ThemeMode, deprecatedAlias, readRoleColors, useAesthetic, useRoleColors, useStructure, withAesthetic };
159
+ export { Badge, type BadgeProps, Button, type ButtonProps, Card, type CardProps, Checkbox, type CheckboxProps, DeprecatedSpec, Input, type InputProps, Kbd, type KbdProps, Label, type LabelProps, Progress, type ProgressProps, type Rgb, type RoleColors, Separator, type SeparatorProps, Skeleton, type SkeletonProps, Spinner, type SpinnerProps, SurrealTheme, type SurrealThemeProps, Switch, type SwitchProps, Table, type TableProps, Textarea, type TextareaProps, ThemeMode, deprecatedAlias, readRoleColors, useAesthetic, useRoleColors, useStructure, withAesthetic };
@@ -1,3 +1,6 @@
1
+ import {
2
+ Table
3
+ } from "../chunk-SMMBRN3D.js";
1
4
  import {
2
5
  Textarea
3
6
  } from "../chunk-GPANDAGY.js";
@@ -61,6 +64,7 @@ export {
61
64
  Spinner,
62
65
  SurrealTheme,
63
66
  Switch,
67
+ Table,
64
68
  Textarea,
65
69
  deprecatedAlias,
66
70
  readRoleColors,
@@ -0,0 +1,8 @@
1
+ import {
2
+ Table,
3
+ numericColumns
4
+ } from "./chunk-SMMBRN3D.js";
5
+ export {
6
+ Table,
7
+ numericColumns
8
+ };
@@ -0,0 +1,30 @@
1
+ # Table
2
+
3
+ ```tsx
4
+ import { Table, SurrealTheme } from '@surreal-ui/catalog/react';
5
+
6
+ <SurrealTheme aesthetic="minimalist">
7
+ <Table
8
+ caption="Quarterly revenue (k)"
9
+ columns={['Quarter', '2025', '2026']}
10
+ rows={[
11
+ ['Q1', 120, 140],
12
+ ['Q2', 135, 152]
13
+ ]}
14
+ rowHeaders
15
+ />
16
+ </SurrealTheme>;
17
+ ```
18
+
19
+ Svelte 5: `import { Table } from '@surreal-ui/catalog/svelte'`, with the same props.
20
+
21
+ WebComponent: `import '@surreal-ui/catalog/web'`, then
22
+ `<surreal-table caption="…" columns='["Quarter","2025"]' rows='[["Q1",120]]' row-headers></surreal-table>`
23
+ (or set its `columns` and `rows` properties).
24
+
25
+ The props are the schemas' `UiTableProps`, so a data visual's fallback (a chart as a table) renders
26
+ with it directly. Cells are text, numbers or `null` (empty); numbers line up on the right with
27
+ tabular figures. A wide table scrolls sideways inside its box.
28
+
29
+ The old per-aesthetic `Table`, `TableHeader`, `TableRow`, … were a compound component with a
30
+ different API, so they stay as they are rather than becoming aliases.
@@ -0,0 +1,102 @@
1
+ import { SurrealElement, define } from '@surreal-ui/catalog/web';
2
+
3
+ type TableCell = string | number | null;
4
+
5
+ /**
6
+ * `<surreal-table caption="…" columns='["Quarter","2025"]' rows='[["Q1",120]]' row-headers>`.
7
+ * `columns` and `rows` are JSON (or set the `columns` and `rows` properties); numbers line up on
8
+ * the right.
9
+ */
10
+ export class TableElement extends SurrealElement {
11
+ static get observedAttributes() {
12
+ return ['caption', 'columns', 'rows', 'row-headers'];
13
+ }
14
+ #columns: string[] | null = null;
15
+ #rows: TableCell[][] | null = null;
16
+ get columns(): string[] {
17
+ return this.#columns ?? this.#json<string[]>('columns', []);
18
+ }
19
+ set columns(value: string[]) {
20
+ this.#columns = value;
21
+ this.render();
22
+ }
23
+ get rows(): TableCell[][] {
24
+ return this.#rows ?? this.#json<TableCell[][]>('rows', []);
25
+ }
26
+ set rows(value: TableCell[][]) {
27
+ this.#rows = value;
28
+ this.render();
29
+ }
30
+ get rowHeaders(): boolean {
31
+ return this.hasAttribute('row-headers');
32
+ }
33
+ set rowHeaders(value: boolean) {
34
+ this.toggleAttribute('row-headers', value);
35
+ }
36
+ #json<T>(name: string, fallback: T): T {
37
+ try {
38
+ return JSON.parse(this.getAttribute(name) ?? '') as T;
39
+ } catch {
40
+ return fallback;
41
+ }
42
+ }
43
+ protected render(): void {
44
+ const columns = this.columns;
45
+ const rows = this.rows;
46
+ // A column is numeric when it has a number and every other cell is a number or empty.
47
+ const numeric = columns.map(
48
+ (_, c) =>
49
+ rows.some((r) => typeof r[c] === 'number') &&
50
+ rows.every((r) => r[c] === null || r[c] === undefined || typeof r[c] === 'number')
51
+ );
52
+ const rowHeaders = this.rowHeaders;
53
+ const wrap = document.createElement('div');
54
+ wrap.className = 'sui-table';
55
+ const table = document.createElement('table');
56
+ table.className = 'sui-table__table';
57
+ const caption = this.getAttribute('caption');
58
+ if (caption) {
59
+ const c = document.createElement('caption');
60
+ c.className = 'sui-table__caption';
61
+ c.textContent = caption;
62
+ table.append(c);
63
+ }
64
+ const head = document.createElement('thead');
65
+ const headRow = document.createElement('tr');
66
+ columns.forEach((column, i) => {
67
+ const th = document.createElement('th');
68
+ th.scope = 'col';
69
+ th.className = 'sui-table__heading';
70
+ if (numeric[i]) th.dataset.numeric = 'true';
71
+ th.textContent = column;
72
+ headRow.append(th);
73
+ });
74
+ head.append(headRow);
75
+ const body = document.createElement('tbody');
76
+ for (const row of rows) {
77
+ const tr = document.createElement('tr');
78
+ columns.forEach((_, c) => {
79
+ const cell = row[c] ?? null;
80
+ const text = cell === null ? '' : String(cell);
81
+ if (rowHeaders && c === 0) {
82
+ const th = document.createElement('th');
83
+ th.scope = 'row';
84
+ th.className = 'sui-table__row-heading';
85
+ th.textContent = text;
86
+ tr.append(th);
87
+ } else {
88
+ const td = document.createElement('td');
89
+ td.className = 'sui-table__cell';
90
+ if (typeof cell === 'number') td.dataset.numeric = 'true';
91
+ td.textContent = text;
92
+ tr.append(td);
93
+ }
94
+ });
95
+ body.append(tr);
96
+ }
97
+ table.append(head, body);
98
+ wrap.append(table);
99
+ this.replaceChildren(wrap);
100
+ }
101
+ }
102
+ define('surreal-table', TableElement);
@@ -0,0 +1,72 @@
1
+ import * as React from 'react';
2
+
3
+ export type TableCell = string | number | null;
4
+
5
+ export interface TableProps extends Omit<React.TableHTMLAttributes<HTMLTableElement>, 'children'> {
6
+ /** What the table shows; also its accessible name. */
7
+ caption?: string;
8
+ /** Column headings, in order. */
9
+ columns: string[];
10
+ /** Rows of cells, one per column; null for an empty cell. */
11
+ rows: TableCell[][];
12
+ /** The first cell of each row names the row. */
13
+ rowHeaders?: boolean;
14
+ }
15
+
16
+ /** A column is numeric when it has a number and every other cell is a number or empty. */
17
+ export function numericColumns(columns: string[], rows: TableCell[][]): boolean[] {
18
+ return columns.map(
19
+ (_, c) =>
20
+ rows.some((r) => typeof r[c] === 'number') &&
21
+ rows.every((r) => r[c] === null || r[c] === undefined || typeof r[c] === 'number')
22
+ );
23
+ }
24
+
25
+ /** A data table: a caption, column headings and rows; numbers line up on the right. */
26
+ export function Table({ caption, columns, rows, rowHeaders, className, ...props }: TableProps) {
27
+ const numeric = numericColumns(columns, rows);
28
+ return (
29
+ <div className="sui-table">
30
+ <table className={['sui-table__table', className].filter(Boolean).join(' ')} {...props}>
31
+ {caption && <caption className="sui-table__caption">{caption}</caption>}
32
+ <thead>
33
+ <tr>
34
+ {columns.map((column, i) => (
35
+ <th
36
+ key={i}
37
+ scope="col"
38
+ className="sui-table__heading"
39
+ data-numeric={numeric[i] || undefined}
40
+ >
41
+ {column}
42
+ </th>
43
+ ))}
44
+ </tr>
45
+ </thead>
46
+ <tbody>
47
+ {rows.map((row, r) => (
48
+ <tr key={r}>
49
+ {columns.map((_, c) => {
50
+ const cell = row[c] ?? null;
51
+ const text = cell === null ? '' : String(cell);
52
+ return rowHeaders && c === 0 ? (
53
+ <th key={c} scope="row" className="sui-table__row-heading">
54
+ {text}
55
+ </th>
56
+ ) : (
57
+ <td
58
+ key={c}
59
+ className="sui-table__cell"
60
+ data-numeric={typeof cell === 'number' || undefined}
61
+ >
62
+ {text}
63
+ </td>
64
+ );
65
+ })}
66
+ </tr>
67
+ ))}
68
+ </tbody>
69
+ </table>
70
+ </div>
71
+ );
72
+ }
@@ -0,0 +1,48 @@
1
+ /* A data table: wide tables scroll sideways inside their box rather than the page. */
2
+ .sui-table {
3
+ max-width: 100%;
4
+ overflow-x: auto;
5
+ background: var(--sui-surface-raised);
6
+ border: var(--sui-border-width, 1px) solid var(--sui-border);
7
+ border-radius: var(--sui-radius, 6px);
8
+ }
9
+ .sui-table__table {
10
+ width: 100%;
11
+ border-collapse: collapse;
12
+ color: var(--sui-ink);
13
+ font: 400 14px/1.45 var(--sui-font, system-ui, sans-serif);
14
+ font-variant-numeric: tabular-nums;
15
+ }
16
+ .sui-table__caption {
17
+ caption-side: top;
18
+ padding: 12px 14px 4px;
19
+ text-align: left;
20
+ color: var(--sui-ink);
21
+ font-weight: 600;
22
+ }
23
+ .sui-table__heading,
24
+ .sui-table__row-heading,
25
+ .sui-table__cell {
26
+ padding: 8px 14px;
27
+ text-align: left;
28
+ vertical-align: top;
29
+ }
30
+ .sui-table__heading {
31
+ color: var(--sui-ink-muted);
32
+ font-size: 12px;
33
+ font-weight: 600;
34
+ letter-spacing: 0.02em;
35
+ border-bottom: var(--sui-border-width, 1px) solid var(--sui-border);
36
+ }
37
+ .sui-table__row-heading {
38
+ font-weight: 600;
39
+ }
40
+ .sui-table__cell[data-numeric] {
41
+ text-align: right;
42
+ }
43
+ .sui-table__heading[data-numeric] {
44
+ text-align: right;
45
+ }
46
+ .sui-table__table tbody tr + tr > * {
47
+ border-top: var(--sui-border-width, 1px) solid var(--sui-border);
48
+ }
@@ -0,0 +1,57 @@
1
+ <script lang="ts">
2
+ import type { HTMLTableAttributes } from 'svelte/elements';
3
+
4
+ type TableCell = string | number | null;
5
+
6
+ interface Props extends Omit<HTMLTableAttributes, 'children'> {
7
+ /** What the table shows; also its accessible name. */
8
+ caption?: string;
9
+ /** Column headings, in order. */
10
+ columns: string[];
11
+ /** Rows of cells, one per column; null for an empty cell. */
12
+ rows: TableCell[][];
13
+ /** The first cell of each row names the row. */
14
+ rowHeaders?: boolean;
15
+ }
16
+
17
+ let {
18
+ caption,
19
+ columns,
20
+ rows,
21
+ rowHeaders = false,
22
+ class: className = '',
23
+ ...rest
24
+ }: Props = $props();
25
+ </script>
26
+
27
+ <div class="sui-table">
28
+ <table class={['sui-table__table', className].filter(Boolean).join(' ')} {...rest}>
29
+ {#if caption}<caption class="sui-table__caption">{caption}</caption>{/if}
30
+ <thead>
31
+ <tr>
32
+ {#each columns as column, i (i)}
33
+ <th scope="col" class="sui-table__heading" data-numeric={numeric[i] || undefined}
34
+ >{column}</th
35
+ >
36
+ {/each}
37
+ </tr>
38
+ </thead>
39
+ <tbody>
40
+ {#each rows as row, r (r)}
41
+ <tr>
42
+ {#each columns as _, c (c)}
43
+ {@const cell = row[c] ?? null}
44
+ {#if rowHeaders && c === 0}
45
+ <th scope="row" class="sui-table__row-heading">{cell === null ? '' : String(cell)}</th
46
+ >
47
+ {:else}
48
+ <td class="sui-table__cell" data-numeric={typeof cell === 'number' || undefined}>
49
+ {cell === null ? '' : String(cell)}
50
+ </td>
51
+ {/if}
52
+ {/each}
53
+ </tr>
54
+ {/each}
55
+ </tbody>
56
+ </table>
57
+ </div>
@@ -0,0 +1,57 @@
1
+ <script lang="ts">
2
+ import type { HTMLTableAttributes } from 'svelte/elements';
3
+
4
+ type TableCell = string | number | null;
5
+
6
+ interface Props extends Omit<HTMLTableAttributes, 'children'> {
7
+ /** What the table shows; also its accessible name. */
8
+ caption?: string;
9
+ /** Column headings, in order. */
10
+ columns: string[];
11
+ /** Rows of cells, one per column; null for an empty cell. */
12
+ rows: TableCell[][];
13
+ /** The first cell of each row names the row. */
14
+ rowHeaders?: boolean;
15
+ }
16
+
17
+ let {
18
+ caption,
19
+ columns,
20
+ rows,
21
+ rowHeaders = false,
22
+ class: className = '',
23
+ ...rest
24
+ }: Props = $props();
25
+ </script>
26
+
27
+ <div class="sui-table">
28
+ <table class={['sui-table__table', className].filter(Boolean).join(' ')} {...rest}>
29
+ {#if caption}<caption class="sui-table__caption">{caption}</caption>{/if}
30
+ <thead>
31
+ <tr>
32
+ {#each columns as column, i (i)}
33
+ <th scope="col" class="sui-table__heading" data-numeric={numeric[i] || undefined}
34
+ >{column}</th
35
+ >
36
+ {/each}
37
+ </tr>
38
+ </thead>
39
+ <tbody>
40
+ {#each rows as row, r (r)}
41
+ <tr>
42
+ {#each columns as _, c (c)}
43
+ {@const cell = row[c] ?? null}
44
+ {#if rowHeaders && c === 0}
45
+ <th scope="row" class="sui-table__row-heading">{cell === null ? '' : String(cell)}</th
46
+ >
47
+ {:else}
48
+ <td class="sui-table__cell" data-numeric={typeof cell === 'number' || undefined}>
49
+ {cell === null ? '' : String(cell)}
50
+ </td>
51
+ {/if}
52
+ {/each}
53
+ </tr>
54
+ {/each}
55
+ </tbody>
56
+ </table>
57
+ </div>
@@ -15,4 +15,5 @@ export declare const Separator: Component<Record<string, any>>;
15
15
  export declare const Skeleton: Component<Record<string, any>>;
16
16
  export declare const Spinner: Component<Record<string, any>>;
17
17
  export declare const Switch: Component<Record<string, any>>;
18
+ export declare const Table: Component<Record<string, any>>;
18
19
  export declare const Textarea: Component<Record<string, any>>;
@@ -12,4 +12,5 @@ export { default as Separator } from './Separator.svelte';
12
12
  export { default as Skeleton } from './Skeleton.svelte';
13
13
  export { default as Spinner } from './Spinner.svelte';
14
14
  export { default as Switch } from './Switch.svelte';
15
+ export { default as Table } from './Table.svelte';
15
16
  export { default as Textarea } from './Textarea.svelte';
@@ -12,6 +12,7 @@ const LOADERS = {
12
12
  "skeleton": () => import('./Skeleton.svelte'),
13
13
  "spinner": () => import('./Spinner.svelte'),
14
14
  "switch": () => import('./Switch.svelte'),
15
+ "table": () => import('./Table.svelte'),
15
16
  "textarea": () => import('./Textarea.svelte'),
16
17
  };
17
18
  const loaded = new Map();
@@ -123,6 +123,24 @@ declare class SwitchElement extends SurrealElement {
123
123
  protected render(): void;
124
124
  }
125
125
 
126
+ type TableCell = string | number | null;
127
+ /**
128
+ * `<surreal-table caption="…" columns='["Quarter","2025"]' rows='[["Q1",120]]' row-headers>`.
129
+ * `columns` and `rows` are JSON (or set the `columns` and `rows` properties); numbers line up on
130
+ * the right.
131
+ */
132
+ declare class TableElement extends SurrealElement {
133
+ #private;
134
+ static get observedAttributes(): string[];
135
+ get columns(): string[];
136
+ set columns(value: string[]);
137
+ get rows(): TableCell[][];
138
+ set rows(value: TableCell[][]);
139
+ get rowHeaders(): boolean;
140
+ set rowHeaders(value: boolean);
141
+ protected render(): void;
142
+ }
143
+
126
144
  /** `<surreal-textarea label="Notes" name="notes" rows="4">`. A native `<textarea>` in light DOM. */
127
145
  declare class TextareaElement extends SurrealElement {
128
146
  #private;
@@ -132,4 +150,4 @@ declare class TextareaElement extends SurrealElement {
132
150
  protected render(): void;
133
151
  }
134
152
 
135
- export { BadgeElement, ButtonElement, CardElement, CheckboxElement, InputElement, KbdElement, LabelElement, ProgressElement, SeparatorElement, SkeletonElement, SpinnerElement, SurrealElement, SurrealThemeElement, SwitchElement, TextareaElement, aestheticOf, define, structureFor };
153
+ export { BadgeElement, ButtonElement, CardElement, CheckboxElement, InputElement, KbdElement, LabelElement, ProgressElement, SeparatorElement, SkeletonElement, SpinnerElement, SurrealElement, SurrealThemeElement, SwitchElement, TableElement, TextareaElement, aestheticOf, define, structureFor };
package/dist/web/index.js CHANGED
@@ -463,6 +463,98 @@ var SwitchElement = class extends SurrealElement {
463
463
  };
464
464
  define("surreal-switch", SwitchElement);
465
465
 
466
+ // ../../components/table/element.ts
467
+ var TableElement = class extends SurrealElement {
468
+ static get observedAttributes() {
469
+ return ["caption", "columns", "rows", "row-headers"];
470
+ }
471
+ #columns = null;
472
+ #rows = null;
473
+ get columns() {
474
+ return this.#columns ?? this.#json("columns", []);
475
+ }
476
+ set columns(value) {
477
+ this.#columns = value;
478
+ this.render();
479
+ }
480
+ get rows() {
481
+ return this.#rows ?? this.#json("rows", []);
482
+ }
483
+ set rows(value) {
484
+ this.#rows = value;
485
+ this.render();
486
+ }
487
+ get rowHeaders() {
488
+ return this.hasAttribute("row-headers");
489
+ }
490
+ set rowHeaders(value) {
491
+ this.toggleAttribute("row-headers", value);
492
+ }
493
+ #json(name, fallback) {
494
+ try {
495
+ return JSON.parse(this.getAttribute(name) ?? "");
496
+ } catch {
497
+ return fallback;
498
+ }
499
+ }
500
+ render() {
501
+ const columns = this.columns;
502
+ const rows = this.rows;
503
+ const numeric = columns.map(
504
+ (_, c) => rows.some((r) => typeof r[c] === "number") && rows.every((r) => r[c] === null || r[c] === void 0 || typeof r[c] === "number")
505
+ );
506
+ const rowHeaders = this.rowHeaders;
507
+ const wrap = document.createElement("div");
508
+ wrap.className = "sui-table";
509
+ const table = document.createElement("table");
510
+ table.className = "sui-table__table";
511
+ const caption = this.getAttribute("caption");
512
+ if (caption) {
513
+ const c = document.createElement("caption");
514
+ c.className = "sui-table__caption";
515
+ c.textContent = caption;
516
+ table.append(c);
517
+ }
518
+ const head = document.createElement("thead");
519
+ const headRow = document.createElement("tr");
520
+ columns.forEach((column, i) => {
521
+ const th = document.createElement("th");
522
+ th.scope = "col";
523
+ th.className = "sui-table__heading";
524
+ if (numeric[i]) th.dataset.numeric = "true";
525
+ th.textContent = column;
526
+ headRow.append(th);
527
+ });
528
+ head.append(headRow);
529
+ const body = document.createElement("tbody");
530
+ for (const row of rows) {
531
+ const tr = document.createElement("tr");
532
+ columns.forEach((_, c) => {
533
+ const cell = row[c] ?? null;
534
+ const text = cell === null ? "" : String(cell);
535
+ if (rowHeaders && c === 0) {
536
+ const th = document.createElement("th");
537
+ th.scope = "row";
538
+ th.className = "sui-table__row-heading";
539
+ th.textContent = text;
540
+ tr.append(th);
541
+ } else {
542
+ const td = document.createElement("td");
543
+ td.className = "sui-table__cell";
544
+ if (typeof cell === "number") td.dataset.numeric = "true";
545
+ td.textContent = text;
546
+ tr.append(td);
547
+ }
548
+ });
549
+ body.append(tr);
550
+ }
551
+ table.append(head, body);
552
+ wrap.append(table);
553
+ this.replaceChildren(wrap);
554
+ }
555
+ };
556
+ define("surreal-table", TableElement);
557
+
466
558
  // ../../components/textarea/element.ts
467
559
  var FORWARD2 = ["name", "placeholder", "disabled", "required", "rows", "maxlength"];
468
560
  var TextareaElement = class extends SurrealElement {
@@ -519,6 +611,7 @@ export {
519
611
  SurrealElement,
520
612
  SurrealThemeElement,
521
613
  SwitchElement,
614
+ TableElement,
522
615
  TextareaElement,
523
616
  aestheticOf,
524
617
  define,
package/llms.txt CHANGED
@@ -53,6 +53,7 @@
53
53
  - spinner: Spinner (feedback). A visual loading/spinner indicator. Import `Spinner` from `@surreal-ui/catalog/react`; element `<surreal-spinner>`.
54
54
  - switch: Switch (form). A control that allows the user to toggle between checked and not checked. Import `Switch` from `@surreal-ui/catalog/react`; element `<surreal-switch>`.
55
55
  - flair-toggle-switch: Toggle switch (form, implements switch). A switch whose knob slides across, squashing a little mid-slide, as the track blends to its on colour; the next click slides it back. Import `FlairToggleSwitch` from `@surreal-ui/catalog/react/flair`.
56
+ - table: Table (display). Rows and columns of data with a caption, column headings and optional row headings; numbers line up on the right. Import `Table` from `@surreal-ui/catalog/react`; element `<surreal-table>`.
56
57
  - textarea: Textarea (form). A multi-line text input control. Import `Textarea` from `@surreal-ui/catalog/react`; element `<surreal-textarea>`.
57
58
  - timeline: Timeline (data-visual). Periods along an axis, each with its events stacked under it, one colour per period. Import `Timeline` from `@surreal-ui/catalog/react/editor`.
58
59
  - weave: Weave (data-visual). Items along the top joined to the tags they share along the bottom, many to many; focusing an item lights its tags, and focusing a tag lights its items. Import `Weave` from `@surreal-ui/catalog/react/editor`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@surreal-ui/catalog",
3
- "version": "0.13.0",
3
+ "version": "0.14.1",
4
4
  "description": "Drop-in UI components with a catalog API and aesthetic packs: one implementation per component type, restyled by aesthetics defined as skills.",
5
5
  "license": "MIT",
6
6
  "author": "Pixerate",
@@ -25,6 +25,7 @@ Show content or status without taking input: badges, avatars, typography.
25
25
 
26
26
  - `badge` **Badge**: Displays a badge or a component that looks like a badge; React `Badge` from `@surreal-ui/catalog/react`; Svelte `Badge` from `@surreal-ui/catalog/svelte`; element `<surreal-badge>` from `@surreal-ui/catalog/web`; props `children`, `tone`; examples `neutral`, `accent`; replaces `MinimalistBadge`, `ShadcnBadge`; tags display.
27
27
  - `kbd` **Kbd**: Represents keyboard input or a hotkey combination; React `Kbd` from `@surreal-ui/catalog/react`; Svelte `Kbd` from `@surreal-ui/catalog/svelte`; element `<surreal-kbd>` from `@surreal-ui/catalog/web`; props `children`; examples `shortcut`; replaces `MinimalistKbd`, `ShadcnKbd`; tags display, typography.
28
+ - `table` **Table**: Rows and columns of data with a caption, column headings and optional row headings; numbers line up on the right; React `Table` from `@surreal-ui/catalog/react`; Svelte `Table` from `@surreal-ui/catalog/svelte`; element `<surreal-table>` from `@surreal-ui/catalog/web`; props `caption`, `columns`, `rows`, `rowHeaders`; examples `revenue`; tags display, data.
28
29
 
29
30
  ## Feedback (`feedback`)
30
31