ab-nextjs-components 0.1.14 β 0.2.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 +35 -0
- package/README.md +5 -0
- package/ab-app-bar/index.tsx +16 -5
- package/ab-app-bar/styles.module.css +27 -2
- package/ab-bottom-drawer/styles.module.css +1 -1
- package/ab-breadcrumbs/index.tsx +1 -1
- package/ab-drawer/gestures.ts +134 -0
- package/ab-drawer/index.tsx +163 -12
- package/ab-drawer/kit.module.css +204 -0
- package/ab-drawer/styles.module.css +39 -0
- package/ab-drawer/use-ab-edge-swipe.ts +155 -0
- package/ab-icon-button/index.tsx +1 -1
- package/ab-locale-switcher/index.tsx +64 -3
- package/ab-locale-switcher/styles.module.css +20 -0
- package/ab-mobile-header/index.tsx +100 -0
- package/ab-nav-drawer/index.tsx +158 -0
- package/ab-navbar/index.tsx +1 -1
- package/ab-search-drawer/index.tsx +279 -0
- package/ab-search-trigger/index.tsx +8 -3
- package/ab-search-trigger/styles.module.css +3 -0
- package/ab-settings-drawer/index.tsx +160 -0
- package/ab-sidebar/index.tsx +1 -1
- package/ab-sidebar/styles.module.css +5 -0
- package/ab-sidebar/view.tsx +4 -0
- package/ab-toc-drawer/index.tsx +129 -0
- package/ab-version-switcher/index.tsx +5 -5
- package/index.ts +23 -0
- package/package.json +13 -3
- package/types/index.d.ts +18 -0
|
@@ -0,0 +1,160 @@
|
|
|
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: AbSettingsDrawer
|
|
28
|
+
* @file: ab-settings-drawer/index.tsx
|
|
29
|
+
* @type: Client component
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*
|
|
32
|
+
* Example usage:
|
|
33
|
+
* 1+|> const [open, setOpen] = useState(false)
|
|
34
|
+
* -|> <AbSettingsDrawer open={open} onClose={() => setOpen(false)} theme={mode} onThemeChange={setMode}
|
|
35
|
+
* -|> locales={[{ code: 'en', label: 'English' }, { code: 'fr', label: 'FranΓ§ais' }]} locale="en" onLocaleChange={go} />
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
40
|
+
* MOTTO: We'll always do more π!!!
|
|
41
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
'use client';
|
|
46
|
+
|
|
47
|
+
// βοΈ React
|
|
48
|
+
import { useRef, type KeyboardEvent, type ReactElement, type ReactNode } from 'react';
|
|
49
|
+
// π§΅ classes
|
|
50
|
+
import clsx from 'clsx';
|
|
51
|
+
// ποΈ the drawer (tiers, snap points, centring)
|
|
52
|
+
import AbDrawer, { type AbSheetSnap } from '../ab-drawer';
|
|
53
|
+
// π£ icons
|
|
54
|
+
import AbIcon from '../ab-icon';
|
|
55
|
+
// π¨ the drawers v2 kit
|
|
56
|
+
import kit from '../ab-drawer/kit.module.css';
|
|
57
|
+
|
|
58
|
+
/** π a theme choice */
|
|
59
|
+
export type AbSettingsTheme = 'light' | 'dark' | 'system';
|
|
60
|
+
/** π a language row */
|
|
61
|
+
export interface AbSettingsLocale { code: string; label: string } // π·οΈ `label` in its own language ("FranΓ§ais")
|
|
62
|
+
|
|
63
|
+
/** π·οΈ every visible / accessible string (English defaults) */
|
|
64
|
+
export interface AbSettingsDrawerLabels {
|
|
65
|
+
title?: string; // "Settings"
|
|
66
|
+
theme?: string; // "Theme"
|
|
67
|
+
language?: string; // "Language"
|
|
68
|
+
light?: string; dark?: string; system?: string; // π
|
|
69
|
+
close?: string; // "Close settings"
|
|
70
|
+
expand?: string; collapse?: string; // β the handle: "Expand settings" / "Collapse settings"
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** βοΈ props */
|
|
74
|
+
export interface AbSettingsDrawerProps {
|
|
75
|
+
open: boolean; // πͺ
|
|
76
|
+
onClose: () => void; // β
|
|
77
|
+
theme: AbSettingsTheme; // π the checked theme
|
|
78
|
+
onThemeChange: (theme: AbSettingsTheme) => void; // π£
|
|
79
|
+
locales: readonly AbSettingsLocale[]; // π
|
|
80
|
+
locale: string; // π― the checked locale code
|
|
81
|
+
onLocaleChange: (code: string) => void; // π£
|
|
82
|
+
labels?: AbSettingsDrawerLabels; // π·οΈ
|
|
83
|
+
themes?: readonly AbSettingsTheme[]; // ποΈ default light, dark, system
|
|
84
|
+
children?: ReactNode; // β extra sections after Language (your own; Accessibility / About are not built in)
|
|
85
|
+
defaultSnap?: AbSheetSnap; // π§² default 'partial' (70%)
|
|
86
|
+
returnFocus?: string; // β©οΈ see AbDrawer
|
|
87
|
+
id?: string; // π
|
|
88
|
+
className?: string; // π·οΈ
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// β the 24px 2px-stroke check (the mock's path)
|
|
92
|
+
const Check = () => <svg className={kit.ck} viewBox="0 0 24 24" width="24" height="24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" /></svg>;
|
|
93
|
+
// π the glyph per theme
|
|
94
|
+
const THEME_ICON: Record<AbSettingsTheme, string> = { light: 'light_mode', dark: 'dark_mode', system: 'brightness_auto' };
|
|
95
|
+
|
|
96
|
+
/** β¨οΈ radiogroup keys: arrows move AND check (WAI-ARIA radio pattern), Home / End jump */
|
|
97
|
+
function radioKeys<T>(e: KeyboardEvent, items: readonly T[], current: T, pick: (v: T) => void, root: HTMLElement | null) {
|
|
98
|
+
const i = items.indexOf(current); let n = -1;
|
|
99
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowRight') n = (i + 1) % items.length;
|
|
100
|
+
else if (e.key === 'ArrowUp' || e.key === 'ArrowLeft') n = (i - 1 + items.length) % items.length;
|
|
101
|
+
else if (e.key === 'Home') n = 0; else if (e.key === 'End') n = items.length - 1;
|
|
102
|
+
if (n < 0) return;
|
|
103
|
+
e.preventDefault(); pick(items[n]); // β
check it
|
|
104
|
+
root?.querySelectorAll<HTMLElement>('[role="radio"]')[n]?.focus(); // π― and move focus
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* βοΈ AbSettingsDrawer β John's Settings bottom drawer (drawers v2, spec Β§1): the default bottom sheet, holding
|
|
109
|
+
* THEME (a Light / Dark / System segmented radiogroup, 48px) and LANGUAGE (48px radio rows, each label in its
|
|
110
|
+
* own `lang`, the checked one tinted with a check).
|
|
111
|
+
*
|
|
112
|
+
* - π± below 768px: full width, snaps at 70% and full height via the handle (AbDrawer `snapPoints`)
|
|
113
|
+
* - π» 768px and up: centred in the main pane, min(640px, main width), at most 70% tall
|
|
114
|
+
* - βΏ `role="dialog"` labelled by the title; focus goes to the checked language on open (so the globe's
|
|
115
|
+
* "Change language" lands right there) and back to the opener on close; Esc / scrim / β close it
|
|
116
|
+
* - π₯ tier 'sheet': above the left and right drawers. Opening it from the left drawer? Close that one first.
|
|
117
|
+
*/
|
|
118
|
+
const AbSettingsDrawer = ({ open, onClose, theme, onThemeChange, locales, locale, onLocaleChange, labels = {}, themes = ['light', 'dark', 'system'], children, defaultSnap, returnFocus, id, className }: AbSettingsDrawerProps): ReactElement => {
|
|
119
|
+
const seg = useRef<HTMLDivElement>(null); // ποΈ
|
|
120
|
+
const langs = useRef<HTMLDivElement>(null); // π
|
|
121
|
+
const L = { title: 'Settings', theme: 'Theme', language: 'Language', light: 'Light', dark: 'Dark', system: 'System', close: 'Close settings', expand: 'Expand settings', collapse: 'Collapse settings', ...labels }; // π·οΈ
|
|
122
|
+
const base = id ?? 'ab-settings'; // π
|
|
123
|
+
const codes = locales.map((l) => l.code); // π
|
|
124
|
+
return (
|
|
125
|
+
<AbDrawer
|
|
126
|
+
open={open} onClose={onClose} id={id} side="bottom" scope="app" tier="sheet"
|
|
127
|
+
snapPoints centerIn="main" defaultSnap={defaultSnap} handleLabels={{ expand: L.expand, collapse: L.collapse }}
|
|
128
|
+
title={L.title} closeLabel={L.close} closeIcon={<AbIcon name="close" size={24} />}
|
|
129
|
+
initialFocus='[data-ab-part="settings-language"] [aria-checked="true"]' returnFocus={returnFocus}
|
|
130
|
+
className={clsx('AbSettingsDrawer', kit.sheet, className)}
|
|
131
|
+
>
|
|
132
|
+
<p className={kit.lbl} id={`${base}-theme`}>{L.theme}</p>
|
|
133
|
+
<div ref={seg} className={kit.seg} role="radiogroup" aria-labelledby={`${base}-theme`} data-ab-part="settings-theme">
|
|
134
|
+
{themes.map((t) => (
|
|
135
|
+
<button key={t} type="button" role="radio" aria-checked={t === theme} tabIndex={t === theme ? 0 : -1} className={kit.segBtn} data-value={t}
|
|
136
|
+
onClick={() => onThemeChange(t)} onKeyDown={(e) => radioKeys(e, themes, theme, onThemeChange, seg.current)}>
|
|
137
|
+
<AbIcon name={THEME_ICON[t]} size={18} />{L[t]}
|
|
138
|
+
</button>
|
|
139
|
+
))}
|
|
140
|
+
</div>
|
|
141
|
+
<p className={kit.lbl} id={`${base}-language`}>{L.language}</p>
|
|
142
|
+
<div ref={langs} role="radiogroup" aria-labelledby={`${base}-language`} data-ab-part="settings-language">
|
|
143
|
+
{locales.map((l) => {
|
|
144
|
+
const on = l.code === locale; // π―
|
|
145
|
+
return (
|
|
146
|
+
<button key={l.code} type="button" role="radio" aria-checked={on} tabIndex={on ? 0 : -1} lang={l.code} className={kit.row} data-value={l.code}
|
|
147
|
+
onClick={() => onLocaleChange(l.code)} onKeyDown={(e) => radioKeys(e, codes, locale, onLocaleChange, langs.current)}>
|
|
148
|
+
{l.label}{on && <Check />}
|
|
149
|
+
</button>
|
|
150
|
+
);
|
|
151
|
+
})}
|
|
152
|
+
</div>
|
|
153
|
+
{children}
|
|
154
|
+
</AbDrawer>
|
|
155
|
+
);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// π¦ exports
|
|
159
|
+
export default AbSettingsDrawer;
|
|
160
|
+
export { AbSettingsDrawer };
|
package/ab-sidebar/index.tsx
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
* Example usage:
|
|
33
33
|
* <AbSidebar
|
|
34
34
|
* activeHref="/docs/components"
|
|
35
|
-
* sections={[{ id: '
|
|
35
|
+
* sections={[{ id: 'gs', label: 'Getting started', items: [{ href: '/introduction', icon: 'description', label: 'Introduction' }] }]}
|
|
36
36
|
* />
|
|
37
37
|
*/
|
|
38
38
|
|
|
@@ -187,3 +187,8 @@
|
|
|
187
187
|
.abSidebar[data-density='compact'][data-collapsed='true'] .abSidebarHeader { padding: 12px 0 6px; justify-content: center; } /* πͺ rail */
|
|
188
188
|
.abSidebar[data-density='compact'][data-collapsed='true'] .abSidebarSections { padding-inline: 8px; }
|
|
189
189
|
.abSidebar[data-density='compact'][data-collapsed='true'] .abSidebarLink { width: 40px; height: 40px; } /* π */
|
|
190
|
+
|
|
191
|
+
/* π·οΈ 0.1.15 (God 00:08): the tablet logo row, mock 06 `.sb-logo` = 60px, 0 20px, centred, never shrinks.
|
|
192
|
+
* Height follows core's --ab-header-height (60px at tablet) so it lines up with the main bar. */
|
|
193
|
+
.abSidebarLogo { flex: none; display: flex; align-items: center; box-sizing: border-box; height: var(--ab-header-height, 60px); padding: 0 20px; }
|
|
194
|
+
.abSidebar[data-collapsed='true'] .abSidebarLogo { justify-content: center; padding: 0; } /* πͺ rail: centred */
|
package/ab-sidebar/view.tsx
CHANGED
|
@@ -98,6 +98,9 @@ export interface AbSidebarBaseProps {
|
|
|
98
98
|
density?: 'comfortable' | 'compact'; // π 'compact' = 32px rows, 13.5/500, 18px icons, 11px group labels
|
|
99
99
|
activeShape?: 'pill' | 'rounded'; // π· 'rounded' = 8px-radius --tint row (default 'pill')
|
|
100
100
|
badgeVariant?: 'chip' | 'text'; // π·οΈ 'text' = plain mono 10.5 --faint meta (e.g. a version), no chip
|
|
101
|
+
// π·οΈ 0.1.15 (God 00:08): a 60px logo row above `header` (mock 06 `.sb-logo`). With core β₯ 0.2.1 panes it only shows
|
|
102
|
+
// where the app header is hidden (tabletHeader="main" at 768β1179); elsewhere it always shows
|
|
103
|
+
logo?: ReactNode;
|
|
101
104
|
// π°οΈ legacy API (β€ 0.1.12)
|
|
102
105
|
type?: 'customer' | 'admin';
|
|
103
106
|
page?: string;
|
|
@@ -174,6 +177,7 @@ export function AbSidebarView({ props, Icon, active, toggle }: {
|
|
|
174
177
|
data-badge={badgeVariant === 'text' ? 'text' : undefined} // π·οΈ P8
|
|
175
178
|
aria-label={labels?.nav ?? 'Sidebar'} // βΏ
|
|
176
179
|
>
|
|
180
|
+
{props.logo != null && <div className={styles.abSidebarLogo} data-ab-part="sidebar-logo">{props.logo}</div> /* π·οΈ 0.1.15 */}
|
|
177
181
|
{/* π·οΈ header slot, or the legacy brand link */}
|
|
178
182
|
<div className={styles.abSidebarHeader}>
|
|
179
183
|
{header ?? (links?.length && !sections?.length ? <Link href={brandHref} className={styles.abSidebarBrand}>{brandLabel}</Link> : null)}
|
|
@@ -0,0 +1,129 @@
|
|
|
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: AbTocDrawer
|
|
28
|
+
* @file: ab-toc-drawer/index.tsx
|
|
29
|
+
* @type: Client component
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*
|
|
32
|
+
* Example usage:
|
|
33
|
+
* 1+|> useAbEdgeSwipe({ edge: 'right', onOpen: () => setToc(true), enabled: hasAside && !toc })
|
|
34
|
+
* -|> <AbTocDrawer open={toc} onClose={() => setToc(false)} items={outline} activeId={spy}
|
|
35
|
+
* -|> onNavigate={(id) => scrollToAbSection(id)} links={[{ href: editUrl, label: 'Edit this page', icon: 'github' }]} />
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
40
|
+
* MOTTO: We'll always do more π!!!
|
|
41
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
'use client';
|
|
46
|
+
|
|
47
|
+
// βοΈ React
|
|
48
|
+
import type { MouseEvent, ReactElement } from 'react';
|
|
49
|
+
// π§΅ classes
|
|
50
|
+
import clsx from 'clsx';
|
|
51
|
+
// ποΈ the drawer
|
|
52
|
+
import AbDrawer from '../ab-drawer';
|
|
53
|
+
// π£ icons
|
|
54
|
+
import AbIcon from '../ab-icon';
|
|
55
|
+
// π the app's link
|
|
56
|
+
import Link from '../ab-link';
|
|
57
|
+
// π the outline item type (shared with AbToc)
|
|
58
|
+
import type { AbTocItem } from '../ab-toc';
|
|
59
|
+
// π¨ the drawers v2 kit
|
|
60
|
+
import kit from '../ab-drawer/kit.module.css';
|
|
61
|
+
|
|
62
|
+
/** π a row under the outline (Edit this page, Changelog) */
|
|
63
|
+
export interface AbTocDrawerLink { href: string; label: string; icon?: string; external?: boolean }
|
|
64
|
+
|
|
65
|
+
/** βοΈ props */
|
|
66
|
+
export interface AbTocDrawerProps {
|
|
67
|
+
open: boolean; // πͺ
|
|
68
|
+
onClose: () => void; // β scrim, Esc, β, a left-to-right swipe, or choosing a heading
|
|
69
|
+
items: readonly AbTocItem[]; // π the page outline (level 2 / 3 / 4)
|
|
70
|
+
activeId?: string | null; // π― e.g. from useAbScrollSpy (hooks 0.1.7)
|
|
71
|
+
onNavigate?: (id: string) => void; // π scroll there (e.g. scrollToAbSection); without it a plain #id jump. The drawer closes after
|
|
72
|
+
links?: readonly AbTocDrawerLink[]; // π below a divider
|
|
73
|
+
labels?: { title?: string; close?: string }; // π "On this page", "Close outline"
|
|
74
|
+
returnFocus?: string; // β©οΈ after a swipe-open
|
|
75
|
+
id?: string; // π
|
|
76
|
+
className?: string; // π·οΈ
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* β‘οΈ AbTocDrawer β John's right drawer (drawers v2 Β§3): the page aside ("On this page") on mobile.
|
|
81
|
+
*
|
|
82
|
+
* - π§ Only for routes whose layout has an aside: render it (and enable the right edge swipe) there, nowhere else
|
|
83
|
+
* - π 296px, 16 0 0 16 radius, title Mulish 800 20px; 44px outline rows on a 2px rail, level 3 indented 16px,
|
|
84
|
+
* the active one bronze with `aria-current="location"`; then a divider and the links
|
|
85
|
+
* - π€ opens with `useAbEdgeSwipe({ edge: 'right' })` or an "On this page" chip; closes with a left-to-right swipe
|
|
86
|
+
* - π₯ tier 'aside': one level below the left drawer
|
|
87
|
+
*/
|
|
88
|
+
const AbTocDrawer = ({ open, onClose, items, activeId, onNavigate, links = [], labels = {}, returnFocus, id = 'ab-toc-drawer', className }: AbTocDrawerProps): ReactElement => {
|
|
89
|
+
const L = { title: 'On this page', close: 'Close outline', ...labels }; // π
|
|
90
|
+
const go = (target: string) => (e: MouseEvent) => {
|
|
91
|
+
if (onNavigate) { e.preventDefault(); onNavigate(target); } // π the app scrolls
|
|
92
|
+
onClose(); // πͺ then close
|
|
93
|
+
};
|
|
94
|
+
return (
|
|
95
|
+
<AbDrawer
|
|
96
|
+
open={open} onClose={onClose} id={id} side="right" scope="app" tier="aside" swipe size="296px"
|
|
97
|
+
title={L.title} closeLabel={L.close} closeIcon={<AbIcon name="close" size={24} />}
|
|
98
|
+
initialFocus="panel" returnFocus={returnFocus} // π― the sheet itself (WebKit drew a focus ring on the active row; Tab then enters)
|
|
99
|
+
className={clsx('AbTocDrawer', kit.sheet, kit.titleSm, className)}
|
|
100
|
+
>
|
|
101
|
+
<nav aria-labelledby={`${id}-title`} data-ab-part="toc-drawer-nav">
|
|
102
|
+
<ol className={kit.toc}>
|
|
103
|
+
{items.map((it) => {
|
|
104
|
+
const on = it.id === activeId; // π―
|
|
105
|
+
return (
|
|
106
|
+
<li key={it.id}>
|
|
107
|
+
<a href={`#${it.id}`} className={kit.tocLink} data-level={it.level ?? 2} aria-current={on ? 'location' : undefined} onClick={go(it.id)}>{it.label}</a>
|
|
108
|
+
</li>
|
|
109
|
+
);
|
|
110
|
+
})}
|
|
111
|
+
</ol>
|
|
112
|
+
</nav>
|
|
113
|
+
{links.length > 0 && (
|
|
114
|
+
<>
|
|
115
|
+
<hr className={clsx(kit.hr, kit.tocHr)} />
|
|
116
|
+
{links.map((l) => (
|
|
117
|
+
<Link key={l.href} href={l.href} className={clsx(kit.row, kit.tocRow)} {...(l.external ? { target: '_blank', rel: 'noreferrer' } : {})} onClick={onClose}>
|
|
118
|
+
{l.icon && <AbIcon name={l.icon} size={24} />}<span>{l.label}</span>
|
|
119
|
+
</Link>
|
|
120
|
+
))}
|
|
121
|
+
</>
|
|
122
|
+
)}
|
|
123
|
+
</AbDrawer>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// π¦ exports
|
|
128
|
+
export default AbTocDrawer;
|
|
129
|
+
export { AbTocDrawer };
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
31
|
*
|
|
32
32
|
* Example usage:
|
|
33
|
-
* 1+|> <AbVersionSwitcher
|
|
33
|
+
* 1+|> <AbVersionSwitcher version="v0.2.x" versions={[{ value: "v0.2.x", href: "/" }, { value: "v0.1.x", href: "/v0.1" }]} />
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
/*
|
|
@@ -62,7 +62,7 @@ export interface AbVersionOption {
|
|
|
62
62
|
|
|
63
63
|
/** βοΈ props */
|
|
64
64
|
export interface AbVersionSwitcherProps {
|
|
65
|
-
label?: string; // π·οΈ default "Docs"
|
|
65
|
+
label?: string; // π·οΈ text before the version; default none (0.2.0, God 01:27: the app IS the docs, so no "Docs" prefix)
|
|
66
66
|
version: string; // β
current version (shown bold), e.g. 'v0.2.x'
|
|
67
67
|
versions?: readonly AbVersionOption[]; // π the choices (none / one = a static label, no menu)
|
|
68
68
|
onSelect?: (value: string) => void; // π£ button items
|
|
@@ -75,12 +75,12 @@ export interface AbVersionSwitcherProps {
|
|
|
75
75
|
* card background, 16px `expand_more`; opens an AbMenu below it (Escape / outside click close, focus returns).
|
|
76
76
|
* JS off: with `href`s it's a native `<details>` list of links.
|
|
77
77
|
*/
|
|
78
|
-
const AbVersionSwitcher = ({ label = '
|
|
78
|
+
const AbVersionSwitcher = ({ label = '', version, versions = [], onSelect, menuLabel, className }: AbVersionSwitcherProps): ReactElement => {
|
|
79
79
|
const [open, setOpen] = useState(false); // πͺ
|
|
80
80
|
const menuId = `ab-version-menu-${useId().replace(/:/g, '')}`; // π
|
|
81
81
|
const wrap = useRef<HTMLDivElement>(null); // π
|
|
82
82
|
const btn = useRef<HTMLButtonElement>(null); // π
|
|
83
|
-
const name = menuLabel ?? `${label} ${version}
|
|
83
|
+
const name = menuLabel ?? (label ? `${label} ${version}` : `Version ${version}`); // βΏ WCAG 2.5.3 label-in-name (James); no label β "Version v0.2.x" (James P2, still contains the visible text)
|
|
84
84
|
const hasMenu = versions.length > 1; // π
|
|
85
85
|
|
|
86
86
|
// β Escape + outside click close it
|
|
@@ -96,7 +96,7 @@ const AbVersionSwitcher = ({ label = 'Docs', version, versions = [], onSelect, m
|
|
|
96
96
|
// π§± the visible face (same for button, static label and no-JS summary)
|
|
97
97
|
const face = (
|
|
98
98
|
<>
|
|
99
|
-
|
|
99
|
+
{label && <><span>{label}</span> </>}<b className={styles.abVersionValue}>{version}</b>
|
|
100
100
|
{hasMenu && <AbIcon name="expand_more" size={16} className={styles.abVersionIcon} />}
|
|
101
101
|
</>
|
|
102
102
|
);
|
package/index.ts
CHANGED
|
@@ -135,6 +135,11 @@ const supportedComponents: Array<ComponentCatalogEntry> = [
|
|
|
135
135
|
{ name: 'AbDrawerList', file: 'ab-drawer-list/index.tsx', kind: 'client', status: 'Done' },
|
|
136
136
|
{ name: 'AbConfirmDrawer', file: 'ab-confirm-drawer/index.tsx', kind: 'client', status: 'Done' },
|
|
137
137
|
{ name: 'AbBottomDrawer', file: 'ab-bottom-drawer/index.tsx', kind: 'client', status: 'Done' },
|
|
138
|
+
{ name: 'AbMobileHeader', file: 'ab-mobile-header/index.tsx', kind: 'client', status: 'Done' }, // π 0.2.0 drawers v2
|
|
139
|
+
{ name: 'AbSearchDrawer', file: 'ab-search-drawer/index.tsx', kind: 'client', status: 'Done' }, // π 0.2.0 drawers v2
|
|
140
|
+
{ name: 'AbTocDrawer', file: 'ab-toc-drawer/index.tsx', kind: 'client', status: 'Done' }, // π 0.2.0 drawers v2
|
|
141
|
+
{ name: 'AbNavDrawer', file: 'ab-nav-drawer/index.tsx', kind: 'client', status: 'Done' }, // π 0.2.0 drawers v2
|
|
142
|
+
{ name: 'AbSettingsDrawer', file: 'ab-settings-drawer/index.tsx', kind: 'client', status: 'Done' }, // π 0.2.0 drawers v2
|
|
138
143
|
{ name: 'AbVersionSwitcher', file: 'ab-version-switcher/index.tsx', kind: 'client', status: 'Done' },
|
|
139
144
|
{ name: 'AbBreadcrumbs', file: 'ab-breadcrumbs/index.tsx', kind: 'server', status: 'Done' },
|
|
140
145
|
{ name: 'AbList', file: 'ab-list/index.tsx', kind: 'server', status: 'Done' },
|
|
@@ -179,6 +184,9 @@ export { default as AbToc, getAbMainScroller, AB_MAIN_SCROLLER_SELECTOR } from '
|
|
|
179
184
|
export type { AbTocItem, AbTocProps } from './ab-toc/index.tsx'
|
|
180
185
|
// ποΈ 0.1.14 (G53): AbDrawer + useAbDrawer (also at `ab-nextjs-components/ab-drawer`)
|
|
181
186
|
export { default as AbDrawer, useAbDrawer, getAbDrawerHost, AB_DRAWER_DURATION } from './ab-drawer/index.tsx'
|
|
187
|
+
// π€ 0.2.0 drawers v2: edge swipes + the swipe / snap rules
|
|
188
|
+
export { useAbEdgeSwipe, AB_SWIPE, resolveAbSheetRelease, resolveAbSideRelease } from './ab-drawer/index.tsx'
|
|
189
|
+
export type { AbDrawerTier, AbSheetSnap, UseAbEdgeSwipeOptions } from './ab-drawer/index.tsx'
|
|
182
190
|
export type { AbDrawerProps, AbDrawerSide, AbDrawerScope, UseAbDrawer } from './ab-drawer/index.tsx'
|
|
183
191
|
export { default as AbDrawerList } from './ab-drawer-list/index.tsx'
|
|
184
192
|
export type { AbDrawerListItem, AbDrawerListProps } from './ab-drawer-list/index.tsx'
|
|
@@ -187,6 +195,21 @@ export type { AbConfirmDrawerProps } from './ab-confirm-drawer/index.tsx'
|
|
|
187
195
|
// π± 0.1.14 (D40): AbBottomDrawer, the mobile bottom drawer
|
|
188
196
|
export { default as AbBottomDrawer } from './ab-bottom-drawer/index.tsx'
|
|
189
197
|
export type { AbBottomDrawerProps } from './ab-bottom-drawer/index.tsx'
|
|
198
|
+
// π 0.2.0 drawers v2: AbMobileHeader
|
|
199
|
+
export { default as AbMobileHeader } from './ab-mobile-header/index.tsx'
|
|
200
|
+
export type { AbMobileHeaderProps } from './ab-mobile-header/index.tsx'
|
|
201
|
+
// π 0.2.0 drawers v2: AbSearchDrawer
|
|
202
|
+
export { default as AbSearchDrawer, addAbSearchRecent, highlightAbSearch, AB_SEARCH_RECENT_KEY } from './ab-search-drawer/index.tsx'
|
|
203
|
+
export type { AbSearchDrawerProps, AbSearchDrawerItem, AbSearchDrawerGroup, AbSearchDrawerLabels } from './ab-search-drawer/index.tsx'
|
|
204
|
+
// π 0.2.0 drawers v2: AbTocDrawer
|
|
205
|
+
export { default as AbTocDrawer } from './ab-toc-drawer/index.tsx'
|
|
206
|
+
export type { AbTocDrawerProps, AbTocDrawerLink } from './ab-toc-drawer/index.tsx'
|
|
207
|
+
// π 0.2.0 drawers v2: AbNavDrawer
|
|
208
|
+
export { default as AbNavDrawer } from './ab-nav-drawer/index.tsx'
|
|
209
|
+
export type { AbNavDrawerProps, AbNavDrawerItem, AbNavDrawerSection } from './ab-nav-drawer/index.tsx'
|
|
210
|
+
// π 0.2.0 drawers v2: AbSettingsDrawer
|
|
211
|
+
export { default as AbSettingsDrawer } from './ab-settings-drawer/index.tsx'
|
|
212
|
+
export type { AbSettingsDrawerProps, AbSettingsDrawerLabels, AbSettingsLocale, AbSettingsTheme } from './ab-settings-drawer/index.tsx'
|
|
190
213
|
// π·οΈ 0.1.14 (P9): AbVersionSwitcher
|
|
191
214
|
export { default as AbVersionSwitcher } from './ab-version-switcher/index.tsx'
|
|
192
215
|
export type { AbVersionOption, AbVersionSwitcherProps } from './ab-version-switcher/index.tsx'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ab-nextjs-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"ab-nextjs-animations": "^0.2.4",
|
|
44
44
|
"ab-nextjs-hooks": "^0.1.7",
|
|
45
45
|
"ab-nextjs-icons": "^0.2.4",
|
|
46
|
-
"ab-nextjs-theme": "^0.3.
|
|
46
|
+
"ab-nextjs-theme": "^0.3.6",
|
|
47
47
|
"clsx": "^2",
|
|
48
48
|
"next": "^16.3.4",
|
|
49
49
|
"react": "^19",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"ab-nextjs-animations": "^0.2.4",
|
|
57
57
|
"ab-nextjs-hooks": "^0.1.7",
|
|
58
58
|
"ab-nextjs-icons": "^0.2.4",
|
|
59
|
-
"ab-nextjs-theme": "^0.3.
|
|
59
|
+
"ab-nextjs-theme": "^0.3.6",
|
|
60
60
|
"clsx": "^2.1.1",
|
|
61
61
|
"esbuild": "^0.28.2",
|
|
62
62
|
"eslint": "^9.39.0",
|
|
@@ -118,6 +118,11 @@
|
|
|
118
118
|
"ab-drawer-list",
|
|
119
119
|
"ab-confirm-drawer",
|
|
120
120
|
"ab-bottom-drawer",
|
|
121
|
+
"ab-mobile-header",
|
|
122
|
+
"ab-search-drawer",
|
|
123
|
+
"ab-toc-drawer",
|
|
124
|
+
"ab-nav-drawer",
|
|
125
|
+
"ab-settings-drawer",
|
|
121
126
|
"ab-version-switcher",
|
|
122
127
|
"ab-breadcrumbs",
|
|
123
128
|
"ab-list",
|
|
@@ -165,6 +170,11 @@
|
|
|
165
170
|
"./ab-drawer-list": "./ab-drawer-list/index.tsx",
|
|
166
171
|
"./ab-confirm-drawer": "./ab-confirm-drawer/index.tsx",
|
|
167
172
|
"./ab-bottom-drawer": "./ab-bottom-drawer/index.tsx",
|
|
173
|
+
"./ab-mobile-header": "./ab-mobile-header/index.tsx",
|
|
174
|
+
"./ab-search-drawer": "./ab-search-drawer/index.tsx",
|
|
175
|
+
"./ab-toc-drawer": "./ab-toc-drawer/index.tsx",
|
|
176
|
+
"./ab-nav-drawer": "./ab-nav-drawer/index.tsx",
|
|
177
|
+
"./ab-settings-drawer": "./ab-settings-drawer/index.tsx",
|
|
168
178
|
"./ab-version-switcher": "./ab-version-switcher/index.tsx",
|
|
169
179
|
"./ab-breadcrumbs": "./ab-breadcrumbs/index.tsx",
|
|
170
180
|
"./ab-list": "./ab-list/index.tsx",
|
package/types/index.d.ts
CHANGED
|
@@ -80,6 +80,9 @@ export { default as AbToc, getAbMainScroller, AB_MAIN_SCROLLER_SELECTOR } from '
|
|
|
80
80
|
export type { AbTocItem, AbTocProps } from '../ab-toc/index.tsx';
|
|
81
81
|
// ποΈ 0.1.14 (G53): AbDrawer + useAbDrawer (also at `ab-nextjs-components/ab-drawer`)
|
|
82
82
|
export { default as AbDrawer, useAbDrawer, getAbDrawerHost, AB_DRAWER_DURATION } from '../ab-drawer/index.tsx';
|
|
83
|
+
// π€ 0.2.0 drawers v2: edge swipes + the swipe / snap rules
|
|
84
|
+
export { useAbEdgeSwipe, AB_SWIPE, resolveAbSheetRelease, resolveAbSideRelease } from '../ab-drawer/index.tsx';
|
|
85
|
+
export type { AbDrawerTier, AbSheetSnap, UseAbEdgeSwipeOptions } from '../ab-drawer/index.tsx';
|
|
83
86
|
export type { AbDrawerProps, AbDrawerSide, AbDrawerScope, UseAbDrawer } from '../ab-drawer/index.tsx';
|
|
84
87
|
export { default as AbDrawerList } from '../ab-drawer-list/index.tsx';
|
|
85
88
|
export type { AbDrawerListItem, AbDrawerListProps } from '../ab-drawer-list/index.tsx';
|
|
@@ -88,6 +91,21 @@ export type { AbConfirmDrawerProps } from '../ab-confirm-drawer/index.tsx';
|
|
|
88
91
|
// π± 0.1.14 (D40): AbBottomDrawer, the mobile bottom drawer
|
|
89
92
|
export { default as AbBottomDrawer } from '../ab-bottom-drawer/index.tsx';
|
|
90
93
|
export type { AbBottomDrawerProps } from '../ab-bottom-drawer/index.tsx';
|
|
94
|
+
// π 0.2.0 drawers v2: AbMobileHeader
|
|
95
|
+
export { default as AbMobileHeader } from '../ab-mobile-header/index.tsx';
|
|
96
|
+
export type { AbMobileHeaderProps } from '../ab-mobile-header/index.tsx';
|
|
97
|
+
// π 0.2.0 drawers v2: AbSearchDrawer
|
|
98
|
+
export { default as AbSearchDrawer, addAbSearchRecent, highlightAbSearch, AB_SEARCH_RECENT_KEY } from '../ab-search-drawer/index.tsx';
|
|
99
|
+
export type { AbSearchDrawerProps, AbSearchDrawerItem, AbSearchDrawerGroup, AbSearchDrawerLabels } from '../ab-search-drawer/index.tsx';
|
|
100
|
+
// π 0.2.0 drawers v2: AbTocDrawer
|
|
101
|
+
export { default as AbTocDrawer } from '../ab-toc-drawer/index.tsx';
|
|
102
|
+
export type { AbTocDrawerProps, AbTocDrawerLink } from '../ab-toc-drawer/index.tsx';
|
|
103
|
+
// π 0.2.0 drawers v2: AbNavDrawer
|
|
104
|
+
export { default as AbNavDrawer } from '../ab-nav-drawer/index.tsx';
|
|
105
|
+
export type { AbNavDrawerProps, AbNavDrawerItem, AbNavDrawerSection } from '../ab-nav-drawer/index.tsx';
|
|
106
|
+
// π 0.2.0 drawers v2: AbSettingsDrawer
|
|
107
|
+
export { default as AbSettingsDrawer } from '../ab-settings-drawer/index.tsx';
|
|
108
|
+
export type { AbSettingsDrawerProps, AbSettingsDrawerLabels, AbSettingsLocale, AbSettingsTheme } from '../ab-settings-drawer/index.tsx';
|
|
91
109
|
// π·οΈ 0.1.14 (P9): AbVersionSwitcher
|
|
92
110
|
export { default as AbVersionSwitcher } from '../ab-version-switcher/index.tsx';
|
|
93
111
|
export type { AbVersionOption, AbVersionSwitcherProps } from '../ab-version-switcher/index.tsx';
|