ab-nextjs-components 0.1.14 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -0
- package/README.md +5 -0
- package/ab-app-bar/index.tsx +17 -6
- package/ab-app-bar/styles.module.css +27 -2
- package/ab-balloon/index.tsx +35 -3
- package/ab-balloon/styles.module.css +8 -0
- 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 +168 -12
- package/ab-drawer/kit.module.css +210 -0
- package/ab-drawer/styles.module.css +39 -0
- package/ab-drawer/use-ab-edge-swipe.ts +165 -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-package-card/index.tsx +2 -0
- package/ab-package-card/previews.tsx +94 -0
- package/ab-package-card/styles.module.css +21 -0
- package/ab-profile-avatar/index.tsx +105 -0
- package/ab-profile-avatar/styles.module.css +53 -0
- 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 +203 -0
- package/ab-sidebar/index.tsx +10 -2
- package/ab-sidebar/profile-button.tsx +115 -0
- package/ab-sidebar/styles.module.css +43 -0
- package/ab-sidebar/view.tsx +9 -1
- package/ab-toc/index.tsx +3 -0
- package/ab-toc/promo.tsx +74 -0
- package/ab-toc/styles.module.css +16 -0
- package/ab-toc-drawer/index.tsx +129 -0
- package/ab-version-switcher/index.tsx +5 -5
- package/index.ts +36 -1
- package/package.json +15 -3
- package/types/index.d.ts +27 -1
|
@@ -0,0 +1,94 @@
|
|
|
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: AbPackageCard Home previews (0.2.1, God 02:44, mock .pv-*)
|
|
28
|
+
* @file: ab-package-card/previews.tsx
|
|
29
|
+
* @type: React Component (no hooks: client + server)
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*
|
|
32
|
+
* Example usage (pass one as AbPackageCard `preview`):
|
|
33
|
+
* <AbPackageCard preview={<AbPackagePreviewCurve />} … /> // 〰️ Animations: ease-out curve
|
|
34
|
+
* <AbPackageCard preview={<AbPackagePreviewCode lines={['*use*Theme()', '*use*Media()']} />} … /> // 🪝 Hooks
|
|
35
|
+
* <AbPackageCard preview={<AbPackagePreviewCode lines={['<*AbProvider*>', '~ {children}']} />} … /> // 🧱 Core
|
|
36
|
+
* <AbPackageCard preview={<AbPackagePreviewComponents />} … /> // 🧩 Components: button · switch · chip
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
41
|
+
* MOTTO: We'll always do more 😜!!!
|
|
42
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
// ⚛️ React
|
|
46
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
47
|
+
// 🎨 styles (the card's module: the previews sit in its 56px tile)
|
|
48
|
+
import styles from './styles.module.css';
|
|
49
|
+
|
|
50
|
+
/** 〰️ Animations tile: two axes, the accent ease-out curve with its end dots, and the easing name bottom right. */
|
|
51
|
+
export function AbPackagePreviewCurve({ label = 'ease-out', path = 'M6 38 C 50 38, 58 6, 114 6' }: { label?: string; path?: string }): ReactElement {
|
|
52
|
+
return (
|
|
53
|
+
<span className={styles.pvAnim} data-ab-part="preview-curve">
|
|
54
|
+
<svg viewBox="0 0 120 44" preserveAspectRatio="none" aria-hidden="true" focusable="false">
|
|
55
|
+
<line x1="6" y1="38" x2="114" y2="38" className={styles.pvAx} /> {/* ➖ x axis */}
|
|
56
|
+
<line x1="6" y1="6" x2="6" y2="38" className={styles.pvAx} /> {/* ➖ y axis */}
|
|
57
|
+
<path d={path} className={styles.pvCrv} /> {/* 〰️ the curve (mock: cubic 50,38 · 58,6) */}
|
|
58
|
+
<circle cx="114" cy="6" r="3.2" className={styles.pvDot} /> {/* 🔴 end */}
|
|
59
|
+
<circle cx="6" cy="38" r="2.4" className={styles.pvDot2} /> {/* ⚪ start */}
|
|
60
|
+
</svg>
|
|
61
|
+
<span className={styles.pvEase}>{label}</span> {/* 🏷️ ease-out */}
|
|
62
|
+
</span>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 🎨 one code line: `*kw*` = a keyword (accent, 600), a leading `~` = a dim line (faint). */
|
|
67
|
+
function codeLine(src: string): ReactNode {
|
|
68
|
+
const parts = src.split(/(\*[^*]+\*)/g).filter(Boolean); // ✂️ keywords vs text
|
|
69
|
+
return parts.map((p, i) => (p.startsWith('*') && p.endsWith('*') ? <b key={i}>{p.slice(1, -1)}</b> : p)); // 🖍️
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** 🪝🧱 Hooks / Core tile: left-aligned, slightly bold mono lines with the keywords syntax-coloured. */
|
|
73
|
+
export function AbPackagePreviewCode({ lines }: { lines: readonly string[] }): ReactElement {
|
|
74
|
+
return (
|
|
75
|
+
<span className={styles.pvCode} data-ab-part="preview-code">
|
|
76
|
+
{lines.map((l, i) => {
|
|
77
|
+
const dim = l.startsWith('~'); // 🌫️
|
|
78
|
+
const text = dim ? l.slice(1).replace(/^ +/, (m) => '\u00a0'.repeat(m.length)) : l; // ␣ keep the indent
|
|
79
|
+
return <span key={i} className={dim ? styles.pvDim : undefined}>{codeLine(text)}</span>;
|
|
80
|
+
})}
|
|
81
|
+
</span>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 🧩 Components tile: a mini button, an on switch and a pill chip, intrinsic size (no stretch), centred both ways. */
|
|
86
|
+
export function AbPackagePreviewComponents({ button = 'Button', chip = 'Chip' }: { button?: string; chip?: string }): ReactElement {
|
|
87
|
+
return (
|
|
88
|
+
<span className={styles.pvComp} data-ab-part="preview-components">
|
|
89
|
+
<span className={styles.pvBtn}>{button}</span> {/* 🔘 6px radius (kept) */}
|
|
90
|
+
<span className={styles.pvSw}><i /></span> {/* 🎚️ on */}
|
|
91
|
+
<span className={styles.pvChip}>{chip}</span> {/* 💊 pill */}
|
|
92
|
+
</span>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -79,3 +79,24 @@
|
|
|
79
79
|
.homeFoot { margin-top: 8px; }
|
|
80
80
|
}
|
|
81
81
|
@media (prefers-reduced-motion: reduce) { .home:hover { transform: none; } } /* ♿ no lift */
|
|
82
|
+
|
|
83
|
+
/* ===== 🖼️ 0.2.1 (God 02:44): Home preview tiles, John's mock `.pv-*` (theme tokens, fallbacks = the mock) ===== */
|
|
84
|
+
.homePreview > * { flex: none; } /* 🚫 no child stretches; the tile centres them both ways */
|
|
85
|
+
/* 〰️ Animations */
|
|
86
|
+
.pvAnim { position: relative; display: block; box-sizing: border-box; width: 100%; height: 100%; padding: 6px 10px; } /* 📐 */
|
|
87
|
+
.pvAnim svg { display: block; width: 100%; height: 44px; } /* 📏 */
|
|
88
|
+
.pvAx { stroke: var(--ab-color-border, rgb(92 64 48 / 0.13)); stroke-width: 1; } /* ➖ */
|
|
89
|
+
.pvCrv { fill: none; stroke: var(--ab-color-accent, #a67c52); stroke-width: 2.2; stroke-linecap: round; } /* 〰️ */
|
|
90
|
+
.pvDot { fill: var(--ab-color-accent, #a67c52); } /* 🔴 */
|
|
91
|
+
.pvDot2 { fill: var(--ab-color-faint, #807062); } /* ⚪ */
|
|
92
|
+
.pvEase { position: absolute; right: 10px; bottom: 6px; font: 500 9.5px/1 var(--ab-font-code, ui-monospace, monospace); color: var(--ab-color-faint, #807062); } /* 🏷️ */
|
|
93
|
+
/* 🪝🧱 Hooks / Core code */
|
|
94
|
+
.pvCode { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; justify-content: center; align-self: stretch; flex: 1 1 auto; padding: 0 12px; text-align: left; font: 500 11.5px/1.25 var(--ab-font-code, ui-monospace, monospace); color: var(--ab-color-muted, #6b5b50); } /* ⬅️ left-aligned */
|
|
95
|
+
.pvCode b { color: var(--ab-color-accent-text, #88603d); font-weight: 600; } /* 🖍️ keyword */
|
|
96
|
+
.pvDim { color: var(--ab-color-faint, #807062); } /* 🌫️ */
|
|
97
|
+
/* 🧩 Components */
|
|
98
|
+
.pvComp { display: inline-flex; align-items: center; justify-content: center; gap: 8px; } /* 🎯 */
|
|
99
|
+
.pvBtn { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 6px; background: var(--ab-color-btn, #8b6340); color: var(--ab-color-btn-text, #fff); font-size: 10.5px; font-weight: 650; } /* 🔘 */
|
|
100
|
+
.pvSw { position: relative; display: inline-block; width: 30px; height: 17px; border-radius: 999px; background: var(--ab-color-accent, #a67c52); } /* 🎚️ */
|
|
101
|
+
.pvSw i { position: absolute; right: 2px; top: 2px; width: 13px; height: 13px; border-radius: 50%; background: var(--ab-color-card, #fff); } /* ⚪ knob */
|
|
102
|
+
.pvChip { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 999px; border: 1px solid var(--ab-color-border, rgb(92 64 48 / 0.13)); background: var(--ab-color-card, #fff); color: var(--ab-color-text, #211a16); font-size: 10.5px; font-weight: 600; } /* 💊 */
|
|
@@ -0,0 +1,105 @@
|
|
|
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: AbProfileAvatar (0.2.1)
|
|
28
|
+
* @file: ab-profile-avatar/index.tsx
|
|
29
|
+
* @type: React Component (no hooks: client + server)
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*
|
|
32
|
+
* Example usage:
|
|
33
|
+
* <AbProfileAvatar user={{ name: 'Abraham Ukachi' }} /> // → "AU" in a container-coloured circle
|
|
34
|
+
* <AbProfileAvatar user={{ name: 'Abraham Ukachi', image: '/me.jpg' }} size={44} />
|
|
35
|
+
* <AbProfileAvatar /> // 👤 signed out: the profile glyph
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
40
|
+
* MOTTO: We'll always do more 😜!!!
|
|
41
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
// ⚛️ React
|
|
45
|
+
import type { ComponentType, ReactElement } from 'react';
|
|
46
|
+
// 🧵 classes
|
|
47
|
+
import clsx from 'clsx';
|
|
48
|
+
// 🎨 styles
|
|
49
|
+
import styles from './styles.module.css';
|
|
50
|
+
|
|
51
|
+
/** 👤 who is signed in (omit / null = signed out) */
|
|
52
|
+
export interface AbProfileUser {
|
|
53
|
+
name: string; // 🏷️ "Abraham Ukachi"
|
|
54
|
+
image?: string; // 🖼️ photo URL (masked to a circle)
|
|
55
|
+
initials?: string; // 🔤 override the computed initials
|
|
56
|
+
email?: string; // ✉️ shown by AbSettingsDrawer's account row
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 🔣 what the avatar needs from an icon component (client and server AbIcon both fit) */
|
|
60
|
+
export type AbProfileIconComponent = ComponentType<{ name: string; size?: number; className?: string }>;
|
|
61
|
+
|
|
62
|
+
/** ⚙️ props */
|
|
63
|
+
export interface AbProfileAvatarProps {
|
|
64
|
+
user?: AbProfileUser | null; // 👤
|
|
65
|
+
size?: number; // 📏 px (default 40)
|
|
66
|
+
icon?: string; // 🔣 signed-out glyph (default "person", the bottom nav's Profile)
|
|
67
|
+
Icon?: AbProfileIconComponent; // 🔣 the icon component (pass AbIcon; without it the Material ligature is used)
|
|
68
|
+
className?: string; // 🏷️
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 🔤 "Abraham Ukachi" → "AU" (first + last word, max 2 letters, upper case) */
|
|
72
|
+
export function getAbInitials(name: string): string {
|
|
73
|
+
const words = name.trim().split(/\s+/).filter(Boolean); // ✂️ the words
|
|
74
|
+
if (!words.length) return ''; // 🚫 nothing
|
|
75
|
+
const first = words[0][0] ?? ''; // 🅰️
|
|
76
|
+
const last = words.length > 1 ? words[words.length - 1][0] ?? '' : ''; // 🅱️
|
|
77
|
+
return (first + last).toUpperCase(); // 🔠
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 👤 AbProfileAvatar — a decorative (aria-hidden) circle: the photo masked to a circle (overflow hidden), else the
|
|
82
|
+
* initials on the container colour, else (signed out) the profile glyph. The surrounding control names it.
|
|
83
|
+
* (AbAvatar is a link with a next/image and an online dot, so it doesn't fit inside a button.)
|
|
84
|
+
*/
|
|
85
|
+
const AbProfileAvatar = ({ user, size = 40, icon = 'person', Icon, className }: AbProfileAvatarProps): ReactElement => {
|
|
86
|
+
const kind = user ? (user.image ? 'image' : 'initials') : 'icon'; // 🧭 what we show
|
|
87
|
+
return (
|
|
88
|
+
<span
|
|
89
|
+
className={clsx('AbProfileAvatar', styles.abProfileAvatar, className)} // 🏷️
|
|
90
|
+
data-ab-part="profile-avatar" // 🧩
|
|
91
|
+
data-kind={kind} // 🧭
|
|
92
|
+
style={{ width: size, height: size, fontSize: Math.round(size * 0.38) }} // 📏 initials scale with the circle
|
|
93
|
+
aria-hidden="true" // ♿ decorative
|
|
94
|
+
>
|
|
95
|
+
{/* eslint-disable-next-line @next/next/no-img-element -- 🖼️ a tiny avatar; the package must not require next/image's loader config in consumer apps */}
|
|
96
|
+
{kind === 'image' && <img src={user!.image} alt="" className={styles.abProfileAvatarImage} width={size} height={size} /> /* 🖼️ */}
|
|
97
|
+
{kind === 'initials' && <span className={styles.abProfileAvatarInitials}>{user!.initials ?? getAbInitials(user!.name)}</span> /* 🔤 */}
|
|
98
|
+
{kind === 'icon' && (Icon ? <Icon name={icon} size={Math.round(size * 0.55)} /> : <span className="material-symbols-rounded">{icon}</span>) /* 👤 */}
|
|
99
|
+
</span>
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// 📦 exports
|
|
104
|
+
export default AbProfileAvatar;
|
|
105
|
+
export { AbProfileAvatar };
|
|
@@ -0,0 +1,53 @@
|
|
|
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: AbProfileAvatar - Styles (0.2.1)
|
|
28
|
+
* @file: ab-profile-avatar/styles.module.css
|
|
29
|
+
* @type: CSS Module
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
36
|
+
* MOTTO: We'll always do more 😜!!!
|
|
37
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/* 👤 the circle: container colour, clipped */
|
|
41
|
+
.abProfileAvatar {
|
|
42
|
+
display: inline-grid; /* 📐 */
|
|
43
|
+
place-items: center; /* 🎯 */
|
|
44
|
+
flex: none; /* 🚫 never squashed */
|
|
45
|
+
box-sizing: border-box; /* 📦 */
|
|
46
|
+
border-radius: 50%; /* ⭕ */
|
|
47
|
+
overflow: hidden; /* ✂️ the photo mask */
|
|
48
|
+
background: var(--ab-color-tint, rgb(166 124 82 / 0.14)); /* 🎨 the container colour */
|
|
49
|
+
color: var(--ab-color-accent-text, #88603d); /* 🖋️ */
|
|
50
|
+
}
|
|
51
|
+
.abProfileAvatar[data-kind='icon'] { background: var(--ab-color-card2, #fbf3ec); color: var(--ab-color-muted, #6b5b50); } /* 👤 signed out */
|
|
52
|
+
.abProfileAvatarImage { width: 100%; height: 100%; object-fit: cover; display: block; } /* 🖼️ fills the circle */
|
|
53
|
+
.abProfileAvatarInitials { font: 700 1em/1 var(--ab-font-body, 'Inter', inherit); letter-spacing: 0.02em; } /* 🔤 */
|
|
@@ -0,0 +1,279 @@
|
|
|
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: AbSearchDrawer
|
|
28
|
+
* @file: ab-search-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
|
+
* -|> <AbSearchTrigger variant="field" label="Search…" onOpen={() => setOpen(true)} hotkey={false} />
|
|
35
|
+
* -|> <AbSearchDrawer open={open} onClose={() => setOpen(false)} search={(q) => index.query(q)} />
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
40
|
+
* MOTTO: We'll always do more 😜!!!
|
|
41
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
'use client';
|
|
46
|
+
|
|
47
|
+
// ⚛️ React
|
|
48
|
+
import { useEffect, useId, useMemo, useRef, useState, type KeyboardEvent, type ReactElement, type ReactNode } from 'react';
|
|
49
|
+
// 🧵 classes
|
|
50
|
+
import clsx from 'clsx';
|
|
51
|
+
// 🗄️ the drawer (fullOnly sheet on mobile, centred on laptop)
|
|
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 drawers v2 kit
|
|
58
|
+
import kit from '../ab-drawer/kit.module.css';
|
|
59
|
+
|
|
60
|
+
/** 🔎 one result row */
|
|
61
|
+
export interface AbSearchDrawerItem {
|
|
62
|
+
id: string; // 🆔 unique across all groups
|
|
63
|
+
href: string; // 🔗 where it opens
|
|
64
|
+
title: string; // 🏷️ e.g. "AbButton"
|
|
65
|
+
description?: string; // 📝 one line (ellipsis)
|
|
66
|
+
meta?: string; // 🏷️ mono, e.g. "v0.2.x"
|
|
67
|
+
icon?: string; // 🔣 the 32px tile's AbIcons name
|
|
68
|
+
}
|
|
69
|
+
/** 📦 results grouped by package */
|
|
70
|
+
export interface AbSearchDrawerGroup { id: string; label: string; meta?: string; items: readonly AbSearchDrawerItem[] } // 🏷️ "Components" + "ab-nextjs-components"
|
|
71
|
+
|
|
72
|
+
/** 🌍 strings (English defaults) */
|
|
73
|
+
export interface AbSearchDrawerLabels {
|
|
74
|
+
title?: string; // "Search"
|
|
75
|
+
close?: string; // "Close search"
|
|
76
|
+
placeholder?: string; // "Search packages, components, hooks…"
|
|
77
|
+
clear?: string; // "Clear search"
|
|
78
|
+
recent?: string; // "Recent"
|
|
79
|
+
remove?: (term: string) => string; // "Remove <term>"
|
|
80
|
+
results?: (n: number) => string; // "4 results"
|
|
81
|
+
noResults?: string; // "No results"
|
|
82
|
+
noResultsFor?: (q: string) => ReactNode; // No results for “q”
|
|
83
|
+
hint?: ReactNode; // the line under it
|
|
84
|
+
didYouMean?: string; // "Did you mean"
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** ⚙️ props */
|
|
88
|
+
export interface AbSearchDrawerProps {
|
|
89
|
+
open: boolean; // 🚪
|
|
90
|
+
onClose: () => void; // ⎋
|
|
91
|
+
search: (query: string) => readonly AbSearchDrawerGroup[] | Promise<readonly AbSearchDrawerGroup[]>; // 🔎 called 150ms after typing stops, from 2 characters
|
|
92
|
+
suggest?: (query: string) => string | null | undefined; // 💡 the "Did you mean …?" term on no results
|
|
93
|
+
onOpenResult?: (item: AbSearchDrawerItem) => void; // 🔔 after a result is chosen (the link still navigates; the drawer closes)
|
|
94
|
+
defaultQuery?: string; // 🌱 the query on open (default '')
|
|
95
|
+
recentKey?: string | null; // 🕘 localStorage key (default `ab:search:recent`; null = no recents)
|
|
96
|
+
recentLimit?: number; // 🕘 default 4
|
|
97
|
+
recentWhen?: 'always' | 'empty'; // 🕘 'always' = above the results (John's frames, default); 'empty' = only with no query
|
|
98
|
+
labels?: AbSearchDrawerLabels; // 🌍
|
|
99
|
+
returnFocus?: string; // ↩️
|
|
100
|
+
id?: string; // 🆔
|
|
101
|
+
className?: string; // 🏷️
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 🕘 recents in localStorage: newest first, de-duplicated, capped
|
|
105
|
+
export const AB_SEARCH_RECENT_KEY = 'ab:search:recent';
|
|
106
|
+
const readRecent = (key: string | null): string[] => {
|
|
107
|
+
if (!key || typeof localStorage === 'undefined') return [];
|
|
108
|
+
try { const v = JSON.parse(localStorage.getItem(key) ?? '[]'); return Array.isArray(v) ? v.filter((x): x is string => typeof x === 'string') : []; } catch { return []; } // 🧯 bad JSON = none
|
|
109
|
+
};
|
|
110
|
+
const writeRecent = (key: string | null, list: string[]) => { if (key && typeof localStorage !== 'undefined') try { localStorage.setItem(key, JSON.stringify(list)); } catch { /* 🧯 private mode */ } };
|
|
111
|
+
/** 🕘 addAbSearchRecent — the next recents list: `term` first, no duplicates (case-insensitive), at most `limit` */
|
|
112
|
+
export function addAbSearchRecent(list: readonly string[], term: string, limit = 4): string[] {
|
|
113
|
+
const t = term.trim(); if (!t) return [...list];
|
|
114
|
+
return [t, ...list.filter((x) => x.toLowerCase() !== t.toLowerCase())].slice(0, limit);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** 🖍️ highlightAbSearch — wrap every case-insensitive match of `q` in `<mark>` (bronze 700 via the kit) */
|
|
118
|
+
export function highlightAbSearch(text: string, q: string): ReactNode {
|
|
119
|
+
const needle = q.trim(); if (needle.length < 2) return text;
|
|
120
|
+
const out: ReactNode[] = []; const lower = text.toLowerCase(); const n = needle.toLowerCase();
|
|
121
|
+
let i = 0; let k = 0;
|
|
122
|
+
for (let j = lower.indexOf(n); j >= 0; j = lower.indexOf(n, i)) {
|
|
123
|
+
if (j > i) out.push(text.slice(i, j));
|
|
124
|
+
out.push(<mark key={k++} className={kit.mark}>{text.slice(j, j + n.length)}</mark>); i = j + n.length;
|
|
125
|
+
}
|
|
126
|
+
if (i < text.length) out.push(text.slice(i));
|
|
127
|
+
return out.length ? out : text;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 🔎 AbSearchDrawer — John's search drawer (drawers v2 §4), a bottom-drawer variant.
|
|
132
|
+
*
|
|
133
|
+
* - 📱 below 768px: straight to full height (no 70% stop: the keyboard is up); a hard swipe down closes
|
|
134
|
+
* - 💻 768px and up: centred in the main pane, min(640px, main width), 70% tall; results scroll inside with a 48px fade
|
|
135
|
+
* - ⌨️ no shortcut key: open it from the Search tab / the search field (AbSearchTrigger `onOpen` + `hotkey={false}`)
|
|
136
|
+
* - 🔤 48px input (2px bronze border), autofocused; a 40px clear button keeps focus in the input
|
|
137
|
+
* - 🕘 up to 4 recent searches (localStorage `ab:search:recent`), saved on Enter or when a result opens; each removable
|
|
138
|
+
* - 📦 results after a 150ms debounce from 2 characters, grouped by package; matches in a bronze `<mark>`
|
|
139
|
+
* - ♿ combobox (aria-expanded / -controls / -autocomplete="list" / -activedescendant) + listbox with labelled groups
|
|
140
|
+
* and options; ↑/↓ wrap across groups, Enter opens the active (else the first) result, Esc clears then closes;
|
|
141
|
+
* a polite live region says "4 results" / "No results"
|
|
142
|
+
*/
|
|
143
|
+
const AbSearchDrawer = ({ open, onClose, search, suggest, onOpenResult, defaultQuery = '', recentKey = AB_SEARCH_RECENT_KEY, recentLimit = 4, recentWhen = 'always', labels = {}, returnFocus, id, className }: AbSearchDrawerProps): ReactElement => {
|
|
144
|
+
const L = {
|
|
145
|
+
title: 'Search', close: 'Close search', placeholder: 'Search packages, components, hooks…', clear: 'Clear search', recent: 'Recent',
|
|
146
|
+
remove: (t: string) => `Remove ${t}`, results: (n: number) => `${n} result${n === 1 ? '' : 's'}`, noResults: 'No results',
|
|
147
|
+
noResultsFor: (q: string) => <>No results for “{q}”</>, didYouMean: 'Did you mean',
|
|
148
|
+
hint: <>Check the spelling or try a package name like <code>components</code> or <code>hooks</code>.</>, ...labels,
|
|
149
|
+
}; // 🌍
|
|
150
|
+
const auto = useId().replace(/[^A-Za-z0-9_-]/g, ''); // 🆔
|
|
151
|
+
const base = id ?? `ab-search-${auto}`;
|
|
152
|
+
// 🆔 James P2: group ids come from app data ("@scope/pkg", "a b"); keep only id-safe characters, and the index keeps them unique
|
|
153
|
+
const groupId = (g: AbSearchDrawerGroup, i: number) => `${base}-g-${i}-${String(g.id).replace(/[^A-Za-z0-9_-]/g, '_')}`;
|
|
154
|
+
const input = useRef<HTMLInputElement>(null); // 🔤
|
|
155
|
+
const list = useRef<HTMLDivElement>(null); // 📜
|
|
156
|
+
const [query, setQuery] = useState(defaultQuery); // 🔤
|
|
157
|
+
const [groups, setGroups] = useState<readonly AbSearchDrawerGroup[] | null>(null); // 📦 null = not searched (or < 2 chars)
|
|
158
|
+
const [active, setActive] = useState(0); // 🎯 index in the flat option list (-1 = none)
|
|
159
|
+
const [recent, setRecent] = useState<string[]>([]); // 🕘
|
|
160
|
+
const latest = useRef(search); // 🔁
|
|
161
|
+
useEffect(() => { latest.current = search; }, [search]);
|
|
162
|
+
|
|
163
|
+
// 🌱 each open: the default query, fresh recents
|
|
164
|
+
const [wasOpen, setWasOpen] = useState(false);
|
|
165
|
+
if (open !== wasOpen) { setWasOpen(open); if (open) { setQuery(defaultQuery); setRecent(readRecent(recentKey)); } }
|
|
166
|
+
|
|
167
|
+
// ⏱️ 150ms debounce, from 2 characters; stale answers are dropped
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
const q = query.trim();
|
|
170
|
+
if (!open || q.length < 2) { const t = setTimeout(() => setGroups(null), 0); return () => clearTimeout(t); } // 🫥
|
|
171
|
+
let live = true;
|
|
172
|
+
const t = setTimeout(() => {
|
|
173
|
+
Promise.resolve().then(() => latest.current(q)) // 🧯 a sync throw becomes a rejection too
|
|
174
|
+
.then((g) => { if (live) { setGroups(g); setActive(g.some((x) => x.items.length) ? 0 : -1); } })
|
|
175
|
+
.catch(() => { if (live) { setGroups([]); setActive(-1); } }); // 🧯 James P2: a failed search shows "no results", never the previous query's results
|
|
176
|
+
}, 150);
|
|
177
|
+
return () => { live = false; clearTimeout(t); };
|
|
178
|
+
}, [query, open]);
|
|
179
|
+
|
|
180
|
+
const flat = useMemo(() => (groups ?? []).flatMap((g) => g.items), [groups]); // 📋 the option order
|
|
181
|
+
const starts = useMemo(() => { const m: Record<string, number> = {}; let n = 0; for (const g of groups ?? []) { m[g.id] = n; n += g.items.length; } return m; }, [groups]); // 🔢 each group's first option index
|
|
182
|
+
const optId = (i: number) => `${base}-opt-${i}`; // 🆔
|
|
183
|
+
const showRecent = recentKey !== null && recent.length > 0 && (recentWhen === 'always' ? !(groups && flat.length === 0) : query.trim() === ''); // 🕘
|
|
184
|
+
const expanded = flat.length > 0; // ♿ the listbox has options
|
|
185
|
+
const saveRecent = (term: string) => { const next = addAbSearchRecent(recent, term, recentLimit); setRecent(next); writeRecent(recentKey, next); }; // 🕘
|
|
186
|
+
const removeRecent = (term: string) => { const next = recent.filter((x) => x !== term); setRecent(next); writeRecent(recentKey, next); input.current?.focus(); };
|
|
187
|
+
const choose = (item: AbSearchDrawerItem) => { saveRecent(query); onOpenResult?.(item); onClose(); }; // 🔗
|
|
188
|
+
|
|
189
|
+
// ⌨️ the combobox keys (focus stays in the input)
|
|
190
|
+
const onKey = (e: KeyboardEvent<HTMLInputElement>) => {
|
|
191
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
192
|
+
if (!flat.length) return; e.preventDefault();
|
|
193
|
+
const n = e.key === 'ArrowDown' ? (active + 1) % flat.length : (active - 1 + flat.length) % flat.length; // 🔁 wraps across groups
|
|
194
|
+
setActive(n);
|
|
195
|
+
const el = document.getElementById(optId(n)); const box = list.current; // 👀 keep it in view, scrolling only the results
|
|
196
|
+
if (el && box) { const b = box.getBoundingClientRect(); const r = el.getBoundingClientRect(); if (r.bottom > b.bottom) box.scrollTop += r.bottom - b.bottom; else if (r.top < b.top) box.scrollTop -= b.top - r.top; }
|
|
197
|
+
} else if (e.key === 'Enter') {
|
|
198
|
+
e.preventDefault(); if (query.trim()) saveRecent(query); // 🕘
|
|
199
|
+
const i = active >= 0 ? active : 0; if (flat[i]) document.getElementById(optId(i))?.click(); // 🔗 the active, else the first
|
|
200
|
+
} else if (e.key === 'Escape' && query) {
|
|
201
|
+
e.preventDefault(); setQuery(''); // ⎋ first press clears (AbDrawer skips handled Escapes), the second closes
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const none = groups !== null && flat.length === 0; // 🫥
|
|
206
|
+
const tip = suggest && none ? suggest(query.trim()) : null; // 💡
|
|
207
|
+
return (
|
|
208
|
+
<AbDrawer
|
|
209
|
+
open={open} onClose={onClose} id={id} side="bottom" scope="app" tier="sheet"
|
|
210
|
+
snapPoints fullOnly centerIn="main" title={L.title} closeLabel={L.close} closeIcon={<AbIcon name="close" size={24} />}
|
|
211
|
+
initialFocus="input" returnFocus={returnFocus}
|
|
212
|
+
className={clsx('AbSearchDrawer', kit.sheet, kit.searchSheet, className)}
|
|
213
|
+
>
|
|
214
|
+
<div className={kit.searchBody}>
|
|
215
|
+
<div className={kit.field}>
|
|
216
|
+
<AbIcon name="search" size={22} />
|
|
217
|
+
<input
|
|
218
|
+
ref={input} type="search" className={kit.input} value={query} placeholder={L.placeholder} aria-label={L.title}
|
|
219
|
+
role="combobox" aria-expanded={expanded} aria-controls={`${base}-list`} aria-autocomplete="list"
|
|
220
|
+
aria-activedescendant={expanded && active >= 0 ? optId(active) : undefined}
|
|
221
|
+
autoComplete="off" autoCorrect="off" spellCheck={false} enterKeyHint="search"
|
|
222
|
+
onChange={(e) => setQuery(e.target.value)} onKeyDown={onKey}
|
|
223
|
+
/>
|
|
224
|
+
{query && <button type="button" className={kit.iconSm} aria-label={L.clear} onClick={() => { setQuery(''); input.current?.focus(); }}><AbIcon name="close" size={20} /></button>}
|
|
225
|
+
</div>
|
|
226
|
+
<div className={kit.resWrap}>
|
|
227
|
+
<div ref={list} className={kit.results} data-ab-part="search-results">
|
|
228
|
+
{showRecent && (
|
|
229
|
+
<>
|
|
230
|
+
<p className={kit.lbl} id={`${base}-recent`}>{L.recent}</p>
|
|
231
|
+
<ul className={kit.list} aria-labelledby={`${base}-recent`}>
|
|
232
|
+
{recent.map((t) => (
|
|
233
|
+
<li key={t} className={clsx(kit.row, kit.recent)}>
|
|
234
|
+
<AbIcon name="history" size={24} />
|
|
235
|
+
<button type="button" className={kit.recentGo} onClick={() => { setQuery(t); input.current?.focus(); }}>{t}</button>
|
|
236
|
+
<button type="button" className={kit.iconSm} aria-label={L.remove(t)} onClick={() => removeRecent(t)}><AbIcon name="close" size={20} /></button>
|
|
237
|
+
</li>
|
|
238
|
+
))}
|
|
239
|
+
</ul>
|
|
240
|
+
{flat.length > 0 && <hr className={kit.hr} />}
|
|
241
|
+
</>
|
|
242
|
+
)}
|
|
243
|
+
<div id={`${base}-list`} role="listbox" aria-label={L.title} hidden={!expanded}>
|
|
244
|
+
{(groups ?? []).filter((g) => g.items.length).map((g, gi) => (
|
|
245
|
+
<div key={g.id} role="group" aria-labelledby={groupId(g, gi)}>
|
|
246
|
+
<p className={kit.grp2} id={groupId(g, gi)}><span>{g.label}</span>{g.meta && <code>{g.meta}</code>}</p>
|
|
247
|
+
{g.items.map((it, j) => {
|
|
248
|
+
const i = starts[g.id] + j; const on = i === active; // 🎯
|
|
249
|
+
return (
|
|
250
|
+
<Link key={it.id} id={optId(i)} href={it.href} role="option" aria-selected={on} tabIndex={-1} className={kit.sr} onClick={() => choose(it)} onMouseMove={() => { if (!on) setActive(i); }}>
|
|
251
|
+
<span className={kit.pkgIc} aria-hidden="true">{it.icon && <AbIcon name={it.icon} size={20} />}</span>
|
|
252
|
+
<span className={kit.srText}><b>{highlightAbSearch(it.title, query)}</b>{it.description && <small>{highlightAbSearch(it.description, query)}</small>}</span>
|
|
253
|
+
{it.meta && <code className={kit.srMeta}>{it.meta}</code>}
|
|
254
|
+
</Link>
|
|
255
|
+
);
|
|
256
|
+
})}
|
|
257
|
+
</div>
|
|
258
|
+
))}
|
|
259
|
+
</div>
|
|
260
|
+
{none && (
|
|
261
|
+
<div className={kit.nores} data-ab-part="search-empty">
|
|
262
|
+
<span className={kit.pkgIc} aria-hidden="true"><AbIcon name="search" size={28} /></span>
|
|
263
|
+
<b>{L.noResultsFor(query.trim())}</b>
|
|
264
|
+
<p>{L.hint}</p>
|
|
265
|
+
{tip && <button type="button" className={clsx(kit.row, kit.didYouMean)} onClick={() => { setQuery(tip); input.current?.focus(); }}>{L.didYouMean} <mark className={kit.mark}>{tip}</mark>?</button>}
|
|
266
|
+
</div>
|
|
267
|
+
)}
|
|
268
|
+
</div>
|
|
269
|
+
<div className={kit.resFade} aria-hidden="true" />
|
|
270
|
+
</div>
|
|
271
|
+
<p className={kit.srOnly} role="status" aria-live="polite">{groups === null ? '' : none ? L.noResults : L.results(flat.length)}</p>
|
|
272
|
+
</div>
|
|
273
|
+
</AbDrawer>
|
|
274
|
+
);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// 📦 exports
|
|
278
|
+
export default AbSearchDrawer;
|
|
279
|
+
export { AbSearchDrawer };
|
|
@@ -64,6 +64,9 @@ export interface AbSearchTriggerProps {
|
|
|
64
64
|
comingSoon?: boolean; // 🚧 visible but inert: aria-disabled, no hotkey
|
|
65
65
|
comingSoonLabel?: string; // 🏷️ default "Coming soon"
|
|
66
66
|
variant?: 'pill' | 'field'; // 🔎 0.1.14 (P6): 'field' = the Home 300×36 bordered field (default 'pill', the legacy look)
|
|
67
|
+
/** 📱 0.1.15 (God 00:08): a shorter label (e.g. "Search") that a compact AbAppBar shows below 768px instead of `label`
|
|
68
|
+
* (CSS picks; only one is ever displayed, so the accessible name stays single). Home field only. */
|
|
69
|
+
compactLabel?: string;
|
|
67
70
|
size?: 'md' | 'sm'; // 📱 0.1.14 (P6): 'sm' = the mobile 34px "Search ⌘K" pill (label + key cap stay visible)
|
|
68
71
|
className?: string; // 🏷️
|
|
69
72
|
}
|
|
@@ -82,7 +85,7 @@ export function isAbApplePlatform(nav?: { platform?: string; userAgent?: string;
|
|
|
82
85
|
* announces `aria-keyshortcuts="Meta+K Control+K"`, and falls back to a link when there's no `onOpen`.
|
|
83
86
|
* Note: the hotkey is a local listener; G48 `useAbHotkey` is deliberately not in hooks 0.1.7.
|
|
84
87
|
*/
|
|
85
|
-
const AbSearchTrigger = ({ label = 'Search', onOpen, href, hotkey, shortcut, compact = false, comingSoon = false, comingSoonLabel = 'Coming soon', variant = 'pill', size = 'md', className }: AbSearchTriggerProps): ReactElement => {
|
|
88
|
+
const AbSearchTrigger = ({ label = 'Search', onOpen, href, hotkey, shortcut, compact = false, comingSoon = false, comingSoonLabel = 'Coming soon', compactLabel, variant = 'pill', size = 'md', className }: AbSearchTriggerProps): ReactElement => {
|
|
86
89
|
// 🍎 SSR renders "Ctrl"; hydration then reads the platform (useSyncExternalStore: no mismatch, no effect)
|
|
87
90
|
const apple = useSyncExternalStore(
|
|
88
91
|
noopSubscribe, // 🔕 the platform never changes
|
|
@@ -105,12 +108,14 @@ const AbSearchTrigger = ({ label = 'Search', onOpen, href, hotkey, shortcut, com
|
|
|
105
108
|
|
|
106
109
|
// 🏠 P6: the Home looks (field / sm pill) show ONE key cap ("⌘ K" / "⌘K") and keep "coming soon" out of the field
|
|
107
110
|
const home = variant === 'field' || size === 'sm';
|
|
108
|
-
|
|
111
|
+
// ⌨️ mock: "⌘ K" (field) · "⌘K" (sm). The gap is its own span so a compact app bar can drop it (0.1.15)
|
|
112
|
+
const keyCap = <>{apple ? '⌘' : 'Ctrl'}{size === 'sm' ? null : <span data-ab-part="key-gap"> </span>}K</>;
|
|
109
113
|
// 🧩 inner content
|
|
110
114
|
const inner = home ? (
|
|
111
115
|
<>
|
|
112
116
|
<AbIcon name="search" size={size === 'sm' ? 17 : 18} className={styles.abSearchTriggerIcon} />
|
|
113
|
-
<span className={styles.abSearchTriggerLabel}>{label}</span>
|
|
117
|
+
<span className={styles.abSearchTriggerLabel} data-ab-part="search-label">{label}</span>
|
|
118
|
+
{compactLabel != null && <span className={clsx(styles.abSearchTriggerLabel, styles.abSearchTriggerShort)} data-ab-part="search-label-compact">{compactLabel}</span> /* 📱 0.1.15 */}
|
|
114
119
|
{/* 🚧 coming soon: tooltip + announced, never painted inside the field (spec §4) */}
|
|
115
120
|
{comingSoon ? <span className={styles.abSearchTriggerSrOnly}>, {comingSoonLabel}</span> : listen && <AbKbd className={styles.abSearchTriggerCap}>{keyCap}</AbKbd>}
|
|
116
121
|
</>
|
|
@@ -94,3 +94,6 @@
|
|
|
94
94
|
}
|
|
95
95
|
.abSearchTrigger[data-size='sm'] .abSearchTriggerCap { min-width: 18px; height: 18px; font-size: 10px; } /* 📱 */
|
|
96
96
|
.abSearchTrigger[data-variant='field'][aria-disabled='true'], .abSearchTrigger[data-size='sm'][aria-disabled='true'] { opacity: 1; } /* 🚧 the Home field looks the same while search is coming soon (the tooltip says so) */
|
|
97
|
+
|
|
98
|
+
/* 📱 0.1.15: the short label is hidden unless a compact AbAppBar (< 768px) swaps it in */
|
|
99
|
+
.abSearchTriggerShort { display: none; }
|