ab-nextjs-components 0.1.13 โ 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 +70 -0
- package/README.md +35 -0
- package/ab-app-bar/index.tsx +53 -13
- package/ab-app-bar/styles.module.css +68 -4
- package/ab-bottom-drawer/index.tsx +71 -0
- package/ab-bottom-drawer/styles.module.css +66 -0
- package/ab-breadcrumbs/index.tsx +92 -0
- package/ab-breadcrumbs/styles.module.css +54 -0
- package/ab-button/helpers.ts +6 -1
- package/ab-button/index.tsx +8 -2
- package/ab-button/styles.module.css +39 -0
- package/ab-card/styles.module.css +1 -1
- package/ab-carousel/styles.module.css +1 -1
- package/ab-chip/index.tsx +16 -4
- package/ab-chip/styles.module.css +12 -1
- package/ab-confirm-drawer/index.tsx +97 -0
- package/ab-confirm-drawer/styles.module.css +41 -0
- package/ab-drawer/gestures.ts +134 -0
- package/ab-drawer/index.tsx +458 -0
- package/ab-drawer/kit.module.css +204 -0
- package/ab-drawer/styles.module.css +166 -0
- package/ab-drawer/use-ab-drawer.ts +89 -0
- package/ab-drawer/use-ab-edge-swipe.ts +155 -0
- package/ab-drawer-list/index.tsx +118 -0
- package/ab-drawer-list/styles.module.css +65 -0
- package/ab-flow-diagram/styles.module.css +2 -2
- package/ab-icon/builtin.ts +4 -0
- package/ab-icon-button/index.tsx +13 -2
- package/ab-icon-button/styles.module.css +1 -1
- package/ab-install-snippet/index.tsx +51 -29
- package/ab-install-snippet/styles.module.css +34 -2
- package/ab-kbd/styles.module.css +1 -1
- package/ab-list/index.tsx +107 -0
- package/ab-list/styles.module.css +82 -0
- package/ab-locale-switcher/index.tsx +103 -10
- package/ab-locale-switcher/styles.module.css +24 -4
- 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-navbar/styles.module.css +20 -2
- package/ab-navbar/view.tsx +7 -4
- package/ab-package-card/index.tsx +49 -2
- package/ab-package-card/styles.module.css +40 -0
- package/ab-search-drawer/index.tsx +279 -0
- package/ab-search-trigger/index.tsx +22 -2
- package/ab-search-trigger/styles.module.css +30 -1
- package/ab-settings-drawer/index.tsx +160 -0
- package/ab-sidebar/index.tsx +6 -3
- package/ab-sidebar/styles.module.css +53 -5
- package/ab-sidebar/view.tsx +18 -4
- package/ab-theme-toggle/index.tsx +21 -6
- package/ab-theme-toggle/styles.module.css +18 -3
- package/ab-toc/index.tsx +9 -2
- package/ab-toc/styles.module.css +20 -8
- package/ab-toc-drawer/index.tsx +129 -0
- package/ab-version-switcher/index.tsx +143 -0
- package/ab-version-switcher/styles.module.css +76 -0
- package/index.ts +50 -0
- package/package.json +28 -3
- package/server/ab-button/index.tsx +6 -2
- package/server/ab-button/styles.module.css +39 -0
- package/types/index.d.ts +37 -0
|
@@ -0,0 +1,54 @@
|
|
|
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: AbBreadcrumbs styles
|
|
28
|
+
* @file: ab-breadcrumbs/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
|
+
|
|
40
|
+
/* ๐๏ธ knobs (mock .crumb; theme tokens from ab-nextjs-theme 0.3.5) */
|
|
41
|
+
.abCrumbs {
|
|
42
|
+
--ab-crumbs-color: var(--ab-color-faint, #807062); /* ๐๏ธ --faint โฟ AA fallback (James) */
|
|
43
|
+
--ab-crumbs-current: var(--ab-color-text, var(--ab-color-on-surface, #211a16)); /* ๐๏ธ --text */
|
|
44
|
+
--ab-crumbs-hover: var(--ab-color-accent-text, var(--ab-color-bronze-text, #8b6340)); /* ๐ฑ๏ธ --accent-t */
|
|
45
|
+
--ab-crumbs-ring: var(--ab-color-accent, var(--ab-color-bronze, #a67c52)); /* โฟ --accent */
|
|
46
|
+
min-width: 0; font-size: 13px; color: var(--ab-crumbs-color); /* ๐ค */
|
|
47
|
+
}
|
|
48
|
+
.abCrumbsList { display: flex; align-items: center; gap: 4px; margin: 0; padding: 0; list-style: none; min-width: 0; } /* ๐ */
|
|
49
|
+
.abCrumb { display: inline-flex; align-items: center; gap: 4px; min-width: 0; white-space: nowrap; } /* ๐ */
|
|
50
|
+
.abCrumbSep { width: 16px; height: 16px; flex: none; } /* โบ */
|
|
51
|
+
.abCrumbCurrent { color: var(--ab-crumbs-current); font-weight: 650; overflow: hidden; text-overflow: ellipsis; } /* ๐ฏ */
|
|
52
|
+
.abCrumbLink { color: inherit; text-decoration: none; border-radius: 4px; } /* ๐ */
|
|
53
|
+
.abCrumbLink:hover { color: var(--ab-crumbs-hover); } /* ๐ฑ๏ธ */
|
|
54
|
+
.abCrumbLink:focus-visible { outline: 2px solid var(--ab-crumbs-ring); outline-offset: 2px; } /* โฟ */
|
package/ab-button/helpers.ts
CHANGED
|
@@ -39,7 +39,12 @@
|
|
|
39
39
|
// ๐จ visual types shared by the client + server twins
|
|
40
40
|
// ๐ฅ 'filled' (0.1.12): solid bronze, painted by ab-nextjs-theme โฅ 0.3.3's
|
|
41
41
|
// `button[data-type="filled"]` rule (fallback in styles.module.css โ .isFilled)
|
|
42
|
-
|
|
42
|
+
// โช 'secondary' (0.1.14, P16): the Home "Browse packages" button: --card bg, 1px --border hairline, --text
|
|
43
|
+
export type AbButtonType = 'contained' | 'filled' | 'outlined' | 'text' | 'secondary';
|
|
44
|
+
// ๐ท 0.1.14 (P16): 'pill' = the legacy 999px look (default) ยท 'rounded' = the Home 10px button
|
|
45
|
+
export type AbButtonShape = 'pill' | 'rounded';
|
|
46
|
+
// ๐ 0.1.14 (P16): 'md' = 40px (44px under 768px, the touch CTA); undefined keeps the legacy sizing
|
|
47
|
+
export type AbButtonSize = 'md';
|
|
43
48
|
// ๐จ colour roles
|
|
44
49
|
export type AbButtonColor = 'primary' | 'secondary' | 'tertiary' | 'white' | 'black';
|
|
45
50
|
// ๐ท๏ธ badge tones (G22): neutral grey or bronze accent
|
package/ab-button/index.tsx
CHANGED
|
@@ -54,11 +54,11 @@ import {
|
|
|
54
54
|
getAbButtonSrReason,
|
|
55
55
|
type AbButtonBadgeTone,
|
|
56
56
|
type AbButtonColor,
|
|
57
|
-
type AbButtonType,
|
|
57
|
+
type AbButtonType, type AbButtonShape, type AbButtonSize,
|
|
58
58
|
} from './helpers';
|
|
59
59
|
|
|
60
60
|
// ๐ฆ re-export the shared types (pre-G22 import paths keep working)
|
|
61
|
-
export type { AbButtonBadgeTone, AbButtonColor, AbButtonType, AbButtonDisabledMode } from './helpers';
|
|
61
|
+
export type { AbButtonBadgeTone, AbButtonColor, AbButtonType, AbButtonDisabledMode, AbButtonShape, AbButtonSize } from './helpers';
|
|
62
62
|
|
|
63
63
|
// โ๏ธ props
|
|
64
64
|
export interface AbButtonProps {
|
|
@@ -71,6 +71,8 @@ export interface AbButtonProps {
|
|
|
71
71
|
style?: CSSProperties; // ๐จ
|
|
72
72
|
iconStyle?: CSSProperties; // ๐จ Material icon style
|
|
73
73
|
rounded?: boolean; // ๐
|
|
74
|
+
shape?: AbButtonShape; // ๐ท 0.1.14 (P16): 'rounded' = Home 10px radius (overrides `rounded`)
|
|
75
|
+
size?: AbButtonSize; // ๐ 0.1.14 (P16): 'md' = 40px / 44px on touch widths
|
|
74
76
|
raised?: boolean; // ๐๏ธ
|
|
75
77
|
shrinks?: boolean; // ๐ค
|
|
76
78
|
expands?: boolean; // ๐
|
|
@@ -117,6 +119,8 @@ const AbButton = forwardRef<HTMLButtonElement | HTMLAnchorElement, AbButtonProps
|
|
|
117
119
|
style, // ๐จ
|
|
118
120
|
iconStyle, // ๐จ
|
|
119
121
|
rounded = true, // ๐
|
|
122
|
+
shape, // ๐ท
|
|
123
|
+
size, // ๐
|
|
120
124
|
raised = false, // ๐๏ธ
|
|
121
125
|
shrinks = false, // ๐ค
|
|
122
126
|
expands = false, // ๐
|
|
@@ -167,6 +171,8 @@ const AbButton = forwardRef<HTMLButtonElement | HTMLAnchorElement, AbButtonProps
|
|
|
167
171
|
'data-iconpos': iconPosition, // โ๏ธ
|
|
168
172
|
'data-color': color, // ๐จ
|
|
169
173
|
'data-disabled-mode': mode, // ๐ฆ
|
|
174
|
+
'data-shape': shape, // ๐ท P16 (omitted when undefined)
|
|
175
|
+
'data-size': size, // ๐ P16
|
|
170
176
|
};
|
|
171
177
|
|
|
172
178
|
// ๐ฃ legacy Material icon (decorative)
|
|
@@ -181,3 +181,42 @@ a.abButton[data-type="outlined"] {
|
|
|
181
181
|
line-height: 32px; /* ๐ */
|
|
182
182
|
}
|
|
183
183
|
a.abButton.abButtonRounded { border-radius: 9999px; } /* ๐ */
|
|
184
|
+
|
|
185
|
+
/* ===== ๐ท 0.1.14 (P16, Home fidelity spec ยง4 CTAs): shape="rounded" ยท size="md" ยท type="secondary" =====
|
|
186
|
+
* Doubled class (0,3,0+) beats the theme's `button[data-type="filled"]` (0,1,1) and its :hover (0,3,1 โ we use 0,5,0). */
|
|
187
|
+
.abButton.abButton[data-shape="rounded"] {
|
|
188
|
+
gap: 6px; /* ๐งฑ icon โ label */
|
|
189
|
+
border-radius: var(--ab-radius-button, 10px); /* ๐ท */
|
|
190
|
+
padding: 0 var(--ab-button-padding-inline, 16px); /* ๐ฆ */
|
|
191
|
+
font-size: 14px; font-weight: 650; line-height: 1; white-space: nowrap; /* ๐ค */
|
|
192
|
+
overflow: visible; /* ๐ the primary shadow must show */
|
|
193
|
+
}
|
|
194
|
+
.abButton.abButton[data-size="md"] { height: var(--ab-button-height, 40px); box-sizing: border-box; } /* ๐ */
|
|
195
|
+
.abButton.abButton[data-shape="rounded"] .abButtonSlot { width: 18px; height: 18px; } /* ๐ผ๏ธ 18px icons */
|
|
196
|
+
.abButton.abButton[data-shape="rounded"] .abButtonSlot svg { width: 100%; height: 100%; }
|
|
197
|
+
/* ๐ฅ primary (filled) */
|
|
198
|
+
.abButton.abButton[data-shape="rounded"][data-type="filled"] {
|
|
199
|
+
background: var(--ab-color-btn, #8b6340); color: var(--ab-color-btn-text, #fff); /* ๐จ AA (theme 0.3.5) */
|
|
200
|
+
border: 0; box-shadow: var(--ab-shadow-button, 0 1px 0 rgb(255 255 255 / 0.2) inset, 0 4px 12px rgb(139 99 64 / 0.25)); /* โจ */
|
|
201
|
+
}
|
|
202
|
+
.abButton.abButton[data-shape="rounded"][data-type="filled"]:not(:disabled, [aria-disabled="true"]):hover {
|
|
203
|
+
background: color-mix(in srgb, var(--ab-color-btn, #8b6340) 90%, #000); /* ๐ฑ๏ธ */
|
|
204
|
+
}
|
|
205
|
+
/* โช secondary */
|
|
206
|
+
.abButton.abButton[data-type="secondary"] {
|
|
207
|
+
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); /* ๐จ */
|
|
208
|
+
box-sizing: border-box;
|
|
209
|
+
}
|
|
210
|
+
.abButton.abButton[data-type="secondary"]:not(:disabled, [aria-disabled="true"]):hover {
|
|
211
|
+
background: linear-gradient(var(--ab-color-hover, rgb(166 124 82 / 0.08)), var(--ab-color-hover, rgb(166 124 82 / 0.08))), var(--ab-color-card, #fff); /* ๐ฑ๏ธ tint over the card */
|
|
212
|
+
}
|
|
213
|
+
.abButton.abButton[data-shape="rounded"]:not(:disabled, [aria-disabled="true"]):active { transform: translateY(1px); } /* ๐ */
|
|
214
|
+
.abButton.abButton[data-shape="rounded"]:focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: 2px; } /* โฟ */
|
|
215
|
+
/* ๐ฑ touch widths: 44px, 14.5px (mock .M .btn; the app sets flex: 1) */
|
|
216
|
+
@media (max-width: 767px) {
|
|
217
|
+
.abButton.abButton[data-size="md"] { height: var(--ab-button-height-touch, 44px); }
|
|
218
|
+
.abButton.abButton[data-shape="rounded"][data-size="md"] { font-size: 14.5px; }
|
|
219
|
+
}
|
|
220
|
+
@media (prefers-reduced-motion: reduce) {
|
|
221
|
+
.abButton.abButton[data-shape="rounded"]:active { transform: none; } /* โฟ no nudge */
|
|
222
|
+
}
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
.abCardLink::after { content: ''; position: absolute; inset: 0; border-radius: inherit; } /* ๐งฒ whole card clickable */
|
|
59
59
|
.abCard[data-linked='true']:hover { background: var(--ab-color-surface-container, rgb(0 0 0 / 0.06)); } /* ๐ฑ๏ธ */
|
|
60
60
|
.abCard:focus-within:has(.abCardLink:focus-visible) {
|
|
61
|
-
outline: var(--ab-focus-ring-width, 2px) solid var(--ab-color-primary, #8f4c38); /* โฟ ring on the card */
|
|
61
|
+
outline: var(--ab-focus-ring-width, 2px) solid var(--ab-color-accent, var(--ab-color-primary, #8f4c38)); /* โฟ ring on the card */
|
|
62
62
|
outline-offset: var(--ab-focus-ring-offset, 2px); /* โฟ */
|
|
63
63
|
}
|
|
64
64
|
.abCardLink:focus-visible { outline: none; } /* โฟ the card shows the ring */
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
/* ๐จ hover / ๐ค press motion: .ab-motion-interactive + .ab-motion-press (ab-nextjs-animations) */
|
|
102
102
|
}
|
|
103
103
|
.nav:hover {
|
|
104
|
-
background-color: color-mix(in srgb, currentColor 8%, transparent); /* ๐ซ๏ธ */
|
|
104
|
+
background-color: var(--ab-color-hover, color-mix(in srgb, currentColor 8%, transparent)); /* ๐ซ๏ธ */
|
|
105
105
|
}
|
|
106
106
|
.nav[data-variant='filled'] {
|
|
107
107
|
border-color: transparent;
|
package/ab-chip/index.tsx
CHANGED
|
@@ -48,6 +48,8 @@ import styles from './styles.module.css';
|
|
|
48
48
|
|
|
49
49
|
// ๐จ dot colours
|
|
50
50
|
export type AbChipDot = 'sage' | 'bronze';
|
|
51
|
+
// ๐จ 0.1.14 (P16): Home chip tones ยท 'accent' = --tint bg + --accent-text ยท 'sage' = the `beta` chip
|
|
52
|
+
export type AbChipTone = 'neutral' | 'accent' | 'sage';
|
|
51
53
|
|
|
52
54
|
// โ๏ธ props
|
|
53
55
|
export interface AbChipProps {
|
|
@@ -57,14 +59,24 @@ export interface AbChipProps {
|
|
|
57
59
|
as?: 'span' | 'li'; // ๐งฑ 'li' inside a <ul> for lists of chips
|
|
58
60
|
className?: string; // ๐ท๏ธ
|
|
59
61
|
style?: CSSProperties; // ๐จ
|
|
62
|
+
size?: 'md' | 'sm'; // ๐ 0.1.14 (P16): 'sm' = the 20px Home chip (version, count, New)
|
|
63
|
+
shape?: 'pill' | 'rounded'; // ๐ท 0.1.14: 'rounded' = 6px radius (default pill)
|
|
64
|
+
mono?: boolean; // โจ๏ธ 0.1.14: Roboto Mono 11/600 (versions, package names)
|
|
65
|
+
tone?: AbChipTone; // ๐จ 0.1.14 (default 'neutral' = the legacy outline chip)
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
/** ๐ท๏ธ Static chip: plain text, never interactive (use AbButton for actions). */
|
|
63
|
-
export function AbChip({ children, dot, icon, as: Tag = 'span', className, style }: AbChipProps): ReactElement {
|
|
64
|
-
const
|
|
69
|
+
export function AbChip({ children, dot, icon, as: Tag = 'span', className, style, size = 'md', shape = 'pill', mono = false, tone = 'neutral' }: AbChipProps): ReactElement {
|
|
70
|
+
const dotTone = dot === true ? 'bronze' : dot || undefined; // ๐จ resolve dot colour
|
|
65
71
|
return (
|
|
66
|
-
<Tag
|
|
67
|
-
{
|
|
72
|
+
<Tag
|
|
73
|
+
className={clsx('AbChip', styles.chip, mono && styles.mono, className)} style={style} data-ab-part="chip"
|
|
74
|
+
data-size={size === 'sm' ? 'sm' : undefined} // ๐ P16
|
|
75
|
+
data-shape={shape === 'rounded' ? 'rounded' : undefined} // ๐ท
|
|
76
|
+
data-tone={tone === 'neutral' ? undefined : tone} // ๐จ
|
|
77
|
+
data-mono={mono ? 'true' : undefined} // โจ๏ธ
|
|
78
|
+
>
|
|
79
|
+
{dotTone ? <span className={styles.dot} data-tone={dotTone} aria-hidden="true" /> : null /* ๐ข decorative */}
|
|
68
80
|
{icon ? <span className={styles.icon} aria-hidden="true">{icon}</span> : null /* ๐ผ๏ธ decorative */}
|
|
69
81
|
<span>{children}</span>
|
|
70
82
|
</Tag>
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
gap: 0.375rem; /* ๐งฑ */
|
|
44
44
|
padding: 0.25rem 0.75rem; /* ๐งฑ */
|
|
45
45
|
border-radius: 9999px; /* ๐ */
|
|
46
|
-
border: 1px solid var(--ab-color-outline-variant, rgb(0 0 0 / 0.12)); /* ๐๏ธ */
|
|
46
|
+
border: 1px solid var(--ab-color-border, var(--ab-color-outline-variant, rgb(0 0 0 / 0.12))); /* ๐๏ธ */
|
|
47
47
|
background: var(--ab-color-surface-container, transparent); /* ๐จ */
|
|
48
48
|
color: var(--ab-color-on-surface, currentColor); /* ๐จ */
|
|
49
49
|
font-size: 0.875rem; /* ๐ก */
|
|
@@ -85,3 +85,14 @@
|
|
|
85
85
|
width: 1em; /* ๐ */
|
|
86
86
|
height: 1em; /* ๐ */
|
|
87
87
|
}
|
|
88
|
+
|
|
89
|
+
/* ===== ๐ 0.1.14 (P16, Home spec ยง2/ยง4): size="sm" ยท shape="rounded" ยท mono ยท tone ===== */
|
|
90
|
+
.chip[data-size='sm'] {
|
|
91
|
+
height: var(--ab-chip-height, 20px); box-sizing: border-box; /* ๐ */
|
|
92
|
+
padding: 0 var(--ab-chip-padding-inline, 7px); gap: 4px; /* ๐ฆ */
|
|
93
|
+
border: 0; font-size: 11px; font-weight: 600; line-height: 1; /* ๐ค mock .chip */
|
|
94
|
+
}
|
|
95
|
+
.chip[data-shape='rounded'] { border-radius: var(--ab-radius-chip, 6px); } /* ๐ท */
|
|
96
|
+
.chip[data-mono='true'] { font-family: var(--ab-font-code, 'Roboto Mono', ui-monospace, monospace); } /* โจ๏ธ */
|
|
97
|
+
.chip[data-tone='accent'] { background: var(--ab-color-tint, #f4e7db); color: var(--ab-color-accent-text, #88603d); border-color: transparent; } /* ๐ฅ */
|
|
98
|
+
.chip[data-tone='sage'] { background: rgb(119 141 121 / 0.12); color: var(--ab-color-sage-accent, #566a58); border-color: transparent; } /* ๐ฟ beta โฟ AA (John): fallback = theme 0.3.5 light value */
|
|
@@ -0,0 +1,97 @@
|
|
|
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: AbConfirmDrawer (G53 preset)
|
|
28
|
+
* @file: ab-confirm-drawer/index.tsx
|
|
29
|
+
* @type: Client component
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*
|
|
32
|
+
* Example usage:
|
|
33
|
+
* 1+|> <AbConfirmDrawer scope="main" open={d.open} onClose={d.close} title="Discard changes?"
|
|
34
|
+
* -|> message="Your edits will be lost." confirmLabel="Discard" tone="danger" onConfirm={discard} />
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
39
|
+
* MOTTO: We'll always do more ๐!!!
|
|
40
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
'use client';
|
|
45
|
+
|
|
46
|
+
// โ๏ธ React
|
|
47
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
48
|
+
// ๐งต classes
|
|
49
|
+
import clsx from 'clsx';
|
|
50
|
+
// ๐๏ธ the drawer
|
|
51
|
+
import AbDrawer, { type AbDrawerProps } from '../ab-drawer';
|
|
52
|
+
// ๐ the house buttons
|
|
53
|
+
import AbButton from '../ab-button';
|
|
54
|
+
// ๐จ styles
|
|
55
|
+
import styles from './styles.module.css';
|
|
56
|
+
|
|
57
|
+
/** โ๏ธ props: every AbDrawer prop (minus children / footer), plus the decision */
|
|
58
|
+
export interface AbConfirmDrawerProps extends Omit<AbDrawerProps, 'children' | 'footer'> {
|
|
59
|
+
message?: ReactNode; // ๐ what happens if you confirm
|
|
60
|
+
confirmLabel?: string; // โ
default "Confirm"
|
|
61
|
+
cancelLabel?: string; // โ default "Cancel"
|
|
62
|
+
onConfirm: () => void; // โ
the drawer closes after it (unless `closeOnConfirm={false}`)
|
|
63
|
+
onCancel?: () => void; // โ default: just close
|
|
64
|
+
tone?: 'default' | 'danger'; // ๐จ `danger` = destructive confirm
|
|
65
|
+
busy?: boolean; // โณ disables both buttons + spinner on confirm
|
|
66
|
+
closeOnConfirm?: boolean; // ๐ช default true
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* โ AbConfirmDrawer โ a yes / no decision that belongs to a region (e.g. "Discard changes?" inside main).
|
|
71
|
+
* Defaults to `side="bottom"`; Escape / scrim / close = cancel. For an app-wide blocking decision use a
|
|
72
|
+
* centred dialog instead (layout-rule guide, "Drawer, menu or dialog?").
|
|
73
|
+
*/
|
|
74
|
+
const AbConfirmDrawer = ({ message, confirmLabel = 'Confirm', cancelLabel = 'Cancel', onConfirm, onCancel, tone = 'default', busy = false, closeOnConfirm = true, onClose, className, side = 'bottom', ...drawer }: AbConfirmDrawerProps): ReactElement => {
|
|
75
|
+
const cancel = () => { onCancel?.(); onClose(); }; // โ then ๐ช
|
|
76
|
+
const confirm = () => { onConfirm(); if (closeOnConfirm) onClose(); }; // โ
then ๐ช
|
|
77
|
+
return (
|
|
78
|
+
<AbDrawer
|
|
79
|
+
{...drawer}
|
|
80
|
+
side={side}
|
|
81
|
+
onClose={cancel} // โ Escape / scrim / โ all mean "no"
|
|
82
|
+
className={clsx('AbConfirmDrawer', className)}
|
|
83
|
+
footer={
|
|
84
|
+
<>
|
|
85
|
+
<AbButton type="text" label={cancelLabel} onClick={cancel} disabled={busy} />
|
|
86
|
+
<AbButton type="filled" label={confirmLabel} onClick={confirm} isLoading={busy} disabled={busy} className={tone === 'danger' ? styles.abConfirmDanger : undefined} />
|
|
87
|
+
</>
|
|
88
|
+
}
|
|
89
|
+
>
|
|
90
|
+
{message != null && <div className={styles.abConfirmMessage} data-ab-part="confirm-message">{message}</div>}
|
|
91
|
+
</AbDrawer>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// ๐ฆ exports
|
|
96
|
+
export default AbConfirmDrawer;
|
|
97
|
+
export { AbConfirmDrawer };
|
|
@@ -0,0 +1,41 @@
|
|
|
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: AbConfirmDrawer styles
|
|
28
|
+
* @file: ab-confirm-drawer/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
|
+
|
|
40
|
+
.abConfirmMessage { margin: 0; line-height: 1.5; } /* ๐ */
|
|
41
|
+
.abConfirmDanger { --ab-button-background-color: var(--ab-color-error, #b3261e); --ab-button-text-color: var(--ab-color-on-error, #fff); } /* ๐จ destructive */
|
|
@@ -0,0 +1,134 @@
|
|
|
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: AbDrawer gestures
|
|
28
|
+
* @file: ab-drawer/gestures.ts
|
|
29
|
+
* @type: TypeScript โ pure swipe / snap resolvers
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
35
|
+
* MOTTO: We'll always do more ๐!!!
|
|
36
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
// ๐ค drawers v2 (John, God 01:22): the thresholds and decisions behind every drawer swipe, as pure functions,
|
|
40
|
+
// so the rules are unit-tested without a DOM and the components only feed them numbers.
|
|
41
|
+
|
|
42
|
+
/** ๐๏ธ the spec numbers (drawer-spec.md "Gestures" + "Edge zones") */
|
|
43
|
+
export const AB_SWIPE = {
|
|
44
|
+
ratio: 0.3, // ๐ 30% of the travel / sheet / drawer width
|
|
45
|
+
velocity: 0.5, // โก px per ms: at or above this a release counts as a fast swipe
|
|
46
|
+
edge: 24, // ๐งฑ edge zone width (px) for the side-drawer swipes
|
|
47
|
+
standaloneInset: 16, // ๐ฑ iOS standalone: the zone starts 16px in (the system owns the very edge)
|
|
48
|
+
slop: 8, // ๐ซณ px of movement before a press becomes a drag (taps stay taps)
|
|
49
|
+
secondSwipe: 24, // โ๏ธ px: after a gentle return to S1, a swipe down this long closes (the "second swipe")
|
|
50
|
+
} as const;
|
|
51
|
+
|
|
52
|
+
/** ๐งฒ bottom-sheet snap states: S1 (`partial`, 70%), S2 (`full`) or gone */
|
|
53
|
+
export type AbSheetSnap = 'partial' | 'full';
|
|
54
|
+
/** ๐ what a release resolves to */
|
|
55
|
+
export type AbSheetRelease = AbSheetSnap | 'closed';
|
|
56
|
+
|
|
57
|
+
/** ๐ฅ one release of a bottom-sheet drag */
|
|
58
|
+
export interface AbSheetReleaseInput {
|
|
59
|
+
from: AbSheetSnap; // ๐งฒ where the drag started
|
|
60
|
+
dy: number; // โ๏ธ total movement, + = down
|
|
61
|
+
velocity: number; // โก px/ms at release, + = down
|
|
62
|
+
partialHeight: number; // ๐ S1 height (70% of the app height)
|
|
63
|
+
fullHeight: number; // ๐ S2 height (app height minus the safe-area top)
|
|
64
|
+
returned?: boolean; // โ๏ธ the sheet came back to S1 from S2 with a gentle drag (so the next swipe down closes)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* ๐งฒ resolveAbSheetRelease โ where a released bottom sheet goes (spec ยง1 "Gestures"):
|
|
69
|
+
* - โฌ๏ธ up past 30% of S1โS2, or faster than 0.5px/ms โ `full`
|
|
70
|
+
* - โฌ๏ธ at S2: fast (โฅ 0.5px/ms) or past 30% of the sheet โ `closed`; a gentle drag โ back to `partial`
|
|
71
|
+
* - โฌ๏ธ at S1: fast or past 30% of S1 โ `closed`; after a gentle return from S2 any real swipe down (โฅ 24px) โ `closed`
|
|
72
|
+
* - otherwise it springs back to where it was
|
|
73
|
+
*/
|
|
74
|
+
export function resolveAbSheetRelease({ from, dy, velocity, partialHeight, fullHeight, returned = false }: AbSheetReleaseInput): AbSheetRelease {
|
|
75
|
+
const fast = Math.abs(velocity) >= AB_SWIPE.velocity; // โก
|
|
76
|
+
if (dy < 0) { // โฌ๏ธ up
|
|
77
|
+
if (from === 'full') return 'full'; // ๐งฑ already at the top
|
|
78
|
+
const travel = Math.max(1, fullHeight - partialHeight); // ๐ S1 โ S2 distance
|
|
79
|
+
return -dy > AB_SWIPE.ratio * travel || (fast && velocity < 0) ? 'full' : 'partial'; // ๐งฒ
|
|
80
|
+
}
|
|
81
|
+
if (from === 'full') { // โฌ๏ธ from S2
|
|
82
|
+
if ((fast && velocity > 0) || dy > AB_SWIPE.ratio * fullHeight) return 'closed'; // ๐จ hard swipe
|
|
83
|
+
return dy > AB_SWIPE.slop ? 'partial' : 'full'; // ๐ซณ gentle โ S1 (a tap jitter stays at S2)
|
|
84
|
+
}
|
|
85
|
+
// โฌ๏ธ from S1
|
|
86
|
+
if ((fast && velocity > 0) || dy > AB_SWIPE.ratio * partialHeight) return 'closed'; // ๐จ
|
|
87
|
+
if (returned && dy >= AB_SWIPE.secondSwipe) return 'closed'; // โ๏ธ the second swipe
|
|
88
|
+
return 'partial'; // ๐งฒ spring back
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** ๐ฅ one release of a side-drawer swipe (edge swipe to open, or a swipe on the sheet to close) */
|
|
92
|
+
export interface AbSideReleaseInput {
|
|
93
|
+
distance: number; // โ๏ธ movement in the opening / closing direction (px, + = that way)
|
|
94
|
+
velocity: number; // โก px/ms in that same direction
|
|
95
|
+
width: number; // ๐ the drawer width (320 left, 296 right)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** โ๏ธ resolveAbSideRelease โ does a side swipe commit? Past 30% of the width, or faster than 0.5px/ms that way. */
|
|
99
|
+
export function resolveAbSideRelease({ distance, velocity, width }: AbSideReleaseInput): boolean {
|
|
100
|
+
if (distance <= 0) return false; // ๐ซ wrong way (or nowhere)
|
|
101
|
+
return distance > AB_SWIPE.ratio * width || velocity >= AB_SWIPE.velocity; // โ
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** ๐งฑ isInAbEdgeZone โ does a press at `x` start inside the `edge` zone of a box [left, right]? */
|
|
105
|
+
export function isInAbEdgeZone(x: number, edge: 'left' | 'right', box: { left: number; right: number }, standalone = false): boolean {
|
|
106
|
+
const inset = standalone ? AB_SWIPE.standaloneInset : 0; // ๐ฑ iOS standalone: 16px in
|
|
107
|
+
const d = edge === 'left' ? x - box.left : box.right - x; // ๐ distance from that edge
|
|
108
|
+
return d >= inset && d <= inset + AB_SWIPE.edge; // ๐ฏ
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** โก a tiny velocity tracker: feed it samples, read px/ms over the last ~100ms */
|
|
112
|
+
export function createAbVelocityTracker(windowMs = 100): { add: (pos: number, t: number) => void; velocity: () => number; reset: () => void } {
|
|
113
|
+
let samples: Array<[number, number]> = []; // ๐งบ [pos, time]
|
|
114
|
+
return {
|
|
115
|
+
add(pos, t) { samples.push([pos, t]); samples = samples.filter(([, ts]) => t - ts <= windowMs); }, // โ keep the window
|
|
116
|
+
velocity() {
|
|
117
|
+
if (samples.length < 2) return 0; // ๐ซฅ
|
|
118
|
+
const [p0, t0] = samples[0]; const [p1, t1] = samples[samples.length - 1]; // ๐ first / last
|
|
119
|
+
return t1 > t0 ? (p1 - p0) / (t1 - t0) : 0; // โก
|
|
120
|
+
},
|
|
121
|
+
reset() { samples = []; }, // ๐งน
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** ๐ isInAbHorizontalScroller โ is `el` inside something that scrolls sideways (a code block, a carousel)?
|
|
126
|
+
* Edge swipes started there are ignored, so they never fight the user's horizontal scroll. */
|
|
127
|
+
export function isInAbHorizontalScroller(el: Element | null, stop?: Element | null): boolean {
|
|
128
|
+
for (let n = el; n && n !== stop && n !== document.documentElement; n = n.parentElement) {
|
|
129
|
+
if (n.closest('[data-ab-no-edge-swipe]') === n) return true; // ๐
explicit opt-out
|
|
130
|
+
const ox = getComputedStyle(n).overflowX; // ๐
|
|
131
|
+
if ((ox === 'auto' || ox === 'scroll') && n.scrollWidth > n.clientWidth) return true; // ๐
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
}
|