@veluai/velu 0.1.13 → 0.1.15

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 (98) hide show
  1. package/README.md +80 -80
  2. package/dist/cli.js +21 -21
  3. package/package.json +3 -2
  4. package/runtime/velu-ui/components/Accordion.jsx +64 -64
  5. package/runtime/velu-ui/components/ApiClient.jsx +121 -121
  6. package/runtime/velu-ui/components/ApiField.jsx +87 -87
  7. package/runtime/velu-ui/components/ApiPath.jsx +63 -63
  8. package/runtime/velu-ui/components/ApiSidebar.jsx +122 -122
  9. package/runtime/velu-ui/components/AskBar.jsx +71 -71
  10. package/runtime/velu-ui/components/Callout.jsx +114 -114
  11. package/runtime/velu-ui/components/Card.jsx +131 -131
  12. package/runtime/velu-ui/components/Chatbot.jsx +596 -596
  13. package/runtime/velu-ui/components/CodeBlock.jsx +375 -375
  14. package/runtime/velu-ui/components/Columns.jsx +56 -56
  15. package/runtime/velu-ui/components/ErrorCard.jsx +138 -138
  16. package/runtime/velu-ui/components/Field.jsx +81 -81
  17. package/runtime/velu-ui/components/Image.jsx +163 -163
  18. package/runtime/velu-ui/components/Logo.jsx +31 -0
  19. package/runtime/velu-ui/components/MethodBadge.jsx +31 -31
  20. package/runtime/velu-ui/components/NavSelect.jsx +108 -108
  21. package/runtime/velu-ui/components/PageFeedback.jsx +219 -219
  22. package/runtime/velu-ui/components/PageFooter.jsx +145 -213
  23. package/runtime/velu-ui/components/PageHeader.jsx +422 -414
  24. package/runtime/velu-ui/components/PageNav.jsx +77 -77
  25. package/runtime/velu-ui/components/PoweredBy.jsx +51 -51
  26. package/runtime/velu-ui/components/Prompt.jsx +115 -115
  27. package/runtime/velu-ui/components/Search.jsx +411 -366
  28. package/runtime/velu-ui/components/Sidebar.jsx +191 -191
  29. package/runtime/velu-ui/components/SocialLinks.jsx +90 -0
  30. package/runtime/velu-ui/components/Steps.jsx +65 -65
  31. package/runtime/velu-ui/components/ThemeToggle.jsx +48 -48
  32. package/runtime/velu-ui/components/Toc.jsx +537 -537
  33. package/runtime/velu-ui/components/TocBar.jsx +195 -195
  34. package/runtime/velu-ui/components/Tree.jsx +87 -87
  35. package/runtime/velu-ui/components/TryItBar.jsx +90 -90
  36. package/runtime/velu-ui/components/accordion.css +92 -92
  37. package/runtime/velu-ui/components/api.css +479 -479
  38. package/runtime/velu-ui/components/ask-bar.css +94 -94
  39. package/runtime/velu-ui/components/card.css +105 -105
  40. package/runtime/velu-ui/components/chatbot.css +617 -617
  41. package/runtime/velu-ui/components/code-block.css +263 -263
  42. package/runtime/velu-ui/components/docs-layout.css +784 -775
  43. package/runtime/velu-ui/components/field.css +82 -82
  44. package/runtime/velu-ui/components/image.css +237 -237
  45. package/runtime/velu-ui/components/nav-select.css +157 -157
  46. package/runtime/velu-ui/components/page-feedback.css +241 -241
  47. package/runtime/velu-ui/components/page-footer.css +130 -130
  48. package/runtime/velu-ui/components/page-header.css +557 -520
  49. package/runtime/velu-ui/components/page-nav.css +50 -50
  50. package/runtime/velu-ui/components/powered-by.css +86 -66
  51. package/runtime/velu-ui/components/prompt.css +99 -99
  52. package/runtime/velu-ui/components/search.css +307 -307
  53. package/runtime/velu-ui/components/sidebar.css +144 -144
  54. package/runtime/velu-ui/components/steps.css +77 -77
  55. package/runtime/velu-ui/components/theme-toggle.css +101 -101
  56. package/runtime/velu-ui/components/toc-bar.css +234 -234
  57. package/runtime/velu-ui/components/tree.css +49 -49
  58. package/runtime/velu-ui/index.js +48 -46
  59. package/runtime/velu-ui/lib/component-schemas.js +100 -100
  60. package/runtime/velu-ui/lib/copyText.js +64 -64
  61. package/runtime/velu-ui/lib/lang-icons.jsx +147 -147
  62. package/runtime/velu-ui/lib/prism-langs.js +957 -957
  63. package/runtime/velu-ui/lib/prism-loader.js +74 -74
  64. package/runtime/velu-ui/lib/resolveIcon.jsx +29 -29
  65. package/runtime/velu-ui/lib/scrollIntoNearestView.js +66 -66
  66. package/runtime/velu-ui/mdx-components.jsx +105 -105
  67. package/runtime/velu-ui/primitives/Cluster.jsx +49 -49
  68. package/runtime/velu-ui/primitives/Stack.jsx +63 -63
  69. package/runtime/velu-ui/primitives/Switcher.jsx +57 -57
  70. package/runtime/velu-ui/primitives/stack.css +3 -3
  71. package/runtime/velu-ui/primitives/switcher.css +25 -25
  72. package/runtime/velu-ui/styles.css +43 -43
  73. package/runtime/velu-ui/tokens.css +4 -4
  74. package/schema/velu.schema.json +281 -167
  75. package/src/lib/extract-mdx-error.js +170 -170
  76. package/src/lib/issues.js +159 -159
  77. package/src/lib/known-components.js +34 -34
  78. package/src/navigation.js +434 -434
  79. package/src/runtime/App.jsx +1506 -1476
  80. package/src/runtime/ErrorBoundary.jsx +54 -54
  81. package/src/runtime/client-entry.jsx +22 -22
  82. package/src/runtime/server-entry.jsx +16 -16
  83. package/src/template.html +48 -48
  84. package/templates/starter/ai-tools/claude-code.mdx +26 -26
  85. package/templates/starter/ai-tools/cursor.mdx +17 -17
  86. package/templates/starter/api-reference/endpoint/create.mdx +24 -24
  87. package/templates/starter/api-reference/endpoint/get.mdx +27 -27
  88. package/templates/starter/api-reference/introduction.mdx +28 -28
  89. package/templates/starter/development.mdx +19 -19
  90. package/templates/starter/essentials/code.mdx +29 -29
  91. package/templates/starter/essentials/images.mdx +29 -29
  92. package/templates/starter/essentials/markdown.mdx +25 -25
  93. package/templates/starter/essentials/navigation.mdx +39 -39
  94. package/templates/starter/essentials/settings.mdx +30 -30
  95. package/templates/starter/favicon.svg +6 -6
  96. package/templates/starter/index.mdx +31 -31
  97. package/templates/starter/quickstart.mdx +31 -31
  98. package/templates/starter/velu.json +33 -33
@@ -1,163 +1,163 @@
1
- import React from 'react';
2
-
3
- /**
4
- * Image — image content with optional caption and decorative chrome.
5
- *
6
- * Variants:
7
- * - plain <Image src alt />
8
- * - captioned <Image src alt caption="..." />
9
- * - window <Image src alt chrome="window" caption?/>
10
- * - frame <Image src alt chrome="frame" caption?/>
11
- *
12
- * Window/frame use a pure SVG+CSS liquid-glass pattern (lucasromerodb/
13
- * liquid-glass-effect-macos): an SVG <filter> with feTurbulence →
14
- * feDisplacementMap provides real refraction; a 4-layer div stack
15
- * (effect/tint/shine/content) builds the glass material.
16
- * No library, no SSR/hydration concerns — pure declarative DOM + CSS.
17
- */
18
-
19
- const GLASS_FILTER_ID = 'velu-glass-distortion';
20
-
21
- function GlassFilterDefs() {
22
- return (
23
- <svg
24
- aria-hidden="true"
25
- style={{ position: 'absolute', inlineSize: 0, blockSize: 0 }}
26
- >
27
- {/* Turbulence-driven displacement of the backdrop. Used via
28
- `backdrop-filter: url(#...)` so SourceGraphic IS the backdrop. */}
29
- <filter
30
- id={GLASS_FILTER_ID}
31
- x="0%"
32
- y="0%"
33
- width="100%"
34
- height="100%"
35
- filterUnits="objectBoundingBox"
36
- >
37
- <feTurbulence
38
- type="fractalNoise"
39
- baseFrequency="0.008 0.008"
40
- numOctaves="2"
41
- seed="5"
42
- result="noise"
43
- />
44
- <feDisplacementMap
45
- in="SourceGraphic"
46
- in2="noise"
47
- scale="80"
48
- xChannelSelector="R"
49
- yChannelSelector="G"
50
- />
51
- </filter>
52
- </svg>
53
- );
54
- }
55
-
56
- function Glass({ className = '', children }) {
57
- return (
58
- <div className={`velu-glass ${className}`.trim()}>
59
- <div className="velu-glass__effect" aria-hidden="true" />
60
- <div className="velu-glass__tint" aria-hidden="true" />
61
- <div className="velu-glass__shine" aria-hidden="true" />
62
- <div className="velu-glass__content">{children}</div>
63
- </div>
64
- );
65
- }
66
-
67
- function WindowChrome({ src, alt }) {
68
- return (
69
- <div className="velu-image__window">
70
- <GlassFilterDefs />
71
- <div className="velu-image__glow" aria-hidden="true" />
72
- <div className="velu-image__noise" aria-hidden="true" />
73
- <Glass className="velu-image__window-surface">
74
- <div className="velu-image__window-inner">
75
- <Glass className="velu-image__chrome">
76
- <span className="velu-image__dots" aria-hidden="true">
77
- <span className="velu-image__dot velu-image__dot--red" />
78
- <span className="velu-image__dot velu-image__dot--yellow" />
79
- <span className="velu-image__dot velu-image__dot--green" />
80
- </span>
81
- <span className="velu-image__urlbar" aria-hidden="true" />
82
- </Glass>
83
- <img
84
- src={src}
85
- alt={alt}
86
- loading="lazy"
87
- className="velu-image__img velu-image__img--flush"
88
- />
89
- </div>
90
- </Glass>
91
- </div>
92
- );
93
- }
94
-
95
- function DeviceFrame({ src, alt }) {
96
- return (
97
- <div className="velu-image__frame">
98
- <GlassFilterDefs />
99
- <div className="velu-image__glow" aria-hidden="true" />
100
- <div className="velu-image__noise" aria-hidden="true" />
101
- <Glass className="velu-image__frame-bezel">
102
- <div className="velu-image__frame-screen">
103
- <img
104
- src={src}
105
- alt={alt}
106
- loading="lazy"
107
- className="velu-image__img velu-image__img--flush"
108
- />
109
- </div>
110
- </Glass>
111
- </div>
112
- );
113
- }
114
-
115
- export default function Image({
116
- src,
117
- alt = '',
118
- caption,
119
- chrome,
120
- className = '',
121
- ...rest
122
- }) {
123
- // Fall back to the caption for alt text when no alt is provided, so a
124
- // captioned image stays accessible without forcing duplication.
125
- // Only string captions are usable as alt — React-node captions are
126
- // ignored here.
127
- const effectiveAlt = alt || (typeof caption === 'string' ? caption : '');
128
-
129
- let body;
130
- let variantClass = '';
131
- if (chrome === 'window') {
132
- body = <WindowChrome src={src} alt={effectiveAlt} />;
133
- variantClass = 'velu-image--chrome';
134
- } else if (chrome === 'frame') {
135
- body = <DeviceFrame src={src} alt={effectiveAlt} />;
136
- variantClass = 'velu-image--chrome';
137
- } else {
138
- body = (
139
- <img
140
- src={src}
141
- alt={effectiveAlt}
142
- loading="lazy"
143
- className="velu-image__img"
144
- />
145
- );
146
- }
147
-
148
- const cls = `velu-image ${variantClass} ${className}`.trim();
149
-
150
- if (caption) {
151
- return (
152
- <figure className={cls} {...rest}>
153
- {body}
154
- <figcaption className="velu-image__caption">{caption}</figcaption>
155
- </figure>
156
- );
157
- }
158
- return (
159
- <div className={cls} {...rest}>
160
- {body}
161
- </div>
162
- );
163
- }
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Image — image content with optional caption and decorative chrome.
5
+ *
6
+ * Variants:
7
+ * - plain <Image src alt />
8
+ * - captioned <Image src alt caption="..." />
9
+ * - window <Image src alt chrome="window" caption?/>
10
+ * - frame <Image src alt chrome="frame" caption?/>
11
+ *
12
+ * Window/frame use a pure SVG+CSS liquid-glass pattern (lucasromerodb/
13
+ * liquid-glass-effect-macos): an SVG <filter> with feTurbulence →
14
+ * feDisplacementMap provides real refraction; a 4-layer div stack
15
+ * (effect/tint/shine/content) builds the glass material.
16
+ * No library, no SSR/hydration concerns — pure declarative DOM + CSS.
17
+ */
18
+
19
+ const GLASS_FILTER_ID = 'velu-glass-distortion';
20
+
21
+ function GlassFilterDefs() {
22
+ return (
23
+ <svg
24
+ aria-hidden="true"
25
+ style={{ position: 'absolute', inlineSize: 0, blockSize: 0 }}
26
+ >
27
+ {/* Turbulence-driven displacement of the backdrop. Used via
28
+ `backdrop-filter: url(#...)` so SourceGraphic IS the backdrop. */}
29
+ <filter
30
+ id={GLASS_FILTER_ID}
31
+ x="0%"
32
+ y="0%"
33
+ width="100%"
34
+ height="100%"
35
+ filterUnits="objectBoundingBox"
36
+ >
37
+ <feTurbulence
38
+ type="fractalNoise"
39
+ baseFrequency="0.008 0.008"
40
+ numOctaves="2"
41
+ seed="5"
42
+ result="noise"
43
+ />
44
+ <feDisplacementMap
45
+ in="SourceGraphic"
46
+ in2="noise"
47
+ scale="80"
48
+ xChannelSelector="R"
49
+ yChannelSelector="G"
50
+ />
51
+ </filter>
52
+ </svg>
53
+ );
54
+ }
55
+
56
+ function Glass({ className = '', children }) {
57
+ return (
58
+ <div className={`velu-glass ${className}`.trim()}>
59
+ <div className="velu-glass__effect" aria-hidden="true" />
60
+ <div className="velu-glass__tint" aria-hidden="true" />
61
+ <div className="velu-glass__shine" aria-hidden="true" />
62
+ <div className="velu-glass__content">{children}</div>
63
+ </div>
64
+ );
65
+ }
66
+
67
+ function WindowChrome({ src, alt }) {
68
+ return (
69
+ <div className="velu-image__window">
70
+ <GlassFilterDefs />
71
+ <div className="velu-image__glow" aria-hidden="true" />
72
+ <div className="velu-image__noise" aria-hidden="true" />
73
+ <Glass className="velu-image__window-surface">
74
+ <div className="velu-image__window-inner">
75
+ <Glass className="velu-image__chrome">
76
+ <span className="velu-image__dots" aria-hidden="true">
77
+ <span className="velu-image__dot velu-image__dot--red" />
78
+ <span className="velu-image__dot velu-image__dot--yellow" />
79
+ <span className="velu-image__dot velu-image__dot--green" />
80
+ </span>
81
+ <span className="velu-image__urlbar" aria-hidden="true" />
82
+ </Glass>
83
+ <img
84
+ src={src}
85
+ alt={alt}
86
+ loading="lazy"
87
+ className="velu-image__img velu-image__img--flush"
88
+ />
89
+ </div>
90
+ </Glass>
91
+ </div>
92
+ );
93
+ }
94
+
95
+ function DeviceFrame({ src, alt }) {
96
+ return (
97
+ <div className="velu-image__frame">
98
+ <GlassFilterDefs />
99
+ <div className="velu-image__glow" aria-hidden="true" />
100
+ <div className="velu-image__noise" aria-hidden="true" />
101
+ <Glass className="velu-image__frame-bezel">
102
+ <div className="velu-image__frame-screen">
103
+ <img
104
+ src={src}
105
+ alt={alt}
106
+ loading="lazy"
107
+ className="velu-image__img velu-image__img--flush"
108
+ />
109
+ </div>
110
+ </Glass>
111
+ </div>
112
+ );
113
+ }
114
+
115
+ export default function Image({
116
+ src,
117
+ alt = '',
118
+ caption,
119
+ chrome,
120
+ className = '',
121
+ ...rest
122
+ }) {
123
+ // Fall back to the caption for alt text when no alt is provided, so a
124
+ // captioned image stays accessible without forcing duplication.
125
+ // Only string captions are usable as alt — React-node captions are
126
+ // ignored here.
127
+ const effectiveAlt = alt || (typeof caption === 'string' ? caption : '');
128
+
129
+ let body;
130
+ let variantClass = '';
131
+ if (chrome === 'window') {
132
+ body = <WindowChrome src={src} alt={effectiveAlt} />;
133
+ variantClass = 'velu-image--chrome';
134
+ } else if (chrome === 'frame') {
135
+ body = <DeviceFrame src={src} alt={effectiveAlt} />;
136
+ variantClass = 'velu-image--chrome';
137
+ } else {
138
+ body = (
139
+ <img
140
+ src={src}
141
+ alt={effectiveAlt}
142
+ loading="lazy"
143
+ className="velu-image__img"
144
+ />
145
+ );
146
+ }
147
+
148
+ const cls = `velu-image ${variantClass} ${className}`.trim();
149
+
150
+ if (caption) {
151
+ return (
152
+ <figure className={cls} {...rest}>
153
+ {body}
154
+ <figcaption className="velu-image__caption">{caption}</figcaption>
155
+ </figure>
156
+ );
157
+ }
158
+ return (
159
+ <div className={cls} {...rest}>
160
+ {body}
161
+ </div>
162
+ );
163
+ }
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Logo — the configured site logo image(s), shown in the header (and mobile
5
+ * drawer) in place of the name wordmark.
6
+ *
7
+ * `logo` is `{ light, dark, mono }` where light/dark are URLs the dev server
8
+ * serves from the project's logo files. When `mono`, a single image covers
9
+ * both themes; otherwise both render and CSS shows the right one per
10
+ * `[data-theme]` (see page-header.css `.velu-logo--light/--dark`).
11
+ *
12
+ * SSR-safe: identical markup on server + client (the theme picks the visible
13
+ * image via CSS, not JS), so there's no hydration mismatch or flash.
14
+ */
15
+ export default function Logo({ logo, alt = '' }) {
16
+ if (!logo) return null;
17
+ if (logo.mono) {
18
+ return <img className="velu-logo" src={logo.light} alt={alt} />;
19
+ }
20
+ return (
21
+ <>
22
+ <img className="velu-logo velu-logo--light" src={logo.light} alt={alt} />
23
+ <img
24
+ className="velu-logo velu-logo--dark"
25
+ src={logo.dark}
26
+ alt={alt}
27
+ aria-hidden="true"
28
+ />
29
+ </>
30
+ );
31
+ }
@@ -1,31 +1,31 @@
1
- import React from 'react';
2
-
3
- /**
4
- * MethodBadge — colored monospace pill showing an HTTP method.
5
- *
6
- * <MethodBadge method="POST" />
7
- *
8
- * Colors come from the per-method tokens in base.css:
9
- * --post-pill-color / --post-pill-stroke-color (and post-cta-color)
10
- * --get-* / --put-* / --delete-* / --patch-*
11
- *
12
- * Used by <ApiPath>, <TryItBar>, and <ApiClient>; also exportable
13
- * standalone for inline endpoint references in prose.
14
- */
15
-
16
- const METHODS = ['get', 'post', 'put', 'patch', 'delete'];
17
-
18
- export default function MethodBadge({
19
- method = 'GET',
20
- className = '',
21
- ...rest
22
- }) {
23
- const key = String(method).toLowerCase();
24
- const safe = METHODS.includes(key) ? key : 'get';
25
- const cls = `velu-method-badge velu-method-badge--${safe} ${className}`.trim();
26
- return (
27
- <span className={cls} {...rest}>
28
- {String(method).toUpperCase()}
29
- </span>
30
- );
31
- }
1
+ import React from 'react';
2
+
3
+ /**
4
+ * MethodBadge — colored monospace pill showing an HTTP method.
5
+ *
6
+ * <MethodBadge method="POST" />
7
+ *
8
+ * Colors come from the per-method tokens in base.css:
9
+ * --post-pill-color / --post-pill-stroke-color (and post-cta-color)
10
+ * --get-* / --put-* / --delete-* / --patch-*
11
+ *
12
+ * Used by <ApiPath>, <TryItBar>, and <ApiClient>; also exportable
13
+ * standalone for inline endpoint references in prose.
14
+ */
15
+
16
+ const METHODS = ['get', 'post', 'put', 'patch', 'delete'];
17
+
18
+ export default function MethodBadge({
19
+ method = 'GET',
20
+ className = '',
21
+ ...rest
22
+ }) {
23
+ const key = String(method).toLowerCase();
24
+ const safe = METHODS.includes(key) ? key : 'get';
25
+ const cls = `velu-method-badge velu-method-badge--${safe} ${className}`.trim();
26
+ return (
27
+ <span className={cls} {...rest}>
28
+ {String(method).toUpperCase()}
29
+ </span>
30
+ );
31
+ }
@@ -1,108 +1,108 @@
1
- import React from 'react';
2
- import { ChevronDown } from 'lucide-react';
3
- import resolveIcon from '../lib/resolveIcon.jsx';
4
-
5
- /**
6
- * NavSelect — a small dropdown for the navigation switchers
7
- * (product / version / language). Generalized from the mobile drawer's
8
- * doc-select: a button showing the current value + chevron, opening a
9
- * menu of link options. Click-outside + Escape close it. The options
10
- * are LINKS (the active axis is a URL path-prefix), so selecting one
11
- * navigates via `linkComponent`.
12
- *
13
- * @param {{
14
- * value: string, // label shown on the button
15
- * options?: Array<{ label, href, icon?, active? }>,
16
- * icon?: string|React.ReactNode, // optional leading button icon (e.g. 'globe')
17
- * ariaLabel?: string,
18
- * size?: 'sm'|'md', // 'sm' = compact (version pill)
19
- * linkComponent?: React.ElementType,
20
- * className?: string,
21
- * }} props
22
- */
23
- export default function NavSelect({
24
- value,
25
- valueCode,
26
- options = [],
27
- icon,
28
- ariaLabel = 'Select',
29
- size = 'md',
30
- bare = false,
31
- linkComponent = 'a',
32
- className = '',
33
- ...rest
34
- }) {
35
- const Link = linkComponent;
36
- const [open, setOpen] = React.useState(false);
37
- const rootRef = React.useRef(null);
38
-
39
- React.useEffect(() => {
40
- if (!open) return;
41
- const onDoc = (e) => {
42
- if (!rootRef.current?.contains(e.target)) setOpen(false);
43
- };
44
- const onKey = (e) => {
45
- if (e.key === 'Escape') setOpen(false);
46
- };
47
- document.addEventListener('mousedown', onDoc);
48
- document.addEventListener('keydown', onKey);
49
- return () => {
50
- document.removeEventListener('mousedown', onDoc);
51
- document.removeEventListener('keydown', onKey);
52
- };
53
- }, [open]);
54
-
55
- return (
56
- <div
57
- ref={rootRef}
58
- className={`velu-nav-select velu-nav-select--${size}${bare ? ' velu-nav-select--bare' : ''} ${className}`.trim()}
59
- data-open={open ? 'true' : 'false'}
60
- {...rest}
61
- >
62
- <button
63
- type="button"
64
- className="velu-nav-select__btn"
65
- aria-haspopup="menu"
66
- aria-expanded={open}
67
- aria-label={ariaLabel}
68
- onClick={() => setOpen((v) => !v)}
69
- >
70
- {icon && (
71
- <span className="velu-nav-select__btn-icon" aria-hidden="true">
72
- {resolveIcon(icon, { size: '1em' })}
73
- </span>
74
- )}
75
- {valueCode && (
76
- <span className="velu-nav-select__code">{valueCode}</span>
77
- )}
78
- <span className="velu-nav-select__value">{value}</span>
79
- <ChevronDown
80
- className="velu-nav-select__chev"
81
- aria-hidden="true"
82
- focusable="false"
83
- />
84
- </button>
85
- <ul className="velu-nav-select__menu" role="menu" aria-hidden={!open}>
86
- {options.map((o, i) => (
87
- <li key={o.href ?? i} role="none">
88
- <Link
89
- role="menuitem"
90
- className={`velu-nav-select__item${o.active ? ' velu-nav-select__item--active' : ''}`}
91
- href={o.href}
92
- tabIndex={open ? 0 : -1}
93
- onClick={() => setOpen(false)}
94
- >
95
- {o.icon && (
96
- <span className="velu-nav-select__item-icon" aria-hidden="true">
97
- {resolveIcon(o.icon, { size: '1em' })}
98
- </span>
99
- )}
100
- {o.code && <span className="velu-nav-select__code">{o.code}</span>}
101
- <span>{o.label}</span>
102
- </Link>
103
- </li>
104
- ))}
105
- </ul>
106
- </div>
107
- );
108
- }
1
+ import React from 'react';
2
+ import { ChevronDown } from 'lucide-react';
3
+ import resolveIcon from '../lib/resolveIcon.jsx';
4
+
5
+ /**
6
+ * NavSelect — a small dropdown for the navigation switchers
7
+ * (product / version / language). Generalized from the mobile drawer's
8
+ * doc-select: a button showing the current value + chevron, opening a
9
+ * menu of link options. Click-outside + Escape close it. The options
10
+ * are LINKS (the active axis is a URL path-prefix), so selecting one
11
+ * navigates via `linkComponent`.
12
+ *
13
+ * @param {{
14
+ * value: string, // label shown on the button
15
+ * options?: Array<{ label, href, icon?, active? }>,
16
+ * icon?: string|React.ReactNode, // optional leading button icon (e.g. 'globe')
17
+ * ariaLabel?: string,
18
+ * size?: 'sm'|'md', // 'sm' = compact (version pill)
19
+ * linkComponent?: React.ElementType,
20
+ * className?: string,
21
+ * }} props
22
+ */
23
+ export default function NavSelect({
24
+ value,
25
+ valueCode,
26
+ options = [],
27
+ icon,
28
+ ariaLabel = 'Select',
29
+ size = 'md',
30
+ bare = false,
31
+ linkComponent = 'a',
32
+ className = '',
33
+ ...rest
34
+ }) {
35
+ const Link = linkComponent;
36
+ const [open, setOpen] = React.useState(false);
37
+ const rootRef = React.useRef(null);
38
+
39
+ React.useEffect(() => {
40
+ if (!open) return;
41
+ const onDoc = (e) => {
42
+ if (!rootRef.current?.contains(e.target)) setOpen(false);
43
+ };
44
+ const onKey = (e) => {
45
+ if (e.key === 'Escape') setOpen(false);
46
+ };
47
+ document.addEventListener('mousedown', onDoc);
48
+ document.addEventListener('keydown', onKey);
49
+ return () => {
50
+ document.removeEventListener('mousedown', onDoc);
51
+ document.removeEventListener('keydown', onKey);
52
+ };
53
+ }, [open]);
54
+
55
+ return (
56
+ <div
57
+ ref={rootRef}
58
+ className={`velu-nav-select velu-nav-select--${size}${bare ? ' velu-nav-select--bare' : ''} ${className}`.trim()}
59
+ data-open={open ? 'true' : 'false'}
60
+ {...rest}
61
+ >
62
+ <button
63
+ type="button"
64
+ className="velu-nav-select__btn"
65
+ aria-haspopup="menu"
66
+ aria-expanded={open}
67
+ aria-label={ariaLabel}
68
+ onClick={() => setOpen((v) => !v)}
69
+ >
70
+ {icon && (
71
+ <span className="velu-nav-select__btn-icon" aria-hidden="true">
72
+ {resolveIcon(icon, { size: '1em' })}
73
+ </span>
74
+ )}
75
+ {valueCode && (
76
+ <span className="velu-nav-select__code">{valueCode}</span>
77
+ )}
78
+ <span className="velu-nav-select__value">{value}</span>
79
+ <ChevronDown
80
+ className="velu-nav-select__chev"
81
+ aria-hidden="true"
82
+ focusable="false"
83
+ />
84
+ </button>
85
+ <ul className="velu-nav-select__menu" role="menu" aria-hidden={!open}>
86
+ {options.map((o, i) => (
87
+ <li key={o.href ?? i} role="none">
88
+ <Link
89
+ role="menuitem"
90
+ className={`velu-nav-select__item${o.active ? ' velu-nav-select__item--active' : ''}`}
91
+ href={o.href}
92
+ tabIndex={open ? 0 : -1}
93
+ onClick={() => setOpen(false)}
94
+ >
95
+ {o.icon && (
96
+ <span className="velu-nav-select__item-icon" aria-hidden="true">
97
+ {resolveIcon(o.icon, { size: '1em' })}
98
+ </span>
99
+ )}
100
+ {o.code && <span className="velu-nav-select__code">{o.code}</span>}
101
+ <span>{o.label}</span>
102
+ </Link>
103
+ </li>
104
+ ))}
105
+ </ul>
106
+ </div>
107
+ );
108
+ }