@bigpixelrocket/uiok 0.1.2 → 0.1.3
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/CHANGELOG.md +8 -1
- package/dist/tabs/PageTabs.d.ts +5 -0
- package/dist/tabs/PageTabs.js +96 -2
- package/dist/tabs/tabs.css +25 -1
- package/dist/themes/tokens.js +4 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.1.3] - 2026-11-09
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- `PageTabs` shows when a strip too narrow for its tabs hides some: it fades each edge with tabs past it and marks the strip `data-overflow` (`start`, `end`, or both). It also keeps the current tab in view when it first draws tabs and whenever `current` or the tabs change, scrolling only the strip, smoothly unless the reader prefers reduced motion. See `docs/components/tabs.md`.
|
|
14
|
+
|
|
9
15
|
## [0.1.2] - 2026-11-08
|
|
10
16
|
|
|
11
17
|
### Added
|
|
@@ -48,7 +54,8 @@ The first published version. The package is published to npm as `@bigpixelrocket
|
|
|
48
54
|
- `lucide-react` 1.31 or later within 1.x is a peer dependency.
|
|
49
55
|
- Terminal (`@bigpixelrocket/uiok/terminal`, `docs/components/terminal.md`): `Terminal`, Ghostty's VT engine as WebAssembly drawn on a canvas, read-only without `onInput`, with a Copy and Paste menu whose chords come from `menuChords`, a visual bell, line-editing actions bound by `actionForKey`, and `TerminalScrollbackContext`. The package root does not export it, so an app without a terminal never loads its assets. Its words are the new `terminal` label group; the package now ships a `NOTICE` with the engine's, adapter's, and font's licences.
|
|
50
56
|
|
|
51
|
-
[Unreleased]: https://github.com/Bigpixelrocket/uiok/compare/v0.1.
|
|
57
|
+
[Unreleased]: https://github.com/Bigpixelrocket/uiok/compare/v0.1.3...HEAD
|
|
58
|
+
[0.1.3]: https://github.com/Bigpixelrocket/uiok/compare/v0.1.2...v0.1.3
|
|
52
59
|
[0.1.2]: https://github.com/Bigpixelrocket/uiok/compare/v0.1.1...v0.1.2
|
|
53
60
|
[0.1.1]: https://github.com/Bigpixelrocket/uiok/compare/v0.1.0...v0.1.1
|
|
54
61
|
[0.1.0]: https://github.com/Bigpixelrocket/uiok/releases/tag/v0.1.0
|
package/dist/tabs/PageTabs.d.ts
CHANGED
|
@@ -34,5 +34,10 @@ export interface PageTabsProps<Id extends string> {
|
|
|
34
34
|
* keep those keys from any listing cursor around it; Tab enters on the
|
|
35
35
|
* current tab. `pills` draws the second, smaller strip a tab's own pages
|
|
36
36
|
* take under the first.
|
|
37
|
+
*
|
|
38
|
+
* A strip too narrow for its tabs scrolls sideways: it fades each edge that
|
|
39
|
+
* hides tabs (`data-overflow`), and keeps the current tab in view when it
|
|
40
|
+
* first draws and whenever `current` or the tabs change, scrolling only
|
|
41
|
+
* the strip, never the page.
|
|
37
42
|
*/
|
|
38
43
|
export declare function PageTabs<Id extends string>({ label, tabs, current, onSelect, pills, look }: PageTabsProps<Id>): ReactElement;
|
package/dist/tabs/PageTabs.js
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useRef } from 'react';
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef } from 'react';
|
|
3
3
|
import { tooltip } from '../tooltip/Tooltip.logic.js';
|
|
4
|
+
/**
|
|
5
|
+
* How far the strip's edge fade reaches, in pixels; `tabs.css` draws the
|
|
6
|
+
* fade this wide, and a tab scrolled into view clears it.
|
|
7
|
+
*/
|
|
8
|
+
const EDGE_FADE = 24;
|
|
9
|
+
/**
|
|
10
|
+
* Marks the sides of `strip` that hide tabs past its edge as
|
|
11
|
+
* `data-overflow="start end"` (either, both, or the attribute removed), so
|
|
12
|
+
* `tabs.css` fades those edges and a reader can tell more tabs are there.
|
|
13
|
+
*/
|
|
14
|
+
function markOverflow(strip) {
|
|
15
|
+
const sides = [];
|
|
16
|
+
if (strip.scrollLeft > 1)
|
|
17
|
+
sides.push('start');
|
|
18
|
+
if (strip.scrollLeft + strip.clientWidth < strip.scrollWidth - 1)
|
|
19
|
+
sides.push('end');
|
|
20
|
+
if (sides.length === 0)
|
|
21
|
+
strip.removeAttribute('data-overflow');
|
|
22
|
+
else
|
|
23
|
+
strip.setAttribute('data-overflow', sides.join(' '));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The tab of `strip` whose id is `id`, if it draws one. The id is compared
|
|
27
|
+
* rather than put in a selector, so any string is a safe id, and no
|
|
28
|
+
* `instanceof` check ties the lookup to this window's realm (a strip
|
|
29
|
+
* rendered into an iframe's document has that window's elements).
|
|
30
|
+
*/
|
|
31
|
+
function tabOf(strip, id) {
|
|
32
|
+
for (const tab of strip.querySelectorAll('[data-page-tab]')) {
|
|
33
|
+
if (tab.dataset.pageTab === id)
|
|
34
|
+
return tab;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Scrolls `strip` sideways, and only `strip`, so `tab` sits clear of the
|
|
40
|
+
* edge fade, or as near as the scroll allows; a tab already clear stays
|
|
41
|
+
* put. Smooth unless `instant` or the reader prefers reduced motion.
|
|
42
|
+
*/
|
|
43
|
+
function revealTab(strip, tab, instant) {
|
|
44
|
+
const bounds = strip.getBoundingClientRect();
|
|
45
|
+
const box = tab.getBoundingClientRect();
|
|
46
|
+
const before = box.left - (bounds.left + EDGE_FADE);
|
|
47
|
+
const after = box.right - (bounds.right - EDGE_FADE);
|
|
48
|
+
// A tab wider than the clear span shows its start.
|
|
49
|
+
const wanted = before < 0 ? before : after > 0 ? Math.min(after, before) : 0;
|
|
50
|
+
// Within the scroll there is: an end tab needs no move into the padding.
|
|
51
|
+
const by = Math.max(-strip.scrollLeft, Math.min(wanted, strip.scrollWidth - strip.clientWidth - strip.scrollLeft));
|
|
52
|
+
if (by === 0)
|
|
53
|
+
return;
|
|
54
|
+
const still = instant || (window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false);
|
|
55
|
+
strip.scrollBy({ left: by, behavior: still ? 'instant' : 'smooth' });
|
|
56
|
+
}
|
|
4
57
|
/**
|
|
5
58
|
* The tab strip a page draws under its path bar: one tab per page of the
|
|
6
59
|
* level shown, in the order the caller gives, the current one marked. A
|
|
@@ -10,10 +63,50 @@ import { tooltip } from '../tooltip/Tooltip.logic.js';
|
|
|
10
63
|
* keep those keys from any listing cursor around it; Tab enters on the
|
|
11
64
|
* current tab. `pills` draws the second, smaller strip a tab's own pages
|
|
12
65
|
* take under the first.
|
|
66
|
+
*
|
|
67
|
+
* A strip too narrow for its tabs scrolls sideways: it fades each edge that
|
|
68
|
+
* hides tabs (`data-overflow`), and keeps the current tab in view when it
|
|
69
|
+
* first draws and whenever `current` or the tabs change, scrolling only
|
|
70
|
+
* the strip, never the page.
|
|
13
71
|
*/
|
|
14
72
|
export function PageTabs({ label, tabs, current, onSelect, pills = false, look = 'both' }) {
|
|
15
73
|
const strip = useRef(null);
|
|
16
74
|
const focusable = current ?? tabs[0]?.id ?? null;
|
|
75
|
+
const drawn = useRef(false);
|
|
76
|
+
// The tabs drawn, as a value that changes only when they do, not with
|
|
77
|
+
// each new array a caller passes.
|
|
78
|
+
const ids = JSON.stringify(tabs.map((tab) => tab.id));
|
|
79
|
+
// The edge fade follows scrolling, resizing (a tab's look or font
|
|
80
|
+
// included), and the tabs drawn.
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const element = strip.current;
|
|
83
|
+
if (element === null)
|
|
84
|
+
return;
|
|
85
|
+
const mark = () => markOverflow(element);
|
|
86
|
+
const resizes = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(mark);
|
|
87
|
+
mark();
|
|
88
|
+
element.addEventListener('scroll', mark, { passive: true });
|
|
89
|
+
resizes?.observe(element);
|
|
90
|
+
for (const tab of element.children)
|
|
91
|
+
resizes?.observe(tab);
|
|
92
|
+
return () => {
|
|
93
|
+
element.removeEventListener('scroll', mark);
|
|
94
|
+
resizes?.disconnect();
|
|
95
|
+
};
|
|
96
|
+
}, [ids]);
|
|
97
|
+
// The current tab stays in view: at once, before the first paint, when
|
|
98
|
+
// the strip first draws tabs, then smoothly as it or the tabs change.
|
|
99
|
+
useLayoutEffect(() => {
|
|
100
|
+
const element = strip.current;
|
|
101
|
+
if (element === null)
|
|
102
|
+
return;
|
|
103
|
+
const instant = !drawn.current;
|
|
104
|
+
const tab = current === null ? null : tabOf(element, current);
|
|
105
|
+
if (element.children.length > 0)
|
|
106
|
+
drawn.current = true;
|
|
107
|
+
if (tab !== null)
|
|
108
|
+
revealTab(element, tab, instant);
|
|
109
|
+
}, [current, ids]);
|
|
17
110
|
const onKeyDown = (event) => {
|
|
18
111
|
if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight')
|
|
19
112
|
return;
|
|
@@ -27,7 +120,8 @@ export function PageTabs({ label, tabs, current, onSelect, pills = false, look =
|
|
|
27
120
|
if (next === undefined)
|
|
28
121
|
return;
|
|
29
122
|
onSelect(next.id);
|
|
30
|
-
strip.current
|
|
123
|
+
if (strip.current !== null)
|
|
124
|
+
tabOf(strip.current, next.id)?.focus();
|
|
31
125
|
};
|
|
32
126
|
return (_jsx("div", { "aria-label": label, className: pills ? 'page-tabs pills' : 'page-tabs', onKeyDown: onKeyDown, ref: strip, role: "tablist", children: tabs.map(({ id, label: name, icon: Icon }) => (_jsxs("button", { "aria-label": look === 'icons' ? name : undefined, "aria-selected": id === current, className: "page-tab", "data-page-tab": id, onClick: () => onSelect(id), role: "tab", tabIndex: id === focusable ? 0 : -1, type: "button", ...(look === 'icons' ? tooltip(name) : {}), children: [look !== 'text' && _jsx(Icon, { "aria-hidden": true, size: 13 }), look !== 'icons' && _jsx("span", { children: name })] }, id))) }));
|
|
33
127
|
}
|
package/dist/tabs/tabs.css
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* ---- Page tabs (PageTabs) ----
|
|
2
2
|
|
|
3
3
|
The level's pages as tabs under a path bar, the current one underlined
|
|
4
|
-
in the accent.
|
|
4
|
+
in the accent. A strip too narrow for its tabs scrolls sideways and
|
|
5
|
+
fades each edge that hides tabs (PageTabs sets data-overflow). */
|
|
5
6
|
.page-tabs {
|
|
6
7
|
flex: none;
|
|
7
8
|
display: flex;
|
|
@@ -15,6 +16,29 @@
|
|
|
15
16
|
scrollbar-width: none;
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
/* The fade is a mask, so it shows whatever lies under the strip; a mask
|
|
20
|
+
reads only alpha, and --text is opaque in every theme. Its 24px matches
|
|
21
|
+
EDGE_FADE in PageTabs.tsx, which scrolls the current tab clear of it. */
|
|
22
|
+
.page-tabs[data-overflow] {
|
|
23
|
+
--page-tabs-fade-start: 0px;
|
|
24
|
+
--page-tabs-fade-end: 0px;
|
|
25
|
+
mask-image: linear-gradient(
|
|
26
|
+
to right,
|
|
27
|
+
transparent,
|
|
28
|
+
var(--text) var(--page-tabs-fade-start),
|
|
29
|
+
var(--text) calc(100% - var(--page-tabs-fade-end)),
|
|
30
|
+
transparent
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.page-tabs[data-overflow~='start'] {
|
|
35
|
+
--page-tabs-fade-start: 24px;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.page-tabs[data-overflow~='end'] {
|
|
39
|
+
--page-tabs-fade-end: 24px;
|
|
40
|
+
}
|
|
41
|
+
|
|
18
42
|
.page-tab {
|
|
19
43
|
display: inline-flex;
|
|
20
44
|
align-items: center;
|
package/dist/themes/tokens.js
CHANGED
|
@@ -326,7 +326,8 @@ function rule(selector, tokens, depth = 0) {
|
|
|
326
326
|
* The custom properties `@bigpixelrocket/uiok/styles.css` declares or reads beside the theme
|
|
327
327
|
* tokens: the base sheet's on `:root`, and the hooks a component stylesheet
|
|
328
328
|
* declares or reads (the activity stripes' colour, a dialog's tone and
|
|
329
|
-
* pinned top, a date picker fraction field's digit count
|
|
329
|
+
* pinned top, a date picker fraction field's digit count, a tab strip's
|
|
330
|
+
* edge fades), which an app
|
|
330
331
|
* token on `:root` would otherwise reach.
|
|
331
332
|
*/
|
|
332
333
|
const BASE_TOKEN_NAMES = [
|
|
@@ -347,6 +348,8 @@ const BASE_TOKEN_NAMES = [
|
|
|
347
348
|
'--pane-row-inset',
|
|
348
349
|
'--pane-grid',
|
|
349
350
|
'--date-picker-digits',
|
|
351
|
+
'--page-tabs-fade-start',
|
|
352
|
+
'--page-tabs-fade-end',
|
|
350
353
|
'--warning-text'
|
|
351
354
|
];
|
|
352
355
|
/** Every token name uiok defines: the fixed tokens, those a theme sets, and the stylesheet's own. */
|