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,204 @@
|
|
|
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: Drawers v2 kit styles
|
|
28
|
+
* @file: ab-drawer/kit.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
|
+
/* ๐งฐ drawers v2 (John's frames, God 01:22): the shared look of AbSettingsDrawer, AbNavDrawer, AbTocDrawer and
|
|
41
|
+
AbSearchDrawer. Values are the mock's (drawer.css), read through the theme tokens where theme 0.3.5+ has them.
|
|
42
|
+
Doubled classes beat AbDrawer's own rules without !important. */
|
|
43
|
+
|
|
44
|
+
/* ๐จ local tokens: light, then dark (CSS modules need :global for the theme classes) */
|
|
45
|
+
.sheet {
|
|
46
|
+
--ab-dr-bg: var(--ab-color-bg, #fff8f5); /* ๐จ --bg */
|
|
47
|
+
--ab-dr-card: var(--ab-color-card, #fff); /* ๐ --card */
|
|
48
|
+
--ab-dr-card2: #fbf3ec; /* ๐ --card2 (segmented track) */
|
|
49
|
+
--ab-dr-on: #f7ede4; /* ๐ฏ the active row (mock .light .row.on) */
|
|
50
|
+
--ab-dr-on-ring: inset 0 0 0 1px rgb(166 124 82 / 0.3); /* ๐ฏ its 1px ring */
|
|
51
|
+
--ab-dr-seg-on: var(--ab-color-card, #fff); /* ๐๏ธ the raised segment */
|
|
52
|
+
--ab-dr-faint: #9c8c80; /* โ the handle bar (--faint) */
|
|
53
|
+
}
|
|
54
|
+
:global(.dark) .sheet, :global([data-theme='dark']) .sheet {
|
|
55
|
+
--ab-dr-bg: var(--ab-color-pane-main, #1d150f); /* ๐ the sheet is #1D150F */
|
|
56
|
+
--ab-dr-card2: #2c2118;
|
|
57
|
+
--ab-dr-on: var(--ab-color-tint, rgb(166 124 82 / 0.2)); /* ๐ tint, no ring */
|
|
58
|
+
--ab-dr-on-ring: none;
|
|
59
|
+
--ab-dr-seg-on: #3a2b1e;
|
|
60
|
+
--ab-dr-faint: #86776b;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* ๐๏ธ every v2 sheet: --bg, a 1px --border edge, the mock shadow */
|
|
64
|
+
.sheet.sheet {
|
|
65
|
+
background: var(--ab-dr-bg); color: var(--ab-color-text, #211a16); /* ๐จ */
|
|
66
|
+
border: 1px solid var(--ab-color-border, rgb(92 64 48 / 0.13)); /* โ */
|
|
67
|
+
box-shadow: 0 -8px 32px rgb(25 18 12 / 0.22); /* ๐ */
|
|
68
|
+
outline: none; /* ๐ฏ */
|
|
69
|
+
}
|
|
70
|
+
/* โฌ๏ธ bottom: 16px top radius, no bottom edge; 16px + home indicator below (24px on laptop) */
|
|
71
|
+
.sheet.sheet[data-side='bottom'] { border-bottom: 0; border-radius: 16px 16px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
|
|
72
|
+
.sheet.sheet[data-side='bottom'][data-center='main'] { padding-bottom: 24px; }
|
|
73
|
+
/* โฌ
๏ธ left: 320px, 0 16 16 0; โก๏ธ right: 296px, 16 0 0 16 (widths come from `size`) */
|
|
74
|
+
.sheet.sheet:is([data-side='left'], [data-side='start']) { border-inline-start: 0; border-radius: 0 16px 16px 0; box-shadow: 8px 0 32px rgb(25 18 12 / 0.22); padding-top: env(safe-area-inset-top, 0px); }
|
|
75
|
+
.sheet.sheet:is([data-side='right'], [data-side='end']) { border-inline-end: 0; border-radius: 16px 0 0 16px; box-shadow: -8px 0 32px rgb(25 18 12 / 0.22); padding-top: env(safe-area-inset-top, 0px); }
|
|
76
|
+
.sheet.sheet:is([data-side='left'], [data-side='start'], [data-side='right'], [data-side='end']) { max-width: 100%; }
|
|
77
|
+
|
|
78
|
+
/* โ the handle bar: 40ร4 in --faint */
|
|
79
|
+
.sheet [data-ab-part='drawer-handle']::before { background: var(--ab-dr-faint); }
|
|
80
|
+
/* ๐ header: 56px, 24px start inset; the title is Mulish 800 22px (20px on the right drawer) */
|
|
81
|
+
.sheet [data-ab-part='drawer-header'] { block-size: 56px; box-sizing: border-box; padding: 0 8px 0 24px; gap: 8px; }
|
|
82
|
+
.sheet [data-ab-part='drawer-header'] > :first-child { font-family: var(--ab-font-title, 'Mulish', inherit); font-weight: 800; font-size: 22px; letter-spacing: -0.01em; line-height: 1.2; }
|
|
83
|
+
.titleSm [data-ab-part='drawer-header'] > :first-child { font-size: 20px; }
|
|
84
|
+
/* โ close: 44px, 8px radius, --muted, 24px glyph */
|
|
85
|
+
.sheet [data-ab-part='drawer-close'] { inline-size: 44px; block-size: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; color: var(--ab-color-muted, #6b5b50); }
|
|
86
|
+
.sheet [data-ab-part='drawer-close']:hover { background: var(--ab-color-hover, rgb(166 124 82 / 0.08)); }
|
|
87
|
+
.sheet [data-ab-part='drawer-close']:focus { outline: none; }
|
|
88
|
+
.sheet [data-ab-part='drawer-close']:focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: 2px; }
|
|
89
|
+
/* ๐ body: 16px sides */
|
|
90
|
+
.sheet [data-ab-part='drawer-body'] { padding: 0 16px; display: flex; flex-direction: column; }
|
|
91
|
+
|
|
92
|
+
/* ๐ท๏ธ section label: Inter 700 12/16 uppercase +0.08em, --muted */
|
|
93
|
+
.lbl { margin: 0; padding: 16px 16px 8px; font: 700 12px/16px var(--ab-font-body, 'Inter', inherit); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ab-color-muted, #6b5b50); }
|
|
94
|
+
/* โญ a 48px row (settings, footer links) */
|
|
95
|
+
.row {
|
|
96
|
+
box-sizing: border-box; display: flex; align-items: center; gap: 16px; flex: none; /* ๐ */
|
|
97
|
+
block-size: 48px; padding: 0 16px; border: 0; border-radius: 8px; margin: 0; inline-size: 100%; /* ๐ */
|
|
98
|
+
background: transparent; color: var(--ab-color-text, #211a16); font: 500 16px/1.2 var(--ab-font-body, 'Inter', inherit); /* ๐ค */
|
|
99
|
+
text-align: start; text-decoration: none; cursor: pointer; /* ๐ฑ๏ธ */
|
|
100
|
+
}
|
|
101
|
+
.row > svg, .row > .ic { flex: none; inline-size: 24px; block-size: 24px; color: var(--ab-color-muted, #6b5b50); }
|
|
102
|
+
.row:hover { background: var(--ab-color-hover, rgb(166 124 82 / 0.08)); }
|
|
103
|
+
.row:focus { outline: none; }
|
|
104
|
+
.row:focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: -2px; }
|
|
105
|
+
.row[aria-checked='true'], .row[aria-current='page'] { background: var(--ab-dr-on); box-shadow: var(--ab-dr-on-ring); color: var(--ab-color-accent-text, #8b6340); font-weight: 700; } /* ๐ฏ */
|
|
106
|
+
.row[aria-checked='true'] > svg, .row[aria-current='page'] > svg { color: var(--ab-color-accent-text, #8b6340); }
|
|
107
|
+
.ck { margin-inline-start: auto; color: var(--ab-color-accent-text, #8b6340); } /* โ 24px check */
|
|
108
|
+
.row > .ck { color: var(--ab-color-accent-text, #8b6340); }
|
|
109
|
+
.chev { margin-inline-start: 0; } /* โบ right after the label (mock: "Settings โบ") */
|
|
110
|
+
.hr { block-size: 1px; margin: 8px 16px; border: 0; background: var(--ab-color-div, rgb(92 64 48 / 0.11)); flex: none; }
|
|
111
|
+
|
|
112
|
+
/* ๐๏ธ segmented control: 48px, 4px track padding, 3 equal segments, 14px 600 */
|
|
113
|
+
.seg { box-sizing: border-box; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; block-size: 48px; padding: 4px; margin: 0 0 8px; border-radius: 8px; background: var(--ab-dr-card2); border: 1px solid var(--ab-color-border, rgb(92 64 48 / 0.13)); }
|
|
114
|
+
.segBtn { display: flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 6px; background: transparent; color: var(--ab-color-muted, #6b5b50); font: 600 14px/1 var(--ab-font-body, 'Inter', inherit); cursor: pointer; padding: 0; }
|
|
115
|
+
.segBtn > svg { inline-size: 18px; block-size: 18px; }
|
|
116
|
+
.segBtn[aria-checked='true'] { background: var(--ab-dr-seg-on); color: var(--ab-color-accent-text, #8b6340); box-shadow: 0 1px 3px rgb(25 18 12 / 0.12); outline: 1px solid var(--ab-color-border, rgb(92 64 48 / 0.13)); }
|
|
117
|
+
.segBtn:focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: 1px; }
|
|
118
|
+
|
|
119
|
+
/* โฌ
๏ธ the nav drawer: logo header, the version chip, a scrolling nav (44px rows, 15px) with a 72px fade, a pinned footer */
|
|
120
|
+
.logoRow { display: flex; align-items: center; min-inline-size: 0; }
|
|
121
|
+
.logoRow a { display: flex; align-items: center; color: inherit; }
|
|
122
|
+
.ver { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; block-size: 32px; padding: 0 8px 0 10px; margin: 0 0 8px 8px; box-sizing: border-box; border-radius: 8px; border: 1px solid var(--ab-color-border, rgb(92 64 48 / 0.13)); background: var(--ab-dr-card); color: var(--ab-color-muted, #6b5b50); font: 500 13px/1 var(--ab-font-body, 'Inter', inherit); }
|
|
123
|
+
.ver b { font-family: var(--ab-font-mono, 'Roboto Mono', monospace); color: var(--ab-color-accent-text, #8b6340); font-weight: 600; }
|
|
124
|
+
.ver > svg { inline-size: 18px; block-size: 18px; }
|
|
125
|
+
.navWrap { position: relative; flex: 1 1 auto; min-block-size: 0; display: flex; flex-direction: column; }
|
|
126
|
+
.nav { flex: 1 1 auto; min-block-size: 0; overflow: hidden auto; overscroll-behavior: contain; padding-bottom: 72px; }
|
|
127
|
+
.fade { position: absolute; inset: auto 0 0; block-size: 72px; pointer-events: none; background: linear-gradient(transparent, var(--ab-dr-bg)); } /* ๐ซ๏ธ marks the scroll */
|
|
128
|
+
.grp { margin: 0; padding: 16px 12px 8px; font: 700 12px/16px var(--ab-font-body, 'Inter', inherit); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ab-color-muted, #6b5b50); }
|
|
129
|
+
.list { list-style: none; margin: 0; padding: 0; }
|
|
130
|
+
.nv { box-sizing: border-box; display: flex; align-items: center; gap: 12px; block-size: 44px; padding: 0 12px; border-radius: 8px; color: var(--ab-color-text, #211a16); font: 500 15px/1.2 var(--ab-font-body, 'Inter', inherit); text-decoration: none; }
|
|
131
|
+
.nv > svg { flex: none; inline-size: 22px; block-size: 22px; color: var(--ab-color-muted, #6b5b50); }
|
|
132
|
+
.nv:hover { background: var(--ab-color-hover, rgb(166 124 82 / 0.08)); }
|
|
133
|
+
.nv:focus { outline: none; }
|
|
134
|
+
.nv:focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: -2px; }
|
|
135
|
+
.nv[aria-current='page'] { background: var(--ab-dr-on); box-shadow: var(--ab-dr-on-ring); color: var(--ab-color-accent-text, #8b6340); font-weight: 700; }
|
|
136
|
+
.nv[aria-current='page'] > svg { color: var(--ab-color-accent-text, #8b6340); }
|
|
137
|
+
.mini { margin-inline-start: auto; font: 400 12px/1 var(--ab-font-mono, 'Roboto Mono', monospace); color: var(--ab-color-muted, #6b5b50); }
|
|
138
|
+
.navFoot { flex: none; border-top: 1px solid var(--ab-color-div, rgb(92 64 48 / 0.11)); margin: 0 -16px; padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px)); } /* ๐ pinned, full-width rule */
|
|
139
|
+
|
|
140
|
+
/* โก๏ธ the outline: 44px rows on a 2px rail, level 3 indented 16px, the active one bronze */
|
|
141
|
+
.toc { list-style: none; margin: 0 0 0 8px; padding: 0; }
|
|
142
|
+
.tocLink { box-sizing: border-box; display: flex; align-items: center; block-size: 44px; padding: 0 16px; border-inline-start: 2px solid var(--ab-color-div, rgb(92 64 48 / 0.11)); color: var(--ab-color-muted, #6b5b50); font: 400 15px/1.2 var(--ab-font-body, 'Inter', inherit); text-decoration: none; }
|
|
143
|
+
.tocLink[data-level='3'] { padding-inline-start: 32px; font-size: 14px; }
|
|
144
|
+
.tocLink[data-level='4'] { padding-inline-start: 48px; font-size: 14px; }
|
|
145
|
+
.tocLink[aria-current='location'] { border-inline-start-color: var(--ab-color-accent, #a67c52); color: var(--ab-color-accent-text, #8b6340); font-weight: 700; background: var(--ab-color-hover, rgb(166 124 82 / 0.08)); }
|
|
146
|
+
.tocLink:focus { outline: none; }
|
|
147
|
+
.tocLink:focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: -2px; }
|
|
148
|
+
.tocHr { margin: 16px 8px; }
|
|
149
|
+
.tocRow { font-size: 15px; margin: 0 -8px; inline-size: calc(100% + 16px); }
|
|
150
|
+
|
|
151
|
+
/* ๐ search: a 48px field with a 2px accent border, then the results (they scroll) */
|
|
152
|
+
.searchBody { flex: 1 1 auto; min-block-size: 0; display: flex; flex-direction: column; }
|
|
153
|
+
.field { box-sizing: border-box; flex: none; display: flex; align-items: center; gap: 12px; block-size: 48px; padding: 0 4px 0 16px; margin: 0 0 8px; border-radius: 8px; border: 2px solid var(--ab-color-accent, #a67c52); background: var(--ab-dr-card); }
|
|
154
|
+
.field > svg { flex: none; inline-size: 22px; block-size: 22px; color: var(--ab-color-muted, #6b5b50); }
|
|
155
|
+
.input { flex: 1 1 auto; min-inline-size: 0; border: 0; outline: none; background: transparent; color: var(--ab-color-text, #211a16); font: 500 16px/1.2 var(--ab-font-body, 'Inter', inherit); caret-color: var(--ab-color-accent-text, #8b6340); padding: 0; }
|
|
156
|
+
.input::placeholder { color: var(--ab-color-muted, #6b5b50); font-weight: 400; }
|
|
157
|
+
.input::-webkit-search-cancel-button { display: none; }
|
|
158
|
+
.iconSm { flex: none; inline-size: 40px; block-size: 40px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 8px; background: transparent; color: var(--ab-color-muted, #6b5b50); cursor: pointer; padding: 0; }
|
|
159
|
+
.iconSm > svg { inline-size: 20px; block-size: 20px; }
|
|
160
|
+
.iconSm:hover { background: var(--ab-color-hover, rgb(166 124 82 / 0.08)); }
|
|
161
|
+
.iconSm:focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: -2px; }
|
|
162
|
+
.results { flex: 1 1 auto; min-block-size: 0; overflow: hidden auto; overscroll-behavior: contain; }
|
|
163
|
+
.recent { gap: 12px; padding-inline-end: 0; font-size: 15px; cursor: default; }
|
|
164
|
+
.recent:hover { background: transparent; }
|
|
165
|
+
.recentGo { flex: 1 1 auto; min-inline-size: 0; border: 0; background: none; padding: 0; text-align: start; color: inherit; font: inherit; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
166
|
+
.recentGo:focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: 2px; }
|
|
167
|
+
.grp2 { display: flex; align-items: baseline; gap: 8px; padding: 12px 16px 4px; margin: 0; }
|
|
168
|
+
.grp2 > span { font: 700 12px/16px var(--ab-font-body, 'Inter', inherit); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ab-color-muted, #6b5b50); }
|
|
169
|
+
.grp2 > code { font: 400 12px/16px var(--ab-font-mono, 'Roboto Mono', monospace); color: var(--ab-color-muted, #6b5b50); }
|
|
170
|
+
.sr { box-sizing: border-box; display: flex; align-items: center; gap: 12px; min-block-size: 56px; padding: 4px 12px; border-radius: 8px; color: inherit; text-decoration: none; }
|
|
171
|
+
.sr[aria-selected='true'] { background: var(--ab-dr-on); box-shadow: var(--ab-dr-on-ring); }
|
|
172
|
+
.sr:hover { background: var(--ab-color-hover, rgb(166 124 82 / 0.08)); }
|
|
173
|
+
.sr[aria-selected='true']:hover { background: var(--ab-dr-on); }
|
|
174
|
+
.pkgIc { flex: none; inline-size: 32px; block-size: 32px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; background: var(--ab-dr-card2); color: var(--ab-color-accent-text, #8b6340); }
|
|
175
|
+
.pkgIc > svg { inline-size: 20px; block-size: 20px; }
|
|
176
|
+
.srText { flex: 1 1 auto; min-inline-size: 0; }
|
|
177
|
+
.srText > b { display: block; font: 600 15px/1.3 var(--ab-font-body, 'Inter', inherit); color: var(--ab-color-text, #211a16); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
178
|
+
.srText > small { display: block; font: 400 13px/1.35 var(--ab-font-body, 'Inter', inherit); color: var(--ab-color-muted, #6b5b50); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
179
|
+
.srMeta { flex: none; font: 400 12px/1 var(--ab-font-mono, 'Roboto Mono', monospace); color: var(--ab-color-muted, #6b5b50); }
|
|
180
|
+
.mark { background: none; color: var(--ab-color-accent-text, #8b6340); font-weight: 700; } /* ๐๏ธ the matched part */
|
|
181
|
+
.nores { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 48px 24px; }
|
|
182
|
+
.nores > .pkgIc { inline-size: 56px; block-size: 56px; border-radius: 16px; }
|
|
183
|
+
.nores > .pkgIc > svg { inline-size: 28px; block-size: 28px; }
|
|
184
|
+
.nores > b { margin-top: 8px; font: 800 20px/1.2 var(--ab-font-title, 'Mulish', inherit); }
|
|
185
|
+
.nores > p { margin: 0; max-inline-size: 300px; font: 400 15px/1.5 var(--ab-font-body, 'Inter', inherit); color: var(--ab-color-muted, #6b5b50); }
|
|
186
|
+
.srOnly { position: absolute; inline-size: 1px; block-size: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
|
|
187
|
+
|
|
188
|
+
/* ๐ฑ the mobile main header: 56px row, logo left, 44px globe + theme buttons right */
|
|
189
|
+
.mh { box-sizing: border-box; display: flex; align-items: center; block-size: 100%; min-block-size: 56px; padding: 0 4px 0 16px; gap: 0; background: transparent; }
|
|
190
|
+
.mh > .logoRow { flex: 1 1 auto; }
|
|
191
|
+
.ibtn { flex: none; inline-size: 44px; block-size: 44px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 8px; background: transparent; color: var(--ab-color-text, #211a16); cursor: pointer; padding: 0; }
|
|
192
|
+
.ibtn > svg { inline-size: 24px; block-size: 24px; }
|
|
193
|
+
.ibtn:hover { background: var(--ab-color-hover, rgb(166 124 82 / 0.08)); }
|
|
194
|
+
.ibtn:focus { outline: none; }
|
|
195
|
+
.ibtn:focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: -2px; }
|
|
196
|
+
.verRow { display: flex; flex: none; } /* ๐ท๏ธ keeps the chip its own size */
|
|
197
|
+
|
|
198
|
+
/* ๐ the search sheet: laptop = a fixed 70% (567px at 810) with the results scrolling inside under a 48px fade */
|
|
199
|
+
.searchSheet.searchSheet[data-center='main'] { block-size: 70%; }
|
|
200
|
+
.resWrap { position: relative; flex: 1 1 auto; min-block-size: 0; display: flex; flex-direction: column; }
|
|
201
|
+
.resFade { display: none; position: absolute; inset: auto 0 0; block-size: 48px; pointer-events: none; background: linear-gradient(transparent, var(--ab-dr-bg)); }
|
|
202
|
+
.searchSheet[data-center='main'] .resFade { display: block; }
|
|
203
|
+
.didYouMean { justify-content: center; gap: 0; margin-top: 8px; font-size: 15px; }
|
|
204
|
+
.nores code { font-family: var(--ab-font-mono, 'Roboto Mono', monospace); }
|
|
@@ -0,0 +1,166 @@
|
|
|
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 styles (G53)
|
|
28
|
+
* @file: ab-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
|
+
/* ๐ the anchor is layout-neutral: the drawer itself lives in the scope's layer */
|
|
41
|
+
.abDrawerAnchor { display: contents; }
|
|
42
|
+
|
|
43
|
+
/* ๐งฑ the layer: absolute `inset: 0` INSIDE the scope box (app / main / aside), so a drawer is clipped
|
|
44
|
+
by its scope and never makes the document scroll (D34). Clicks pass through when no drawer is open. */
|
|
45
|
+
.abDrawerLayer {
|
|
46
|
+
position: absolute; /* ๐ inside the scope box */
|
|
47
|
+
inset: 0; /* ๐ the whole scope */
|
|
48
|
+
z-index: 60; /* โฌ๏ธ above the panes and the aside sheet (30) */
|
|
49
|
+
overflow: hidden; /* โ๏ธ a sliding panel never leaks out */
|
|
50
|
+
overflow: clip; /* โ๏ธ 0.2.0: clip, so nothing (focus, scrollIntoView) can scroll the layer itself */
|
|
51
|
+
pointer-events: none; /* ๐ฑ๏ธ idle layer = transparent to clicks */
|
|
52
|
+
contain: layout paint; /* ๐ */
|
|
53
|
+
}
|
|
54
|
+
.abDrawerLayer[data-host='body'] { position: fixed; } /* ๐ no AbAppLayout: cover the viewport */
|
|
55
|
+
|
|
56
|
+
.abDrawerFrame { position: absolute; inset: 0; pointer-events: auto; } /* ๐ฑ๏ธ a drawer is up */
|
|
57
|
+
|
|
58
|
+
/* ๐ซ๏ธ scrim */
|
|
59
|
+
.abDrawerScrim {
|
|
60
|
+
position: absolute; /* ๐ */
|
|
61
|
+
inset: 0; /* ๐ */
|
|
62
|
+
background: var(--ab-scrim-color, rgb(25 18 12 / 0.4)); /* ๐ซ๏ธ theme 0.3.5: 40% light / 60% dark (John) */
|
|
63
|
+
opacity: 0; /* ๐ซฅ */
|
|
64
|
+
--ab-motion-duration: var(--ab-drawer-duration, 240ms); /* ๐๏ธ fade = .ab-motion-colors (ab-nextjs-animations) */
|
|
65
|
+
}
|
|
66
|
+
.abDrawerFrame[data-state='open'] > .abDrawerScrim { opacity: 1; } /* ๐ซ๏ธ */
|
|
67
|
+
|
|
68
|
+
/* ๐๏ธ the panel */
|
|
69
|
+
.abDrawer {
|
|
70
|
+
--ab-drawer-shift: 100%; /* ๐ how far it starts off-screen */
|
|
71
|
+
position: absolute; /* ๐ */
|
|
72
|
+
display: flex; /* ๐ header ยท body ยท footer */
|
|
73
|
+
flex-direction: column; /* โ๏ธ */
|
|
74
|
+
box-sizing: border-box; /* ๐ฆ */
|
|
75
|
+
margin: 0; /* ๐งน */
|
|
76
|
+
min-width: 0; /* ๐ซ overflow */
|
|
77
|
+
min-height: 0; /* ๐ซ overflow */
|
|
78
|
+
background: var(--ab-color-surface-container-low, var(--surface-color, Canvas)); /* ๐จ */
|
|
79
|
+
color: var(--ab-color-on-surface, var(--on-surface-color, CanvasText)); /* ๐๏ธ */
|
|
80
|
+
box-shadow: 0 8px 32px rgb(0 0 0 / 0.24); /* ๐ */
|
|
81
|
+
outline: none; /* ๐ฏ the panel itself is only a fallback focus target */
|
|
82
|
+
overscroll-behavior: contain; /* ๐ซ scroll chaining (G54) */
|
|
83
|
+
--ab-motion-duration: var(--ab-drawer-duration, 240ms); /* ๐๏ธ the panes slide = .ab-motion-transform (ab-nextjs-animations) */
|
|
84
|
+
--ab-motion-easing: cubic-bezier(0.2, 0, 0, 1); /* ๐ */
|
|
85
|
+
}
|
|
86
|
+
.abDrawer[data-side='bottom'] { inset: auto 0 0 0; max-height: min(85%, var(--ab-drawer-size, 480px)); border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); transform: translateY(var(--ab-drawer-shift)); } /* โฌ๏ธ */
|
|
87
|
+
.abDrawer[data-side='top'] { inset: 0 0 auto 0; max-height: min(85%, var(--ab-drawer-size, 480px)); border-radius: 0 0 16px 16px; padding-top: env(safe-area-inset-top, 0px); transform: translateY(calc(-1 * var(--ab-drawer-shift))); } /* โฌ๏ธ */
|
|
88
|
+
.abDrawer[data-side='left'] { inset: 0 auto 0 0; width: min(85%, var(--ab-drawer-size, 360px)); transform: translateX(calc(-1 * var(--ab-drawer-shift))); } /* โก๏ธ */
|
|
89
|
+
.abDrawer[data-side='right'] { inset: 0 0 0 auto; width: min(85%, var(--ab-drawer-size, 360px)); transform: translateX(var(--ab-drawer-shift)); } /* โฌ
๏ธ */
|
|
90
|
+
/* ๐ logical sides follow the writing direction */
|
|
91
|
+
.abDrawer[data-side='start'] { inset-block: 0; inset-inline-start: 0; width: min(85%, var(--ab-drawer-size, 360px)); transform: translateX(calc(-1 * var(--ab-drawer-shift))); }
|
|
92
|
+
.abDrawer[data-side='end'] { inset-block: 0; inset-inline-end: 0; width: min(85%, var(--ab-drawer-size, 360px)); transform: translateX(var(--ab-drawer-shift)); }
|
|
93
|
+
.abDrawer[data-side='start']:dir(rtl) { transform: translateX(var(--ab-drawer-shift)); } /* ๐ RTL */
|
|
94
|
+
.abDrawer[data-side='end']:dir(rtl) { transform: translateX(calc(-1 * var(--ab-drawer-shift))); } /* ๐ RTL */
|
|
95
|
+
.abDrawerFrame[data-state='open'] > .abDrawer { transform: none; } /* ๐ฌ slid in */
|
|
96
|
+
|
|
97
|
+
.abDrawerHeader { flex: none; display: flex; align-items: center; gap: 8px; padding: 12px 8px 4px 20px; } /* ๐ */
|
|
98
|
+
.abDrawerTitle { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 1.125rem; font-weight: 600; } /* ๐ท๏ธ */
|
|
99
|
+
.abDrawerClose {
|
|
100
|
+
flex: none; /* ๐ */
|
|
101
|
+
inline-size: 40px; /* ๐ */
|
|
102
|
+
block-size: 40px; /* ๐ */
|
|
103
|
+
border: 0; /* ๐งน */
|
|
104
|
+
border-radius: 999px; /* ๐ข */
|
|
105
|
+
background: transparent; /* ๐จ */
|
|
106
|
+
color: inherit; /* ๐๏ธ */
|
|
107
|
+
font: inherit; /* ๐ค */
|
|
108
|
+
cursor: pointer; /* ๐ฑ๏ธ */
|
|
109
|
+
}
|
|
110
|
+
.abDrawerClose:hover { background: var(--ab-color-surface-container-high, rgb(0 0 0 / 0.06)); } /* ๐ฑ๏ธ */
|
|
111
|
+
.abDrawerClose:focus-visible { outline: var(--ab-focus-ring-width, 2px) solid var(--ab-color-accent, var(--ab-color-primary, #8f4c38)); outline-offset: 2px; } /* โฟ */
|
|
112
|
+
.abDrawerBody { flex: 1 1 auto; min-height: 0; overflow: hidden auto; overscroll-behavior: contain; padding: 8px 20px 16px; } /* ๐ its own scroller */
|
|
113
|
+
.abDrawerFooter { flex: none; display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; } /* ๐ */
|
|
114
|
+
|
|
115
|
+
/* โฟ reduced motion: no slide, no fade (handled by ab-nextjs-animations .ab-motion-*) */
|
|
116
|
+
|
|
117
|
+
/* ===== ๐ 0.2.0 drawers v2 (John's frames, God 01:22) ===== */
|
|
118
|
+
/* ๐ฅ stacking tiers (spec z-order): right drawer < left drawer < bottom sheet. The layers are siblings in the host,
|
|
119
|
+
so the tier sits on the layer (z 60 / 61 / 62 keeps all three above the panes and bars, like before) */
|
|
120
|
+
.abDrawerLayer:has(> .abDrawerFrame[data-tier='nav']) { z-index: 61; } /* โฌ
๏ธ the left drawer is in front of the right one */
|
|
121
|
+
.abDrawerLayer:has(> .abDrawerFrame[data-tier='sheet']) { z-index: 62; } /* โฌ๏ธ the bottom sheet is on top */
|
|
122
|
+
/* ๐๏ธ side drawers slide in 200ms and out 160ms, cubic-bezier(.2,0,0,1) (the ab-nextjs-animations tokens) */
|
|
123
|
+
.abDrawerFrame[data-tier] > .abDrawer:is([data-side='left'], [data-side='right'], [data-side='start'], [data-side='end']) { --ab-motion-duration: var(--ab-drawer-duration, 200ms); }
|
|
124
|
+
.abDrawerFrame[data-tier][data-state='closed'] > .abDrawer:is([data-side='left'], [data-side='right'], [data-side='start'], [data-side='end']) { --ab-motion-duration: var(--ab-drawer-close-duration, 160ms); }
|
|
125
|
+
/* ๐ซณ while a finger leads, the sheet follows it 1:1 (no transition); on release CSS takes over again */
|
|
126
|
+
.abDrawer.abDrawer[data-dragging] { --ab-motion-duration: 0ms; } /* โฑ๏ธ the ab-nextjs-animations token at 0 */
|
|
127
|
+
.abDrawer[data-swipe='true']:not([data-side='bottom']) { touch-action: pan-y; } /* โ๏ธ sideways drags reach us, vertical scroll stays native */
|
|
128
|
+
|
|
129
|
+
/* โ the handle: a 40ร4 bar in a 24px strip at the very top; its touch zone reaches 44px (over the header) */
|
|
130
|
+
.abDrawerHandle {
|
|
131
|
+
flex: none; position: relative; z-index: 1; display: block; box-sizing: border-box; /* ๐ */
|
|
132
|
+
inline-size: 100%; block-size: 24px; margin: 0; padding: 0; border: 0; /* ๐ */
|
|
133
|
+
background: transparent; cursor: grab; touch-action: none; /* ๐ค the drag is ours */
|
|
134
|
+
}
|
|
135
|
+
.abDrawerHandle::before { content: ''; position: absolute; inset-block-start: 10px; inset-inline-start: calc(50% - 20px); inline-size: 40px; block-size: 4px; border-radius: 2px; background: var(--ab-color-handle, rgb(25 18 12 / 0.18)); } /* โ the bar */
|
|
136
|
+
.abDrawerHandle::after { content: ''; position: absolute; inset: 0 0 -20px; } /* ๐๏ธ 24 + 20 = 44px touch zone */
|
|
137
|
+
.abDrawerHandle:focus { outline: none; }
|
|
138
|
+
.abDrawerHandle:focus-visible::before { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: 4px; } /* โฟ */
|
|
139
|
+
.abDrawer[data-snap] > .abDrawerHeader { touch-action: none; } /* ๐ค the header drags the sheet too */
|
|
140
|
+
|
|
141
|
+
/* ๐งฒ snap points (bottom, below 768px): the sheet is full height (top at the safe-area top) and slides:
|
|
142
|
+
closed = off-screen, S1 = 70% of the app visible (JS measures --ab-drawer-partial-offset), S2 = all of it */
|
|
143
|
+
.abDrawer[data-side='bottom'][data-snap] { inset: env(safe-area-inset-top, 0px) 0 0 0; max-height: none; transform: translateY(100%); }
|
|
144
|
+
.abDrawerFrame[data-state='open'] > .abDrawer[data-snap='partial'] { transform: translateY(var(--ab-drawer-partial-offset, 30%)); } /* ๐งฒ S1 */
|
|
145
|
+
.abDrawerFrame[data-state='open'] > .abDrawer[data-snap='full'] { transform: none; } /* ๐งฒ S2 */
|
|
146
|
+
|
|
147
|
+
/* ๐ป laptop (768px and up): centred in the main pane, min(640px, main width), at most 70% of the app height */
|
|
148
|
+
.abDrawer[data-side='bottom'][data-center='main'] {
|
|
149
|
+
--ab-drawer-w: min(var(--ab-drawer-max-width, 640px), var(--ab-drawer-main-width, 100%)); /* ๐ never wider than main */
|
|
150
|
+
inset: auto auto 0 calc(var(--ab-drawer-main-left, 0px) + (var(--ab-drawer-main-width, 100%) - var(--ab-drawer-w)) / 2); /* ๐ฏ centred */
|
|
151
|
+
inline-size: var(--ab-drawer-w); max-inline-size: none; margin: 0; /* ๐ */
|
|
152
|
+
max-block-size: 70%; /* ๐ โค 70% of the app (567px at 810) */
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* ๐งฉ D41 no-JS fallback: an in-flow section; hidden as soon as scripting runs (hydration swaps in the drawer) */
|
|
156
|
+
.abDrawerFallback { display: block; margin-block: 16px; border: var(--ab-divider-hairline, 1px solid rgb(0 0 0 / 0.12)); border-radius: 12px; }
|
|
157
|
+
.abDrawerFallback .abDrawerTitle { padding: 12px 20px 0; }
|
|
158
|
+
.abDrawerFallback .abDrawerBody { overflow: visible; }
|
|
159
|
+
@media (scripting: enabled) {
|
|
160
|
+
.abDrawerFallback { display: none; }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/* ๐ the scope box (.AbAppLayout / main / aside pane) is the layer's containing block while a drawer uses it.
|
|
164
|
+
:where() = zero specificity, so a host that is already positioned (fixed / absolute aside) keeps its own.
|
|
165
|
+
The local class inside :has() keeps CSS-modules "pure" mode happy. (A core rule could own this later.) */
|
|
166
|
+
:where([data-ab-drawer-host]:has(> .abDrawerLayer)) { position: relative; }
|
|
@@ -0,0 +1,89 @@
|
|
|
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: useAbDrawer (G53)
|
|
28
|
+
* @file: ab-drawer/use-ab-drawer.ts
|
|
29
|
+
* @type: Client hook
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*
|
|
32
|
+
* Example usage:
|
|
33
|
+
* 1+|> const drawer = useAbDrawer('app')
|
|
34
|
+
* -|> <button {...drawer.triggerProps}>Language</button>
|
|
35
|
+
* -|> <AbDrawer {...drawer.drawerProps} title="Language">โฆ</AbDrawer>
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
40
|
+
* MOTTO: We'll always do more ๐!!!
|
|
41
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
'use client';
|
|
46
|
+
|
|
47
|
+
// โ๏ธ React
|
|
48
|
+
import { useCallback, useId, useMemo, useState } from 'react';
|
|
49
|
+
|
|
50
|
+
/** ๐บ๏ธ which box clips the drawer (G53): the whole app, the main pane or the aside pane */
|
|
51
|
+
export type AbDrawerScope = 'app' | 'main' | 'aside';
|
|
52
|
+
|
|
53
|
+
/** ๐๏ธ what useAbDrawer returns */
|
|
54
|
+
export interface UseAbDrawer {
|
|
55
|
+
scope: AbDrawerScope; // ๐บ๏ธ
|
|
56
|
+
id: string; // ๐ the drawer id (`aria-controls` target)
|
|
57
|
+
open: boolean; // ๐ช is it open?
|
|
58
|
+
show: () => void; // โ open it
|
|
59
|
+
close: () => void; // โ close it (Escape / scrim / buttons)
|
|
60
|
+
toggle: () => void; // ๐
|
|
61
|
+
setOpen: (open: boolean) => void; // ๐๏ธ controlled setter
|
|
62
|
+
/** ๐ spread on the trigger button: aria-expanded / aria-controls / aria-haspopup / onClick */
|
|
63
|
+
triggerProps: { 'aria-expanded': boolean; 'aria-controls': string; 'aria-haspopup': 'dialog'; onClick: () => void };
|
|
64
|
+
/** ๐๏ธ spread on the drawer: id / scope / open / onClose */
|
|
65
|
+
drawerProps: { id: string; scope: AbDrawerScope; open: boolean; onClose: () => void };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* ๐๏ธ useAbDrawer(scope) โ one drawer's open state + the trigger / drawer prop bags (G53).
|
|
70
|
+
*
|
|
71
|
+
* ๐งญ Lives in **components** (next to AbDrawer), not in core: it holds no layout state, only `open`,
|
|
72
|
+
* and components doesn't depend on core. Focus return is handled by AbDrawer itself.
|
|
73
|
+
*/
|
|
74
|
+
export function useAbDrawer(scope: AbDrawerScope = 'app', options: { defaultOpen?: boolean; id?: string } = {}): UseAbDrawer {
|
|
75
|
+
const auto = `ab-drawer-${useId().replace(/[^A-Za-z0-9_-]/g, '')}`; // ๐ stable across SSR + hydration
|
|
76
|
+
const id = options.id ?? auto; // ๐
|
|
77
|
+
const [open, setOpen] = useState<boolean>(options.defaultOpen ?? false); // ๐ช
|
|
78
|
+
const show = useCallback(() => setOpen(true), []); // โ
|
|
79
|
+
const close = useCallback(() => setOpen(false), []); // โ
|
|
80
|
+
const toggle = useCallback(() => setOpen((o) => !o), []); // ๐
|
|
81
|
+
return useMemo(() => ({
|
|
82
|
+
scope, id, open, show, close, toggle, setOpen,
|
|
83
|
+
triggerProps: { 'aria-expanded': open, 'aria-controls': id, 'aria-haspopup': 'dialog' as const, onClick: toggle },
|
|
84
|
+
drawerProps: { id, scope, open, onClose: close },
|
|
85
|
+
}), [scope, id, open, show, close, toggle]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ๐ฆ default export
|
|
89
|
+
export default useAbDrawer;
|
|
@@ -0,0 +1,155 @@
|
|
|
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: useAbEdgeSwipe
|
|
28
|
+
* @file: ab-drawer/use-ab-edge-swipe.ts
|
|
29
|
+
* @type: Client hook
|
|
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, useRef } from 'react';
|
|
43
|
+
// ๐ค the pure rules
|
|
44
|
+
import { AB_SWIPE, createAbVelocityTracker, isInAbEdgeZone, isInAbHorizontalScroller, resolveAbSideRelease } from './gestures';
|
|
45
|
+
// ๐บ๏ธ the app box (same lookup AbDrawer uses)
|
|
46
|
+
import { getAbDrawerHost } from './index';
|
|
47
|
+
|
|
48
|
+
/** โ๏ธ options */
|
|
49
|
+
export interface UseAbEdgeSwipeOptions {
|
|
50
|
+
edge: 'left' | 'right'; // ๐งฑ which edge the swipe starts from (left = left-to-right, opens the left drawer)
|
|
51
|
+
onOpen: () => void; // ๐ช called when the swipe commits
|
|
52
|
+
enabled?: boolean; // ๐๏ธ e.g. false while that drawer is open, or when the page has no aside (default true)
|
|
53
|
+
width?: number; // ๐ the drawer width the 30% rule uses (default 320)
|
|
54
|
+
pointerTypes?: readonly string[]; // ๐๏ธ default touch + pen (a mouse never edge-swipes)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ๐ฑ iOS home-screen web app (the zone starts 16px in there)
|
|
58
|
+
const standalone = (): boolean => typeof navigator !== 'undefined' && (navigator as Navigator & { standalone?: boolean }).standalone === true;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* ๐ค useAbEdgeSwipe โ open a side drawer with an edge swipe (drawer spec ยง2 / ยง3):
|
|
62
|
+
* - ๐งฑ the press starts in a 24px zone on that edge of the app box (16px in on iOS standalone)
|
|
63
|
+
* - โ๏ธ it commits past 30% of the drawer width or above 0.5px/ms toward the middle; slower or shorter does nothing
|
|
64
|
+
* - ๐ ignored inside things that scroll sideways (code blocks, carousels) and `[data-ab-no-edge-swipe]`
|
|
65
|
+
* - ๐งญ a mostly vertical move is a scroll, not a swipe
|
|
66
|
+
* - ๐ฑ iOS Safari's own back gesture starts at the very screen edge and takes the touch before the page sees it,
|
|
67
|
+
* so the two don't fight; in standalone mode the 16px inset leaves that edge to the system
|
|
68
|
+
*
|
|
69
|
+
* - ๐ touch uses touch events (non-passive touchmove only during an edge press, preventDefault only once it's
|
|
70
|
+
* sideways), so Android Chrome's pointercancel-on-pan can't swallow it
|
|
71
|
+
*
|
|
72
|
+
* The drawer opens on release (it doesn't follow the finger), then slides in with its normal 200ms motion.
|
|
73
|
+
*/
|
|
74
|
+
export function useAbEdgeSwipe({ edge, onOpen, enabled = true, width = 320, pointerTypes = ['touch', 'pen'] }: UseAbEdgeSwipeOptions): void {
|
|
75
|
+
const latest = useRef(onOpen); // ๐ latest callback for the listener
|
|
76
|
+
useEffect(() => { latest.current = onOpen; }, [onOpen]);
|
|
77
|
+
const types = pointerTypes.join(','); // ๐งฎ a stable dep
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (!enabled) return;
|
|
80
|
+
let d: { x: number; y: number; axis: 0 | 1 | 2; v: ReturnType<typeof createAbVelocityTracker> } | null = null; // ๐ซณ the current press
|
|
81
|
+
const sign = edge === 'left' ? 1 : -1; // โก๏ธ / โฌ
๏ธ toward the middle
|
|
82
|
+
const allow = types.split(','); // ๐๏ธ
|
|
83
|
+
// ๐งฑ shared start rule (pointer or touch): from the edge zone, not in a sideways scroller / opt-out / open drawer
|
|
84
|
+
const start = (x: number, y: number, t: number, target: Element): boolean => {
|
|
85
|
+
const host = getAbDrawerHost('app', target); // ๐บ๏ธ the app box
|
|
86
|
+
const box = host === document.body ? { left: 0, right: window.innerWidth } : host.getBoundingClientRect();
|
|
87
|
+
if (!isInAbEdgeZone(x, edge, box, standalone())) return false; // ๐งฑ not from the edge
|
|
88
|
+
if (isInAbHorizontalScroller(target)) return false; // ๐ (also [data-ab-no-edge-swipe])
|
|
89
|
+
if (target.closest?.('[data-ab-part="drawer"]')) return false; // ๐๏ธ a drawer is already up there
|
|
90
|
+
const v = createAbVelocityTracker(); v.add(x, t);
|
|
91
|
+
d = { x, y, axis: 0, v }; return true;
|
|
92
|
+
};
|
|
93
|
+
// ๐งญ shared move rule; returns true while the gesture is ours (sideways)
|
|
94
|
+
const step = (x: number, y: number, t: number): boolean => {
|
|
95
|
+
if (!d || d.axis === 2) return false;
|
|
96
|
+
const dx = x - d.x; const dy = y - d.y;
|
|
97
|
+
if (d.axis === 0) {
|
|
98
|
+
if (Math.max(Math.abs(dx), Math.abs(dy)) < AB_SWIPE.slop) return false; // ๐ซณ
|
|
99
|
+
d.axis = Math.abs(dx) > Math.abs(dy) ? 1 : 2; // ๐งญ sideways = ours, vertical = the page's scroll
|
|
100
|
+
}
|
|
101
|
+
if (d.axis === 1) { d.v.add(x, t); return true; } // โก
|
|
102
|
+
return false;
|
|
103
|
+
};
|
|
104
|
+
const finish = (x: number) => {
|
|
105
|
+
const cur = d; d = null;
|
|
106
|
+
if (!cur || cur.axis !== 1) return;
|
|
107
|
+
if (resolveAbSideRelease({ distance: (x - cur.x) * sign, velocity: cur.v.velocity() * sign, width })) latest.current(); // โ
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// ๐๏ธ pointer path: pen (and touch only where there are no touch events)
|
|
111
|
+
const touchy = typeof window !== 'undefined' && 'ontouchstart' in window;
|
|
112
|
+
const byPointer = (e: PointerEvent) => allow.includes(e.pointerType) && !(touchy && e.pointerType === 'touch');
|
|
113
|
+
const down = (e: PointerEvent) => { if (byPointer(e)) start(e.clientX, e.clientY, e.timeStamp, e.target as Element); };
|
|
114
|
+
const move = (e: PointerEvent) => { if (byPointer(e)) step(e.clientX, e.clientY, e.timeStamp); };
|
|
115
|
+
const up = (e: PointerEvent) => { if (byPointer(e)) finish(e.clientX); };
|
|
116
|
+
const cancel = (e: PointerEvent) => { if (byPointer(e)) d = null; }; // ๐งน the browser took it (scroll)
|
|
117
|
+
|
|
118
|
+
// ๐ touch path (Android Chrome fix): Chromium fires pointercancel as soon as it starts a native pan, so a
|
|
119
|
+
// touch swipe is read from touch events instead. A NON-passive touchmove listener is attached only while a
|
|
120
|
+
// touch that started in the edge zone is down (no scroll jank elsewhere), and it calls preventDefault only
|
|
121
|
+
// once the move is sideways. Vertical moves are never prevented, so the page still scrolls from the strip.
|
|
122
|
+
const tmove = (e: TouchEvent) => {
|
|
123
|
+
const t = e.touches[0]; if (!t) return;
|
|
124
|
+
if (step(t.clientX, t.clientY, e.timeStamp) && e.cancelable) e.preventDefault(); // ๐ ours: keep the browser out
|
|
125
|
+
if (d?.axis === 2) detach(); // ๐งญ a scroll: let go early
|
|
126
|
+
};
|
|
127
|
+
const tend = (e: TouchEvent) => { const t = e.changedTouches[0]; detach(); if (t && e.type === 'touchend') finish(t.clientX); else d = null; };
|
|
128
|
+
const attach = () => { document.addEventListener('touchmove', tmove, { capture: true, passive: false }); document.addEventListener('touchend', tend, true); document.addEventListener('touchcancel', tend, true); };
|
|
129
|
+
const detach = () => { document.removeEventListener('touchmove', tmove, true); document.removeEventListener('touchend', tend, true); document.removeEventListener('touchcancel', tend, true); };
|
|
130
|
+
const tstart = (e: TouchEvent) => {
|
|
131
|
+
if (!allow.includes('touch')) return;
|
|
132
|
+
detach(); d = null;
|
|
133
|
+
if (e.touches.length !== 1) return; // โ๏ธ pinch etc. are not swipes
|
|
134
|
+
const t = e.touches[0];
|
|
135
|
+
if (start(t.clientX, t.clientY, e.timeStamp, e.target as Element)) attach();
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
document.addEventListener('pointerdown', down, true); // ๐ง capture: before anything stops it
|
|
139
|
+
document.addEventListener('pointermove', move, true);
|
|
140
|
+
document.addEventListener('pointerup', up, true);
|
|
141
|
+
document.addEventListener('pointercancel', cancel, true);
|
|
142
|
+
document.addEventListener('touchstart', tstart, { capture: true, passive: true }); // ๐ passive: never delays a tap or scroll
|
|
143
|
+
return () => {
|
|
144
|
+
document.removeEventListener('pointerdown', down, true);
|
|
145
|
+
document.removeEventListener('pointermove', move, true);
|
|
146
|
+
document.removeEventListener('pointerup', up, true);
|
|
147
|
+
document.removeEventListener('pointercancel', cancel, true);
|
|
148
|
+
document.removeEventListener('touchstart', tstart, true);
|
|
149
|
+
detach();
|
|
150
|
+
};
|
|
151
|
+
}, [edge, enabled, width, types]);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ๐ฆ default export
|
|
155
|
+
export default useAbEdgeSwipe;
|