ab-nextjs-components 0.5.0 → 0.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/CHANGELOG.md +16 -1
- package/README.md +15 -2
- package/ab-code-block/focus.tsx +63 -0
- package/ab-code-block/index.tsx +54 -27
- package/ab-code-block/styles.module.css +3 -2
- package/ab-content-tabs/index.tsx +24 -2
- package/ab-demo-box/index.tsx +45 -7
- package/ab-demo-box/styles.module.css +19 -7
- package/ab-demo-code/index.tsx +38 -34
- package/ab-demo-code/styles.module.css +3 -41
- package/ab-drawer/index.tsx +9 -1
- package/ab-icon/builtin.ts +4 -0
- package/ab-preview-code/index.tsx +115 -0
- package/ab-preview-code/stage.tsx +153 -0
- package/ab-preview-code/styles.module.css +43 -0
- package/index.ts +12 -4
- package/package.json +3 -1
- package/types/index.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
|
+
## [0.6.0](https://github.com/abraham-ukachi/ab-nextjs-components/compare/v0.5.0...v0.6.0) (2026-11-04)
|
|
2
|
+
|
|
3
|
+
* ⚠️ **Breaking: `html` is now `trustedHtml`** on AbCodeBlock, AbDemoCode and AbPreviewCode. The string goes into `dangerouslySetInnerHTML` **without sanitizing**, so pass only HTML you render yourself (e.g. Shiki `codeToHtml`), never user input. Prefer `highlighted` / children. Rename the prop to upgrade.
|
|
4
|
+
* ⚠️ **Breaking (markup): code-block focus moved.** The focusable, named element is now the scroll wrapper (`[data-ab-part="code-block-code"]`, `role="group"`), not the `<pre>`. The old regex that patched `tabindex` / `aria-label` into the `<pre>` HTML (it broke on `>` inside attributes) is removed; it was internal, so no export changes.
|
|
5
|
+
* 🔐 **`warnAbRiskyHtml`:** a dev-only `console.warn` when `trustedHtml` contains `<script`, an `on…=` handler, `javascript:`, `<iframe` or `srcdoc`. Silent in production. It is not a sanitizer.
|
|
6
|
+
* ✨ **AbPreviewCode (server component):** a docs Preview / Code pair. AbContentTabs over an AbDemoBox preview and an AbDemoCode source block; both panels are in the server HTML. Nothing is parsed or evaluated from `code`.
|
|
7
|
+
* 🧰 **Preview toolbar (`AbPreviewStage`, a small client island):** a `role="toolbar"` with one tab stop (←/→/Home/End), a light/dark toggle (`aria-pressed`) for that preview only, a reload button that remounts the preview, and an open-in-new-tab link with `href` (`target="_blank" rel="noopener noreferrer"`). 44px targets; names via `labels.toolbar`, `labels.dark`, `labels.reload`, `labels.open`. New AbPreviewCode props: `toolbar` (default `true`) and `href`. Exported: `AbPreviewStage`, `AbPreviewStageProps`, `AbPreviewStageLabels`.
|
|
8
|
+
* 🧪 **AbDemoBox:** server-safe, with `scheme` (`'inherit' | 'light' | 'dark'`), a scoped `align` and an optional `label` (a named region).
|
|
9
|
+
* 🗄️ **Drawers inside the preview scope:** AbDrawer hosts its layer in the nearest `[data-ab-preview-scope]`, so a drawer demo stays inside its box. The selector is exported as `AB_PREVIEW_SCOPE_SELECTOR`.
|
|
10
|
+
* 💻 **AbDemoCode is built on AbCodeBlock:** escaped `<pre>`, SVG copy button, polite "Copied".
|
|
11
|
+
* 🔣 **Icons:** `refresh` and `open_in_new` (ab-nextjs-icons) join `AB_ICON_BUILTINS`.
|
|
12
|
+
* ⌨️ **One tab stop per code block:** the scroll wrapper is the stop, so arrow keys scroll long lines. A Shiki `<pre tabindex="0">` from children is dropped; inside a `trustedHtml` string it is set to `-1` after hydration (the string is never edited, so before hydration it is still a second stop).
|
|
13
|
+
* 📋 **Copy-button gutter:** the code scroller ends 48px short of the copy button, so long lines never run under it (390px phones too).
|
|
14
|
+
* ♿ **AbContentTabs:** a tabpanel is a tab stop only when it has no focusable content (checked after mount and on changes). The server render keeps `tabIndex 0` on every panel, so hydration matches. `AB_FOCUSABLE_SELECTOR` is exported.
|
|
15
|
+
|
|
1
16
|
## [0.5.0](https://github.com/abraham-ukachi/ab-nextjs-components/compare/v0.4.2...v0.5.0) (2026-11-04)
|
|
2
17
|
|
|
3
18
|
* ⚠️ **Heads-up (default change, not breaking):** AbSidebar and AbNavDrawer now light only the **deepest** matching item, so `/docs` no longer lights up alongside `/docs/x` on `/docs/x`. A parent still lights on routes that have no listed child (`/docs/y`). Pass `activeMatch="prefix"` for the old look.
|
|
4
19
|
* 🐛 **One active item in AbSidebar and AbNavDrawer:** new `activeMatch?: 'best' | 'prefix' | 'exact'` (default `'best'`) on both, plus a per-item `exact?: boolean` override (`true` = never a parent match, `false` = parent matching allowed under `'exact'`). Query strings, hashes and trailing slashes are ignored. AbNavDrawer also gets `locales`, and both share one helper.
|
|
5
20
|
* ✨ **Exports:** `getAbActiveHrefs`, `matchAbHref`, `normalizeAbHref`, `flattenAbNavItems`, and the types `AbActiveMatch`, `AbActiveMatchable` and `AbActiveMatchOptions`. `isAbSidebarActive` stays, and it now ignores query strings, hashes and trailing slashes too.
|
|
6
|
-
* 📝 **Neutral wording:** comments, test names, the README and this changelog no longer name reviewers. The AbProgressChips demo
|
|
21
|
+
* 📝 **Neutral wording:** comments, test names, the README and this changelog no longer name reviewers. The AbProgressChips demo data uses a neutral step name ("Simmer").
|
|
7
22
|
* ✅ **G59, stacked drawers and Escape (confirmed, regression test added):** with two drawers open, Escape closes only the topmost one, and focus returns to that drawer's trigger. A second Escape closes the next one. This works across scopes (app, main, aside). An Escape an inner widget already handled closes nothing. The shared open-drawer stack in `AbDrawer` already did this, so there is no runtime change.
|
|
8
23
|
|
|
9
24
|
## [0.4.2](https://github.com/abraham-ukachi/ab-nextjs-components/compare/v0.4.1...v0.4.2) (2026-11-04)
|
package/README.md
CHANGED
|
@@ -146,6 +146,18 @@ A drawer belongs to a **region**: the whole app, the main pane or the aside pane
|
|
|
146
146
|
* **`<AbMobileHeader>`** (logo · globe · theme toggle) needs **ab-nextjs-core ≥ 0.2.1** with `<AbAppLayout variant="panes" mobileHeader="main">`. Pass it as `mainHeader`; core hides the app header below 768px and makes the main header the 56px mobile bar.
|
|
147
147
|
* **Edge swipes (`useAbEdgeSwipe`, `AbNavDrawer`/`AbTocDrawer` `swipe`):** a touch starting in the 24px edge zone is read from touch events. A non-passive `touchmove` listener exists only while that touch is down, and it calls `preventDefault` only once the move is sideways, so Android Chrome can't cancel it for a pan. Vertical scrolling from the edge, sideways code blocks and `[data-ab-no-edge-swipe]` keep working. Checked on WebKit and Chromium touch emulation.
|
|
148
148
|
|
|
149
|
+
### Docs Preview / Code (0.6.0) 🧪💻
|
|
150
|
+
|
|
151
|
+
* **`<AbPreviewCode>` (G16, server component)**: a tabbed **Preview / Code** pair for MDX docs. The preview is the real JSX you pass as `children` (package components only). Nothing is parsed or evaluated from `code`: no `eval`, `new Function`, react-live or sandpack. Props: `code` (raw source, always what Copy copies), `trustedHtml` (Shiki `codeToHtml` output, injected **without sanitizing**: trusted HTML you render yourself only, never user input; dev builds warn on `<script`, `on…=`, `javascript:`, `<iframe`, `srcdoc`) or `highlighted` (an already highlighted `<pre>`, **the preferred route**), `language` (default `tsx`), `filename`, `label` (the tablist name, default "Example"), `labels` (`preview`, `code`, `copy`, `copied`), `defaultTab` (`'preview'` or `'code'`), `scheme` (`'inherit'`, `'light'` or `'dark'`), `align`, `toolbar` (default `true`), `href` and `className`. **0.6.0 preview toolbar** (`AbPreviewStage`, a small client island; AbPreviewCode stays a server component): a `role="toolbar"` with one tab stop (←/→/Home/End), a light/dark toggle (`aria-pressed` = dark) that changes only that preview's scheme, a reload button that remounts the preview, and, with `href`, an open-in-new-tab link (`target="_blank" rel="noopener noreferrer"`). Every tool is a 44px target; rename them with `labels.toolbar`, `labels.dark`, `labels.reload`, `labels.open`. Both panels are in the server HTML. The tabs are AbContentTabs (arrows, Home/End, one tab stop).
|
|
152
|
+
* **`<AbDemoBox>` is the preview scope** (now server-safe): `scheme` re-applies the theme's `[data-theme]` tokens with a matching `color-scheme`, `contain: layout paint` + `isolation: isolate` keep fixed and absolute children and z-indexes inside, and its own font, colour and surface stop page prose styles from leaking in (`ab-prose-none`). **AbDrawer layers inside a preview are hosted by the box** for every `scope` (`AB_PREVIEW_SCOPE_SELECTOR`), unless a layout scope sits inside the preview. `label` makes it a named region. No motion.
|
|
153
|
+
* **`<AbDemoCode>`** is built on AbCodeBlock (escaped `<pre>`, focusable and named, SVG copy button, polite "Copied"). **0.6.0:** one tab stop per block: the scroll wrapper is focusable and named, so arrow keys scroll long lines; a Shiki `<pre tabindex="0">` from children is dropped, and inside a `trustedHtml` string it is demoted to `-1` after hydration (the string is never edited, so before hydration it is still a second stop). The scroller ends 48px short of the copy button, so lines never run under it, even at 390px. It also takes `trustedHtml` (not sanitized: trusted HTML only, prefer a highlighted child), a highlighted child, `filename`, `copyLabel` and `copiedLabel`.
|
|
154
|
+
|
|
155
|
+
```mdx
|
|
156
|
+
<AbPreviewCode label="Button example" code={`<AbButton label="Save" />`}>
|
|
157
|
+
<AbButton label="Save" />
|
|
158
|
+
</AbPreviewCode>
|
|
159
|
+
```
|
|
160
|
+
|
|
149
161
|
## Getting Started
|
|
150
162
|
|
|
151
163
|
### Installation
|
|
@@ -209,8 +221,6 @@ A list of all the **client components** and their current status:
|
|
|
209
221
|
| 27 | *`AbText`* | **ab-text/index.tsx** | Done |
|
|
210
222
|
| 28 | *`AbProduct`* | **ab-product/index.tsx** | Done |
|
|
211
223
|
| 29 | *`AbProductItem`* | **ab-product-item/index.tsx** | Done |
|
|
212
|
-
| 30 | *`AbDemoBox`* | **ab-demo-box/index.tsx** | Done |
|
|
213
|
-
| 31 | *`AbDemoCode`* | **ab-demo-code/index.tsx** | Done |
|
|
214
224
|
|
|
215
225
|
## Server Components
|
|
216
226
|
|
|
@@ -230,6 +240,9 @@ A list of all the **server components** and their current status:
|
|
|
230
240
|
| 10 | *`AbSidebar`* | **server/ab-sidebar/index.tsx** | Done |
|
|
231
241
|
| 11 | *`AbNavLink`* | **server/ab-nav-link/index.tsx** | Done |
|
|
232
242
|
| 12 | *`AbText`* | **server/ab-text/index.tsx** | Done |
|
|
243
|
+
| 13 | *`AbDemoBox`* | **ab-demo-box/index.tsx** | Done (server-safe since 0.6.0) |
|
|
244
|
+
| 14 | *`AbDemoCode`* | **ab-demo-code/index.tsx** | Done (server-safe since 0.6.0) |
|
|
245
|
+
| 15 | *`AbPreviewCode`* | **ab-preview-code/index.tsx** | Done (0.6.0) |
|
|
233
246
|
|
|
234
247
|
|
|
235
248
|
## Learn More abElements
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license MIT
|
|
3
|
+
* ~~~~~~~~~~~~
|
|
4
|
+
* ab-nextjs-components
|
|
5
|
+
* ~~~~~~~~~~~~
|
|
6
|
+
* Copyright (c) 2026 Abraham Ukachi. The abElements Project.
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the 'Software'), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* @project: ab-nextjs-components
|
|
27
|
+
* @name: AbCodeBlockFocus (0.6.0)
|
|
28
|
+
* @file: ab-code-block/focus.tsx
|
|
29
|
+
* @type: Client component (island)
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
35
|
+
* MOTTO: We'll always do more 😜!!!
|
|
36
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
'use client';
|
|
40
|
+
|
|
41
|
+
// ⚛️ React
|
|
42
|
+
import { useEffect, useRef, type ReactElement } from 'react';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* ⌨️ AbCodeBlockFocus — keeps ONE tab stop in a `trustedHtml` block. Shiki's string carries
|
|
46
|
+
* `<pre tabindex="0">`; we never edit that string, so after hydration this island sets the inner <pre>'s
|
|
47
|
+
* tabindex to -1 in the DOM (the wrapper scroller stays the stop). Before hydration / without JS the
|
|
48
|
+
* leftover tabindex remains (a harmless second stop); pass `highlighted` / children to avoid it entirely.
|
|
49
|
+
*/
|
|
50
|
+
const AbCodeBlockFocus = (): ReactElement => {
|
|
51
|
+
const ref = useRef<HTMLSpanElement>(null); // 📍 to find our block
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const block = ref.current?.closest('[data-ab-part="code-block"]'); // 🧱 our AbCodeBlock
|
|
54
|
+
block?.querySelectorAll<HTMLElement>('[data-ab-part="code-block-code"] pre[tabindex]').forEach((pre) => {
|
|
55
|
+
if (pre.tabIndex >= 0) pre.setAttribute('tabindex', '-1'); // ✂️ demote Shiki's stop (string untouched)
|
|
56
|
+
});
|
|
57
|
+
}); // 🔁 every render: a new trustedHtml string brings a new <pre>
|
|
58
|
+
return <span ref={ref} hidden data-ab-part="code-block-focus" />; // 🫥 an invisible anchor
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// 📦 exports
|
|
62
|
+
export default AbCodeBlockFocus;
|
|
63
|
+
export { AbCodeBlockFocus };
|
package/ab-code-block/index.tsx
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
31
|
*
|
|
32
32
|
* Example usage:
|
|
33
|
-
* 1+|> <AbCodeBlock filename="app/page.tsx" language="tsx" code={source}
|
|
33
|
+
* 1+|> <AbCodeBlock filename="app/page.tsx" language="tsx" code={source} trustedHtml={await codeToHtml(source, …)} />
|
|
34
34
|
* 2+|> <AbCodeBlock language="bash" copyLabel={t('copy')} copiedLabel={t('copied')}><pre><code>pnpm add ab-nextjs-components</code></pre></AbCodeBlock>
|
|
35
35
|
*/
|
|
36
36
|
|
|
@@ -46,40 +46,52 @@ import { Children, cloneElement, isValidElement, type ReactElement, type ReactNo
|
|
|
46
46
|
import clsx from 'clsx';
|
|
47
47
|
// 📋 the copy button (the only client part)
|
|
48
48
|
import AbCodeBlockCopy from './copy';
|
|
49
|
+
// ⌨️ 0.6.0: demotes Shiki's <pre tabindex="0"> inside a trustedHtml block after hydration (one tab stop)
|
|
50
|
+
import AbCodeBlockFocus from './focus';
|
|
49
51
|
// 🎨 styles
|
|
50
52
|
import styles from './styles.module.css';
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
/**
|
|
55
|
+
* 🚨 risky patterns in a `trustedHtml` string (dev warning only, NOT a sanitizer):
|
|
56
|
+
* <script, an on…= event handler, javascript:, <iframe, srcdoc
|
|
57
|
+
*/
|
|
58
|
+
const AB_RISKY_HTML: ReadonlyArray<[string, RegExp]> = [
|
|
59
|
+
['<script', /<script\b/i], // 📜 inline script
|
|
60
|
+
['on…= handler', /\son[a-z]+\s*=/i], // 🖱️ onclick=, onerror=, …
|
|
61
|
+
['javascript:', /javascript\s*:/i], // 🔗 script URL
|
|
62
|
+
['<iframe', /<iframe\b/i], // 🪟 embedded frame
|
|
63
|
+
['srcdoc', /\bsrcdoc\b/i], // 📄 inline frame document
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
/** ⚠️ dev only: warn when `trustedHtml` looks like it carries script (silent in production) */
|
|
67
|
+
export function warnAbRiskyHtml(html: string, where = 'AbCodeBlock'): void {
|
|
68
|
+
if (process.env.NODE_ENV === 'production') return; // 🤫 never in production
|
|
69
|
+
const hits = AB_RISKY_HTML.filter(([, re]) => re.test(html)).map(([n]) => n); // 🔎
|
|
70
|
+
if (hits.length) console.warn(`[${where}] trustedHtml contains ${hits.join(', ')}. It is injected without sanitizing: only pass HTML you render yourself (e.g. Shiki), never user input. Prefer \`highlighted\`/children.`); // ⚠️
|
|
71
|
+
}
|
|
54
72
|
|
|
55
73
|
/**
|
|
56
|
-
* ⌨️ 0.
|
|
57
|
-
*
|
|
74
|
+
* ⌨️ 0.6.0: ONE tab stop per block. The wrapper (`code-block-code`) is the horizontal scroller and the focus
|
|
75
|
+
* target (arrow keys scroll long lines), so a direct <pre> child loses an auto/Shiki `tabIndex={0}` (it would be
|
|
76
|
+
* a second stop). An author's explicit negative tabIndex and any aria-label on the <pre> are kept.
|
|
58
77
|
*/
|
|
59
|
-
function
|
|
78
|
+
function withAbSingleStopPre(children: ReactNode): ReactNode {
|
|
60
79
|
return Children.map(children, (c) => {
|
|
61
80
|
if (!isValidElement<Record<string, unknown>>(c) || c.type !== 'pre') return c; // 🙅 only a direct <pre>
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
return Object.keys(extra).length ? cloneElement(c, extra) : c; // ✅
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** 🧾 the same for an `html` string: patch the FIRST <pre …> tag only */
|
|
70
|
-
function withAbFocusablePreHtml(html: string, name?: string): string {
|
|
71
|
-
return html.replace(/<pre\b([^>]*)>/i, (tag, attrs: string) => {
|
|
72
|
-
let a = attrs; // 🧩
|
|
73
|
-
if (!/\stabindex\s*=/i.test(a)) a += ' tabindex="0"'; // ⌨️ Shiki already has one → untouched
|
|
74
|
-
if (name && !/\saria-label(ledby)?\s*=/i.test(a)) a += ` aria-label="${escAttr(name)}"`; // 🏷️
|
|
75
|
-
return `<pre${a}>`; // ✅
|
|
81
|
+
const t = c.props.tabIndex ?? c.props.tabindex; // 🔎 Shiki sets 0
|
|
82
|
+
if (t == null || Number(t) < 0) return c; // ✅ nothing to drop (or an author's -1)
|
|
83
|
+
return cloneElement(c, { tabIndex: undefined, tabindex: undefined }); // ✂️ the wrapper is the stop now
|
|
76
84
|
});
|
|
77
85
|
}
|
|
78
86
|
|
|
79
87
|
/** ⚙️ props */
|
|
80
88
|
export interface AbCodeBlockProps {
|
|
81
89
|
children?: ReactNode; // 🖍️ Shiki-rendered (or plain) <pre><code>…</code></pre>, e.g. from rehype-pretty-code in MDX
|
|
82
|
-
|
|
90
|
+
/**
|
|
91
|
+
* 🧾 OR a pre-rendered HTML string (Shiki `codeToHtml`). ⚠️ Injected via dangerouslySetInnerHTML WITHOUT
|
|
92
|
+
* sanitizing: it MUST be trusted (you render it at build/server time), never user input. Prefer children.
|
|
93
|
+
*/
|
|
94
|
+
trustedHtml?: string;
|
|
83
95
|
code?: string; // 📋 the raw source to copy (best). Without it the button copies the rendered <pre>'s text
|
|
84
96
|
title?: ReactNode; // 🏷️ a caption in the header bar (e.g. "Install")
|
|
85
97
|
filename?: string; // 📄 a file name in the header bar (mono), e.g. "app/page.tsx"
|
|
@@ -92,15 +104,16 @@ export interface AbCodeBlockProps {
|
|
|
92
104
|
|
|
93
105
|
/**
|
|
94
106
|
* 💻 AbCodeBlock — a server-rendered code block for MDX docs: an optional header (title / filename · language),
|
|
95
|
-
* the highlighted code (children or
|
|
107
|
+
* the highlighted code (children or a `trustedHtml` string, both from Shiki), and a small client copy button. It is a
|
|
96
108
|
* <figure> (with a <figcaption> when there is a header), so the caption names the code for assistive tech; the
|
|
97
|
-
*
|
|
109
|
+
* scroller wrapper is the single focusable, named tab stop, so keyboard users can scroll long lines with the arrows.
|
|
98
110
|
*/
|
|
99
|
-
const AbCodeBlock = ({ children,
|
|
111
|
+
const AbCodeBlock = ({ children, trustedHtml, code, title, filename, language, copyLabel = 'Copy code', copiedLabel = 'Copied', copy = true, className }: AbCodeBlockProps): ReactElement => {
|
|
100
112
|
const hasHeader = title != null || !!filename || !!language; // 🏷️ a header bar?
|
|
101
113
|
const caption = (title ?? filename) != null; // 💬 a visible name for the figure
|
|
102
114
|
// 🏷️ the scroller's name: the title (if text), else the filename, else "<language> code"
|
|
103
115
|
const preName = typeof title === 'string' ? title : filename || (language ? `${language} code` : undefined);
|
|
116
|
+
if (trustedHtml != null) warnAbRiskyHtml(trustedHtml); // ⚠️ dev-only check
|
|
104
117
|
return (
|
|
105
118
|
<figure
|
|
106
119
|
className={clsx('AbCodeBlock', 'ab-prose-none', styles.abCodeBlock, className)} // 🎨 (opts out of theme .ab-prose)
|
|
@@ -116,9 +129,23 @@ const AbCodeBlock = ({ children, html, code, title, filename, language, copyLabe
|
|
|
116
129
|
</figcaption>
|
|
117
130
|
)}
|
|
118
131
|
<div className={styles.abCodeBlockBody}>
|
|
119
|
-
{
|
|
120
|
-
? <div
|
|
121
|
-
|
|
132
|
+
{trustedHtml != null
|
|
133
|
+
? <div
|
|
134
|
+
className={styles.abCodeBlockCode} // ↔️ 0.6.0: the scroller (the inner <pre> is overflow: visible)
|
|
135
|
+
data-ab-part="code-block-code"
|
|
136
|
+
tabIndex={0} // ⌨️ the ONE tab stop: arrow keys scroll long lines (no regex patching of the HTML)
|
|
137
|
+
role="group" // ♿ a named, focusable group (aria-label needs a role)
|
|
138
|
+
aria-label={preName} // 🏷️
|
|
139
|
+
dangerouslySetInnerHTML={{ __html: trustedHtml }} // 🧾 trusted Shiki string, injected as-is
|
|
140
|
+
/>
|
|
141
|
+
: <div
|
|
142
|
+
className={styles.abCodeBlockCode} // ↔️ the scroller
|
|
143
|
+
data-ab-part="code-block-code"
|
|
144
|
+
tabIndex={0} // ⌨️ the ONE tab stop
|
|
145
|
+
role="group" // ♿
|
|
146
|
+
aria-label={preName} // 🏷️
|
|
147
|
+
>{withAbSingleStopPre(children) /* 🖍️ Shiki children, minus their own tab stop */}</div>}
|
|
148
|
+
{trustedHtml != null && <AbCodeBlockFocus /> /* ⌨️ client island: Shiki's leftover <pre tabindex> → -1 */}
|
|
122
149
|
{copy && <AbCodeBlockCopy code={code} label={copyLabel} copiedLabel={copiedLabel} /> /* 📋 client island */}
|
|
123
150
|
</div>
|
|
124
151
|
</figure>
|
|
@@ -53,8 +53,9 @@
|
|
|
53
53
|
.abCodeBlockLang { margin-inline-start: auto; padding: 2px 6px; border-radius: 4px; background: rgb(255 255 255 / 0.08); font: 600 11px/1 var(--ab-font-code, ui-monospace, monospace); text-transform: lowercase; } /* 🔤 badge */
|
|
54
54
|
/* 🧱 body: the code + the copy button in its top-end corner */
|
|
55
55
|
.abCodeBlockBody { position: relative; } /* 📌 */
|
|
56
|
-
.abCodeBlockCode :
|
|
57
|
-
.abCodeBlockCode
|
|
56
|
+
.abCodeBlockCode { overflow-x: auto; margin-inline-end: 48px; } /* ↔️ 0.6.0: the WRAPPER is the scroller + the one tab stop; 📋 its end stops 48px short, so long lines (390px phones too) never scroll UNDER the 44px copy button */
|
|
57
|
+
.abCodeBlockCode:focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: -2px; } /* ♿ */
|
|
58
|
+
.abCodeBlockCode :where(pre) { margin: 0; padding: 14px 8px 14px 16px; overflow: visible; inline-size: max-content; min-inline-size: 100%; box-sizing: border-box; background: transparent !important; font: 13.5px/1.6 var(--ab-font-code, ui-monospace, monospace); } /* 📜 (end room comes from the scroller's gutter) grows with its longest line, the wrapper scrolls it; Shiki's inline bg yields to ours */
|
|
58
59
|
.abCodeBlockCode :where(code) { font: inherit; } /* 🔤 */
|
|
59
60
|
.abCodeBlockCopy { position: absolute; inset-block-start: 4px; inset-inline-end: 4px; color: inherit; } /* 📋 44px button (AbIconButton) */
|
|
60
61
|
.srOnly { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } /* 🕶️ */
|
|
@@ -43,12 +43,18 @@
|
|
|
43
43
|
'use client';
|
|
44
44
|
|
|
45
45
|
// ⚛️ React
|
|
46
|
-
import { Children, isValidElement, useId, useRef, useState, type KeyboardEvent, type ReactElement, type ReactNode } from 'react';
|
|
46
|
+
import { Children, isValidElement, useEffect, useId, useRef, useState, type KeyboardEvent, type ReactElement, type ReactNode } from 'react';
|
|
47
47
|
// 🧵 classes
|
|
48
48
|
import clsx from 'clsx';
|
|
49
49
|
// 🎨 styles
|
|
50
50
|
import styles from './styles.module.css';
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* ⌨️ 0.6.0: what counts as "already focusable" inside a panel. A panel that holds one of these is left OUT of
|
|
54
|
+
* the tab order (its content is the stop, e.g. a code block's scroller); an empty / text-only panel stays tabIndex 0.
|
|
55
|
+
*/
|
|
56
|
+
export const AB_FOCUSABLE_SELECTOR = 'a[href], button, input, select, textarea, [tabindex]:not([tabindex="-1"]), [contenteditable]:not([contenteditable="false"]), summary';
|
|
57
|
+
|
|
52
58
|
/** ⚙️ one tab (a marker element: AbContentTabs reads its props, it renders only its children) */
|
|
53
59
|
export interface AbContentTabProps {
|
|
54
60
|
label: ReactNode; // 🏷️ the tab's text, e.g. "pnpm"
|
|
@@ -85,6 +91,21 @@ const AbContentTabs = ({ children, label, defaultValue, onChange, className }: A
|
|
|
85
91
|
const [selected, setSelected] = useState(() => (defaultValue && values.includes(defaultValue) ? defaultValue : values[0])); // 🎯
|
|
86
92
|
const current = values.includes(selected) ? selected : values[0]; // 🛟 children changed
|
|
87
93
|
const refs = useRef<Array<HTMLButtonElement | null>>([]); // 📍 to move focus
|
|
94
|
+
const panels = useRef<Array<HTMLDivElement | null>>([]); // 📍 the tabpanels (focusable-content check)
|
|
95
|
+
// ⌨️ 0.6.0: which panels already contain a focusable element. SSR + the first client render say "none"
|
|
96
|
+
// (every panel tabIndex 0, the APG-safe no-JS default), so hydration matches; the effect then refines it.
|
|
97
|
+
const [hasFocusable, setHasFocusable] = useState<boolean[]>([]);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
const check = () => {
|
|
100
|
+
const next = panels.current.slice(0, tabs.length).map((el) => !!el?.querySelector(AB_FOCUSABLE_SELECTOR)); // 🔎
|
|
101
|
+
setHasFocusable((prev) => (prev.length === next.length && prev.every((v, k) => v === next[k]) ? prev : next)); // 🧘 no-op when unchanged
|
|
102
|
+
};
|
|
103
|
+
check(); // 🚀 after mount
|
|
104
|
+
if (typeof MutationObserver === 'undefined') return; // 🛟 very old engines: the mount check only
|
|
105
|
+
const mo = new MutationObserver(check); // 👀 content changes (MDX, islands, hydration fixes)
|
|
106
|
+
panels.current.forEach((el) => el && mo.observe(el, { childList: true, subtree: true, attributes: true, attributeFilter: ['tabindex', 'href', 'contenteditable', 'disabled'] }));
|
|
107
|
+
return () => mo.disconnect(); // 🧹
|
|
108
|
+
}, [tabs.length]);
|
|
88
109
|
const select = (v: string) => { setSelected(v); onChange?.(v); }; // ✅
|
|
89
110
|
// ⌨️ roving keys on the tablist
|
|
90
111
|
const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
|
|
@@ -128,7 +149,8 @@ const AbContentTabs = ({ children, label, defaultValue, onChange, className }: A
|
|
|
128
149
|
id={`${id}-panel-${i}`} // 🆔
|
|
129
150
|
aria-labelledby={`${id}-tab-${i}`} // 🔗
|
|
130
151
|
hidden={values[i] !== current} // 🙈 inactive
|
|
131
|
-
|
|
152
|
+
ref={(el) => { panels.current[i] = el; }} // 📍
|
|
153
|
+
tabIndex={hasFocusable[i] ? undefined : 0} // ⌨️ 0.6.0 (APG): a stop ONLY when nothing inside is focusable
|
|
132
154
|
className={styles.abContentTabsPanel} // 🎨
|
|
133
155
|
data-ab-part="content-tab-panel" // 🗂️
|
|
134
156
|
>
|
package/ab-demo-box/index.tsx
CHANGED
|
@@ -6,34 +6,72 @@
|
|
|
6
6
|
* Copyright (c) 2026 Abraham Ukachi. The abElements Project.
|
|
7
7
|
*
|
|
8
8
|
* @project: ab-nextjs-components
|
|
9
|
-
* @name: AbDemoBox
|
|
9
|
+
* @name: AbDemoBox (port of lyd-demo-box; 0.6.0: the G16 preview scope)
|
|
10
10
|
* @file: ab-demo-box/index.tsx
|
|
11
|
+
* @type: Server-safe component (no 'use client', no hooks)
|
|
11
12
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
13
|
+
*
|
|
14
|
+
* Example usage:
|
|
15
|
+
* 1+|> <AbDemoBox label="Button preview" scheme="dark"><AbButton label="Save" /></AbDemoBox>
|
|
12
16
|
*/
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
/*
|
|
19
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
20
|
+
* MOTTO: We'll always do more 😜!!!
|
|
21
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
22
|
+
*/
|
|
15
23
|
|
|
24
|
+
// ⚛️ React (forwardRef works in server components too)
|
|
16
25
|
import type { ReactElement, ReactNode } from 'react';
|
|
17
26
|
import { forwardRef } from 'react';
|
|
27
|
+
// 🧵 classes
|
|
18
28
|
import clsx from 'clsx';
|
|
29
|
+
// 🎨 styles
|
|
19
30
|
import styles from './styles.module.css';
|
|
20
31
|
|
|
32
|
+
/** 🌗 the preview's colour scheme: follow the page, or force one (theme `[data-theme]` tokens re-apply inside) */
|
|
33
|
+
export type AbDemoBoxScheme = 'inherit' | 'light' | 'dark';
|
|
34
|
+
|
|
35
|
+
/** ⚙️ props */
|
|
21
36
|
export interface AbDemoBoxProps {
|
|
22
|
-
className?: string;
|
|
23
|
-
hidden?: boolean;
|
|
24
|
-
children?: ReactNode;
|
|
37
|
+
className?: string; // 🏷️
|
|
38
|
+
hidden?: boolean; // 🙈
|
|
39
|
+
children?: ReactNode; // 🧪 the live preview: real JSX (package components), never eval'd strings
|
|
40
|
+
label?: string; // ♿ 0.6.0: names the preview as a region, e.g. "AbButton preview" (no role without it)
|
|
41
|
+
scheme?: AbDemoBoxScheme; // 🌗 0.6.0: default 'inherit'
|
|
42
|
+
align?: 'center' | 'start' | 'stretch'; // 📐 0.6.0: how the content sits in the box (default 'center')
|
|
25
43
|
}
|
|
26
44
|
|
|
45
|
+
/**
|
|
46
|
+
* 🧪 AbDemoBox — the G16 **preview scope**: an isolated surface for a live component preview.
|
|
47
|
+
*
|
|
48
|
+
* - 🌗 `scheme` forces light / dark through the theme's `[data-theme]` tokens, with matching `color-scheme`.
|
|
49
|
+
* - 📦 `contain: layout paint` + `isolation: isolate`: fixed / absolute children (balloons, drawers) are positioned
|
|
50
|
+
* and clipped by the box, and z-indexes can't climb over the page. AbDrawer hosts its layer here (any scope).
|
|
51
|
+
* - 🧱 its own text + background from the theme tokens, so the page's prose styles don't leak in (`ab-prose-none`).
|
|
52
|
+
* - ♿ with `label` it is a named `role="region"`. No motion (all motion lives in ab-nextjs-animations).
|
|
53
|
+
*/
|
|
27
54
|
const AbDemoBox = forwardRef<HTMLDivElement, AbDemoBoxProps>(function AbDemoBox(
|
|
28
|
-
{ className, hidden = false, children },
|
|
55
|
+
{ className, hidden = false, children, label, scheme = 'inherit', align = 'center' },
|
|
29
56
|
ref,
|
|
30
57
|
): ReactElement {
|
|
31
58
|
return (
|
|
32
|
-
<div
|
|
59
|
+
<div
|
|
60
|
+
ref={ref}
|
|
61
|
+
hidden={hidden}
|
|
62
|
+
className={clsx('AbDemoBox', 'ab-prose-none', styles.abDemoBox, className)} // 🎨 + opt out of theme prose
|
|
63
|
+
data-ab-part="demo-box" // 🗂️
|
|
64
|
+
data-ab-preview-scope="" // 📦 drawers + portals inside stay inside (AbDrawer reads it)
|
|
65
|
+
data-theme={scheme === 'inherit' ? undefined : scheme} // 🌗 theme tokens re-declared on this box
|
|
66
|
+
data-align={align === 'center' ? undefined : align} // 📐
|
|
67
|
+
role={label ? 'region' : undefined} // ♿ a landmark only when it has a name
|
|
68
|
+
aria-label={label} // 🏷️
|
|
69
|
+
>
|
|
33
70
|
{children}
|
|
34
71
|
</div>
|
|
35
72
|
);
|
|
36
73
|
});
|
|
37
74
|
|
|
75
|
+
// 📦 exports
|
|
38
76
|
export default AbDemoBox;
|
|
39
77
|
export { AbDemoBox };
|
|
@@ -30,16 +30,28 @@
|
|
|
30
30
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
+
/* 🧪 0.6.0 (G16): the preview scope. Theme tokens first, the old M3 names as fallbacks */
|
|
33
34
|
.abDemoBox {
|
|
34
|
-
position: relative;
|
|
35
|
+
position: relative; /* 📌 the drawer layer + absolute children anchor here */
|
|
36
|
+
contain: layout paint; /* 📦 a containing block for position: fixed too, and clips paint to the box */
|
|
37
|
+
isolation: isolate; /* 🥞 z-indexes stay inside */
|
|
35
38
|
display: flex;
|
|
36
39
|
flex-direction: column;
|
|
40
|
+
align-items: center; /* 📐 default: centred */
|
|
41
|
+
justify-content: center;
|
|
37
42
|
gap: 1rem;
|
|
43
|
+
min-block-size: 160px; /* 📏 room for a drawer / menu demo */
|
|
38
44
|
padding: 1.25rem;
|
|
39
|
-
border-radius:
|
|
40
|
-
border: 1px solid color-mix(in srgb, currentColor 12%, transparent);
|
|
41
|
-
background:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
border-radius: var(--ab-radius-code, 12px); /* 🟢 same corner as AbCodeBlock */
|
|
46
|
+
border: 1px solid var(--ab-color-border, color-mix(in srgb, currentColor 12%, transparent)); /* 🔲 */
|
|
47
|
+
background: var(--ab-color-card, var(--ab-surface, #fff)); /* 🃏 its own surface */
|
|
48
|
+
color: var(--ab-color-on-background, var(--ab-color-on-surface, inherit)); /* 🖋️ its own text colour */
|
|
49
|
+
font-family: var(--ab-font-body, system-ui, sans-serif); /* 🔤 the page's prose font size doesn't leak in */
|
|
50
|
+
font-size: 1rem;
|
|
51
|
+
line-height: 1.5;
|
|
52
|
+
overflow: hidden; /* ✂️ */
|
|
45
53
|
}
|
|
54
|
+
.abDemoBox[data-theme='light'] { color-scheme: light; } /* 🌞 native UI follows (also without the theme) */
|
|
55
|
+
.abDemoBox[data-theme='dark'] { color-scheme: dark; } /* 🌙 */
|
|
56
|
+
.abDemoBox[data-align='start'] { align-items: flex-start; justify-content: flex-start; } /* 📐 */
|
|
57
|
+
.abDemoBox[data-align='stretch'] { align-items: stretch; justify-content: flex-start; } /* 📐 */
|
package/ab-demo-code/index.tsx
CHANGED
|
@@ -6,58 +6,62 @@
|
|
|
6
6
|
* Copyright (c) 2026 Abraham Ukachi. The abElements Project.
|
|
7
7
|
*
|
|
8
8
|
* @project: ab-nextjs-components
|
|
9
|
-
* @name: AbDemoCode
|
|
9
|
+
* @name: AbDemoCode (port of lyd-demo-code; 0.6.0: built on AbCodeBlock)
|
|
10
10
|
* @file: ab-demo-code/index.tsx
|
|
11
|
+
* @type: Server-safe component (the copy button is AbCodeBlock's client island)
|
|
11
12
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
13
|
+
*
|
|
14
|
+
* Example usage:
|
|
15
|
+
* 1+|> <AbDemoCode language="tsx" code={`<AbButton label="Save" />`} />
|
|
12
16
|
*/
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
/*
|
|
19
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
20
|
+
* MOTTO: We'll always do more 😜!!!
|
|
21
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
22
|
+
*/
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
import {
|
|
24
|
+
// ⚛️ React
|
|
25
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
26
|
+
import { forwardRef } from 'react';
|
|
27
|
+
// 🧵 classes
|
|
18
28
|
import clsx from 'clsx';
|
|
29
|
+
// 💻 the docs code block (header, focusable <pre>, AbIcon copy button with a polite "Copied")
|
|
30
|
+
import AbCodeBlock from '../ab-code-block';
|
|
31
|
+
// 🎨 styles
|
|
19
32
|
import styles from './styles.module.css';
|
|
20
33
|
|
|
34
|
+
/** ⚙️ props (the 0.1.x shape, plus the AbCodeBlock options a preview pair needs) */
|
|
21
35
|
export interface AbDemoCodeProps {
|
|
22
|
-
className?: string;
|
|
23
|
-
hidden?: boolean;
|
|
24
|
-
language?: 'tsx' | 'css' | 'ts' | 'js' | string;
|
|
25
|
-
code: string;
|
|
36
|
+
className?: string; // 🏷️
|
|
37
|
+
hidden?: boolean; // 🙈
|
|
38
|
+
language?: 'tsx' | 'css' | 'ts' | 'js' | string; // 🔤 default 'tsx'
|
|
39
|
+
code: string; // 📋 the raw source (shown when there is no `trustedHtml` / `children`, always what Copy copies)
|
|
40
|
+
trustedHtml?: string; // 🧾 0.6.0: Shiki `codeToHtml` output, ⚠️ NOT sanitized: trusted HTML only, never user input (prefer children)
|
|
41
|
+
children?: ReactNode; // 🖍️ 0.6.0: OR an already highlighted <pre> (e.g. an MDX fenced block)
|
|
42
|
+
filename?: string; // 📄 0.6.0
|
|
43
|
+
copyLabel?: string; // ♿ 0.6.0 (default "Copy code")
|
|
44
|
+
copiedLabel?: string; // ✅ 0.6.0 (default "Copied")
|
|
26
45
|
}
|
|
27
46
|
|
|
47
|
+
/**
|
|
48
|
+
* 💻 AbDemoCode — the source half of a preview pair. Since 0.6.0 it is an AbCodeBlock, so it shares the
|
|
49
|
+
* highlighted rendering, the named + focusable <pre> and the SVG copy button (no icon font, no local timer).
|
|
50
|
+
* The plain fallback is a <pre><code> of `code` (React escapes it; nothing is ever evaluated).
|
|
51
|
+
*/
|
|
28
52
|
const AbDemoCode = forwardRef<HTMLDivElement, AbDemoCodeProps>(function AbDemoCode(
|
|
29
|
-
{ className, hidden = false, language = 'tsx', code },
|
|
53
|
+
{ className, hidden = false, language = 'tsx', code, trustedHtml, children, filename, copyLabel, copiedLabel },
|
|
30
54
|
ref,
|
|
31
55
|
): ReactElement {
|
|
32
|
-
const [copied, setCopied] = useState(false);
|
|
33
|
-
|
|
34
|
-
const copy = async () => {
|
|
35
|
-
try {
|
|
36
|
-
await navigator.clipboard.writeText(code);
|
|
37
|
-
setCopied(true);
|
|
38
|
-
window.setTimeout(() => setCopied(false), 1500);
|
|
39
|
-
} catch {
|
|
40
|
-
setCopied(false);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
56
|
return (
|
|
45
|
-
<div ref={ref} hidden={hidden} className={clsx('AbDemoCode', styles.abDemoCode, className)}>
|
|
46
|
-
<
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
<span className="material-symbols-rounded" aria-hidden style={{ fontSize: 16 }}>
|
|
50
|
-
{copied ? 'check' : 'content_copy'}
|
|
51
|
-
</span>
|
|
52
|
-
{copied ? 'Copied' : 'Copy'}
|
|
53
|
-
</button>
|
|
54
|
-
</div>
|
|
55
|
-
<pre className={styles.abDemoCodePre}>
|
|
56
|
-
<code className={styles.abDemoCodeCode}>{code}</code>
|
|
57
|
-
</pre>
|
|
57
|
+
<div ref={ref} hidden={hidden} className={clsx('AbDemoCode', styles.abDemoCode, className)} data-ab-part="demo-code">
|
|
58
|
+
<AbCodeBlock code={code} trustedHtml={trustedHtml} language={language} filename={filename} copyLabel={copyLabel} copiedLabel={copiedLabel}>
|
|
59
|
+
{children ?? <pre><code>{code}</code></pre> /* 🧾 plain, escaped */}
|
|
60
|
+
</AbCodeBlock>
|
|
58
61
|
</div>
|
|
59
62
|
);
|
|
60
63
|
});
|
|
61
64
|
|
|
65
|
+
// 📦 exports
|
|
62
66
|
export default AbDemoCode;
|
|
63
67
|
export { AbDemoCode };
|
|
@@ -30,44 +30,6 @@
|
|
|
30
30
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
overflow: hidden;
|
|
37
|
-
background: #1e1e2e;
|
|
38
|
-
color: #cdd6f4;
|
|
39
|
-
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
40
|
-
font-size: 0.8125rem;
|
|
41
|
-
line-height: 1.5;
|
|
42
|
-
}
|
|
43
|
-
.abDemoCodeHeader {
|
|
44
|
-
display: flex;
|
|
45
|
-
align-items: center;
|
|
46
|
-
justify-content: space-between;
|
|
47
|
-
gap: 0.5rem;
|
|
48
|
-
padding: 0.4rem 0.75rem;
|
|
49
|
-
background: color-mix(in srgb, #000 25%, transparent);
|
|
50
|
-
font-size: 0.7rem;
|
|
51
|
-
text-transform: uppercase;
|
|
52
|
-
letter-spacing: 0.06em;
|
|
53
|
-
opacity: 0.85;
|
|
54
|
-
}
|
|
55
|
-
.abDemoCodeCopy {
|
|
56
|
-
border: none;
|
|
57
|
-
background: transparent;
|
|
58
|
-
color: inherit;
|
|
59
|
-
cursor: pointer;
|
|
60
|
-
display: inline-flex;
|
|
61
|
-
align-items: center;
|
|
62
|
-
gap: 0.25rem;
|
|
63
|
-
font: inherit;
|
|
64
|
-
opacity: 0.8;
|
|
65
|
-
}
|
|
66
|
-
.abDemoCodeCopy:hover { opacity: 1; }
|
|
67
|
-
.abDemoCodePre {
|
|
68
|
-
margin: 0;
|
|
69
|
-
padding: 0.85rem 1rem 1rem;
|
|
70
|
-
overflow: auto;
|
|
71
|
-
max-height: 24rem;
|
|
72
|
-
}
|
|
73
|
-
.abDemoCodeCode { white-space: pre; }
|
|
33
|
+
/* 💻 0.6.0: AbCodeBlock draws the block; this wrapper only drops its bottom margin inside a preview pair */
|
|
34
|
+
.abDemoCode { min-inline-size: 0; } /* ↔️ long lines scroll in the <pre>, never widen the page */
|
|
35
|
+
.abDemoCode > :global(.AbCodeBlock) { margin: 0; } /* ↕️ */
|
package/ab-drawer/index.tsx
CHANGED
|
@@ -122,9 +122,17 @@ const SCOPE_SELECTOR: Record<AbDrawerScope, string> = {
|
|
|
122
122
|
*/
|
|
123
123
|
export function getAbDrawerHost(scope: AbDrawerScope, from?: Element | null): HTMLElement {
|
|
124
124
|
const sel = SCOPE_SELECTOR[scope]; // 🔎
|
|
125
|
-
|
|
125
|
+
const own = from?.closest<HTMLElement>(sel) ?? null; // 🎯 the nearest scope box around the drawer
|
|
126
|
+
// 🧪 0.6.0 (G16): inside a docs preview (AbDemoBox / AbPreviewCode) the preview box is the app: a drawer never
|
|
127
|
+
// escapes to the real page layout. A scope box that is itself INSIDE the preview (a layout demo) still wins.
|
|
128
|
+
const preview = from?.closest<HTMLElement>(AB_PREVIEW_SCOPE_SELECTOR) ?? null;
|
|
129
|
+
if (preview && (!own || !preview.contains(own))) return preview; // 📦 clipped by the preview
|
|
130
|
+
return own ?? document.querySelector<HTMLElement>(sel) ?? document.body; // 🎯
|
|
126
131
|
}
|
|
127
132
|
|
|
133
|
+
/** 🧪 0.6.0 (G16): the attribute that marks a preview scope (AbDemoBox sets it); drawers inside stay inside */
|
|
134
|
+
export const AB_PREVIEW_SCOPE_SELECTOR = '[data-ab-preview-scope]';
|
|
135
|
+
|
|
128
136
|
// ♿ everything that can take focus inside the panel
|
|
129
137
|
const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable="true"]';
|
|
130
138
|
|
package/ab-icon/builtin.ts
CHANGED
|
@@ -59,6 +59,8 @@ import close from 'ab-nextjs-icons/ab-icons/icons/close'; // ✖️ AbPage aside
|
|
|
59
59
|
import expandMore from 'ab-nextjs-icons/ab-icons/icons/expand_more'; // 🔽 AbLocaleSwitcher no-JS list (0.1.13)
|
|
60
60
|
import doubleLeft from 'ab-nextjs-icons/ab-icons/icons/keyboard_double_arrow_left'; // ⏪ AbSidebar outlined collapse (0.1.14, P9)
|
|
61
61
|
import doubleRight from 'ab-nextjs-icons/ab-icons/icons/keyboard_double_arrow_right'; // ⏩ AbSidebar outlined expand (0.1.14, P9)
|
|
62
|
+
import refresh from 'ab-nextjs-icons/ab-icons/icons/refresh'; // 🔄 0.6.0 AbPreviewCode reload
|
|
63
|
+
import openInNew from 'ab-nextjs-icons/ab-icons/icons/open_in_new'; // ↗️ 0.6.0 AbPreviewCode open in a new tab
|
|
62
64
|
// 🧾 shape
|
|
63
65
|
import type { AbIconSvgData } from './helpers';
|
|
64
66
|
|
|
@@ -86,4 +88,6 @@ export const AB_ICON_BUILTINS: Record<string, AbIconSvgData> = {
|
|
|
86
88
|
expand_more: expandMore, // 🔽
|
|
87
89
|
keyboard_double_arrow_left: doubleLeft, // ⏪
|
|
88
90
|
keyboard_double_arrow_right: doubleRight, // ⏩
|
|
91
|
+
refresh, // 🔄 0.6.0
|
|
92
|
+
open_in_new: openInNew, // ↗️ 0.6.0
|
|
89
93
|
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license MIT
|
|
3
|
+
* ~~~~~~~~~~~~
|
|
4
|
+
* ab-nextjs-components
|
|
5
|
+
* ~~~~~~~~~~~~
|
|
6
|
+
* Copyright (c) 2026 Abraham Ukachi. The abElements Project.
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the 'Software'), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* @project: ab-nextjs-components
|
|
27
|
+
* @name: AbPreviewCode (G16, 0.6.0)
|
|
28
|
+
* @file: ab-preview-code/index.tsx
|
|
29
|
+
* @type: Server component (AbContentTabs + the copy button are the only client islands)
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*
|
|
32
|
+
* Example usage (MDX):
|
|
33
|
+
* 1+|> <AbPreviewCode label="Button" code={`<AbButton label="Save" />`}>
|
|
34
|
+
* -|> <AbButton label="Save" />
|
|
35
|
+
* -|> </AbPreviewCode>
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
40
|
+
* MOTTO: We'll always do more 😜!!!
|
|
41
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
// ⚛️ React
|
|
45
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
46
|
+
// 🧵 classes
|
|
47
|
+
import clsx from 'clsx';
|
|
48
|
+
// 🗂️ WAI-ARIA tabs (client island)
|
|
49
|
+
import AbContentTabs, { AbContentTab } from '../ab-content-tabs';
|
|
50
|
+
// 🧪 the preview scope's scheme type
|
|
51
|
+
import type { AbDemoBoxScheme } from '../ab-demo-box';
|
|
52
|
+
// 🧰 0.6.0: the toolbar + preview (a small client island; this file stays server-safe)
|
|
53
|
+
import AbPreviewStage from './stage';
|
|
54
|
+
// 💻 the source half
|
|
55
|
+
import AbDemoCode from '../ab-demo-code';
|
|
56
|
+
// 🎨 styles
|
|
57
|
+
import styles from './styles.module.css';
|
|
58
|
+
|
|
59
|
+
/** 🌍 translatable strings */
|
|
60
|
+
export interface AbPreviewCodeLabels {
|
|
61
|
+
preview?: string; // 🧪 the Preview tab (default "Preview")
|
|
62
|
+
code?: string; // 💻 the Code tab (default "Code")
|
|
63
|
+
copy?: string; // 📋 the copy button (default "Copy code")
|
|
64
|
+
copied?: string; // ✅ announced after a copy (default "Copied")
|
|
65
|
+
toolbar?: string; // 🧰 0.6.0: names the preview toolbar (default "Preview tools")
|
|
66
|
+
dark?: string; // 🌙 0.6.0: the scheme toggle (default "Dark preview", aria-pressed = dark)
|
|
67
|
+
reload?: string; // 🔄 0.6.0: the remount button (default "Reload preview")
|
|
68
|
+
open?: string; // ↗️ 0.6.0: the open-in-new-tab link (default "Open preview in a new tab")
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** ⚙️ props */
|
|
72
|
+
export interface AbPreviewCodeProps {
|
|
73
|
+
children: ReactNode; // 🧪 the live preview: real JSX with package components (D-c: no eval, no live editor)
|
|
74
|
+
code: string; // 📋 the matching source: shown plain when there is no `trustedHtml` / `highlighted`, always what Copy copies
|
|
75
|
+
trustedHtml?: string; // 🧾 Shiki `codeToHtml(code)` output, ⚠️ NOT sanitized: trusted HTML only, never user input (prefer `highlighted`)
|
|
76
|
+
highlighted?: ReactNode; // 🖍️ OR an already highlighted <pre> (e.g. an MDX fenced block)
|
|
77
|
+
language?: string; // 🔤 default 'tsx'
|
|
78
|
+
filename?: string; // 📄 shown in the code header
|
|
79
|
+
label?: string; // ♿ names the tablist, e.g. "Button example" (default "Example")
|
|
80
|
+
labels?: AbPreviewCodeLabels; // 🌍
|
|
81
|
+
defaultTab?: 'preview' | 'code'; // 🎯 default 'preview'
|
|
82
|
+
scheme?: AbDemoBoxScheme; // 🌗 force the preview's scheme (default: follow the page)
|
|
83
|
+
align?: 'center' | 'start' | 'stretch'; // 📐 the preview's alignment (default 'center')
|
|
84
|
+
toolbar?: boolean; // 🧰 0.6.0: the preview toolbar (light/dark toggle + reload [+ open]); default true
|
|
85
|
+
href?: string; // ↗️ 0.6.0: a standalone page for this example → an open-in-new-tab link in the toolbar
|
|
86
|
+
className?: string; // 🏷️
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 🧪💻 AbPreviewCode — the docs Preview / Code pair (G16): AbContentTabs over an AbDemoBox preview scope and an
|
|
91
|
+
* AbDemoCode source block. Both panels are in the server HTML (the inactive one `hidden`), so the preview's
|
|
92
|
+
* markup and the code are crawlable and work before hydration. The preview is the children you pass, rendered
|
|
93
|
+
* as-is: nothing is parsed or evaluated from `code`, so keep the two in sync (a test can compare them).
|
|
94
|
+
*/
|
|
95
|
+
const AbPreviewCode = ({ children, code, trustedHtml, highlighted, language = 'tsx', filename, label = 'Example', labels = {}, defaultTab = 'preview', scheme, align, toolbar = true, href, className }: AbPreviewCodeProps): ReactElement => {
|
|
96
|
+
const L = { preview: 'Preview', code: 'Code', copy: 'Copy code', copied: 'Copied', ...labels }; // 🌍
|
|
97
|
+
const stageLabels = { toolbar: L.toolbar, dark: L.dark, reload: L.reload, open: L.open }; // 🧰 undefined → the island's defaults
|
|
98
|
+
return (
|
|
99
|
+
<div className={clsx('AbPreviewCode', styles.abPreviewCode, className)} data-ab-part="preview-code">
|
|
100
|
+
<AbContentTabs label={label} defaultValue={defaultTab}>
|
|
101
|
+
<AbContentTab label={L.preview} value="preview">
|
|
102
|
+
{/* 🧪 the tabpanel already names it (aria-labelledby the tab), so the box needs no region role */}
|
|
103
|
+
<AbPreviewStage scheme={scheme} align={align} href={href} toolbar={toolbar} labels={stageLabels} className={styles.abPreviewCodeBox}>{children}</AbPreviewStage>
|
|
104
|
+
</AbContentTab>
|
|
105
|
+
<AbContentTab label={L.code} value="code">
|
|
106
|
+
<AbDemoCode code={code} trustedHtml={trustedHtml} language={language} filename={filename} copyLabel={L.copy} copiedLabel={L.copied}>{highlighted}</AbDemoCode>
|
|
107
|
+
</AbContentTab>
|
|
108
|
+
</AbContentTabs>
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// 📦 exports
|
|
114
|
+
export default AbPreviewCode;
|
|
115
|
+
export { AbPreviewCode };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license MIT
|
|
3
|
+
* ~~~~~~~~~~~~
|
|
4
|
+
* ab-nextjs-components
|
|
5
|
+
* ~~~~~~~~~~~~
|
|
6
|
+
* Copyright (c) 2026 Abraham Ukachi. The abElements Project.
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the 'Software'), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* @project: ab-nextjs-components
|
|
27
|
+
* @name: AbPreviewStage (0.6.0)
|
|
28
|
+
* @file: ab-preview-code/stage.tsx
|
|
29
|
+
* @type: Client component (island)
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
35
|
+
* MOTTO: We'll always do more 😜!!!
|
|
36
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
'use client';
|
|
40
|
+
|
|
41
|
+
'use client';
|
|
42
|
+
|
|
43
|
+
// ⚛️ React
|
|
44
|
+
import { useRef, useState, type KeyboardEvent, type ReactElement, type ReactNode } from 'react';
|
|
45
|
+
// 🧵 classes
|
|
46
|
+
import clsx from 'clsx';
|
|
47
|
+
// 🔣 icons (ab-nextjs-icons built-ins: dark_mode, light_mode, refresh, open_in_new)
|
|
48
|
+
import AbIcon from '../ab-icon';
|
|
49
|
+
// 🧪 the preview scope (server-safe, fine inside a client island)
|
|
50
|
+
import AbDemoBox, { type AbDemoBoxScheme } from '../ab-demo-box';
|
|
51
|
+
// 🎨 styles
|
|
52
|
+
import styles from './styles.module.css';
|
|
53
|
+
|
|
54
|
+
/** 🌍 the toolbar's translatable names */
|
|
55
|
+
export interface AbPreviewStageLabels {
|
|
56
|
+
toolbar?: string; // ♿ names the toolbar (default "Preview tools")
|
|
57
|
+
dark?: string; // 🌙 the scheme toggle, a pressed-state button (default "Dark preview")
|
|
58
|
+
reload?: string; // 🔄 the remount button (default "Reload preview")
|
|
59
|
+
open?: string; // ↗️ the open-in-new-tab link (default "Open preview in a new tab")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** ⚙️ props */
|
|
63
|
+
export interface AbPreviewStageProps {
|
|
64
|
+
children?: ReactNode; // 🧪 the live preview (server-rendered JSX passes straight through)
|
|
65
|
+
scheme?: AbDemoBoxScheme; // 🌗 the starting scheme (default 'inherit'); the toggle then forces light / dark
|
|
66
|
+
align?: 'center' | 'start' | 'stretch'; // 📐 forwarded to AbDemoBox
|
|
67
|
+
href?: string; // ↗️ shows an "open in a new tab" link (target _blank, rel noopener noreferrer)
|
|
68
|
+
toolbar?: boolean; // 🧰 show the toolbar (default true); false = just the box
|
|
69
|
+
labels?: AbPreviewStageLabels; // 🌍
|
|
70
|
+
className?: string; // 🏷️ on the AbDemoBox
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 🧰 AbPreviewStage — the small client island behind AbPreviewCode's preview: a WAI-ARIA toolbar (one tab stop,
|
|
75
|
+
* ←/→/Home/End move between tools) over an AbDemoBox.
|
|
76
|
+
* - 🌗 a light/dark toggle (`aria-pressed` = dark) that changes ONLY this preview's scheme (AbDemoBox `data-theme`)
|
|
77
|
+
* - 🔄 reload: remounts the preview with a key bump (state, timers and animations start fresh)
|
|
78
|
+
* - ↗️ with `href`: an open-in-new-tab link
|
|
79
|
+
* Every tool is a ≥44px target with an overridable aria-label. No motion here (motion lives in ab-nextjs-animations).
|
|
80
|
+
*/
|
|
81
|
+
const AbPreviewStage = ({ children, scheme = 'inherit', align, href, toolbar = true, labels = {}, className }: AbPreviewStageProps): ReactElement => {
|
|
82
|
+
const L = { toolbar: 'Preview tools', dark: 'Dark preview', reload: 'Reload preview', open: 'Open preview in a new tab', ...Object.fromEntries(Object.entries(labels).filter(([, v]) => v != null)) }; // 🌍 undefined keeps the default
|
|
83
|
+
const [current, setCurrent] = useState<AbDemoBoxScheme>(scheme); // 🌗 this preview only
|
|
84
|
+
const [key, setKey] = useState(0); // 🔄 bumped → AbDemoBox remounts
|
|
85
|
+
const [active, setActive] = useState(0); // 🎯 roving tab stop (index of the focusable tool)
|
|
86
|
+
const bar = useRef<HTMLDivElement>(null); // 🧰
|
|
87
|
+
const dark = current === 'dark'; // 🌙 pressed?
|
|
88
|
+
|
|
89
|
+
/** ⌨️ APG toolbar keys: ←/→ wrap, Home/End jump; only the active tool is in the tab order */
|
|
90
|
+
const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
|
|
91
|
+
const tools = Array.from(bar.current?.querySelectorAll<HTMLElement>('[data-ab-tool]') ?? []); // 🔘 the tools
|
|
92
|
+
const i = tools.indexOf(document.activeElement as HTMLElement); // 📍
|
|
93
|
+
if (i < 0) return; // 🙅 focus is elsewhere
|
|
94
|
+
const n = tools.length; // 🔢
|
|
95
|
+
const next = e.key === 'ArrowRight' ? (i + 1) % n : e.key === 'ArrowLeft' ? (i - 1 + n) % n : e.key === 'Home' ? 0 : e.key === 'End' ? n - 1 : -1; // 🧭
|
|
96
|
+
if (next < 0) return; // ⏭️ other keys pass through
|
|
97
|
+
e.preventDefault(); // 🛑 no page scroll
|
|
98
|
+
setActive(next); // 🎯
|
|
99
|
+
tools[next]?.focus(); // ⌨️
|
|
100
|
+
};
|
|
101
|
+
const tab = (i: number) => (i === active ? 0 : -1); // 🎯 roving tabindex
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<div className={styles.abPreviewStage} data-ab-part="preview-stage">
|
|
105
|
+
{toolbar && (
|
|
106
|
+
<div ref={bar} role="toolbar" aria-label={L.toolbar} className={styles.abPreviewToolbar} data-ab-part="preview-toolbar" onKeyDown={onKeyDown}>
|
|
107
|
+
<button
|
|
108
|
+
type="button"
|
|
109
|
+
data-ab-tool="scheme" // 🌗
|
|
110
|
+
className={styles.abPreviewTool}
|
|
111
|
+
aria-label={L.dark} // ♿ the name stays; the state is aria-pressed
|
|
112
|
+
aria-pressed={dark} // 🌙 true = dark preview
|
|
113
|
+
tabIndex={tab(0)}
|
|
114
|
+
onFocus={() => setActive(0)}
|
|
115
|
+
onClick={() => setCurrent(dark ? 'light' : 'dark')} // 🔁 light ⇄ dark (from 'inherit' → dark first)
|
|
116
|
+
>
|
|
117
|
+
<AbIcon name={dark ? 'dark_mode' : 'light_mode'} size={20} /> {/* 🌞/🌙 decorative */}
|
|
118
|
+
</button>
|
|
119
|
+
<button
|
|
120
|
+
type="button"
|
|
121
|
+
data-ab-tool="reload" // 🔄
|
|
122
|
+
className={styles.abPreviewTool}
|
|
123
|
+
aria-label={L.reload}
|
|
124
|
+
tabIndex={tab(1)}
|
|
125
|
+
onFocus={() => setActive(1)}
|
|
126
|
+
onClick={() => setKey((k) => k + 1)} // 🔑 key bump → remount
|
|
127
|
+
>
|
|
128
|
+
<AbIcon name="refresh" size={20} />
|
|
129
|
+
</button>
|
|
130
|
+
{href && (
|
|
131
|
+
<a
|
|
132
|
+
href={href}
|
|
133
|
+
target="_blank" // ↗️ new tab
|
|
134
|
+
rel="noopener noreferrer" // 🔐 no window.opener, no referrer
|
|
135
|
+
data-ab-tool="open"
|
|
136
|
+
className={styles.abPreviewTool}
|
|
137
|
+
aria-label={L.open}
|
|
138
|
+
tabIndex={tab(2)}
|
|
139
|
+
onFocus={() => setActive(2)}
|
|
140
|
+
>
|
|
141
|
+
<AbIcon name="open_in_new" size={20} />
|
|
142
|
+
</a>
|
|
143
|
+
)}
|
|
144
|
+
</div>
|
|
145
|
+
)}
|
|
146
|
+
<AbDemoBox key={key} scheme={current} align={align} className={className}>{children}</AbDemoBox>
|
|
147
|
+
</div>
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// 📦 exports
|
|
152
|
+
export default AbPreviewStage;
|
|
153
|
+
export { AbPreviewStage };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license MIT
|
|
3
|
+
* ~~~~~~~~~~~~
|
|
4
|
+
* ab-nextjs-components
|
|
5
|
+
* ~~~~~~~~~~~~
|
|
6
|
+
* Copyright (c) 2026 Abraham Ukachi. The abElements Project.
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the 'Software'), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* @project: ab-nextjs-components
|
|
27
|
+
* @name: styles.module.css
|
|
28
|
+
* @file: ab-preview-code/styles.module.css
|
|
29
|
+
* @type: CSS Stylesheet
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
|
|
32
|
+
/* 🧪💻 the pair: one block in the prose rhythm; the tabs' own bottom margin is dropped inside it */
|
|
33
|
+
.abPreviewCode { margin: 0 0 1.25em; min-inline-size: 0; } /* ↕️ + ↔️ never widens the page */
|
|
34
|
+
.abPreviewCode > :global(.AbContentTabs) { margin: 0; } /* ↕️ */
|
|
35
|
+
.abPreviewCodeBox { min-block-size: 180px; } /* 📏 room for a menu / drawer demo */
|
|
36
|
+
|
|
37
|
+
/* 🧰 0.6.0: the preview toolbar (AbPreviewStage) — tools end-aligned above the box */
|
|
38
|
+
.abPreviewStage { display: grid; min-inline-size: 0; } /* 📐 */
|
|
39
|
+
.abPreviewToolbar { display: flex; justify-content: flex-end; gap: 4px; padding: 2px; } /* 🧰 */
|
|
40
|
+
.abPreviewTool { display: inline-flex; align-items: center; justify-content: center; min-inline-size: 44px; min-block-size: 44px; padding: 0; border: 0; border-radius: 10px; background: transparent; color: inherit; cursor: pointer; } /* 🔘 ≥44px targets */
|
|
41
|
+
.abPreviewTool:hover { background: var(--ab-color-hover, rgb(92 64 48 / 0.08)); } /* 🖱️ */
|
|
42
|
+
.abPreviewTool:focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: 2px; } /* ♿ */
|
|
43
|
+
.abPreviewTool[aria-pressed='true'] { background: var(--ab-color-selected, rgb(92 64 48 / 0.14)); } /* 🌙 pressed */
|
package/index.ts
CHANGED
|
@@ -80,8 +80,9 @@ const supportedComponents: Array<ComponentCatalogEntry> = [
|
|
|
80
80
|
{ name: 'AbText', file: 'ab-text/index.tsx', kind: 'client', status: 'Done' },
|
|
81
81
|
{ name: 'AbProduct', file: 'ab-product/index.tsx', kind: 'client', status: 'Done' },
|
|
82
82
|
{ name: 'AbProductItem', file: 'ab-product-item/index.tsx', kind: 'client', status: 'Done' },
|
|
83
|
-
{ name: 'AbDemoBox', file: 'ab-demo-box/index.tsx', kind: '
|
|
84
|
-
{ name: 'AbDemoCode', file: 'ab-demo-code/index.tsx', kind: '
|
|
83
|
+
{ name: 'AbDemoBox', file: 'ab-demo-box/index.tsx', kind: 'server', status: 'Done' },
|
|
84
|
+
{ name: 'AbDemoCode', file: 'ab-demo-code/index.tsx', kind: 'server', status: 'Done' },
|
|
85
|
+
{ name: 'AbPreviewCode', file: 'ab-preview-code/index.tsx', kind: 'server', status: 'Done' }, // 🧪💻 0.6.0 (G16): the docs Preview / Code pair
|
|
85
86
|
|
|
86
87
|
// SERVER
|
|
87
88
|
{ name: 'AbIcon', file: 'server/ab-icon/index.tsx', kind: 'server', status: 'Done' },
|
|
@@ -200,7 +201,7 @@ export type { AbTocItem, AbTocProps } from './ab-toc/index.tsx'
|
|
|
200
201
|
export { default as AbErrorHero } from './ab-error-hero/index.tsx'
|
|
201
202
|
export type { AbErrorHeroProps } from './ab-error-hero/index.tsx'
|
|
202
203
|
// 🗄️ 0.1.14 (G53): AbDrawer + useAbDrawer (also at `ab-nextjs-components/ab-drawer`)
|
|
203
|
-
export { default as AbDrawer, useAbDrawer, getAbDrawerHost, AB_DRAWER_DURATION, AB_DRAWER_RETURN_FOCUS } from './ab-drawer/index.tsx'
|
|
204
|
+
export { default as AbDrawer, useAbDrawer, getAbDrawerHost, AB_DRAWER_DURATION, AB_DRAWER_RETURN_FOCUS, AB_PREVIEW_SCOPE_SELECTOR } from './ab-drawer/index.tsx'
|
|
204
205
|
// 🤏 0.2.0 drawers v2: edge swipes + the swipe / snap rules
|
|
205
206
|
export { useAbEdgeSwipe, AB_ASIDE_DRAWER_MAX_WIDTH, AB_SWIPE, resolveAbSheetRelease, resolveAbSideRelease } from './ab-drawer/index.tsx'
|
|
206
207
|
export type { AbDrawerTier, AbSheetSnap, UseAbEdgeSwipeOptions } from './ab-drawer/index.tsx'
|
|
@@ -250,7 +251,14 @@ export { default as AbText } from './ab-text/index.tsx'
|
|
|
250
251
|
export { default as AbProduct } from './ab-product/index.tsx'
|
|
251
252
|
export { default as AbProductItem } from './ab-product-item/index.tsx'
|
|
252
253
|
export { default as AbDemoBox } from './ab-demo-box/index.tsx'
|
|
254
|
+
export type { AbDemoBoxProps, AbDemoBoxScheme } from './ab-demo-box/index.tsx'
|
|
253
255
|
export { default as AbDemoCode } from './ab-demo-code/index.tsx'
|
|
256
|
+
export type { AbDemoCodeProps } from './ab-demo-code/index.tsx'
|
|
257
|
+
// 🧪💻 0.6.0 (G16): the docs Preview / Code pair (AbContentTabs + AbDemoBox + AbDemoCode)
|
|
258
|
+
export { default as AbPreviewCode } from './ab-preview-code/index.tsx'
|
|
259
|
+
export type { AbPreviewCodeProps, AbPreviewCodeLabels } from './ab-preview-code/index.tsx'
|
|
260
|
+
export { default as AbPreviewStage } from './ab-preview-code/stage.tsx' // 🧰 0.6.0: the preview toolbar island
|
|
261
|
+
export type { AbPreviewStageProps, AbPreviewStageLabels } from './ab-preview-code/stage.tsx'
|
|
254
262
|
export { default as AbPolygon } from './server/ab-polygon/index.tsx'
|
|
255
263
|
// 💡 0.3.4 (0.2.24 MDX docs): AbCallout
|
|
256
264
|
export { default as AbCallout, AB_CALLOUT_ICONS } from './ab-callout/index.tsx'
|
|
@@ -261,7 +269,7 @@ export { default as AbCodeBlockCopy } from './ab-code-block/copy.tsx'
|
|
|
261
269
|
export type { AbCodeBlockCopyProps } from './ab-code-block/copy.tsx'
|
|
262
270
|
export type { AbCodeBlockProps } from './ab-code-block/index.tsx'
|
|
263
271
|
// 🗂️ 0.3.4 (0.2.24 MDX docs): AbContentTabs + AbContentTab (MDX <Tabs>/<Tab>)
|
|
264
|
-
export { default as AbContentTabs, AbContentTab } from './ab-content-tabs/index.tsx'
|
|
272
|
+
export { default as AbContentTabs, AbContentTab, AB_FOCUSABLE_SELECTOR } from './ab-content-tabs/index.tsx' // ⌨️ 0.6.0: the panel tab-stop check
|
|
265
273
|
export type { AbContentTabsProps, AbContentTabProps } from './ab-content-tabs/index.tsx'
|
|
266
274
|
// ⏮️⏭️ 0.3.4 (0.2.24 MDX docs): AbDocPager
|
|
267
275
|
export { default as AbDocPager } from './ab-doc-pager/index.tsx'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ab-nextjs-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "🚀 A lightweight collection of server & client React components created by Abraham Ukachi, and optimized for Next.js applications 😎.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -106,6 +106,7 @@
|
|
|
106
106
|
"ab-product-item",
|
|
107
107
|
"ab-demo-box",
|
|
108
108
|
"ab-demo-code",
|
|
109
|
+
"ab-preview-code",
|
|
109
110
|
"ab-splash",
|
|
110
111
|
"ab-linear-progress",
|
|
111
112
|
"ab-carousel",
|
|
@@ -227,6 +228,7 @@
|
|
|
227
228
|
"./ab-product-item": "./ab-product-item/index.tsx",
|
|
228
229
|
"./ab-demo-box": "./ab-demo-box/index.tsx",
|
|
229
230
|
"./ab-demo-code": "./ab-demo-code/index.tsx",
|
|
231
|
+
"./ab-preview-code": "./ab-preview-code/index.tsx",
|
|
230
232
|
"./server/ab-brand": "./server/ab-brand/index.tsx",
|
|
231
233
|
"./server/ab-name": "./server/ab-name/index.tsx",
|
|
232
234
|
"./server/ab-navbar": "./server/ab-navbar/index.tsx",
|
package/types/index.d.ts
CHANGED
|
@@ -138,6 +138,7 @@ export { default as AbProduct } from '../ab-product/index.tsx';
|
|
|
138
138
|
export { default as AbProductItem } from '../ab-product-item/index.tsx';
|
|
139
139
|
export { default as AbDemoBox } from '../ab-demo-box/index.tsx';
|
|
140
140
|
export { default as AbDemoCode } from '../ab-demo-code/index.tsx';
|
|
141
|
+
export { default as AbPreviewCode } from '../ab-preview-code/index.tsx';
|
|
141
142
|
export { default as AbPolygon } from '../server/ab-polygon/index.tsx';
|
|
142
143
|
// 💡 0.3.4 (0.2.24 MDX docs): AbCallout
|
|
143
144
|
export { default as AbCallout, AB_CALLOUT_ICONS } from '../ab-callout/index.tsx';
|