ab-nextjs-components 0.1.8 โ 0.1.10
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 +42 -0
- package/ab-brand/index.tsx +30 -1
- package/ab-brand/styles.module.css +40 -1
- package/ab-button/helpers.ts +90 -0
- package/ab-button/index.tsx +164 -87
- package/ab-button/styles.module.css +79 -1
- package/ab-carousel/helpers.ts +146 -0
- package/ab-carousel/index.tsx +643 -0
- package/ab-carousel/styles.module.css +206 -0
- package/ab-chip/index.tsx +75 -0
- package/ab-chip/styles.module.css +87 -0
- package/ab-collapsible/index.tsx +30 -1
- package/ab-collapsible/styles.module.css +40 -1
- package/ab-flow-diagram/helpers.ts +77 -0
- package/ab-flow-diagram/index.tsx +141 -0
- package/ab-flow-diagram/styles.module.css +141 -0
- package/ab-icon/builtin.ts +61 -0
- package/ab-icon/helpers.ts +102 -0
- package/ab-icon/index.tsx +77 -16
- package/ab-icon/styles.module.css +53 -9
- package/ab-icon-button/index.tsx +110 -46
- package/ab-icon-button/styles.module.css +28 -10
- package/ab-install-snippet/helpers.ts +62 -0
- package/ab-install-snippet/index.tsx +170 -0
- package/ab-install-snippet/styles.module.css +104 -0
- package/ab-like-button/index.tsx +33 -1
- package/ab-like-button/styles.module.css +41 -6
- package/ab-linear-progress/index.tsx +129 -0
- package/ab-linear-progress/styles.module.css +105 -0
- package/ab-locale-switcher/index.tsx +213 -0
- package/ab-locale-switcher/styles.module.css +127 -0
- package/ab-logo/index.tsx +88 -30
- package/ab-logo/styles.module.css +79 -11
- package/ab-pill/index.tsx +74 -0
- package/ab-progress-chips/index.tsx +30 -1
- package/ab-progress-chips/styles.module.css +40 -1
- package/ab-searchbar/index.tsx +33 -2
- package/ab-searchbar/styles.module.css +41 -5
- package/ab-splash/csp.d.ts +54 -0
- package/ab-splash/csp.mjs +82 -0
- package/ab-splash/csp.ts +60 -0
- package/ab-splash/gate.ts +216 -0
- package/ab-splash/index.tsx +140 -0
- package/ab-splash/styles.module.css +103 -0
- package/ab-theme-toggle/index.tsx +188 -0
- package/ab-theme-toggle/styles.module.css +89 -0
- package/css/dialog.css +38 -3
- package/index.ts +47 -0
- package/package.json +46 -18
- package/server/ab-brand/index.tsx +29 -1
- package/server/ab-brand/styles.module.css +40 -1
- package/server/ab-button/index.tsx +96 -79
- package/server/ab-button/styles.module.css +79 -1
- package/server/ab-icon/index.tsx +68 -16
- package/server/ab-icon/styles.module.css +53 -9
- package/server/ab-logo/index.tsx +88 -29
- package/server/ab-logo/styles.module.css +79 -11
- package/types/css.d.ts +43 -0
- package/types/index.d.ts +2 -0
package/ab-like-button/index.tsx
CHANGED
|
@@ -5,17 +5,48 @@
|
|
|
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
27
|
* @name: AbLikeButton - Client (port of lyd-like-button)
|
|
10
28
|
* @file: ab-like-button/index.tsx
|
|
29
|
+
* @type: TypeScript (React)
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
11
31
|
*/
|
|
12
32
|
|
|
33
|
+
/*
|
|
34
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
35
|
+
* MOTTO: We'll always do more ๐!!!
|
|
36
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
|
|
13
40
|
'use client';
|
|
14
41
|
|
|
15
42
|
import type { CSSProperties, MouseEvent, ReactElement } from 'react';
|
|
16
43
|
import Link from 'next/link';
|
|
17
44
|
import clsx from 'clsx';
|
|
18
45
|
import styles from './styles.module.css';
|
|
46
|
+
import { AB_MOTION } from 'ab-nextjs-animations/motion'; // ๐ฌ transition class names (ab-nextjs-animations >= 0.2.4)
|
|
47
|
+
import 'ab-nextjs-animations/motion/styles.css'; // ๐จ .ab-motion-*
|
|
48
|
+
import { AB_SPIN_CLASS } from 'ab-nextjs-animations/spin'; // ๐ spinner (ab-nextjs-animations >= 0.2.4)
|
|
49
|
+
import 'ab-nextjs-animations/spin/styles.css'; // ๐ .ab-spin
|
|
19
50
|
|
|
20
51
|
export interface AbLikeButtonProps {
|
|
21
52
|
className?: string;
|
|
@@ -58,6 +89,7 @@ const AbLikeButton = ({
|
|
|
58
89
|
const classNames = clsx(
|
|
59
90
|
'AbLikeButton',
|
|
60
91
|
styles.abLikeButton,
|
|
92
|
+
AB_MOTION.interactive, // ๐ฌ hover / state motion (ab-nextjs-animations)
|
|
61
93
|
liked && styles.isLiked,
|
|
62
94
|
isActive && styles.isActive,
|
|
63
95
|
isNaked && styles.isNaked,
|
|
@@ -69,7 +101,7 @@ const AbLikeButton = ({
|
|
|
69
101
|
);
|
|
70
102
|
|
|
71
103
|
const inner = isLoading ? (
|
|
72
|
-
<span className={styles.abLikeButtonSpinner} aria-hidden />
|
|
104
|
+
<span className={clsx(styles.abLikeButtonSpinner, AB_SPIN_CLASS)} aria-hidden />
|
|
73
105
|
) : (
|
|
74
106
|
<span className={clsx('material-symbols-rounded', styles.abLikeButtonIcon)} aria-hidden>
|
|
75
107
|
{icon}
|
|
@@ -1,3 +1,42 @@
|
|
|
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: ab-like-button - styles
|
|
28
|
+
* @file: ab-like-button/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
|
+
|
|
1
40
|
.abLikeButton {
|
|
2
41
|
position: relative;
|
|
3
42
|
display: inline-flex;
|
|
@@ -13,7 +52,7 @@
|
|
|
13
52
|
color: inherit;
|
|
14
53
|
text-decoration: none;
|
|
15
54
|
cursor: pointer;
|
|
16
|
-
|
|
55
|
+
/* ๐ฌ motion = .ab-motion-interactive (ab-nextjs-animations) */
|
|
17
56
|
}
|
|
18
57
|
|
|
19
58
|
.abLikeButton:hover:not(.isDisabled):not(.isNaked) {
|
|
@@ -52,9 +91,5 @@
|
|
|
52
91
|
border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
|
|
53
92
|
border-top-color: currentColor;
|
|
54
93
|
border-radius: 9999px;
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
@keyframes abLikeSpin {
|
|
59
|
-
to { transform: rotate(360deg); }
|
|
94
|
+
/* ๐ rotation = .ab-spin (ab-nextjs-animations) */
|
|
60
95
|
}
|
|
@@ -0,0 +1,129 @@
|
|
|
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: AB Linear Progress
|
|
28
|
+
* @file: ab-linear-progress/index.tsx
|
|
29
|
+
* @type: Component (server-safe, no hooks) โ ported from the reviewed ab-nextjs-core version
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
35
|
+
* MOTTO: We'll always do more ๐!!!
|
|
36
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
// ๐งฉ React types only (no runtime hooks โ works in server components too)
|
|
40
|
+
import type { CSSProperties, ReactElement } from 'react';
|
|
41
|
+
// ๐งต tiny class-name joiner
|
|
42
|
+
import clsx from 'clsx';
|
|
43
|
+
// ๐จ package-shipped CSS module (no Tailwind scanning of node_modules needed)
|
|
44
|
+
import styles from './styles.module.css';
|
|
45
|
+
import { AB_MOTION } from 'ab-nextjs-animations/motion'; // ๐ฌ transition class names (ab-nextjs-animations >= 0.2.4)
|
|
46
|
+
import 'ab-nextjs-animations/motion/styles.css'; // ๐จ .ab-motion-*
|
|
47
|
+
import { AB_PROGRESS_SWEEP_CLASS } from 'ab-nextjs-animations/progress-sweep'; // ๐ indeterminate sweep (ab-nextjs-animations >= 0.2.4)
|
|
48
|
+
import 'ab-nextjs-animations/progress-sweep/styles.css'; // ๐ .ab-progress-sweep
|
|
49
|
+
|
|
50
|
+
// ๐ public props of <AbLinearProgress />
|
|
51
|
+
export interface AbLinearProgressProps {
|
|
52
|
+
// ๐ท๏ธ extra class names from the consumer
|
|
53
|
+
className?: string;
|
|
54
|
+
// ๐จ bar color (any CSS color); defaults to the bronze brand color
|
|
55
|
+
color?: string;
|
|
56
|
+
// ๐ hide the whole bar (kept for API parity with LYD chrome)
|
|
57
|
+
hidden?: boolean;
|
|
58
|
+
// ๐ indeterminate mode: no known value, bar sweeps back and forth
|
|
59
|
+
isIndeterminate?: boolean;
|
|
60
|
+
// ๐ determinate value from 0 to 100
|
|
61
|
+
progress?: number;
|
|
62
|
+
// ๐ฃ๏ธ accessible name for screen readers
|
|
63
|
+
label?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ๐ clamp any number into the 0..100 range (NaN โ 0)
|
|
67
|
+
export const clampAbProgress = (value: number): number => {
|
|
68
|
+
// ๐ซ non-finite values become 0
|
|
69
|
+
if (!Number.isFinite(value)) return 0;
|
|
70
|
+
// โ๏ธ clamp and return
|
|
71
|
+
return Math.min(100, Math.max(0, value));
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* ๐ AbLinearProgress โ determinate (`progress`) or indeterminate (`isIndeterminate`)
|
|
76
|
+
* linear progress bar. Respects prefers-reduced-motion and html.dark.
|
|
77
|
+
*/
|
|
78
|
+
const AbLinearProgress = ({
|
|
79
|
+
className, // ๐ท๏ธ consumer classes
|
|
80
|
+
color, // ๐จ optional custom color
|
|
81
|
+
hidden = false, // ๐ visible by default
|
|
82
|
+
isIndeterminate = false, // ๐ determinate by default
|
|
83
|
+
progress = 0, // ๐ start empty
|
|
84
|
+
label = 'Loading', // ๐ฃ๏ธ default accessible name
|
|
85
|
+
}: AbLinearProgressProps): ReactElement => {
|
|
86
|
+
// โ๏ธ safe 0..100 value
|
|
87
|
+
const value = clampAbProgress(progress);
|
|
88
|
+
// ๐จ expose the color as a CSS custom property (only when provided)
|
|
89
|
+
const rootStyle = (color ? { '--ab-linear-progress-color': color } : undefined) as CSSProperties | undefined;
|
|
90
|
+
|
|
91
|
+
// ๐งฑ render the track + bar
|
|
92
|
+
return (
|
|
93
|
+
<div
|
|
94
|
+
// ๐ท๏ธ stable public class + module class + consumer class
|
|
95
|
+
className={clsx('AbLinearProgress', styles.abLinearProgress, className)}
|
|
96
|
+
// ๐จ custom color, if any
|
|
97
|
+
style={rootStyle}
|
|
98
|
+
// ๐ native hidden attribute
|
|
99
|
+
hidden={hidden}
|
|
100
|
+
// โฟ ARIA progressbar role
|
|
101
|
+
role="progressbar"
|
|
102
|
+
// ๐ฃ๏ธ accessible name (dropped when empty, e.g. inside an aria-hidden overlay)
|
|
103
|
+
aria-label={label ? label : undefined}
|
|
104
|
+
// ๐ range lower bound
|
|
105
|
+
aria-valuemin={0}
|
|
106
|
+
// ๐ range upper bound
|
|
107
|
+
aria-valuemax={100}
|
|
108
|
+
// ๐ current value only in determinate mode (omitted = indeterminate per ARIA)
|
|
109
|
+
aria-valuenow={isIndeterminate ? undefined : value}
|
|
110
|
+
// โณ tell AT we're busy while indeterminate
|
|
111
|
+
aria-busy={isIndeterminate ? true : undefined}
|
|
112
|
+
// ๐ hide from AT when hidden
|
|
113
|
+
aria-hidden={hidden ? true : undefined}
|
|
114
|
+
// ๐ mode hook for styling/tests
|
|
115
|
+
data-ab-mode={isIndeterminate ? 'indeterminate' : 'determinate'}
|
|
116
|
+
>
|
|
117
|
+
{/* ๐ซ the moving / filling bar */}
|
|
118
|
+
<div
|
|
119
|
+
// ๐ท๏ธ bar class (indeterminate gets the sweep class)
|
|
120
|
+
className={clsx(styles.abLinearProgress__bar, isIndeterminate ? [styles.abLinearProgress__bar_indeterminate, AB_PROGRESS_SWEEP_CLASS] : AB_MOTION.transform)} // ๐ฌ sweep / value tween from ab-nextjs-animations
|
|
121
|
+
// ๐ determinate width via transform (GPU friendly) โ none in indeterminate
|
|
122
|
+
style={isIndeterminate ? undefined : { transform: `scaleX(${value / 100})` }}
|
|
123
|
+
/>
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// ๐ฆ default export
|
|
129
|
+
export default AbLinearProgress;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license MIT
|
|
3
|
+
* ~~~~~~~~~~~~
|
|
4
|
+
* ab-nextjs-components
|
|
5
|
+
* ~~~~~~~~~~~~
|
|
6
|
+
* Copyright (c) 2026 Abraham Ukachi. The abElements Project.
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the 'Software'), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
* @project: ab-nextjs-components
|
|
27
|
+
* @name: AB Linear Progress - Component Stylesheet (plain CSS, Tailwind-independent)
|
|
28
|
+
* @file: ab-linear-progress/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
|
+
/* ===== ๐ AB LINEAR PROGRESS ===== */
|
|
40
|
+
|
|
41
|
+
/* ๐งฑ track */
|
|
42
|
+
.abLinearProgress {
|
|
43
|
+
/* ๐จ default bronze color (light) */
|
|
44
|
+
--_ab-lp-color: var(--ab-linear-progress-color, #A67C52);
|
|
45
|
+
/* ๐ default height, overridable */
|
|
46
|
+
--_ab-lp-height: var(--ab-linear-progress-height, 4px);
|
|
47
|
+
position: relative; /* ๐ anchor for the bar */
|
|
48
|
+
display: block; /* ๐งฑ full-width block */
|
|
49
|
+
width: 100%; /* โ๏ธ fill the parent */
|
|
50
|
+
height: var(--_ab-lp-height); /* โ๏ธ thin bar */
|
|
51
|
+
overflow: hidden; /* โ๏ธ clip the sweeping bar */
|
|
52
|
+
border-radius: 9999px; /* ๐ pill */
|
|
53
|
+
/* ๐ซ๏ธ faint track tinted by the bar color */
|
|
54
|
+
background-color: color-mix(in srgb, var(--_ab-lp-color) 18%, transparent);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* ๐ honor the hidden attribute even if display is set */
|
|
58
|
+
.abLinearProgress[hidden] {
|
|
59
|
+
display: none;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* ๐ dark mode: lighter bronze on dark surfaces */
|
|
63
|
+
:global(html.dark) .abLinearProgress {
|
|
64
|
+
--_ab-lp-color: var(--ab-linear-progress-color, #C9A27A);
|
|
65
|
+
background-color: color-mix(in srgb, var(--_ab-lp-color) 22%, transparent);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* ๐ซ bar */
|
|
69
|
+
.abLinearProgress__bar {
|
|
70
|
+
position: absolute; /* ๐ sits on the track */
|
|
71
|
+
inset: 0; /* ๐ full size, scaled via transform */
|
|
72
|
+
border-radius: inherit; /* ๐ same pill */
|
|
73
|
+
background-color: var(--_ab-lp-color); /* ๐จ bar color */
|
|
74
|
+
transform-origin: left center; /* โฌ
๏ธ grow from the start */
|
|
75
|
+
--ab-motion-duration: 240ms; /* ๐๏ธ value tween = .ab-motion-transform (ab-nextjs-animations) */
|
|
76
|
+
--ab-motion-easing: ease-out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* โ๏ธ RTL: grow from the right */
|
|
80
|
+
:global([dir='rtl']) .abLinearProgress__bar {
|
|
81
|
+
transform-origin: right center;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* ๐ indeterminate: a 40% segment; the sweep itself = .ab-progress-sweep (ab-nextjs-animations, RTL-mirrored) */
|
|
85
|
+
.abLinearProgress__bar_indeterminate {
|
|
86
|
+
right: auto; /* ๐ free the right edge */
|
|
87
|
+
width: 40%; /* ๐ segment width */
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* โ๏ธ RTL indeterminate: anchor on the right (the package mirrors the sweep) */
|
|
91
|
+
:global([dir='rtl']) .abLinearProgress__bar_indeterminate {
|
|
92
|
+
left: auto; /* ๐ free the left edge */
|
|
93
|
+
right: 0; /* ๐ start on the right */
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* โฟ reduced motion: the package stops the sweep + tween; this only lays the static bar out across the track */
|
|
97
|
+
@media (prefers-reduced-motion: reduce) {
|
|
98
|
+
.abLinearProgress__bar_indeterminate,
|
|
99
|
+
:global([dir='rtl']) .abLinearProgress__bar_indeterminate {
|
|
100
|
+
left: 0; /* ๐ */
|
|
101
|
+
right: 0; /* ๐ */
|
|
102
|
+
width: 100%; /* ๐ซ full static bar */
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
@@ -0,0 +1,213 @@
|
|
|
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: AbLocaleSwitcher - Client (G7)
|
|
28
|
+
* @file: ab-locale-switcher/index.tsx
|
|
29
|
+
* @type: Component (client) โ globe menu button (APG menu + menuitemradio)
|
|
30
|
+
* @authors: Abraham Ukachi <abrahamukachi@gmail.com>
|
|
31
|
+
*
|
|
32
|
+
* Example usage:
|
|
33
|
+
* 1+|> const { switchLocale } = useAbLocaleSwitch() // ๐ from ab-nextjs-i18n/navigation
|
|
34
|
+
* -|> <AbLocaleSwitcher label={t('language')} current={locale} locales={[{ code: 'en', label: 'English' }, { code: 'fr', label: 'Franรงais' }]} onSelect={switchLocale} />
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
39
|
+
* MOTTO: We'll always do more ๐!!!
|
|
40
|
+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
'use client';
|
|
44
|
+
|
|
45
|
+
// โ๏ธ React
|
|
46
|
+
import type { CSSProperties, KeyboardEvent, ReactNode } from 'react';
|
|
47
|
+
import { useCallback, useEffect, useId, useRef, useState } from 'react';
|
|
48
|
+
// ๐งต classes
|
|
49
|
+
import clsx from 'clsx';
|
|
50
|
+
// ๐ฃ globe glyph
|
|
51
|
+
import AbIcon from '../ab-icon';
|
|
52
|
+
// ๐จ styles
|
|
53
|
+
import styles from './styles.module.css';
|
|
54
|
+
|
|
55
|
+
// ๐ one locale option
|
|
56
|
+
export interface AbLocaleOption {
|
|
57
|
+
code: string; // ๐ท๏ธ BCP 47, e.g. 'fr'
|
|
58
|
+
label: string; // ๐ฃ๏ธ endonym, e.g. 'Franรงais' (shown in its own language)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// โ๏ธ props
|
|
62
|
+
export interface AbLocaleSwitcherProps {
|
|
63
|
+
locales: readonly AbLocaleOption[]; // ๐ choices
|
|
64
|
+
current: string; // โ
active locale code
|
|
65
|
+
label: string; // ๐ท๏ธ trigger name, e.g. "Language"
|
|
66
|
+
onSelect?: (code: string) => void; // ๐ฃ button items (e.g. useAbLocaleSwitch().switchLocale)
|
|
67
|
+
getHref?: (code: string) => string; // ๐ link items instead (real navigation, hreflang)
|
|
68
|
+
variant?: 'icon' | 'menu'; // ๐จ 'icon' = globe only; 'menu' = globe + current endonym
|
|
69
|
+
align?: 'start' | 'end'; // โ๏ธ menu alignment under the trigger
|
|
70
|
+
icon?: ReactNode; // ๐ผ๏ธ override the globe
|
|
71
|
+
className?: string; // ๐ท๏ธ
|
|
72
|
+
style?: CSSProperties; // ๐จ
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @name getAbTypeaheadIndex
|
|
77
|
+
* @description ๐ค Index of the next option whose label starts with `char` (wraps), else -1.
|
|
78
|
+
*/
|
|
79
|
+
export function getAbTypeaheadIndex(labels: readonly string[], from: number, char: string): number {
|
|
80
|
+
const c = char.toLocaleLowerCase(); // ๐ก
|
|
81
|
+
for (let step = 1; step <= labels.length; step++) {
|
|
82
|
+
const i = (from + step) % labels.length; // ๐
|
|
83
|
+
if (labels[i].toLocaleLowerCase().startsWith(c)) return i; // โ
|
|
84
|
+
}
|
|
85
|
+
return -1; // ๐
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function AbLocaleSwitcher(props: AbLocaleSwitcherProps) {
|
|
89
|
+
// ๐งฉ props
|
|
90
|
+
const { locales, current, label, onSelect, getHref, variant = 'icon', align = 'end', icon, className, style } = props;
|
|
91
|
+
// ๐ช open?
|
|
92
|
+
const [open, setOpen] = useState(false);
|
|
93
|
+
// ๐ ids
|
|
94
|
+
const base = useId();
|
|
95
|
+
// ๐ refs
|
|
96
|
+
const triggerRef = useRef<HTMLButtonElement>(null);
|
|
97
|
+
const itemRefs = useRef<Array<HTMLElement | null>>([]);
|
|
98
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
99
|
+
// ๐ท๏ธ current option
|
|
100
|
+
const active = locales.find((l) => l.code === current);
|
|
101
|
+
const activeIndex = Math.max(0, locales.findIndex((l) => l.code === current));
|
|
102
|
+
|
|
103
|
+
// ๐ฏ focus an item
|
|
104
|
+
const focusItem = (i: number) => itemRefs.current[i]?.focus();
|
|
105
|
+
// ๐ช close and return focus to the trigger
|
|
106
|
+
const close = useCallback((returnFocus = true) => {
|
|
107
|
+
setOpen(false); // ๐ช
|
|
108
|
+
if (returnFocus) triggerRef.current?.focus(); // ๐ฏ
|
|
109
|
+
}, []);
|
|
110
|
+
|
|
111
|
+
// ๐ฏ on open, focus the checked item (after paint)
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
if (!open) return; // ๐ค
|
|
114
|
+
const id = requestAnimationFrame(() => focusItem(activeIndex)); // โญ๏ธ
|
|
115
|
+
return () => cancelAnimationFrame(id); // ๐งน
|
|
116
|
+
}, [open, activeIndex]);
|
|
117
|
+
|
|
118
|
+
// ๐ฑ๏ธ click outside closes (no focus steal)
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!open) return; // ๐ค
|
|
121
|
+
const onDown = (e: PointerEvent) => { if (!rootRef.current?.contains(e.target as Node)) close(false); }; // ๐ช
|
|
122
|
+
document.addEventListener('pointerdown', onDown); // ๐
|
|
123
|
+
return () => document.removeEventListener('pointerdown', onDown); // ๐งน
|
|
124
|
+
}, [open, close]);
|
|
125
|
+
|
|
126
|
+
// โจ๏ธ trigger: ArrowDown/Up/Enter/Space open the menu
|
|
127
|
+
const onTriggerKey = (e: KeyboardEvent<HTMLButtonElement>) => {
|
|
128
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); setOpen(true); } // โฌ๏ธ
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// โจ๏ธ menu keys
|
|
132
|
+
const onMenuKey = (e: KeyboardEvent<HTMLUListElement>) => {
|
|
133
|
+
const i = itemRefs.current.findIndex((el) => el === document.activeElement); // ๐
|
|
134
|
+
const n = locales.length; // ๐ข
|
|
135
|
+
if (e.key === 'ArrowDown') { e.preventDefault(); focusItem((i + 1) % n); } // โฌ๏ธ
|
|
136
|
+
else if (e.key === 'ArrowUp') { e.preventDefault(); focusItem((i - 1 + n) % n); } // โฌ๏ธ
|
|
137
|
+
else if (e.key === 'Home') { e.preventDefault(); focusItem(0); } // โฎ๏ธ
|
|
138
|
+
else if (e.key === 'End') { e.preventDefault(); focusItem(n - 1); } // โญ๏ธ
|
|
139
|
+
else if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); close(); } // ๐ช
|
|
140
|
+
else if (e.key === 'Tab') { close(false); } // โฅ let Tab move on
|
|
141
|
+
else if (e.key.length === 1 && /\S/.test(e.key)) { // ๐ค typeahead
|
|
142
|
+
const j = getAbTypeaheadIndex(locales.map((l) => l.label), Math.max(i, 0), e.key);
|
|
143
|
+
if (j >= 0) focusItem(j);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// โ
choose
|
|
148
|
+
const choose = (code: string) => {
|
|
149
|
+
onSelect?.(code); // ๐ฃ
|
|
150
|
+
close(); // ๐ช
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<div ref={rootRef} className={clsx('AbLocaleSwitcher', styles.root, className)} style={style} data-ab-part="locale-switcher" data-align={align}>
|
|
155
|
+
{/* ๐ trigger */}
|
|
156
|
+
<button
|
|
157
|
+
ref={triggerRef} // ๐
|
|
158
|
+
id={`${base}-trigger`} // ๐
|
|
159
|
+
type="button" // ๐งพ
|
|
160
|
+
className={clsx(styles.trigger, variant === 'menu' && styles.withText)} // ๐จ
|
|
161
|
+
aria-haspopup="menu" // โฟ
|
|
162
|
+
aria-expanded={open} // โฟ
|
|
163
|
+
aria-controls={`${base}-menu`} // ๐
|
|
164
|
+
aria-label={variant === 'icon' ? `${label}: ${active?.label ?? current}` : undefined} // ๐ท๏ธ "Language: Franรงais"
|
|
165
|
+
title={label} // ๐ฌ
|
|
166
|
+
onClick={() => setOpen((o) => !o)} // ๐ฑ๏ธ
|
|
167
|
+
onKeyDown={onTriggerKey} // โจ๏ธ
|
|
168
|
+
>
|
|
169
|
+
<span aria-hidden="true">{icon ?? <AbIcon name="language" size={20} />}</span>
|
|
170
|
+
{variant === 'menu' ? <span lang={current}>{active?.label ?? current}</span> : null /* ๐ฃ๏ธ endonym */}
|
|
171
|
+
</button>
|
|
172
|
+
{/* ๐ menu */}
|
|
173
|
+
<ul
|
|
174
|
+
id={`${base}-menu`} // ๐
|
|
175
|
+
role="menu" // โฟ
|
|
176
|
+
aria-labelledby={`${base}-trigger`} // ๐
|
|
177
|
+
hidden={!open} // ๐
|
|
178
|
+
className={styles.menu} // ๐จ
|
|
179
|
+
onKeyDown={onMenuKey} // โจ๏ธ
|
|
180
|
+
>
|
|
181
|
+
{locales.map((l, i) => {
|
|
182
|
+
const checked = l.code === current; // โ
|
|
183
|
+
const common = {
|
|
184
|
+
ref: (el: HTMLElement | null) => { itemRefs.current[i] = el; }, // ๐
|
|
185
|
+
role: 'menuitemradio' as const, // โฟ
|
|
186
|
+
'aria-checked': checked, // โ
|
|
187
|
+
tabIndex: -1, // โจ๏ธ focus managed by arrows
|
|
188
|
+
lang: l.code, // ๐ฃ๏ธ pronounced in its own language
|
|
189
|
+
className: styles.item, // ๐จ
|
|
190
|
+
};
|
|
191
|
+
return (
|
|
192
|
+
<li key={l.code} role="none">
|
|
193
|
+
{getHref ? (
|
|
194
|
+
// ๐ real navigation (works with middle-click, crawlers see hreflang)
|
|
195
|
+
<a {...common} href={getHref(l.code)} hrefLang={l.code} onClick={() => choose(l.code)}>
|
|
196
|
+
<span className={styles.check} aria-hidden="true">{checked ? 'โ' : ''}</span>{l.label}
|
|
197
|
+
</a>
|
|
198
|
+
) : (
|
|
199
|
+
// ๐ callback item
|
|
200
|
+
<button {...common} type="button" onClick={() => choose(l.code)}>
|
|
201
|
+
<span className={styles.check} aria-hidden="true">{checked ? 'โ' : ''}</span>{l.label}
|
|
202
|
+
</button>
|
|
203
|
+
)}
|
|
204
|
+
</li>
|
|
205
|
+
);
|
|
206
|
+
})}
|
|
207
|
+
</ul>
|
|
208
|
+
</div>
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ๐ฆ default export
|
|
213
|
+
export default AbLocaleSwitcher;
|