ab-nextjs-components 0.1.11 → 0.1.13
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 +36 -0
- package/README.md +30 -0
- package/ab-app-bar/index.tsx +181 -0
- package/ab-app-bar/styles.module.css +119 -0
- package/ab-avatar/index.tsx +2 -1
- package/ab-avatar/styles.module.css +32 -0
- package/ab-balloon/index.tsx +134 -23
- package/ab-balloon/styles.module.css +84 -7
- package/ab-brand/index.tsx +1 -1
- package/ab-button/helpers.ts +3 -1
- package/ab-button/index.tsx +17 -3
- package/ab-button/styles.module.css +42 -0
- package/ab-card/index.tsx +89 -0
- package/ab-card/styles.module.css +68 -0
- package/ab-collapsible/index.tsx +1 -1
- package/ab-color/index.tsx +1 -0
- package/ab-color/styles.module.css +32 -0
- package/ab-demo-box/index.tsx +1 -0
- package/ab-demo-box/styles.module.css +32 -0
- package/ab-demo-code/index.tsx +1 -0
- package/ab-demo-code/styles.module.css +32 -0
- package/ab-icon/builtin.ts +15 -1
- package/ab-icon/helpers.ts +37 -0
- package/ab-icon/index.tsx +14 -8
- package/ab-icon/registrar.tsx +68 -0
- package/ab-icon-button/index.tsx +8 -3
- package/ab-image/index.tsx +1 -0
- package/ab-image/styles.module.css +32 -0
- package/ab-info/index.tsx +2 -1
- package/ab-info/styles.module.css +32 -0
- package/ab-input/index.tsx +1 -0
- package/ab-input/styles.module.css +1 -0
- package/ab-install-snippet/styles.module.css +32 -8
- package/ab-kbd/index.tsx +65 -0
- package/ab-kbd/styles.module.css +55 -0
- package/ab-key-feature/index.tsx +2 -1
- package/ab-key-feature/styles.module.css +32 -0
- package/ab-like-button/index.tsx +1 -1
- package/ab-link/index.tsx +112 -0
- package/ab-link/locale.ts +53 -0
- package/ab-locale-switcher/index.tsx +17 -0
- package/ab-locale-switcher/styles.module.css +11 -0
- package/ab-main-headline/index.tsx +1 -0
- package/ab-main-headline/styles.module.css +32 -0
- package/ab-menu/index.tsx +6 -5
- package/ab-menu/styles.module.css +32 -0
- package/ab-name/index.tsx +1 -0
- package/ab-name/styles.module.css +32 -0
- package/ab-navbar/index.tsx +54 -46
- package/ab-navbar/styles.module.css +84 -28
- package/ab-navbar/view.tsx +163 -0
- package/ab-package-card/index.tsx +94 -0
- package/ab-package-card/styles.module.css +41 -0
- package/ab-page-paginator/index.tsx +1 -0
- package/ab-page-paginator/styles.module.css +32 -0
- package/ab-page-switcher/index.tsx +1 -0
- package/ab-page-switcher/styles.module.css +32 -0
- package/ab-preview/index.tsx +1 -0
- package/ab-preview/styles.module.css +32 -0
- package/ab-price/index.tsx +1 -0
- package/ab-price/styles.module.css +32 -0
- package/ab-price-tag/index.tsx +1 -0
- package/ab-price-tag/styles.module.css +32 -0
- package/ab-product/index.tsx +1 -0
- package/ab-product/styles.module.css +32 -0
- package/ab-product-item/index.tsx +1 -0
- package/ab-product-item/styles.module.css +32 -0
- package/ab-search-result/index.tsx +1 -0
- package/ab-search-result/styles.module.css +32 -0
- package/ab-search-trigger/index.tsx +142 -0
- package/ab-search-trigger/styles.module.css +70 -0
- package/ab-sidebar/index.tsx +88 -49
- package/ab-sidebar/styles.module.css +136 -31
- package/ab-sidebar/view.tsx +182 -0
- package/ab-switch-back/index.tsx +2 -1
- package/ab-switch-back/styles.module.css +32 -0
- package/ab-tab/index.tsx +2 -1
- package/ab-tab/styles.module.css +32 -0
- package/ab-tabs/index.tsx +1 -0
- package/ab-tabs/styles.module.css +32 -0
- package/ab-test-hello/index.tsx +1 -0
- package/ab-test-hello/styles.module.css +32 -0
- package/ab-text/index.tsx +1 -0
- package/ab-text/styles.module.css +32 -0
- package/ab-toc/index.tsx +124 -0
- package/ab-toc/styles.module.css +54 -0
- package/css/chrome-mq.css +32 -0
- package/css/doodle.css +32 -0
- package/css/logo.css +32 -0
- package/css/spinner.css +32 -0
- package/css/toast.css +32 -0
- package/index.ts +18 -0
- package/package.json +27 -10
- package/server/ab-avatar/index.tsx +2 -1
- package/server/ab-avatar/styles.module.css +32 -0
- package/server/ab-badge/index.tsx +1 -0
- package/server/ab-badge/styles.module.css +32 -0
- package/server/ab-brand/index.tsx +1 -1
- package/server/ab-button/index.tsx +1 -1
- package/server/ab-button/styles.module.css +11 -0
- package/server/ab-icon/index.tsx +13 -8
- package/server/ab-key-feature/index.tsx +2 -1
- package/server/ab-key-feature/styles.module.css +32 -0
- package/server/ab-name/index.tsx +1 -0
- package/server/ab-name/styles.module.css +32 -0
- package/server/ab-nav-link/index.tsx +2 -1
- package/server/ab-nav-link/styles.module.css +32 -0
- package/server/ab-navbar/index.tsx +44 -45
- package/server/ab-polygon/index.tsx +1 -0
- package/server/ab-polygon/styles.module.css +32 -0
- package/server/ab-sidebar/index.tsx +44 -49
- package/server/ab-switch-back/index.tsx +2 -1
- package/server/ab-switch-back/styles.module.css +32 -0
- package/server/ab-test-hello/index.tsx +1 -0
- package/server/ab-test-hello/styles.module.css +32 -0
- package/server/ab-text/index.tsx +1 -0
- package/server/ab-text/styles.module.css +32 -0
- package/server/index.ts +1 -0
- package/styles.css +32 -0
- package/types/index.d.ts +35 -0
- package/server/ab-navbar/styles.module.css +0 -35
- package/server/ab-sidebar/styles.module.css +0 -41
|
@@ -0,0 +1,142 @@
|
|
|
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: index.tsx
|
|
28
|
+
* @file: ab-search-trigger/index.tsx
|
|
29
|
+
* @type: Component
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
35
|
+
* MOTTO: We'll always do more 😜!!!
|
|
36
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
'use client';
|
|
40
|
+
|
|
41
|
+
// ⚛️ React
|
|
42
|
+
import { useEffect, useSyncExternalStore, type MouseEvent, type ReactElement } from 'react';
|
|
43
|
+
// 🧵 classes
|
|
44
|
+
import clsx from 'clsx';
|
|
45
|
+
// 🔗 G42 link (href fallback)
|
|
46
|
+
import Link from '../ab-link';
|
|
47
|
+
// 🔣 icon (search is a built-in)
|
|
48
|
+
import AbIcon from '../ab-icon';
|
|
49
|
+
// ⌨️ key hint
|
|
50
|
+
import AbKbd from '../ab-kbd';
|
|
51
|
+
// 🎬 hover / press motion from the package
|
|
52
|
+
import 'ab-nextjs-animations/motion/styles.css';
|
|
53
|
+
// 🎨 styles
|
|
54
|
+
import styles from './styles.module.css';
|
|
55
|
+
|
|
56
|
+
/** ⚙️ props */
|
|
57
|
+
export interface AbSearchTriggerProps {
|
|
58
|
+
label?: string; // 🏷️ placeholder text (default "Search")
|
|
59
|
+
onOpen?: () => void; // 🔔 opens your search dialog (button mode)
|
|
60
|
+
href?: string; // 🔗 no onOpen → a link to a search page (also the JS-off path)
|
|
61
|
+
hotkey?: boolean; // ⌨️ listen for ⌘K / Ctrl+K (default true when onOpen is set)
|
|
62
|
+
shortcut?: boolean; // ⌨️ alias of `hotkey` (Joseph's spec name); `hotkey` wins when both are set
|
|
63
|
+
compact?: boolean; // 📱 icon-only pill (the label stays for screen readers), e.g. the mobile app bar
|
|
64
|
+
comingSoon?: boolean; // 🚧 visible but inert: aria-disabled, no hotkey
|
|
65
|
+
comingSoonLabel?: string; // 🏷️ default "Coming soon"
|
|
66
|
+
className?: string; // 🏷️
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 🔕 nothing to subscribe to
|
|
70
|
+
const noopSubscribe = () => () => {};
|
|
71
|
+
|
|
72
|
+
/** 🍎 Apple platforms show ⌘, everyone else Ctrl. */
|
|
73
|
+
export function isAbApplePlatform(nav?: { platform?: string; userAgent?: string; userAgentData?: { platform?: string } }): boolean {
|
|
74
|
+
const p = nav?.userAgentData?.platform ?? nav?.platform ?? nav?.userAgent ?? ''; // 🔍
|
|
75
|
+
return /mac|iphone|ipad|ipod/i.test(p); // 🍎
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 🔎 AbSearchTrigger (G44): a search "field" that opens your dialog. Shows ⌘K on Apple, Ctrl K elsewhere,
|
|
80
|
+
* announces `aria-keyshortcuts="Meta+K Control+K"`, and falls back to a link when there's no `onOpen`.
|
|
81
|
+
* Note: the hotkey is a local listener; G48 `useAbHotkey` is deliberately not in hooks 0.1.7.
|
|
82
|
+
*/
|
|
83
|
+
const AbSearchTrigger = ({ label = 'Search', onOpen, href, hotkey, shortcut, compact = false, comingSoon = false, comingSoonLabel = 'Coming soon', className }: AbSearchTriggerProps): ReactElement => {
|
|
84
|
+
// 🍎 SSR renders "Ctrl"; hydration then reads the platform (useSyncExternalStore: no mismatch, no effect)
|
|
85
|
+
const apple = useSyncExternalStore(
|
|
86
|
+
noopSubscribe, // 🔕 the platform never changes
|
|
87
|
+
() => isAbApplePlatform(navigator as Navigator & { userAgentData?: { platform?: string } }), // 🖥️ client
|
|
88
|
+
() => false, // 🖨️ server
|
|
89
|
+
);
|
|
90
|
+
// ⌨️ ⌘K / Ctrl+K
|
|
91
|
+
const listen = !comingSoon && !!onOpen && (hotkey ?? shortcut ?? true);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (!listen) return;
|
|
94
|
+
const onKey = (e: KeyboardEvent) => {
|
|
95
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {
|
|
96
|
+
e.preventDefault(); // 🚫 browser search bar
|
|
97
|
+
onOpen?.(); // 🔔
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
window.addEventListener('keydown', onKey); // 👂
|
|
101
|
+
return () => window.removeEventListener('keydown', onKey); // 🧹
|
|
102
|
+
}, [listen, onOpen]);
|
|
103
|
+
|
|
104
|
+
// 🧩 inner content
|
|
105
|
+
const inner = (
|
|
106
|
+
<>
|
|
107
|
+
<AbIcon name="search" size={20} className={styles.abSearchTriggerIcon} />
|
|
108
|
+
<span className={clsx(styles.abSearchTriggerLabel, compact && styles.abSearchTriggerSrOnly)}>{label}</span>
|
|
109
|
+
{/* 🚧 coming soon tag, or ⌨️ the key hint ONLY while a hotkey is really listening (James #3, D24a) */}
|
|
110
|
+
{comingSoon
|
|
111
|
+
? !compact && <span className={styles.abSearchTriggerSoon}>{comingSoonLabel}</span>
|
|
112
|
+
: listen && !compact && <AbKbd keys={[apple ? '⌘' : 'Ctrl', 'K']} className={styles.abSearchTriggerKbd} />}
|
|
113
|
+
</>
|
|
114
|
+
);
|
|
115
|
+
const common = {
|
|
116
|
+
className: clsx('AbSearchTrigger', styles.abSearchTrigger, !comingSoon && 'ab-motion-interactive', className), // 🏷️
|
|
117
|
+
'data-ab-part': 'search-trigger', // 🧩
|
|
118
|
+
'aria-keyshortcuts': listen ? 'Meta+K Control+K' : undefined, // ♿ only announced when bound (James #3)
|
|
119
|
+
'data-compact': compact ? 'true' : undefined, // 📱
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// 🚧 coming soon: focusable, announced, inert
|
|
123
|
+
if (comingSoon) return <button type="button" {...common} aria-disabled="true" data-coming-soon="true">{inner}</button>;
|
|
124
|
+
// 🔗 href → ALWAYS a real link, so it works with JS off (D24a: /docs). With onOpen too, JS intercepts
|
|
125
|
+
// the click and opens the dialog instead (James #4); modified clicks (new tab, …) keep the link.
|
|
126
|
+
if (href) {
|
|
127
|
+
const onClick = onOpen
|
|
128
|
+
? (e: MouseEvent<HTMLAnchorElement>) => {
|
|
129
|
+
if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return; // 🖱️ let the browser handle it
|
|
130
|
+
e.preventDefault(); // 🚫 navigation
|
|
131
|
+
onOpen(); // 🔔
|
|
132
|
+
}
|
|
133
|
+
: undefined;
|
|
134
|
+
return <Link href={href} {...common} onClick={onClick} aria-haspopup={onOpen ? 'dialog' : undefined}>{inner}</Link>;
|
|
135
|
+
}
|
|
136
|
+
// 🔘 dialog opener
|
|
137
|
+
return <button type="button" {...common} aria-haspopup="dialog" onClick={onOpen}>{inner}</button>;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// 📦 exports
|
|
141
|
+
export default AbSearchTrigger;
|
|
142
|
+
export { AbSearchTrigger };
|
|
@@ -0,0 +1,70 @@
|
|
|
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: AbSearchTrigger - Styles (G44)
|
|
28
|
+
* @file: ab-search-trigger/styles.module.css
|
|
29
|
+
* @type: CSS Module
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
35
|
+
* MOTTO: We'll always do more 😜!!!
|
|
36
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/* 🔎 pill "field" */
|
|
40
|
+
.abSearchTrigger {
|
|
41
|
+
display: inline-flex; /* 📐 */
|
|
42
|
+
align-items: center; /* ↕️ */
|
|
43
|
+
gap: 8px; /* ↔️ */
|
|
44
|
+
min-width: 0; /* 📏 */
|
|
45
|
+
width: 100%; /* 📏 */
|
|
46
|
+
max-width: 360px; /* 📏 */
|
|
47
|
+
height: 40px; /* 📏 */
|
|
48
|
+
padding: 0 8px 0 12px; /* 📦 */
|
|
49
|
+
border: 0; /* 🚫 */
|
|
50
|
+
border-radius: 999px; /* 🟢 */
|
|
51
|
+
background: var(--ab-color-surface-container-high, rgb(0 0 0 / 0.06)); /* 🎨 */
|
|
52
|
+
color: var(--ab-color-on-surface-variant, inherit); /* 🖋️ */
|
|
53
|
+
font: inherit; /* 🔤 */
|
|
54
|
+
text-decoration: none; /* 🚫 */
|
|
55
|
+
cursor: pointer; /* 👆 */
|
|
56
|
+
box-sizing: border-box; /* 📦 */
|
|
57
|
+
}
|
|
58
|
+
.abSearchTrigger:focus-visible {
|
|
59
|
+
outline: var(--ab-focus-ring-width, 2px) solid var(--ab-color-primary, #8f4c38); /* ♿ */
|
|
60
|
+
outline-offset: var(--ab-focus-ring-offset, 2px); /* ♿ */
|
|
61
|
+
}
|
|
62
|
+
.abSearchTrigger[aria-disabled='true'] { cursor: default; opacity: 0.72; } /* 🚧 */
|
|
63
|
+
.abSearchTriggerLabel { flex: 1; text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } /* 🏷️ */
|
|
64
|
+
.abSearchTriggerIcon { flex: none; } /* 🔣 */
|
|
65
|
+
.abSearchTriggerSoon { font-size: 12px; opacity: 0.8; } /* 🚧 */
|
|
66
|
+
|
|
67
|
+
/* 📱 compact (Joseph #3/#16): icon-only round pill for small app bars, no overflow at 390px */
|
|
68
|
+
.abSearchTrigger[data-compact='true'] { flex: none; width: 40px; min-width: 40px; padding: 0; justify-content: center; } /* 🔘 */
|
|
69
|
+
/* 🕶️ visually hidden, still read by screen readers */
|
|
70
|
+
.abSearchTriggerSrOnly { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; flex: none; }
|
package/ab-sidebar/index.tsx
CHANGED
|
@@ -5,68 +5,107 @@
|
|
|
5
5
|
* ~~~~~~~~~~~~
|
|
6
6
|
* Copyright (c) 2026 Abraham Ukachi. The abElements Project.
|
|
7
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
|
+
*
|
|
8
26
|
* @project: ab-nextjs-components
|
|
9
|
-
* @name: AbSidebar - Client (
|
|
27
|
+
* @name: AbSidebar - Client (G40)
|
|
10
28
|
* @file: ab-sidebar/index.tsx
|
|
29
|
+
* @type: Client Component
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*
|
|
32
|
+
* Example usage:
|
|
33
|
+
* <AbSidebar
|
|
34
|
+
* activeHref="/docs/components"
|
|
35
|
+
* sections={[{ id: 'docs', label: 'Docs', items: [{ href: '/docs/components', icon: 'widgets', label: 'Components' }] }]}
|
|
36
|
+
* />
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
41
|
+
* MOTTO: We'll always do more 😜!!!
|
|
42
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
11
43
|
*/
|
|
12
44
|
|
|
13
45
|
'use client';
|
|
14
46
|
|
|
15
|
-
|
|
16
|
-
import
|
|
47
|
+
// ⚛️ React
|
|
48
|
+
import { useState, type ReactElement } from 'react';
|
|
49
|
+
// 🧭 current route (fallback when `activeHref` is omitted)
|
|
17
50
|
import { usePathname } from 'next/navigation';
|
|
18
|
-
|
|
51
|
+
// 🌍 0.1.13 (Joseph #10): locale-stripped pathname
|
|
52
|
+
import { stripAbLocalePrefix, useAbLocales } from '../ab-link';
|
|
53
|
+
// 🔣 client AbIcon (built-in chevrons are always registered)
|
|
54
|
+
import AbIcon from '../ab-icon';
|
|
55
|
+
// 🖼️ shared view
|
|
56
|
+
import { AbSidebarView, isAbSidebarActive, type AbSidebarBaseProps } from './view';
|
|
57
|
+
// 🎨 styles
|
|
19
58
|
import styles from './styles.module.css';
|
|
20
59
|
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
value: string;
|
|
25
|
-
label: string;
|
|
26
|
-
};
|
|
60
|
+
// 📦 re-export the shared types
|
|
61
|
+
export type { AbSidebarItem, AbSidebarSection, AbSidebarLink, AbSidebarLabels } from './view';
|
|
62
|
+
export { isAbSidebarActive, toAbSidebarSections } from './view';
|
|
27
63
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
brandHref?: string;
|
|
34
|
-
brandLabel?: string;
|
|
64
|
+
/** ⚙️ Client props: the shared ones + collapse control. */
|
|
65
|
+
export interface AbSidebarProps extends AbSidebarBaseProps {
|
|
66
|
+
defaultCollapsed?: boolean; // 🚪 uncontrolled start
|
|
67
|
+
onCollapsedChange?: (collapsed: boolean) => void; // 🔔
|
|
68
|
+
collapsible?: boolean; // 🔘 show the collapse button (default true when sections are given)
|
|
35
69
|
}
|
|
36
70
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const pathname = usePathname() ?? '';
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
/**
|
|
72
|
+
* 🧭 AbSidebar (client, G40): sections, filled icon on the active item, aria-current, an icon rail with balloon
|
|
73
|
+
* tooltips, and a collapse button (aria-expanded + aria-controls; hidden when JS is off).
|
|
74
|
+
*/
|
|
75
|
+
const AbSidebar = (props: AbSidebarProps): ReactElement => {
|
|
76
|
+
const { collapsed: controlled, defaultCollapsed = false, onCollapsedChange, collapsible, activeHref, page, labels, id = 'ab-sidebar-list' } = props;
|
|
77
|
+
// 🧭 route
|
|
78
|
+
const appLocales = useAbLocales(); // 🌍 from AbLinkProvider
|
|
79
|
+
const pathname = stripAbLocalePrefix(usePathname() ?? '', props.locales ?? appLocales); // 🧭 `/fr/docs` → `/docs`
|
|
80
|
+
// 🚪 controlled or not
|
|
81
|
+
const [inner, setInner] = useState(defaultCollapsed);
|
|
82
|
+
const collapsed = controlled ?? inner;
|
|
83
|
+
const setCollapsed = (next: boolean) => {
|
|
84
|
+
if (controlled === undefined) setInner(next); // 🧠 uncontrolled
|
|
85
|
+
onCollapsedChange?.(next); // 🔔
|
|
86
|
+
};
|
|
87
|
+
// 🎯 legacy `page` wins, then activeHref, then the pathname
|
|
88
|
+
const active = (href: string, value?: string) => (page ? page === value : isAbSidebarActive(href, activeHref ?? pathname));
|
|
89
|
+
// 🔘 the toggle
|
|
90
|
+
const showToggle = collapsible ?? !!props.sections?.length;
|
|
91
|
+
const toggleLabel = collapsed ? labels?.expand ?? 'Expand sidebar' : labels?.collapse ?? 'Collapse sidebar';
|
|
92
|
+
const toggle = showToggle ? (
|
|
93
|
+
<button
|
|
94
|
+
type="button"
|
|
95
|
+
className={styles.abSidebarToggle} // 🙈 hidden under (scripting: none)
|
|
96
|
+
data-ab-part="collapse"
|
|
97
|
+
aria-expanded={!collapsed} // ♿
|
|
98
|
+
aria-controls={id} // ♿
|
|
99
|
+
aria-label={toggleLabel} // 🏷️
|
|
100
|
+
onClick={() => setCollapsed(!collapsed)}
|
|
101
|
+
>
|
|
102
|
+
<AbIcon name={collapsed ? 'chevron_right' : 'chevron_left'} size={20} />
|
|
103
|
+
</button>
|
|
104
|
+
) : undefined;
|
|
105
|
+
|
|
106
|
+
return <AbSidebarView props={{ ...props, collapsed }} Icon={AbIcon} active={active} toggle={toggle} />;
|
|
69
107
|
};
|
|
70
108
|
|
|
109
|
+
// 📦 exports
|
|
71
110
|
export default AbSidebar;
|
|
72
111
|
export { AbSidebar };
|
|
@@ -1,41 +1,146 @@
|
|
|
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: AbSidebar - Styles (G40)
|
|
28
|
+
* @file: ab-sidebar/styles.module.css
|
|
29
|
+
* @type: CSS Module
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
35
|
+
* MOTTO: We'll always do more 😜!!!
|
|
36
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/* 🧭 shell */
|
|
1
40
|
.abSidebar {
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-direction: column;
|
|
4
|
-
gap:
|
|
5
|
-
width: 100%;
|
|
6
|
-
max-width:
|
|
7
|
-
padding:
|
|
8
|
-
box-sizing: border-box;
|
|
41
|
+
display: flex; /* 📐 */
|
|
42
|
+
flex-direction: column; /* ⬇️ */
|
|
43
|
+
gap: 12px; /* ↕️ */
|
|
44
|
+
width: 100%; /* 📏 */
|
|
45
|
+
max-width: 280px; /* 📏 docs-shell sidebar */
|
|
46
|
+
padding: 12px; /* 📦 */
|
|
47
|
+
box-sizing: border-box; /* 📦 */
|
|
9
48
|
}
|
|
49
|
+
.abSidebar[data-collapsed='true'] {
|
|
50
|
+
max-width: 72px; /* 🚪 rail */
|
|
51
|
+
align-items: center; /* ↔️ */
|
|
52
|
+
}
|
|
53
|
+
/* 🏷️ header row: brand/slot + toggle */
|
|
54
|
+
.abSidebarHeader {
|
|
55
|
+
display: flex; /* 📐 */
|
|
56
|
+
align-items: center; /* ↕️ */
|
|
57
|
+
justify-content: space-between; /* ↔️ */
|
|
58
|
+
gap: 8px; /* ↔️ */
|
|
59
|
+
min-height: 40px; /* 📏 */
|
|
60
|
+
}
|
|
61
|
+
.abSidebarHeader:empty { display: none; } /* 🙈 */
|
|
10
62
|
.abSidebarBrand {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
63
|
+
font-weight: 700; /* 🔤 */
|
|
64
|
+
text-decoration: none; /* 🚫 */
|
|
65
|
+
color: inherit; /* 🖋️ */
|
|
66
|
+
}
|
|
67
|
+
/* 🔘 collapse button */
|
|
68
|
+
.abSidebarToggle {
|
|
69
|
+
display: inline-grid; /* 📐 */
|
|
70
|
+
place-items: center; /* 🎯 */
|
|
71
|
+
width: 40px; /* 📏 */
|
|
72
|
+
height: 40px; /* 📏 */
|
|
73
|
+
border: 0; /* 🚫 */
|
|
74
|
+
border-radius: 999px; /* 🟢 */
|
|
75
|
+
background: transparent; /* 🎨 */
|
|
76
|
+
color: inherit; /* 🖋️ */
|
|
77
|
+
cursor: pointer; /* 👆 */
|
|
78
|
+
}
|
|
79
|
+
.abSidebarToggle:hover { background: color-mix(in srgb, currentColor 8%, transparent); } /* 🖱️ */
|
|
80
|
+
.abSidebarToggle:focus-visible,
|
|
81
|
+
.abSidebarLink:focus-visible {
|
|
82
|
+
outline: var(--ab-focus-ring-width, 2px) solid var(--ab-color-primary, #8f4c38); /* ♿ */
|
|
83
|
+
outline-offset: var(--ab-focus-ring-offset, 2px); /* ♿ */
|
|
17
84
|
}
|
|
85
|
+
@media (scripting: none) {
|
|
86
|
+
.abSidebarToggle { display: none; } /* 🚫 JS off: no toggle */
|
|
87
|
+
}
|
|
88
|
+
/* 🗂️ sections */
|
|
89
|
+
.abSidebarSections { display: flex; flex-direction: column; gap: 16px; width: 100%; }
|
|
90
|
+
.abSidebarSection { display: flex; flex-direction: column; gap: 4px; }
|
|
91
|
+
.abSidebarHeading {
|
|
92
|
+
margin: 0; /* 🚫 */
|
|
93
|
+
padding: 0 12px; /* 📦 */
|
|
94
|
+
font-size: 12px; /* 🔤 */
|
|
95
|
+
font-weight: 600; /* 🔤 */
|
|
96
|
+
letter-spacing: 0.04em; /* 🔤 */
|
|
97
|
+
text-transform: uppercase; /* 🔠 */
|
|
98
|
+
opacity: 0.7; /* 🌫️ */
|
|
99
|
+
}
|
|
100
|
+
.abSidebar[data-collapsed='true'] .abSidebarHeading { display: none; } /* 🚪 */
|
|
18
101
|
.abSidebarList {
|
|
19
|
-
display: flex;
|
|
20
|
-
flex-direction: column;
|
|
21
|
-
gap:
|
|
22
|
-
list-style: none;
|
|
23
|
-
margin: 0;
|
|
24
|
-
padding: 0;
|
|
102
|
+
display: flex; /* 📐 */
|
|
103
|
+
flex-direction: column; /* ⬇️ */
|
|
104
|
+
gap: 2px; /* ↕️ */
|
|
105
|
+
list-style: none; /* 🚫 */
|
|
106
|
+
margin: 0; /* 🚫 */
|
|
107
|
+
padding: 0; /* 🚫 */
|
|
25
108
|
}
|
|
109
|
+
/* 🔗 item */
|
|
26
110
|
.abSidebarLink {
|
|
27
|
-
display: flex;
|
|
28
|
-
align-items: center;
|
|
29
|
-
gap:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
font-weight:
|
|
111
|
+
display: flex; /* 📐 */
|
|
112
|
+
align-items: center; /* ↕️ */
|
|
113
|
+
gap: 12px; /* ↔️ */
|
|
114
|
+
min-height: 40px; /* 👆 target */
|
|
115
|
+
padding: 0 12px; /* 📦 */
|
|
116
|
+
border-radius: 999px; /* 🟢 */
|
|
117
|
+
text-decoration: none; /* 🚫 */
|
|
118
|
+
color: inherit; /* 🖋️ */
|
|
119
|
+
font-weight: 500; /* 🔤 */
|
|
120
|
+
/* 🔤 0.1.13 (Joseph #15): M3 label-large, so names stop inheriting the big body size and wrapping at 280px */
|
|
121
|
+
font-family: var(--md-sys-typescale-label-large-font, inherit);
|
|
122
|
+
font-size: var(--md-sys-typescale-label-large-size, 14px);
|
|
123
|
+
line-height: var(--md-sys-typescale-label-large-line-height, 20px);
|
|
124
|
+
letter-spacing: var(--md-sys-typescale-label-large-tracking, 0.1px);
|
|
36
125
|
}
|
|
126
|
+
.abSidebarLabel { min-width: 0; overflow-wrap: anywhere; } /* 🚫 no overflow, ReactNode-friendly */
|
|
127
|
+
.abSidebarLink[data-depth='1'] { padding-inline-start: 44px; font-size: 14px; } /* 🌳 */
|
|
128
|
+
.abSidebarLink:hover { background: color-mix(in srgb, currentColor 8%, transparent); } /* 🖱️ */
|
|
37
129
|
.abSidebarLink[data-active='true'] {
|
|
38
|
-
|
|
39
|
-
|
|
130
|
+
background: var(--ab-color-secondary-container, color-mix(in srgb, #8f4c38 14%, transparent)); /* 🎯 */
|
|
131
|
+
color: var(--ab-color-on-secondary-container, inherit); /* 🖋️ */
|
|
132
|
+
font-weight: 600; /* 🔤 */
|
|
133
|
+
}
|
|
134
|
+
.abSidebarIcon { flex: none; } /* 🔣 */
|
|
135
|
+
.abSidebarBadge {
|
|
136
|
+
margin-inline-start: auto; /* ➡️ */
|
|
137
|
+
padding: 0 6px; /* 📦 */
|
|
138
|
+
border-radius: 999px; /* 🟢 */
|
|
139
|
+
font-size: 11px; /* 🔤 */
|
|
140
|
+
line-height: 18px; /* 📏 */
|
|
141
|
+
background: var(--ab-color-tertiary-container, rgb(0 0 0 / 0.08)); /* 🎨 */
|
|
40
142
|
}
|
|
41
|
-
|
|
143
|
+
/* 🚪 rail: icons only (labels stay for screen readers via aria-label) */
|
|
144
|
+
.abSidebar[data-collapsed='true'] .abSidebarLink { width: 48px; justify-content: center; padding: 0; }
|
|
145
|
+
.abSidebar[data-collapsed='true'] .abSidebarLabel,
|
|
146
|
+
.abSidebar[data-collapsed='true'] .abSidebarBadge { display: none; }
|