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,100 @@
|
|
|
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: AbMobileHeader
|
|
28
|
+
* @file: ab-mobile-header/index.tsx
|
|
29
|
+
* @type: Client component
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*
|
|
32
|
+
* Example usage:
|
|
33
|
+
* 1+|> <AbAppLayout variant="panes" mobileHeader="main" content={<AbMainLayout
|
|
34
|
+
* -|> mainHeader={<AbMobileHeader logo={<a href="/" id="home-logo">…</a>} onLanguage={openLanguage}
|
|
35
|
+
* -|> theme={mode} onThemeChange={setMode} />} … />} />
|
|
36
|
+
*
|
|
37
|
+
* 📌 Requires ab-nextjs-core ≥ 0.2.1 with `mobileHeader="main"` on AbAppLayout. That hides the app header below
|
|
38
|
+
* 768px and turns the main header slot into this 56px bar; older core shows it inside the normal main header.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
43
|
+
* MOTTO: We'll always do more 😜!!!
|
|
44
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
'use client';
|
|
49
|
+
|
|
50
|
+
// ⚛️ React
|
|
51
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
52
|
+
// 🧵 classes
|
|
53
|
+
import clsx from 'clsx';
|
|
54
|
+
// 🔣 icons
|
|
55
|
+
import AbIcon from '../ab-icon';
|
|
56
|
+
// 🎨 the drawers v2 kit
|
|
57
|
+
import kit from '../ab-drawer/kit.module.css';
|
|
58
|
+
|
|
59
|
+
/** ⚙️ props */
|
|
60
|
+
export interface AbMobileHeaderProps {
|
|
61
|
+
logo: ReactNode; // 🏷️ the logoname (22px), usually a link home: the focus target after a swipe-opened drawer closes
|
|
62
|
+
onLanguage?: () => void; // 🌍 the globe: open the Settings sheet with the language list in view
|
|
63
|
+
theme?: 'light' | 'dark'; // 🌗 the resolved theme now
|
|
64
|
+
onThemeChange?: (next: 'light' | 'dark') => void; // 🌗 the toggle (it shows the mode it switches TO: a moon in light)
|
|
65
|
+
actions?: ReactNode; // ➕ more 44px buttons after the two (none in John's frame)
|
|
66
|
+
labels?: { language?: string; toDark?: string; toLight?: string; header?: string }; // 🌍 "Change language", "Switch to dark theme", "Switch to light theme", "Main header"
|
|
67
|
+
languageExpanded?: boolean; // ♿ aria-expanded on the globe while its sheet is open
|
|
68
|
+
className?: string; // 🏷️
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 📱 AbMobileHeader — John's mobile main header (drawers v2): logo left; a globe ("Change language",
|
|
73
|
+
* `aria-haspopup="dialog"`) and a theme toggle right, each 44×44. No search (the bottom nav has a Search tab) and
|
|
74
|
+
* no menu button (the left drawer opens with an edge swipe). Put it in AbMainLayout's `mainHeader` with core
|
|
75
|
+
* ≥ 0.2.1 `mobileHeader="main"`: the 56px row, its divider and the hidden app header come from core.
|
|
76
|
+
*/
|
|
77
|
+
const AbMobileHeader = ({ logo, onLanguage, theme = 'light', onThemeChange, actions, labels = {}, languageExpanded, className }: AbMobileHeaderProps): ReactElement => {
|
|
78
|
+
const L = { language: 'Change language', toDark: 'Switch to dark theme', toLight: 'Switch to light theme', header: 'Main header', ...labels }; // 🌍
|
|
79
|
+
const next = theme === 'dark' ? 'light' : 'dark'; // 🌗 the target
|
|
80
|
+
return (
|
|
81
|
+
<div className={clsx('AbMobileHeader', kit.mh, className)} role="group" aria-label={L.header} data-ab-part="mobile-header">
|
|
82
|
+
<span className={kit.logoRow}>{logo}</span>
|
|
83
|
+
{onLanguage && (
|
|
84
|
+
<button type="button" className={kit.ibtn} aria-label={L.language} aria-haspopup="dialog" aria-expanded={languageExpanded} onClick={onLanguage} data-ab-part="mobile-header-language">
|
|
85
|
+
<AbIcon name="language" size={24} />
|
|
86
|
+
</button>
|
|
87
|
+
)}
|
|
88
|
+
{onThemeChange && (
|
|
89
|
+
<button type="button" className={kit.ibtn} aria-label={next === 'dark' ? L.toDark : L.toLight} onClick={() => onThemeChange(next)} data-ab-part="mobile-header-theme">
|
|
90
|
+
<AbIcon name={next === 'dark' ? 'dark_mode' : 'light_mode'} size={24} />
|
|
91
|
+
</button>
|
|
92
|
+
)}
|
|
93
|
+
{actions}
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// 📦 exports
|
|
99
|
+
export default AbMobileHeader;
|
|
100
|
+
export { AbMobileHeader };
|
|
@@ -0,0 +1,158 @@
|
|
|
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: AbNavDrawer
|
|
28
|
+
* @file: ab-nav-drawer/index.tsx
|
|
29
|
+
* @type: Client component
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*
|
|
32
|
+
* Example usage:
|
|
33
|
+
* 1+|> useAbEdgeSwipe({ edge: 'left', onOpen: () => setNav(true), enabled: !nav })
|
|
34
|
+
* -|> <AbNavDrawer open={nav} onClose={() => setNav(false)} logo={<AbLogo />} version="v0.2.x"
|
|
35
|
+
* -|> sections={[{ id: 'top', items: [{ href: '/', label: 'Home', icon: 'home' }] }]} activeHref="/"
|
|
36
|
+
* -|> footer={[{ href: '/changelog', label: 'Changelog', icon: 'history' }]} onSettings={openSettings} />
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
41
|
+
* MOTTO: We'll always do more 😜!!!
|
|
42
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
'use client';
|
|
47
|
+
|
|
48
|
+
// ⚛️ React
|
|
49
|
+
import type { MouseEvent, ReactElement, ReactNode } from 'react';
|
|
50
|
+
// 🧵 classes
|
|
51
|
+
import clsx from 'clsx';
|
|
52
|
+
// 🗄️ the drawer
|
|
53
|
+
import AbDrawer from '../ab-drawer';
|
|
54
|
+
// 🔣 icons
|
|
55
|
+
import AbIcon from '../ab-icon';
|
|
56
|
+
// 🔗 the app's link (AbLinkProvider: next/link, or a locale-aware one)
|
|
57
|
+
import Link from '../ab-link';
|
|
58
|
+
// 🎯 the same active rule as the laptop sidebar
|
|
59
|
+
import { isAbSidebarActive } from '../ab-sidebar/view';
|
|
60
|
+
// 🎨 the drawers v2 kit
|
|
61
|
+
import kit from '../ab-drawer/kit.module.css';
|
|
62
|
+
|
|
63
|
+
/** 🔗 one nav row */
|
|
64
|
+
export interface AbNavDrawerItem {
|
|
65
|
+
href: string; // 🔗
|
|
66
|
+
label: string; // 🏷️
|
|
67
|
+
icon?: string; // 🔣 an AbIcons name
|
|
68
|
+
meta?: string; // 🏷️ trailing mono text, e.g. a version
|
|
69
|
+
}
|
|
70
|
+
/** 🗂️ one group: an optional uppercase label (a heading for its list) + rows */
|
|
71
|
+
export interface AbNavDrawerSection { id: string; label?: string; items: readonly AbNavDrawerItem[] }
|
|
72
|
+
|
|
73
|
+
/** ⚙️ props */
|
|
74
|
+
export interface AbNavDrawerProps {
|
|
75
|
+
open: boolean; // 🚪
|
|
76
|
+
onClose: () => void; // ⎋ scrim, Esc, ✕, a swipe back, or choosing a link
|
|
77
|
+
logo: ReactNode; // 🏷️ the logoname (a link home, usually)
|
|
78
|
+
version?: ReactNode; // 🏷️ a string = the mono version chip ("v0.2.x ⌄"); or your own picker node
|
|
79
|
+
onVersionClick?: () => void; // 🔽 the chip as a button (e.g. open a version menu)
|
|
80
|
+
sections: readonly AbNavDrawerSection[]; // 🗂️ same content as the laptop sidebar
|
|
81
|
+
activeHref?: string; // 🎯 exact match or parent prefix ("/" only matches itself)
|
|
82
|
+
footer?: readonly AbNavDrawerItem[]; // 📌 pinned 48px rows (e.g. Changelog)
|
|
83
|
+
onSettings?: () => void; // ⚙️ adds a "Settings ›" row; close this drawer, then open the Settings sheet
|
|
84
|
+
onNavigate?: (href: string) => void; // 🔔 after a link is chosen (the drawer closes either way)
|
|
85
|
+
labels?: { title?: string; close?: string; settings?: string; version?: string }; // 🌍 "Site navigation", "Close navigation", "Settings", "Version"
|
|
86
|
+
returnFocus?: string; // ↩️ e.g. the main header logo link (where focus goes after a swipe-open)
|
|
87
|
+
id?: string; // 🆔
|
|
88
|
+
className?: string; // 🏷️
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* ⬅️ AbNavDrawer — John's left drawer (drawers v2 §2): the mobile sidebar.
|
|
93
|
+
*
|
|
94
|
+
* - 📐 320px, full height, 0 16 16 0 radius; header = logo + 44px ✕; the version chip; a scrolling nav
|
|
95
|
+
* (44px rows, uppercase group headings, a 72px fade); a pinned footer of 48px rows
|
|
96
|
+
* - 🤏 opens with `useAbEdgeSwipe({ edge: 'left' })`; closes with a right-to-left swipe on the sheet (AbDrawer `swipe`),
|
|
97
|
+
* the scrim, Esc, ✕, or choosing a link
|
|
98
|
+
* - ♿ `role="dialog"` + aria-modal, aria-label "Site navigation"; `aria-current="page"` on the active row; each
|
|
99
|
+
* group label is a heading that labels its list
|
|
100
|
+
* - 🥞 tier 'nav': in front of the right drawer, under the bottom sheet
|
|
101
|
+
*/
|
|
102
|
+
const AbNavDrawer = ({ open, onClose, logo, version, onVersionClick, sections, activeHref, footer = [], onSettings, onNavigate, labels = {}, returnFocus, id = 'ab-nav-drawer', className }: AbNavDrawerProps): ReactElement => {
|
|
103
|
+
const L = { title: 'Site navigation', close: 'Close navigation', settings: 'Settings', version: 'Version', ...labels }; // 🌍
|
|
104
|
+
const choose = (href: string) => (e: MouseEvent) => { if (e.defaultPrevented) return; onNavigate?.(href); onClose(); }; // 🔗 then close
|
|
105
|
+
const row = (it: AbNavDrawerItem, cls: string) => {
|
|
106
|
+
const on = isAbSidebarActive(it.href, activeHref); // 🎯
|
|
107
|
+
return (
|
|
108
|
+
<Link href={it.href} className={cls} aria-current={on ? 'page' : undefined} onClick={choose(it.href)}>
|
|
109
|
+
{it.icon && <AbIcon name={it.icon} filled={on} size={cls === kit.row ? 24 : 22} />}
|
|
110
|
+
<span>{it.label}</span>
|
|
111
|
+
{it.meta && <span className={kit.mini}>{it.meta}</span>}
|
|
112
|
+
</Link>
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
// 🏷️ a string version = the mock chip (mono, accent), optionally a button
|
|
116
|
+
const chip = typeof version === 'string'
|
|
117
|
+
? (onVersionClick
|
|
118
|
+
? <button type="button" className={kit.ver} aria-label={`${L.version} ${version}`} aria-haspopup="menu" onClick={onVersionClick}><b>{version}</b><AbIcon name="expand_more" size={18} /></button>
|
|
119
|
+
: <span className={kit.ver} aria-label={`${L.version} ${version}`}><b>{version}</b><AbIcon name="expand_more" size={18} /></span>)
|
|
120
|
+
: version;
|
|
121
|
+
return (
|
|
122
|
+
<AbDrawer
|
|
123
|
+
open={open} onClose={onClose} id={id} side="left" scope="app" tier="nav" swipe size="320px"
|
|
124
|
+
headerStart={<span className={kit.logoRow}>{logo}</span>} aria-label={L.title}
|
|
125
|
+
closeLabel={L.close} closeIcon={<AbIcon name="close" size={24} />} initialFocus="panel" returnFocus={returnFocus}
|
|
126
|
+
className={clsx('AbNavDrawer', kit.sheet, className)}
|
|
127
|
+
>
|
|
128
|
+
{chip != null && <div className={kit.verRow}>{chip}</div>}
|
|
129
|
+
<div className={kit.navWrap}>
|
|
130
|
+
<nav className={kit.nav} aria-label={L.title} data-ab-part="nav-drawer-nav">
|
|
131
|
+
{sections.map((s) => (
|
|
132
|
+
<div key={s.id} role="group" aria-labelledby={s.label ? `${id}-${s.id}` : undefined}>
|
|
133
|
+
{s.label && <h3 id={`${id}-${s.id}`} className={kit.grp}>{s.label}</h3>}
|
|
134
|
+
<ul className={kit.list} aria-labelledby={s.label ? `${id}-${s.id}` : undefined}>
|
|
135
|
+
{s.items.map((it) => <li key={it.href}>{row(it, kit.nv)}</li>)}
|
|
136
|
+
</ul>
|
|
137
|
+
</div>
|
|
138
|
+
))}
|
|
139
|
+
</nav>
|
|
140
|
+
<div className={kit.fade} aria-hidden="true" />
|
|
141
|
+
</div>
|
|
142
|
+
{(footer.length > 0 || onSettings) && (
|
|
143
|
+
<div className={kit.navFoot} data-ab-part="nav-drawer-footer">
|
|
144
|
+
{footer.map((it) => <div key={it.href}>{row(it, kit.row)}</div>)}
|
|
145
|
+
{onSettings && (
|
|
146
|
+
<button type="button" className={kit.row} aria-haspopup="dialog" onClick={() => { onClose(); onSettings(); }}>
|
|
147
|
+
<AbIcon name="settings" size={24} /><span>{L.settings}</span><AbIcon name="chevron_right" size={24} className={kit.chev} />
|
|
148
|
+
</button>
|
|
149
|
+
)}
|
|
150
|
+
</div>
|
|
151
|
+
)}
|
|
152
|
+
</AbDrawer>
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// 📦 exports
|
|
157
|
+
export default AbNavDrawer;
|
|
158
|
+
export { AbNavDrawer };
|
package/ab-navbar/index.tsx
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
31
|
*
|
|
32
32
|
* Example usage:
|
|
33
|
-
* <AbNavbar activeHref="/
|
|
33
|
+
* <AbNavbar activeHref="/" items={[
|
|
34
34
|
* { kind: 'link', href: '/', icon: 'home', label: 'Home' },
|
|
35
35
|
* { kind: 'button', id: 'menu', icon: 'menu', label: 'Menu', onSelect: openSheet },
|
|
36
36
|
* ]} />
|
|
@@ -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; }
|