@overdoser/react-toolkit 0.19.0 → 0.20.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/llms.txt CHANGED
@@ -26,7 +26,7 @@ All components forward `className` and `style`. Most also accept a `classes` obj
26
26
 
27
27
  ### Dark mode
28
28
 
29
- The stylesheet ships a full dark token set. Contract: no attribute = follow the OS (`prefers-color-scheme`); `data-theme="light"` / `data-theme="dark"` on `<html>` forces a theme — and on **any element** forces it for that subtree (`<div data-theme="dark">` for a dark sidebar). `color-scheme` follows, so native controls and scrollbars match.
29
+ The stylesheet ships a full dark token set. Contract: **no attribute = light** (an upgrade never changes an app's look); `data-theme="dark"` / `"light"` on `<html>` forces a theme — and on **any element** forces it for that subtree (`<div data-theme="dark">` for a dark sidebar); `data-theme="system"` on `<html>` follows the OS (`prefers-color-scheme`). `useTheme` / `ThemeToggle` / `THEME_INIT_SCRIPT` write these for you, so dark mode is opt-in per app. `color-scheme` follows, so native controls and scrollbars match.
30
30
 
31
31
  ```tsx
32
32
  // <head>, before first paint — applies the stored choice without a flash
@@ -37,7 +37,7 @@ import { THEME_INIT_SCRIPT } from '@overdoser/react-toolkit';
37
37
  <ThemeToggle />
38
38
  const { theme, resolved, setTheme, toggle } = useTheme(); // theme: 'light' | 'dark' | 'system'; resolved: 'light' | 'dark'
39
39
  ```
40
- The choice is stored in `localStorage` under `crk-theme` (`storageKey` option on both). Text-on-tint colours use the `--crk-color-*-text` tokens (`primary`, `info`, `success`, `warning`, `danger`); backdrops use `--crk-color-backdrop` / `--crk-color-backdrop-soft`; hover overlays `--crk-color-overlay-hover`. Override dark values under `[data-theme="dark"]` (and the `prefers-color-scheme` branch if you rely on it).
40
+ The choice is stored in `localStorage` under `crk-theme` (`storageKey` option on all three; `defaultTheme` on `useTheme`, `ThemeToggle` and `getThemeInitScript` — keep them equal). An app that is dark-only can just put `data-theme="dark"` on `<html>` and skip the hook. Text-on-tint colours use the `--crk-color-*-text` tokens (`primary`, `info`, `success`, `warning`, `danger`); `--crk-color-primary-text` / `--crk-color-primary-selected` derive from `--crk-color-primary` via `color-mix`, so overriding the primary carries into them. Backdrops use `--crk-color-backdrop` / `--crk-color-backdrop-soft`; hover overlays `--crk-color-overlay-hover`. Override dark values under `[data-theme="dark"]`.
41
41
 
42
42
  ### Making your overrides always win (CSS ordering)
43
43
 
@@ -245,7 +245,7 @@ Props:
245
245
  - `classes?: Partial<TableClasses>` where `TableClasses = { wrapper, root, headerCell, row, cell, emptyCell, paginator, pageButton, rowClickable, rowSelected, selectCell, selectHeaderCell, bulkBar, bulkLabel, bulkClear, bulkActions, loadingRow }`
246
246
 
247
247
  `ColumnDef<T>`:
248
- - `key: keyof T & string` — required.
248
+ - `key: keyof T & string` — required for a **data column** (a misspelled key is a type error). For a column with no backing field use `id: string` + a required `render(row, index)` instead (a **display column**: actions, checkboxes); it is not sortable and its `cellClassName`/`cellStyle` callbacks receive `(row, index)`.
249
249
  - `header: ReactNode` — required. Interactive elements (e.g. a remove-column button) are allowed; inside a `sortable` column they must call `e.stopPropagation()` in their click handler so the click doesn't trigger a sort.
250
250
  - `sortable?: boolean`
251
251
  - `defaultSortDirection?: 'asc' | 'desc'` — default `'asc'`. Direction the sort cycle starts with: `none → defaultSortDirection → opposite → none`. Use `'desc'` for "highest first" columns (scores, amounts, %DV).
@@ -991,7 +991,7 @@ Element: `<button>` (icon variant, forwards ref) or `<div role="radiogroup">` (s
991
991
  - `variant?: 'icon' | 'segmented'` — default `'icon'` (sun / moon / monitor icon cycling light → dark → system, `aria-label` "Theme: Light, switch to Dark") or three `role="radio"` buttons.
992
992
  - `allowSystem?: boolean` — default `true`; `false` = two states.
993
993
  - `size?: 'sm' | 'md'` — default `'md'`. `showLabel?: boolean` — default `false`.
994
- - `labels?: Partial<Record<'light' | 'dark' | 'system', string>>`. `storageKey?: string` — default `'crk-theme'`.
994
+ - `labels?: Partial<Record<'light' | 'dark' | 'system', string>>`. `storageKey?: string` — default `'crk-theme'`. `defaultTheme?: 'light' | 'dark' | 'system'` — default `'system'` (match `THEME_INIT_SCRIPT`'s).
995
995
  - `classes?: Partial<ThemeToggleClasses>` where `ThemeToggleClasses = { root, icon, label, option, optionSelected }`.
996
996
 
997
997
  ```tsx
@@ -2142,7 +2142,7 @@ Signature: `useMediaQuery(query: string, serverValue = false): boolean` — subs
2142
2142
  Signature: `useElementSize(ref, box = 'content-box'): { width, height }` — `ResizeObserver`-backed; `{ 0, 0 }` until measured; stable object while unchanged.
2143
2143
 
2144
2144
  ### useTheme
2145
- Signature: `useTheme({ storageKey?: 'crk-theme', attribute?: 'data-theme', defaultTheme?: 'system' }?): { theme: 'light' | 'dark' | 'system', resolved: 'light' | 'dark', setTheme, toggle }` — persists the choice, sets `data-theme` on `<html>` (removed for `system`), follows `prefers-color-scheme` for `resolved`; all instances stay in sync; SSR-safe. Pair with `THEME_INIT_SCRIPT` in `<head>` to avoid a flash.
2145
+ Signature: `useTheme({ storageKey?: 'crk-theme', attribute?: 'data-theme', defaultTheme?: 'system' }?): { theme: 'light' | 'dark' | 'system', resolved: 'light' | 'dark', setTheme, toggle }` — persists the choice, writes `data-theme` on `<html>` (`light` / `dark` / `system`), follows `prefers-color-scheme` for `resolved`; all instances stay in sync; SSR-safe. Pair with `THEME_INIT_SCRIPT` in `<head>` to avoid a flash.
2146
2146
 
2147
2147
  ### useResizable
2148
2148
  Signature: `useResizable({ size?, defaultSize?, min?, max?: number | (() => number), axis?: 'x' | 'y', invert?, step?, onResize?, onResizeStart?, onResizeEnd?, disabled? }): { size, setSize, isResizing, reset, handleProps }` — the drag/keyboard engine behind `SplitPane`. Spread `handleProps` (pointer + key handlers, `role="separator"`, aria values, `tabIndex`) on your own handle element; `invert` for a right/bottom-anchored pane; double-click resets.
@@ -2156,7 +2156,7 @@ Signature: `useNow(interval = 1000, active = true): number` — current epoch ms
2156
2156
  `formatBytes(bytes: number, { decimals = 1, base = 1024, iec = false, locale }?): string` — `formatBytes(1536)` → `"1.5 KB"`, `formatBytes(2048, { iec: true })` → `"2.0 KiB"`, whole bytes have no decimals (`"512 B"`).
2157
2157
 
2158
2158
  ### THEME_INIT_SCRIPT / getThemeInitScript
2159
- `THEME_INIT_SCRIPT: string` — inline script for `<head>` that applies the stored theme before first paint. `getThemeInitScript({ storageKey?, attribute? })` builds one for custom keys.
2159
+ `THEME_INIT_SCRIPT: string` — inline script for `<head>` that applies the stored theme before first paint (writes `system` when nothing is stored). `getThemeInitScript({ storageKey?, attribute?, defaultTheme? })` builds one for custom keys or a different default (an app that defaults to dark passes `defaultTheme: 'dark'`).
2160
2160
 
2161
2161
  ### timeAgo
2162
2162
  `timeAgo(value: Date | number | string, { now, locale, format, numeric, maxAge }?): string | null` — `"3 minutes ago"`, `"in 2 hours"`, `"yesterday"` via `Intl.RelativeTimeFormat`; `null` past `maxAge` or for an unparsable value. `RelativeTime` is the live component version.
package/manifest.json CHANGED
@@ -388,9 +388,9 @@
388
388
  "props": {}
389
389
  },
390
390
  "Table": {
391
- "import": "import { Table, type ColumnDef, type SortConfig } from '@overdoser/react-toolkit'",
391
+ "import": "import { Table, type ColumnDef, type DataColumnDef, type DisplayColumnDef, type SortConfig } from '@overdoser/react-toolkit'",
392
392
  "element": "table (inside wrapper div)",
393
- "generic": "T extends Record<string, unknown>",
393
+ "generic": "T extends object",
394
394
  "props": {
395
395
  "data": {
396
396
  "type": "T[]",
@@ -526,15 +526,36 @@
526
526
  },
527
527
  "subTypes": {
528
528
  "ColumnDef<T>": {
529
+ "type": "DataColumnDef<T> | DisplayColumnDef<T>",
530
+ "notes": "A column backed by a row field (key) or a display-only column (id + required render). A misspelled key is a type error; display columns are not sortable."
531
+ },
532
+ "DataColumnDef<T>": {
529
533
  "key": {
530
534
  "type": "keyof T & string",
531
- "required": true
535
+ "required": true,
536
+ "notes": "Row field to read the cell value from."
532
537
  },
533
538
  "header": {
534
539
  "type": "ReactNode",
535
540
  "required": true,
536
541
  "notes": "Interactive elements allowed; inside a sortable column they must call e.stopPropagation() in their click handler."
537
542
  },
543
+ "width": {
544
+ "type": "string | number"
545
+ },
546
+ "align": {
547
+ "type": "enum",
548
+ "values": [
549
+ "left",
550
+ "center",
551
+ "right"
552
+ ]
553
+ },
554
+ "sticky": {
555
+ "type": "boolean",
556
+ "default": false,
557
+ "notes": "Pin to the left edge while the table scrolls horizontally. Needs scrollable/dragScroll; intended for the first column."
558
+ },
538
559
  "sortable": {
539
560
  "type": "boolean"
540
561
  },
@@ -548,7 +569,28 @@
548
569
  "notes": "Direction the sort cycle starts with. Use desc for highest-first columns."
549
570
  },
550
571
  "render": {
551
- "type": "(value, row, index) => ReactNode"
572
+ "type": "(value: T[keyof T], row: T, index: number) => ReactNode",
573
+ "notes": "Optional; defaults to rendering row[key]."
574
+ },
575
+ "cellClassName": {
576
+ "type": "string | ((value, row, index) => string | undefined)",
577
+ "notes": "Per-cell class for this column, e.g. value-bucket shading."
578
+ },
579
+ "cellStyle": {
580
+ "type": "CSSProperties | ((value, row, index) => CSSProperties | undefined)",
581
+ "notes": "Per-cell inline style; merged over the column's align."
582
+ }
583
+ },
584
+ "DisplayColumnDef<T>": {
585
+ "id": {
586
+ "type": "string",
587
+ "required": true,
588
+ "notes": "Column identifier (React key, columnVisibility key)."
589
+ },
590
+ "header": {
591
+ "type": "ReactNode",
592
+ "required": true,
593
+ "notes": "Interactive elements allowed; inside a sortable column they must call e.stopPropagation() in their click handler."
552
594
  },
553
595
  "width": {
554
596
  "type": "string | number"
@@ -566,13 +608,15 @@
566
608
  "default": false,
567
609
  "notes": "Pin to the left edge while the table scrolls horizontally. Needs scrollable/dragScroll; intended for the first column."
568
610
  },
611
+ "render": {
612
+ "type": "(row: T, index: number) => ReactNode",
613
+ "required": true
614
+ },
569
615
  "cellClassName": {
570
- "type": "string | ((value, row, index) => string | undefined)",
571
- "notes": "Per-cell class for this column, e.g. value-bucket shading."
616
+ "type": "string | ((row: T, index: number) => string | undefined)"
572
617
  },
573
618
  "cellStyle": {
574
- "type": "CSSProperties | ((value, row, index) => CSSProperties | undefined)",
575
- "notes": "Per-cell inline style; merged over the column's align."
619
+ "type": "CSSProperties | ((row: T, index: number) => CSSProperties | undefined)"
576
620
  }
577
621
  },
578
622
  "SortConfig": {
@@ -1524,6 +1568,10 @@
1524
1568
  "option",
1525
1569
  "optionSelected"
1526
1570
  ]
1571
+ },
1572
+ "defaultTheme": {
1573
+ "type": "'light' | 'dark' | 'system'",
1574
+ "default": "system"
1527
1575
  }
1528
1576
  }
1529
1577
  },
@@ -5412,12 +5460,12 @@
5412
5460
  },
5413
5461
  "THEME_INIT_SCRIPT": {
5414
5462
  "import": "import { THEME_INIT_SCRIPT, getThemeInitScript } from '@overdoser/react-toolkit'",
5415
- "signature": "THEME_INIT_SCRIPT: string; getThemeInitScript({ storageKey?, attribute? }?): string",
5463
+ "signature": "THEME_INIT_SCRIPT: string; getThemeInitScript({ storageKey?, attribute?, defaultTheme? }?): string",
5416
5464
  "notes": "Inline in <head> before first paint."
5417
5465
  }
5418
5466
  },
5419
5467
  "darkMode": {
5420
- "contract": "No attribute = follows prefers-color-scheme. data-theme=\"light\"|\"dark\" on <html> forces a theme; on any element forces it for that subtree.",
5468
+ "contract": "No attribute = light. data-theme=\"dark\"|\"light\" on <html> forces a theme; on any element forces it for that subtree. data-theme=\"system\" on <html> follows prefers-color-scheme. useTheme / ThemeToggle / THEME_INIT_SCRIPT write these (opt-in).",
5421
5469
  "storageKey": "crk-theme",
5422
5470
  "headScript": "THEME_INIT_SCRIPT (inline in <head> before first paint)",
5423
5471
  "toggle": "<ThemeToggle />",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overdoser/react-toolkit",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "homepage": "https://react-toolkit.overdoser.org",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -3,6 +3,8 @@ export interface ThemeInitScriptOptions {
3
3
  storageKey?: string;
4
4
  /** Attribute set on `<html>`. @default 'data-theme' */
5
5
  attribute?: string;
6
+ /** Written when nothing valid is stored — match `useTheme`'s `defaultTheme`. @default 'system' */
7
+ defaultTheme?: 'light' | 'dark' | 'system';
6
8
  }
7
9
  /**
8
10
  * Builds the pre-paint theme script: reads the persisted theme and sets the
@@ -1,9 +1,9 @@
1
- function a(t = {}) {
2
- const e = JSON.stringify(t.storageKey ?? "crk-theme"), r = JSON.stringify(t.attribute ?? "data-theme");
3
- return "(function(){try{var k=" + e + ",a=" + r + ',d=document.documentElement,v=localStorage.getItem(k);if(v){try{v=JSON.parse(v)}catch(e){}}if(v==="dark"||v==="light"){d.setAttribute(a,v)}else{d.removeAttribute(a)}}catch(e){}})();';
1
+ function c(t = {}) {
2
+ const e = JSON.stringify(t.storageKey ?? "crk-theme"), r = JSON.stringify(t.attribute ?? "data-theme"), a = JSON.stringify(t.defaultTheme ?? "system");
3
+ return "(function(){var k=" + e + ",a=" + r + ",f=" + a + ',v=null;try{v=localStorage.getItem(k);if(v){try{v=JSON.parse(v)}catch(e){}}}catch(e){}try{document.documentElement.setAttribute(a,v==="dark"||v==="light"||v==="system"?v:f)}catch(e){}})();';
4
4
  }
5
- const c = a();
5
+ const n = c();
6
6
  export {
7
- c as THEME_INIT_SCRIPT,
8
- a as getThemeInitScript
7
+ n as THEME_INIT_SCRIPT,
8
+ c as getThemeInitScript
9
9
  };