ab-nextjs-components 0.1.9 โ†’ 0.1.11

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 (49) hide show
  1. package/CHANGELOG.md +36 -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 +152 -0
  16. package/ab-flow-diagram/styles.module.css +158 -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 +5 -1
  29. package/ab-linear-progress/styles.module.css +8 -24
  30. package/ab-locale-switcher/index.tsx +213 -0
  31. package/ab-locale-switcher/styles.module.css +127 -0
  32. package/ab-pill/index.tsx +74 -0
  33. package/ab-progress-chips/index.tsx +30 -1
  34. package/ab-progress-chips/styles.module.css +40 -1
  35. package/ab-searchbar/index.tsx +33 -2
  36. package/ab-searchbar/styles.module.css +41 -5
  37. package/ab-splash/index.tsx +3 -1
  38. package/ab-splash/styles.module.css +2 -5
  39. package/ab-theme-toggle/index.tsx +188 -0
  40. package/ab-theme-toggle/styles.module.css +89 -0
  41. package/css/dialog.css +38 -3
  42. package/index.ts +41 -0
  43. package/package.json +33 -17
  44. package/server/ab-brand/index.tsx +29 -1
  45. package/server/ab-brand/styles.module.css +40 -1
  46. package/server/ab-button/index.tsx +96 -79
  47. package/server/ab-button/styles.module.css +79 -1
  48. package/server/ab-icon/index.tsx +68 -16
  49. package/server/ab-icon/styles.module.css +53 -9
@@ -0,0 +1,74 @@
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: AbPill - Server (G36)
28
+ * @file: ab-pill/index.tsx
29
+ * @type: Server component (static, no JS)
30
+ * @authors: Abraham Ukachi <abrahamukachi@gmail.com>
31
+ *
32
+ * Example usage:
33
+ * 1+|> <AbPill dot="sage">Free forever ยท MIT</AbPill>
34
+ * -|> <AbPill mono>ab-nextjs-core</AbPill>
35
+ */
36
+
37
+ /*
38
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
39
+ * MOTTO: We'll always do more ๐Ÿ˜œ!!!
40
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
41
+ */
42
+
43
+ // โš›๏ธ types
44
+ import type { CSSProperties, ReactElement, ReactNode } from 'react';
45
+ // ๐Ÿงต classes
46
+ import clsx from 'clsx';
47
+ // ๐ŸŽจ shares the chip stylesheet (pill composes chip)
48
+ import styles from '../ab-chip/styles.module.css';
49
+ // ๐ŸŽจ dot colours
50
+ import type { AbChipDot } from '../ab-chip';
51
+
52
+ // โš™๏ธ props
53
+ export interface AbPillProps {
54
+ children: ReactNode; // ๐Ÿท๏ธ eyebrow text
55
+ dot?: AbChipDot; // ๐ŸŸข leading dot
56
+ icon?: ReactNode; // ๐Ÿ–ผ๏ธ decorative icon
57
+ mono?: boolean; // โŒจ๏ธ monospace (package names)
58
+ className?: string; // ๐Ÿท๏ธ
59
+ style?: CSSProperties; // ๐ŸŽจ
60
+ }
61
+
62
+ /** ๐Ÿ’Š Eyebrow pill above a title. Static text; dot + icon are decorative. */
63
+ export function AbPill({ children, dot, icon, mono = false, className, style }: AbPillProps): ReactElement {
64
+ return (
65
+ <span className={clsx('AbPill', styles.pill, mono && styles.mono, className)} style={style} data-ab-part="pill">
66
+ {dot ? <span className={styles.dot} data-tone={dot} aria-hidden="true" /> : null /* ๐ŸŸข */}
67
+ {icon ? <span className={styles.icon} aria-hidden="true">{icon}</span> : null /* ๐Ÿ–ผ๏ธ */}
68
+ <span>{children}</span>
69
+ </span>
70
+ );
71
+ }
72
+
73
+ // ๐Ÿ“ฆ default export
74
+ export default AbPill;
@@ -5,17 +5,46 @@
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: AbProgressChips - Client (port of lyd-progress-chips)
10
28
  * @file: ab-progress-chips/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, ReactElement } from 'react';
16
43
  import { useState } from 'react';
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-*
19
48
 
20
49
  export interface AbProgressChip {
21
50
  id: number;
@@ -91,7 +120,7 @@ const AbProgressChips = ({
91
120
  onChipClick?.(chip.id, chip.code, chip.name, chip.duration);
92
121
  }}
93
122
  >
94
- <span className={styles.abProgressChipBar} aria-hidden />
123
+ <span className={clsx(styles.abProgressChipBar, AB_MOTION.size)} aria-hidden />{/* ๐Ÿ“ width fill = .ab-motion-size */}
95
124
  <span className={styles.abProgressChipCode}>{chip.code}</span>
96
125
  {!isChipNameHidden ? <span className={styles.abProgressChipName}>{chip.name}</span> : null}
97
126
  </button>
@@ -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-progress-chips - styles
28
+ * @file: ab-progress-chips/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
  .abProgressChips {
2
41
  display: flex;
3
42
  flex-wrap: wrap;
@@ -29,7 +68,7 @@
29
68
  height: 3px;
30
69
  background: var(--ab-primary, #6750a4);
31
70
  width: var(--chip-progress, 0%);
32
- transition: width 0.2s linear;
71
+ --ab-motion-easing: linear; /* ๐Ÿ“ fill motion = .ab-motion-size (ab-nextjs-animations) */
33
72
  }
34
73
  .abProgressChipName {
35
74
  font-size: 0.8125rem;
@@ -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: AbSearchbar - Client (port of lyd-searchbar)
10
28
  * @file: ab-searchbar/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, KeyboardEvent, ReactElement } from 'react';
16
43
  import { useId, useRef, useState } from 'react';
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 AbSearchbarProps {
21
52
  className?: string;
@@ -99,7 +130,7 @@ const AbSearchbar = ({
99
130
  <div
100
131
  hidden={hidden}
101
132
  style={style}
102
- className={clsx('AbSearchbar', styles.abSearchbar, disabled && styles.isDisabled, className)}
133
+ className={clsx('AbSearchbar', styles.abSearchbar, AB_MOTION.colors, disabled && styles.isDisabled, className)}
103
134
  data-busy={busy ? 'true' : 'false'}
104
135
  >
105
136
  <span className={clsx('material-symbols-rounded', styles.abSearchbarIcon)} aria-hidden>
@@ -124,7 +155,7 @@ const AbSearchbar = ({
124
155
  }}
125
156
  onKeyUp={(e) => onKeyUp?.(e.currentTarget.value, e)}
126
157
  />
127
- {busy ? <span className={styles.abSearchbarSpinner} aria-hidden /> : null}
158
+ {busy ? <span className={clsx(styles.abSearchbarSpinner, AB_SPIN_CLASS)} aria-hidden /> : null}
128
159
  {current && !disabled ? (
129
160
  <button type="button" className={styles.abSearchbarClear} aria-label={clearLabel} onClick={clear}>
130
161
  <span className="material-symbols-rounded" aria-hidden>close</span>
@@ -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-searchbar - styles
28
+ * @file: ab-searchbar/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
  .abSearchbar {
2
41
  position: relative;
3
42
  display: flex;
@@ -10,7 +49,7 @@
10
49
  border-radius: 9999px;
11
50
  overflow: hidden;
12
51
  background: color-mix(in srgb, var(--ab-surface-container-high, #e6e0e9) 90%, transparent);
13
- transition: background 0.3s ease;
52
+ --ab-motion-duration: 300ms; /* ๐ŸŽจ focus fade = .ab-motion-colors (ab-nextjs-animations) */
14
53
  }
15
54
  .abSearchbar:focus-within {
16
55
  background: var(--ab-surface-container-high, #e6e0e9);
@@ -65,10 +104,7 @@
65
104
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
66
105
  border-top-color: currentColor;
67
106
  border-radius: 50%;
68
- animation: abSearchbarSpin 0.7s linear infinite;
69
- }
70
- @keyframes abSearchbarSpin {
71
- to { transform: rotate(360deg); }
107
+ /* ๐ŸŒ€ rotation = .ab-spin (ab-nextjs-animations) */
72
108
  }
73
109
  .isDisabled {
74
110
  opacity: 0.55;
@@ -60,6 +60,8 @@ import {
60
60
  } from './gate';
61
61
  // ๐ŸŽจ package-shipped styles
62
62
  import styles from './styles.module.css';
63
+ import { AB_MOTION } from 'ab-nextjs-animations/motion'; // ๐ŸŽฌ fade-out transition (ab-nextjs-animations >= 0.2.4)
64
+ import 'ab-nextjs-animations/motion/styles.css'; // ๐ŸŒซ๏ธ .ab-motion-colors (covers opacity)
63
65
 
64
66
  // ๐Ÿ“ฆ re-export the gate so `import { abSplashGateScript } from 'ab-nextjs-components/ab-splash'` works
65
67
  export * from './gate';
@@ -125,7 +127,7 @@ export default function AbSplash({ className, wordmark = 'Elements', maxMs }: Ab
125
127
 
126
128
  return (
127
129
  // ๐Ÿ’ฆ the overlay (decorative โ†’ hidden from assistive tech)
128
- <div ref={ref} className={clsx('AbSplash', styles.abSplash, className)} aria-hidden="true">
130
+ <div ref={ref} className={clsx('AbSplash', styles.abSplash, AB_MOTION.colors, className)} aria-hidden="true">
129
131
  {/* ๐Ÿ…ฐ๏ธ mark + wordmark */}
130
132
  <AbLogo wordmark={wordmark} alt="" className={styles.abSplash__brand} />
131
133
  {/* ๐Ÿ“ถ progress */}
@@ -49,7 +49,7 @@
49
49
  gap: 2.25rem; /* โ†•๏ธ brand โ†” bar */
50
50
  background-color: #FFF8F3; /* โ˜€๏ธ light surface (matches the splash mocks) */
51
51
  color: #A67C52; /* ๐ŸŽจ bronze brand */
52
- transition: opacity 200ms ease; /* ๐ŸŒซ๏ธ fade-out */
52
+ --ab-motion-duration: 200ms; /* ๐ŸŒซ๏ธ fade-out = .ab-motion-colors (ab-nextjs-animations; off under reduced motion) */
53
53
  animation: abSplashFailsafe 0s linear 1.2s forwards; /* โฑ๏ธ never longer than 1.2 s, even without hydration */
54
54
  }
55
55
 
@@ -95,10 +95,7 @@
95
95
  --ab-linear-progress-color: #A67C52; /* ๐ŸŽจ bronze bar in both themes */
96
96
  }
97
97
 
98
- /* โ™ฟ reduced motion: no fade */
99
- @media (prefers-reduced-motion: reduce) {
100
- .abSplash { transition: none; }
101
- }
98
+ /* โ™ฟ reduced motion: no fade (handled by ab-nextjs-animations .ab-motion-colors) */
102
99
 
103
100
  /* โฑ๏ธ failsafe keyframes */
104
101
  @keyframes abSplashFailsafe {
@@ -0,0 +1,188 @@
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: AbThemeToggle - Client (G9/G34)
28
+ * @file: ab-theme-toggle/index.tsx
29
+ * @type: Component (client) โ€” light / dark / system
30
+ * @authors: Abraham Ukachi <abrahamukachi@gmail.com>
31
+ *
32
+ * Example usage:
33
+ * 1+|> <AbThemeToggle labels={{ group: t('theme.label'), light: t('theme.light'), dark: t('theme.dark'), system: t('theme.system') }} />
34
+ */
35
+
36
+ /*
37
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
38
+ * MOTTO: We'll always do more ๐Ÿ˜œ!!!
39
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
40
+ */
41
+
42
+ 'use client';
43
+
44
+ // โš›๏ธ React
45
+ import type { CSSProperties, KeyboardEvent, ReactNode } from 'react';
46
+ import { useRef } from 'react';
47
+ // ๐Ÿงต classes
48
+ import clsx from 'clsx';
49
+ // ๐ŸŒ— theme engine (hooks โ‰ฅ 0.1.6, deep import = tree-shaken)
50
+ import { useAbThemeMode, AB_THEME_MODES, type AbThemeMode } from 'ab-nextjs-hooks/useAbTheme';
51
+ // ๐Ÿ”ฃ icons (SVG once G2 lands)
52
+ import AbIcon from '../ab-icon';
53
+ // ๐ŸŽจ styles
54
+ import styles from './styles.module.css';
55
+ import { AB_MOTION } from 'ab-nextjs-animations/motion'; // ๐ŸŽฌ transition class names (ab-nextjs-animations >= 0.2.4)
56
+ import 'ab-nextjs-animations/motion/styles.css'; // ๐ŸŽจ .ab-motion-*
57
+
58
+ // ๐Ÿ“ฆ re-export the mode type for consumers
59
+ export type { AbThemeMode } from 'ab-nextjs-hooks/useAbTheme';
60
+
61
+ // ๐Ÿท๏ธ i18n labels (required: no English defaults baked into a11y names)
62
+ export interface AbThemeToggleLabels {
63
+ group: string; // ๐Ÿ—‚๏ธ "Theme"
64
+ light: string; // ๐ŸŒž "Light"
65
+ dark: string; // ๐ŸŒ™ "Dark"
66
+ system: string; // ๐Ÿ–ฅ๏ธ "System"
67
+ }
68
+
69
+ // โš™๏ธ props
70
+ export interface AbThemeToggleProps {
71
+ labels: AbThemeToggleLabels; // ๐Ÿท๏ธ
72
+ variant?: 'segmented' | 'icon'; // ๐ŸŽจ pill of radios, or one cycling icon button
73
+ modes?: readonly AbThemeMode[]; // ๐ŸŽš๏ธ default light, dark, system
74
+ value?: AbThemeMode; // ๐ŸŽ›๏ธ controlled
75
+ onChange?: (mode: AbThemeMode) => void; // ๐Ÿ“ฃ
76
+ defaultMode?: AbThemeMode; // ๐ŸŒฑ before hydration (default 'light')
77
+ icons?: Partial<Record<AbThemeMode, ReactNode>>; // ๐Ÿ–ผ๏ธ override glyphs
78
+ size?: 'sm' | 'md'; // ๐Ÿ“ sm = 32px, md = 40px segments (hit area โ‰ฅ 24px either way)
79
+ className?: string; // ๐Ÿท๏ธ
80
+ style?: CSSProperties; // ๐ŸŽจ
81
+ }
82
+
83
+ // ๐Ÿ”ฃ default glyphs (AbIcons names)
84
+ const DEFAULT_ICON_NAMES: Record<AbThemeMode, string> = { light: 'light_mode', dark: 'dark_mode', system: 'computer' };
85
+
86
+ /**
87
+ * @name getNextAbThemeMode
88
+ * @description ๐Ÿ” Radio-group arrow logic (pure): wraps, RTL flips Left/Right.
89
+ */
90
+ export function getNextAbThemeMode(modes: readonly AbThemeMode[], current: AbThemeMode, key: string, dir: 'ltr' | 'rtl' = 'ltr'): AbThemeMode | null {
91
+ const i = Math.max(0, modes.indexOf(current)); // ๐Ÿ“
92
+ const forward = dir === 'rtl' ? 'ArrowLeft' : 'ArrowRight'; // โžก๏ธ
93
+ const backward = dir === 'rtl' ? 'ArrowRight' : 'ArrowLeft'; // โฌ…๏ธ
94
+ if (key === forward || key === 'ArrowDown') return modes[(i + 1) % modes.length]; // โญ๏ธ
95
+ if (key === backward || key === 'ArrowUp') return modes[(i - 1 + modes.length) % modes.length]; // โฎ๏ธ
96
+ if (key === 'Home') return modes[0]; // โฎ๏ธโฎ๏ธ
97
+ if (key === 'End') return modes[modes.length - 1]; // โญ๏ธโญ๏ธ
98
+ return null; // ๐Ÿ™…
99
+ }
100
+
101
+ export function AbThemeToggle(props: AbThemeToggleProps) {
102
+ // ๐Ÿงฉ props
103
+ const { labels, variant = 'segmented', modes = AB_THEME_MODES, value, onChange, defaultMode = 'light', icons, size = 'md', className, style } = props;
104
+ // ๐ŸŒ— engine: persists + applies to <html>
105
+ const engine = useAbThemeMode(defaultMode);
106
+ // ๐ŸŽ›๏ธ controlled or engine-driven
107
+ const current = (value ?? engine.mode) as AbThemeMode;
108
+ // ๐Ÿ“ refs to move focus with the selection
109
+ const refs = useRef<Array<HTMLButtonElement | null>>([]);
110
+
111
+ // โœ๏ธ select a mode
112
+ const select = (mode: AbThemeMode) => {
113
+ if (value === undefined) engine.setMode(mode); // ๐ŸŽš๏ธ uncontrolled: apply + persist
114
+ onChange?.(mode); // ๐Ÿ“ฃ
115
+ };
116
+
117
+ // ๐Ÿ–ผ๏ธ glyph for a mode (decorative: the label names it)
118
+ const glyph = (mode: AbThemeMode) => icons?.[mode] ?? <AbIcon name={DEFAULT_ICON_NAMES[mode]} size={20} />;
119
+
120
+ // ๐Ÿ”˜ single cycling button variant
121
+ if (variant === 'icon') {
122
+ const next = modes[(Math.max(0, modes.indexOf(current)) + 1) % modes.length]; // โญ๏ธ
123
+ return (
124
+ <button
125
+ type="button" // ๐Ÿงพ
126
+ className={clsx('AbThemeToggle', styles.icon, AB_MOTION.colors, className)} // ๐Ÿท๏ธ
127
+ style={style} // ๐ŸŽจ
128
+ data-ab-part="theme-toggle" // ๐Ÿ—‚๏ธ
129
+ data-mode={current} // ๐ŸŽš๏ธ
130
+ data-size={size} // ๐Ÿ“
131
+ aria-label={`${labels.group}: ${labels[current]}`} // โ™ฟ "Theme: Dark"
132
+ title={`${labels.group}: ${labels[current]}`} // ๐Ÿ’ฌ
133
+ onClick={() => select(next)} // ๐Ÿ”
134
+ >
135
+ <span aria-hidden="true">{glyph(current)}</span>
136
+ </button>
137
+ );
138
+ }
139
+
140
+ // โŒจ๏ธ roving radio keys
141
+ const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
142
+ const dir = (event.currentTarget.closest('[dir]')?.getAttribute('dir') === 'rtl' ? 'rtl' : 'ltr') as 'ltr' | 'rtl'; // ๐ŸŒ
143
+ const target = getNextAbThemeMode(modes, current, event.key, dir); // ๐ŸŽฏ
144
+ if (!target) return; // ๐Ÿ™… other keys untouched
145
+ event.preventDefault(); // ๐Ÿ›‘ no scroll
146
+ select(target); // โœ… selection follows focus (radio pattern)
147
+ refs.current[modes.indexOf(target)]?.focus(); // ๐ŸŽฏ
148
+ };
149
+
150
+ // ๐ŸŽ›๏ธ segmented radiogroup
151
+ return (
152
+ <div
153
+ role="radiogroup" // โ™ฟ
154
+ aria-label={labels.group} // ๐Ÿท๏ธ
155
+ className={clsx('AbThemeToggle', styles.group, className)} // ๐Ÿท๏ธ
156
+ style={style} // ๐ŸŽจ
157
+ data-ab-part="theme-toggle" // ๐Ÿ—‚๏ธ
158
+ data-mode={current} // ๐ŸŽš๏ธ
159
+ data-size={size} // ๐Ÿ“
160
+ onKeyDown={onKeyDown} // โŒจ๏ธ
161
+ >
162
+ {modes.map((mode, i) => {
163
+ const checked = mode === current; // โœ…
164
+ return (
165
+ <button
166
+ key={mode} // ๐Ÿ”‘
167
+ ref={(el) => { refs.current[i] = el; }} // ๐Ÿ“
168
+ type="button" // ๐Ÿงพ
169
+ role="radio" // โ™ฟ
170
+ aria-checked={checked} // โœ…
171
+ aria-label={labels[mode]} // ๐Ÿท๏ธ
172
+ title={labels[mode]} // ๐Ÿ’ฌ
173
+ tabIndex={checked ? 0 : -1} // โŒจ๏ธ roving: one tab stop
174
+ className={clsx(styles.segment, AB_MOTION.colors)} // ๐ŸŽจ + colour fade (ab-nextjs-animations)
175
+ data-ab-part="theme-option" // ๐Ÿ—‚๏ธ
176
+ data-mode={mode} // ๐ŸŽš๏ธ
177
+ onClick={() => select(mode)} // ๐Ÿ–ฑ๏ธ
178
+ >
179
+ <span aria-hidden="true">{glyph(mode)}</span>
180
+ </button>
181
+ );
182
+ })}
183
+ </div>
184
+ );
185
+ }
186
+
187
+ // ๐Ÿ“ฆ default export
188
+ export default AbThemeToggle;
@@ -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: AbThemeToggle - Styles
28
+ * @file: ab-theme-toggle/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
+ /* ๐Ÿ’Š segmented pill */
40
+ .group {
41
+ display: inline-flex; /* ๐Ÿ“ row */
42
+ gap: 2px; /* ๐Ÿงฑ */
43
+ padding: 3px; /* ๐Ÿงฑ */
44
+ border-radius: 9999px; /* ๐Ÿ’Š */
45
+ border: 1px solid var(--ab-color-outline-variant, rgb(0 0 0 / 0.12)); /* ๐Ÿ–Š๏ธ */
46
+ background: var(--ab-color-surface-container, transparent); /* ๐ŸŽจ */
47
+ }
48
+
49
+ /* ๐Ÿ”˜ each option; md = 40px, sm = 32px (both โ‰ฅ 24px target, WCAG 2.5.8) */
50
+ .segment,
51
+ .icon {
52
+ display: inline-grid; /* ๐Ÿ“ */
53
+ place-items: center; /* ๐ŸŽฏ */
54
+ width: 40px; /* ๐Ÿ“ */
55
+ height: 40px; /* ๐Ÿ“ */
56
+ padding: 0; /* ๐Ÿงน */
57
+ border: 0; /* ๐Ÿงน */
58
+ border-radius: 9999px; /* ๐Ÿ’Š */
59
+ color: var(--ab-color-on-surface-variant, currentColor); /* ๐ŸŽจ */
60
+ background: transparent; /* ๐Ÿซฅ */
61
+ cursor: pointer; /* ๐Ÿ‘† */
62
+ --ab-motion-duration: var(--ab-motion-duration-short, 160ms); /* ๐ŸŽž๏ธ colour fade = .ab-motion-colors (ab-nextjs-animations) */
63
+ }
64
+ [data-size='sm'] .segment,
65
+ .icon[data-size='sm'] {
66
+ width: 32px; /* ๐Ÿ“ */
67
+ height: 32px; /* ๐Ÿ“ */
68
+ }
69
+
70
+ /* โœ… selected */
71
+ .segment[aria-checked='true'] {
72
+ color: var(--ab-color-on-primary, #fff); /* ๐ŸŽจ */
73
+ background: var(--ab-color-primary, #A67C52); /* ๐Ÿฅ‰ bronze */
74
+ }
75
+
76
+ /* ๐Ÿ–ฑ๏ธ hover (unselected only) */
77
+ .segment[aria-checked='false']:hover,
78
+ .icon:hover {
79
+ background: color-mix(in srgb, currentColor 10%, transparent); /* ๐ŸŒซ๏ธ */
80
+ }
81
+
82
+ /* โ™ฟ visible focus ring (theme token, G18) */
83
+ .segment:focus-visible,
84
+ .icon:focus-visible {
85
+ outline: 2px solid var(--ab-focus-ring, var(--ab-color-primary, #A67C52)); /* ๐Ÿ’ */
86
+ outline-offset: 2px; /* โ†”๏ธ */
87
+ }
88
+
89
+ /* ๐Ÿง˜ reduced motion: handled by ab-nextjs-animations (.ab-motion-colors) */