@veluai/velu 0.2.13 → 0.2.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 (109) hide show
  1. package/README.md +80 -80
  2. package/dist/cli.js +37 -37
  3. package/package.json +64 -64
  4. package/runtime/velu-ui/base.css +320 -320
  5. package/runtime/velu-ui/components/Accordion.jsx +64 -64
  6. package/runtime/velu-ui/components/ApiClient.jsx +207 -207
  7. package/runtime/velu-ui/components/ApiField.jsx +87 -87
  8. package/runtime/velu-ui/components/ApiPath.jsx +63 -63
  9. package/runtime/velu-ui/components/ApiReferencePage.jsx +384 -384
  10. package/runtime/velu-ui/components/ApiSamples.jsx +36 -36
  11. package/runtime/velu-ui/components/ApiSidebar.jsx +122 -122
  12. package/runtime/velu-ui/components/AskBar.jsx +71 -71
  13. package/runtime/velu-ui/components/Callout.jsx +114 -114
  14. package/runtime/velu-ui/components/Card.jsx +131 -131
  15. package/runtime/velu-ui/components/Chatbot.jsx +885 -885
  16. package/runtime/velu-ui/components/CodeBlock.jsx +375 -375
  17. package/runtime/velu-ui/components/Columns.jsx +56 -56
  18. package/runtime/velu-ui/components/ContextMenu.jsx +298 -273
  19. package/runtime/velu-ui/components/ErrorCard.jsx +138 -138
  20. package/runtime/velu-ui/components/Field.jsx +81 -81
  21. package/runtime/velu-ui/components/Image.jsx +163 -163
  22. package/runtime/velu-ui/components/Logo.jsx +31 -31
  23. package/runtime/velu-ui/components/MethodBadge.jsx +31 -31
  24. package/runtime/velu-ui/components/NavSelect.jsx +108 -108
  25. package/runtime/velu-ui/components/NotFound.jsx +63 -63
  26. package/runtime/velu-ui/components/PageFeedback.jsx +219 -219
  27. package/runtime/velu-ui/components/PageFooter.jsx +145 -145
  28. package/runtime/velu-ui/components/PageHeader.jsx +422 -422
  29. package/runtime/velu-ui/components/PageNav.jsx +77 -77
  30. package/runtime/velu-ui/components/PoweredBy.jsx +51 -51
  31. package/runtime/velu-ui/components/Prompt.jsx +115 -115
  32. package/runtime/velu-ui/components/Search.jsx +460 -460
  33. package/runtime/velu-ui/components/Sidebar.jsx +254 -254
  34. package/runtime/velu-ui/components/SocialLinks.jsx +90 -90
  35. package/runtime/velu-ui/components/Steps.jsx +65 -65
  36. package/runtime/velu-ui/components/ThemeToggle.jsx +48 -48
  37. package/runtime/velu-ui/components/Toc.jsx +537 -537
  38. package/runtime/velu-ui/components/TocBar.jsx +195 -195
  39. package/runtime/velu-ui/components/Tree.jsx +87 -87
  40. package/runtime/velu-ui/components/TryItBar.jsx +102 -102
  41. package/runtime/velu-ui/components/accordion.css +92 -92
  42. package/runtime/velu-ui/components/api-page.css +208 -208
  43. package/runtime/velu-ui/components/api.css +635 -635
  44. package/runtime/velu-ui/components/ask-bar.css +94 -94
  45. package/runtime/velu-ui/components/card.css +105 -105
  46. package/runtime/velu-ui/components/chatbot.css +622 -622
  47. package/runtime/velu-ui/components/code-block.css +263 -263
  48. package/runtime/velu-ui/components/context-menu.css +173 -173
  49. package/runtime/velu-ui/components/docs-layout.css +822 -822
  50. package/runtime/velu-ui/components/field.css +82 -82
  51. package/runtime/velu-ui/components/image.css +237 -237
  52. package/runtime/velu-ui/components/nav-select.css +157 -157
  53. package/runtime/velu-ui/components/not-found.css +94 -94
  54. package/runtime/velu-ui/components/page-feedback.css +241 -241
  55. package/runtime/velu-ui/components/page-footer.css +130 -130
  56. package/runtime/velu-ui/components/page-header.css +558 -558
  57. package/runtime/velu-ui/components/page-nav.css +50 -50
  58. package/runtime/velu-ui/components/powered-by.css +92 -92
  59. package/runtime/velu-ui/components/prompt.css +99 -99
  60. package/runtime/velu-ui/components/search.css +307 -307
  61. package/runtime/velu-ui/components/sidebar.css +205 -205
  62. package/runtime/velu-ui/components/steps.css +77 -77
  63. package/runtime/velu-ui/components/theme-toggle.css +102 -102
  64. package/runtime/velu-ui/components/toc-bar.css +234 -234
  65. package/runtime/velu-ui/components/tree.css +49 -49
  66. package/runtime/velu-ui/index.js +54 -54
  67. package/runtime/velu-ui/lib/api-send.js +92 -92
  68. package/runtime/velu-ui/lib/brand-icons.jsx +103 -103
  69. package/runtime/velu-ui/lib/component-schemas.js +100 -100
  70. package/runtime/velu-ui/lib/copyText.js +64 -64
  71. package/runtime/velu-ui/lib/docs-assistant.js +250 -250
  72. package/runtime/velu-ui/lib/lang-icons.jsx +147 -147
  73. package/runtime/velu-ui/lib/pagefind.js +113 -113
  74. package/runtime/velu-ui/lib/prism-langs.js +957 -957
  75. package/runtime/velu-ui/lib/prism-loader.js +74 -74
  76. package/runtime/velu-ui/lib/resolveIcon.jsx +29 -29
  77. package/runtime/velu-ui/lib/scrollIntoNearestView.js +66 -66
  78. package/runtime/velu-ui/mdx-components.jsx +105 -105
  79. package/runtime/velu-ui/primitives/Cluster.jsx +49 -49
  80. package/runtime/velu-ui/primitives/Stack.jsx +63 -63
  81. package/runtime/velu-ui/primitives/Switcher.jsx +57 -57
  82. package/runtime/velu-ui/primitives/stack.css +3 -3
  83. package/runtime/velu-ui/primitives/switcher.css +25 -25
  84. package/runtime/velu-ui/styles.css +46 -46
  85. package/runtime/velu-ui/tokens.css +4 -4
  86. package/schema/velu.schema.json +423 -423
  87. package/src/lib/extract-mdx-error.js +170 -170
  88. package/src/lib/issues.js +159 -159
  89. package/src/lib/known-components.js +34 -34
  90. package/src/navigation.js +443 -443
  91. package/src/runtime/App.jsx +1669 -1668
  92. package/src/runtime/ErrorBoundary.jsx +54 -54
  93. package/src/runtime/client-entry.jsx +22 -22
  94. package/src/runtime/server-entry.jsx +16 -16
  95. package/src/template.html +48 -48
  96. package/templates/starter/ai-tools/claude-code.mdx +26 -26
  97. package/templates/starter/ai-tools/cursor.mdx +17 -17
  98. package/templates/starter/api-reference/introduction.mdx +43 -43
  99. package/templates/starter/development.mdx +19 -19
  100. package/templates/starter/essentials/code.mdx +29 -29
  101. package/templates/starter/essentials/images.mdx +29 -29
  102. package/templates/starter/essentials/markdown.mdx +25 -25
  103. package/templates/starter/essentials/navigation.mdx +39 -39
  104. package/templates/starter/essentials/settings.mdx +30 -30
  105. package/templates/starter/favicon.svg +6 -6
  106. package/templates/starter/index.mdx +31 -31
  107. package/templates/starter/openapi.json +160 -160
  108. package/templates/starter/quickstart.mdx +31 -31
  109. package/templates/starter/velu.json +41 -41
@@ -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
+ }
@@ -1,31 +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
+ 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
+ }