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.
Files changed (59) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/ab-brand/index.tsx +30 -1
  3. package/ab-brand/styles.module.css +40 -1
  4. package/ab-button/helpers.ts +90 -0
  5. package/ab-button/index.tsx +164 -87
  6. package/ab-button/styles.module.css +79 -1
  7. package/ab-carousel/helpers.ts +146 -0
  8. package/ab-carousel/index.tsx +643 -0
  9. package/ab-carousel/styles.module.css +206 -0
  10. package/ab-chip/index.tsx +75 -0
  11. package/ab-chip/styles.module.css +87 -0
  12. package/ab-collapsible/index.tsx +30 -1
  13. package/ab-collapsible/styles.module.css +40 -1
  14. package/ab-flow-diagram/helpers.ts +77 -0
  15. package/ab-flow-diagram/index.tsx +141 -0
  16. package/ab-flow-diagram/styles.module.css +141 -0
  17. package/ab-icon/builtin.ts +61 -0
  18. package/ab-icon/helpers.ts +102 -0
  19. package/ab-icon/index.tsx +77 -16
  20. package/ab-icon/styles.module.css +53 -9
  21. package/ab-icon-button/index.tsx +110 -46
  22. package/ab-icon-button/styles.module.css +28 -10
  23. package/ab-install-snippet/helpers.ts +62 -0
  24. package/ab-install-snippet/index.tsx +170 -0
  25. package/ab-install-snippet/styles.module.css +104 -0
  26. package/ab-like-button/index.tsx +33 -1
  27. package/ab-like-button/styles.module.css +41 -6
  28. package/ab-linear-progress/index.tsx +129 -0
  29. package/ab-linear-progress/styles.module.css +105 -0
  30. package/ab-locale-switcher/index.tsx +213 -0
  31. package/ab-locale-switcher/styles.module.css +127 -0
  32. package/ab-logo/index.tsx +88 -30
  33. package/ab-logo/styles.module.css +79 -11
  34. package/ab-pill/index.tsx +74 -0
  35. package/ab-progress-chips/index.tsx +30 -1
  36. package/ab-progress-chips/styles.module.css +40 -1
  37. package/ab-searchbar/index.tsx +33 -2
  38. package/ab-searchbar/styles.module.css +41 -5
  39. package/ab-splash/csp.d.ts +54 -0
  40. package/ab-splash/csp.mjs +82 -0
  41. package/ab-splash/csp.ts +60 -0
  42. package/ab-splash/gate.ts +216 -0
  43. package/ab-splash/index.tsx +140 -0
  44. package/ab-splash/styles.module.css +103 -0
  45. package/ab-theme-toggle/index.tsx +188 -0
  46. package/ab-theme-toggle/styles.module.css +89 -0
  47. package/css/dialog.css +38 -3
  48. package/index.ts +47 -0
  49. package/package.json +46 -18
  50. package/server/ab-brand/index.tsx +29 -1
  51. package/server/ab-brand/styles.module.css +40 -1
  52. package/server/ab-button/index.tsx +96 -79
  53. package/server/ab-button/styles.module.css +79 -1
  54. package/server/ab-icon/index.tsx +68 -16
  55. package/server/ab-icon/styles.module.css +53 -9
  56. package/server/ab-logo/index.tsx +88 -29
  57. package/server/ab-logo/styles.module.css +79 -11
  58. package/types/css.d.ts +43 -0
  59. package/types/index.d.ts +2 -0
@@ -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
- transition: transform 0.2s ease, background 0.2s ease;
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
- animation: abLikeSpin 0.7s linear infinite;
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;