doccupine 0.0.139 → 0.0.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -7
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +191 -0
- package/dist/index.d.ts +3 -7
- package/dist/index.js +5 -1895
- package/dist/lib/config-manager.d.ts +1 -0
- package/dist/lib/config-manager.js +63 -3
- package/dist/lib/generated-artifacts.d.ts +26 -0
- package/dist/lib/generated-artifacts.js +147 -0
- package/dist/lib/layout.js +30 -30
- package/dist/lib/metadata.js +58 -30
- package/dist/lib/openapi-types.d.ts +2 -2
- package/dist/lib/openapi.d.ts +6 -3
- package/dist/lib/openapi.js +330 -50
- package/dist/lib/output-safety.d.ts +15 -0
- package/dist/lib/output-safety.js +428 -0
- package/dist/lib/structures.js +11 -0
- package/dist/lib/utils.d.ts +18 -0
- package/dist/lib/utils.js +125 -0
- package/dist/mdx-to-nextjs-generator.d.ts +166 -0
- package/dist/mdx-to-nextjs-generator.js +2229 -0
- package/dist/templates/app/api/gate/route.d.ts +1 -1
- package/dist/templates/app/api/gate/route.js +18 -6
- package/dist/templates/app/api/mcp/route.d.ts +1 -1
- package/dist/templates/app/api/mcp/route.js +181 -111
- package/dist/templates/app/api/playground/route.d.ts +1 -1
- package/dist/templates/app/api/playground/route.js +45 -13
- package/dist/templates/app/api/rag/route.d.ts +1 -1
- package/dist/templates/app/api/rag/route.js +102 -25
- package/dist/templates/app/api/search/route.d.ts +1 -1
- package/dist/templates/app/api/search/route.js +5 -0
- package/dist/templates/app/robots.d.ts +1 -1
- package/dist/templates/app/robots.js +1 -26
- package/dist/templates/app/theme.d.ts +1 -1
- package/dist/templates/app/theme.js +31 -19
- package/dist/templates/components/Chat.d.ts +1 -1
- package/dist/templates/components/Chat.js +411 -104
- package/dist/templates/components/Docs.d.ts +1 -1
- package/dist/templates/components/Docs.js +56 -13
- package/dist/templates/components/SearchDocs.d.ts +1 -1
- package/dist/templates/components/SearchDocs.js +63 -11
- package/dist/templates/components/SearchModalContent.d.ts +1 -1
- package/dist/templates/components/SearchModalContent.js +191 -49
- package/dist/templates/components/SideBar.d.ts +1 -1
- package/dist/templates/components/SideBar.js +8 -2
- package/dist/templates/components/layout/Accordion.d.ts +1 -1
- package/dist/templates/components/layout/Accordion.js +26 -3
- package/dist/templates/components/layout/ApiPlayground.d.ts +1 -1
- package/dist/templates/components/layout/ApiPlayground.js +4 -7
- package/dist/templates/components/layout/Badge.d.ts +1 -1
- package/dist/templates/components/layout/Badge.js +1 -1
- package/dist/templates/components/layout/Button.d.ts +1 -1
- package/dist/templates/components/layout/Button.js +4 -4
- package/dist/templates/components/layout/Callout.d.ts +1 -1
- package/dist/templates/components/layout/Callout.js +6 -6
- package/dist/templates/components/layout/Card.d.ts +1 -1
- package/dist/templates/components/layout/Card.js +9 -4
- package/dist/templates/components/layout/CherryThemeProvider.d.ts +1 -1
- package/dist/templates/components/layout/CherryThemeProvider.js +63 -12
- package/dist/templates/components/layout/Code.d.ts +1 -1
- package/dist/templates/components/layout/Code.js +5 -5
- package/dist/templates/components/layout/CopyButton.d.ts +1 -1
- package/dist/templates/components/layout/CopyButton.js +1 -1
- package/dist/templates/components/layout/DemoTheme.d.ts +1 -1
- package/dist/templates/components/layout/DemoTheme.js +8 -28
- package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
- package/dist/templates/components/layout/DocsComponents.js +57 -18
- package/dist/templates/components/layout/GlobalStyles.d.ts +1 -1
- package/dist/templates/components/layout/GlobalStyles.js +15 -9
- package/dist/templates/components/layout/Prompt.d.ts +1 -1
- package/dist/templates/components/layout/Prompt.js +4 -7
- package/dist/templates/components/layout/Steps.d.ts +1 -1
- package/dist/templates/components/layout/Steps.js +7 -1
- package/dist/templates/components/layout/Tabs.d.ts +1 -1
- package/dist/templates/components/layout/Tabs.js +108 -19
- package/dist/templates/env.example.d.ts +1 -1
- package/dist/templates/env.example.js +11 -0
- package/dist/templates/eslint.config.d.ts +1 -1
- package/dist/templates/eslint.config.js +20 -0
- package/dist/templates/gitignore.d.ts +1 -1
- package/dist/templates/gitignore.js +4 -3
- package/dist/templates/lib/access.d.ts +1 -0
- package/dist/templates/lib/access.js +41 -0
- package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/ai-assistant.mdx.js +17 -1
- package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/api-playground.mdx.js +5 -3
- package/dist/templates/mdx/authentication.mdx.d.ts +1 -1
- package/dist/templates/mdx/authentication.mdx.js +5 -3
- package/dist/templates/mdx/commands.mdx.d.ts +1 -1
- package/dist/templates/mdx/commands.mdx.js +20 -6
- package/dist/templates/mdx/components.mdx.d.ts +1 -1
- package/dist/templates/mdx/components.mdx.js +3 -0
- package/dist/templates/mdx/deployment-and-hosting.mdx.d.ts +1 -1
- package/dist/templates/mdx/deployment-and-hosting.mdx.js +2 -2
- package/dist/templates/mdx/globals.mdx.d.ts +1 -1
- package/dist/templates/mdx/globals.mdx.js +14 -11
- package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.js +22 -35
- package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/ai-assistant.mdx.js +23 -0
- package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/api-playground.mdx.js +7 -0
- package/dist/templates/mdx/platform/authentication.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/authentication.mdx.js +63 -0
- package/dist/templates/mdx/platform/build-and-deploy.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/build-and-deploy.mdx.js +1 -1
- package/dist/templates/mdx/platform/import-from-github.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/import-from-github.mdx.js +2 -2
- package/dist/templates/mdx/platform/index.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/index.mdx.js +1 -0
- package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/mcp.mdx.js +2 -1
- package/dist/templates/mdx/platform/navigation-settings.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/navigation-settings.mdx.js +12 -1
- package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/publishing.mdx.js +43 -10
- package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/self-updating-docs.mdx.js +48 -9
- package/dist/templates/mdx/sections.mdx.d.ts +1 -1
- package/dist/templates/mdx/sections.mdx.js +4 -0
- package/dist/templates/mdx/space.mdx.d.ts +1 -0
- package/dist/templates/mdx/space.mdx.js +125 -0
- package/dist/templates/mdx/tabs.mdx.d.ts +1 -1
- package/dist/templates/mdx/tabs.mdx.js +4 -0
- package/dist/templates/next.config.js +20 -8
- package/dist/templates/package.js +3 -3
- package/dist/templates/prettierignore.d.ts +1 -1
- package/dist/templates/prettierignore.js +1 -0
- package/dist/templates/proxy.js +47 -19
- package/dist/templates/scripts/build-docs-index.d.ts +1 -1
- package/dist/templates/scripts/build-docs-index.js +1 -0
- package/dist/templates/services/mcp/docsContentStub.d.ts +1 -0
- package/dist/templates/services/mcp/docsContentStub.js +1 -0
- package/dist/templates/services/mcp/server.d.ts +1 -1
- package/dist/templates/services/mcp/server.js +140 -83
- package/dist/templates/services/mcp/tools.d.ts +1 -1
- package/dist/templates/services/mcp/tools.js +65 -137
- package/dist/templates/utils/playgroundAllowlist.d.ts +1 -1
- package/dist/templates/utils/playgroundAllowlist.js +13 -4
- package/dist/templates/utils/rateLimit.d.ts +1 -1
- package/dist/templates/utils/rateLimit.js +40 -3
- package/dist/templates/utils/requestBody.d.ts +1 -0
- package/dist/templates/utils/requestBody.js +56 -0
- package/dist/templates/utils/ssrfGuard.d.ts +1 -1
- package/dist/templates/utils/ssrfGuard.js +138 -33
- package/package.json +14 -9
- package/dist/lib/mdxToMarkdown.d.ts +0 -1
- package/dist/lib/mdxToMarkdown.js +0 -134
- package/dist/templates/mdx/image-and-embeds.mdx.d.ts +0 -1
- package/dist/templates/mdx/image-and-embeds.mdx.js +0 -118
|
@@ -42,6 +42,8 @@ export interface SearchModalContentProps {
|
|
|
42
42
|
) => void;
|
|
43
43
|
canAskAssistant: boolean;
|
|
44
44
|
onAskAssistant: () => void;
|
|
45
|
+
shouldRestoreFocus: () => boolean;
|
|
46
|
+
returnFocusTo: HTMLElement | null;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
const ANIMATION_MS = 300;
|
|
@@ -133,6 +135,14 @@ const StyledInput = styled.input<{ theme: Theme }>\`
|
|
|
133
135
|
&::placeholder {
|
|
134
136
|
color: \${({ theme }) => theme.colors.gray};
|
|
135
137
|
}
|
|
138
|
+
|
|
139
|
+
/* type="search" gets the platform clear button, which duplicates the modal's
|
|
140
|
+
own close control and sits at a size and color we do not control. */
|
|
141
|
+
&::-webkit-search-cancel-button,
|
|
142
|
+
&::-webkit-search-decoration {
|
|
143
|
+
-webkit-appearance: none;
|
|
144
|
+
appearance: none;
|
|
145
|
+
}
|
|
136
146
|
\`;
|
|
137
147
|
|
|
138
148
|
// "Ask AI" affordance shown before the close button when the AI chat is
|
|
@@ -211,21 +221,20 @@ const StyledResults = styled.ul<{ theme: Theme }>\`
|
|
|
211
221
|
-webkit-overflow-scrolling: touch;
|
|
212
222
|
\${thinScrollbar};
|
|
213
223
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
by the scroll overflow) instead of the browser's default outline. */
|
|
217
|
-
&:focus-visible {
|
|
218
|
-
outline: none;
|
|
219
|
-
border-radius: \${({ theme }) => theme.spacing.radius.xs};
|
|
220
|
-
box-shadow: inset 0 0 0 2px \${({ theme }) => theme.colors.primaryLight};
|
|
224
|
+
&[hidden] {
|
|
225
|
+
display: none;
|
|
221
226
|
}
|
|
222
227
|
\`;
|
|
223
228
|
|
|
224
229
|
// Single indicator that slides between result items instead of each item
|
|
225
|
-
// fading its own background in and out. Positioned/sized
|
|
226
|
-
//
|
|
230
|
+
// fading its own background in and out. Positioned/sized from the active item's
|
|
231
|
+
// measured offset (see the layout effect below); the transition on
|
|
227
232
|
// transform + height produces the up/down glide as the active item changes.
|
|
228
|
-
const StyledHighlight = styled.div<{
|
|
233
|
+
const StyledHighlight = styled.div<{
|
|
234
|
+
theme: Theme;
|
|
235
|
+
$top: number;
|
|
236
|
+
$height: number;
|
|
237
|
+
}>\`
|
|
229
238
|
position: absolute;
|
|
230
239
|
left: 8px;
|
|
231
240
|
right: 8px;
|
|
@@ -239,6 +248,8 @@ const StyledHighlight = styled.div<{ theme: Theme }>\`
|
|
|
239
248
|
transform 0.2s cubic-bezier(0.22, 1, 0.36, 1),
|
|
240
249
|
height 0.2s cubic-bezier(0.22, 1, 0.36, 1);
|
|
241
250
|
will-change: transform, height;
|
|
251
|
+
transform: translateY(\${({ $top }) => $top}px);
|
|
252
|
+
height: \${({ $height }) => $height}px;
|
|
242
253
|
|
|
243
254
|
@media (prefers-reduced-motion: reduce) {
|
|
244
255
|
transition: none;
|
|
@@ -252,6 +263,11 @@ const StyledResultItem = styled.li<{ theme: Theme; $isActive: boolean }>\`
|
|
|
252
263
|
border-radius: \${({ theme }) => theme.spacing.radius.xs};
|
|
253
264
|
cursor: pointer;
|
|
254
265
|
|
|
266
|
+
&:focus-visible {
|
|
267
|
+
outline: none;
|
|
268
|
+
box-shadow: inset 0 0 0 2px \${({ theme }) => theme.colors.primaryLight};
|
|
269
|
+
}
|
|
270
|
+
|
|
255
271
|
\${({ $isActive, theme }) =>
|
|
256
272
|
$isActive &&
|
|
257
273
|
css\`
|
|
@@ -301,11 +317,26 @@ const StyledEmpty = styled.div<{ theme: Theme }>\`
|
|
|
301
317
|
display: flex;
|
|
302
318
|
align-items: center;
|
|
303
319
|
justify-content: center;
|
|
320
|
+
/* Separates the spinner from "Searching documentation..."; the whitespace
|
|
321
|
+
between them in the markup collapses away as an anonymous flex item. */
|
|
322
|
+
gap: 8px;
|
|
304
323
|
text-align: center;
|
|
305
324
|
font-size: \${({ theme }) => theme.fontSizes.small.lg};
|
|
306
325
|
color: \${({ theme }) => theme.colors.gray};
|
|
307
326
|
\`;
|
|
308
327
|
|
|
328
|
+
const StyledLiveStatus = styled.div\`
|
|
329
|
+
position: absolute;
|
|
330
|
+
width: 1px;
|
|
331
|
+
height: 1px;
|
|
332
|
+
padding: 0;
|
|
333
|
+
margin: -1px;
|
|
334
|
+
overflow: hidden;
|
|
335
|
+
clip: rect(0 0 0 0);
|
|
336
|
+
white-space: nowrap;
|
|
337
|
+
border: 0;
|
|
338
|
+
\`;
|
|
339
|
+
|
|
309
340
|
function escapeHtml(str: string): string {
|
|
310
341
|
return str
|
|
311
342
|
.replace(/&/g, "&")
|
|
@@ -341,7 +372,79 @@ export function SearchModalContent({
|
|
|
341
372
|
navigate,
|
|
342
373
|
canAskAssistant,
|
|
343
374
|
onAskAssistant,
|
|
375
|
+
shouldRestoreFocus,
|
|
376
|
+
returnFocusTo,
|
|
344
377
|
}: SearchModalContentProps) {
|
|
378
|
+
const dialogRef = React.useRef<HTMLDivElement | null>(null);
|
|
379
|
+
const inputRef = React.useRef<HTMLInputElement | null>(null);
|
|
380
|
+
const previouslyFocusedRef = React.useRef<HTMLElement | null>(
|
|
381
|
+
returnFocusTo?.isConnected === true
|
|
382
|
+
? returnFocusTo
|
|
383
|
+
: typeof document === "undefined"
|
|
384
|
+
? null
|
|
385
|
+
: (document.activeElement as HTMLElement | null),
|
|
386
|
+
);
|
|
387
|
+
const listboxId = React.useId();
|
|
388
|
+
const optionId = (index: number) => listboxId + "-option-" + index;
|
|
389
|
+
|
|
390
|
+
React.useEffect(() => {
|
|
391
|
+
const previouslyFocused = previouslyFocusedRef.current;
|
|
392
|
+
const containFocus = (event: FocusEvent) => {
|
|
393
|
+
if (
|
|
394
|
+
event.target instanceof Node &&
|
|
395
|
+
!dialogRef.current?.contains(event.target)
|
|
396
|
+
) {
|
|
397
|
+
inputRef.current?.focus();
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
document.addEventListener("focusin", containFocus);
|
|
402
|
+
inputRef.current?.focus();
|
|
403
|
+
|
|
404
|
+
return () => {
|
|
405
|
+
document.removeEventListener("focusin", containFocus);
|
|
406
|
+
if (shouldRestoreFocus() && previouslyFocused?.isConnected) {
|
|
407
|
+
previouslyFocused.focus();
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
}, [shouldRestoreFocus]);
|
|
411
|
+
|
|
412
|
+
const handleDialogKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
413
|
+
if (event.key === "Escape") {
|
|
414
|
+
event.preventDefault();
|
|
415
|
+
event.stopPropagation();
|
|
416
|
+
closeSearch();
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (event.key !== "Tab") return;
|
|
421
|
+
|
|
422
|
+
const focusable = Array.from(
|
|
423
|
+
dialogRef.current?.querySelectorAll<HTMLElement>(
|
|
424
|
+
'a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])',
|
|
425
|
+
) ?? [],
|
|
426
|
+
).filter(
|
|
427
|
+
(element) =>
|
|
428
|
+
element.offsetParent !== null &&
|
|
429
|
+
element.getAttribute("aria-hidden") !== "true",
|
|
430
|
+
);
|
|
431
|
+
|
|
432
|
+
if (focusable.length === 0) {
|
|
433
|
+
event.preventDefault();
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
const first = focusable[0];
|
|
438
|
+
const last = focusable[focusable.length - 1];
|
|
439
|
+
if (event.shiftKey && document.activeElement === first) {
|
|
440
|
+
event.preventDefault();
|
|
441
|
+
last.focus();
|
|
442
|
+
} else if (!event.shiftKey && document.activeElement === last) {
|
|
443
|
+
event.preventDefault();
|
|
444
|
+
first.focus();
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
|
|
345
448
|
// Measure the active item so the sliding highlight can be placed over it.
|
|
346
449
|
// useLayoutEffect runs before paint, so the first position is committed
|
|
347
450
|
// without a transition (no slide-in on open); later activeIndex/hover
|
|
@@ -397,11 +500,21 @@ export function SearchModalContent({
|
|
|
397
500
|
if (e.target === e.currentTarget) onCloseAnimationEnd();
|
|
398
501
|
}}
|
|
399
502
|
>
|
|
400
|
-
<StyledModal
|
|
503
|
+
<StyledModal
|
|
504
|
+
ref={dialogRef}
|
|
505
|
+
$isClosing={isClosing}
|
|
506
|
+
role="dialog"
|
|
507
|
+
aria-modal="true"
|
|
508
|
+
aria-label="Search documentation"
|
|
509
|
+
data-search-dialog
|
|
510
|
+
onKeyDownCapture={handleDialogKeyDown}
|
|
511
|
+
onClick={(e) => e.stopPropagation()}
|
|
512
|
+
>
|
|
401
513
|
<StyledInputWrapper>
|
|
402
514
|
<Search size={18} />
|
|
403
515
|
<StyledInput
|
|
404
|
-
|
|
516
|
+
ref={inputRef}
|
|
517
|
+
type="search"
|
|
405
518
|
value={query}
|
|
406
519
|
onChange={(e) => {
|
|
407
520
|
setQuery(e.target.value);
|
|
@@ -411,6 +524,15 @@ export function SearchModalContent({
|
|
|
411
524
|
placeholder="Search docs..."
|
|
412
525
|
autoComplete="off"
|
|
413
526
|
spellCheck={false}
|
|
527
|
+
aria-label="Search documentation"
|
|
528
|
+
role="combobox"
|
|
529
|
+
aria-autocomplete="list"
|
|
530
|
+
aria-haspopup="listbox"
|
|
531
|
+
aria-expanded="true"
|
|
532
|
+
aria-controls={listboxId}
|
|
533
|
+
aria-activedescendant={
|
|
534
|
+
merged[activeIndex] ? optionId(activeIndex) : undefined
|
|
535
|
+
}
|
|
414
536
|
/>
|
|
415
537
|
{canAskAssistant && (
|
|
416
538
|
<StyledAskAssistant
|
|
@@ -437,44 +559,64 @@ export function SearchModalContent({
|
|
|
437
559
|
<X />
|
|
438
560
|
</IconButton>
|
|
439
561
|
</StyledInputWrapper>
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
562
|
+
<StyledLiveStatus role="status" aria-live="polite" aria-atomic="true">
|
|
563
|
+
{isSearching
|
|
564
|
+
? "Searching documentation"
|
|
565
|
+
: merged.length === 0
|
|
566
|
+
? "No search results found"
|
|
567
|
+
: \`\${merged.length} search \${merged.length === 1 ? "result" : "results"} available\`}
|
|
568
|
+
</StyledLiveStatus>
|
|
569
|
+
<StyledResults
|
|
570
|
+
ref={resultsRef}
|
|
571
|
+
id={listboxId}
|
|
572
|
+
role="listbox"
|
|
573
|
+
aria-label="Search results"
|
|
574
|
+
aria-busy={isSearching}
|
|
575
|
+
hidden={merged.length === 0}
|
|
576
|
+
>
|
|
577
|
+
{indicator && (
|
|
578
|
+
<StyledHighlight
|
|
579
|
+
aria-hidden="true"
|
|
580
|
+
$top={indicator.top}
|
|
581
|
+
$height={indicator.height}
|
|
582
|
+
/>
|
|
583
|
+
)}
|
|
584
|
+
{merged.map((result, index) => (
|
|
585
|
+
<StyledResultItem
|
|
586
|
+
key={result.page.slug + result.page.section}
|
|
587
|
+
id={optionId(index)}
|
|
588
|
+
role="option"
|
|
589
|
+
aria-selected={index === activeIndex}
|
|
590
|
+
$isActive={index === activeIndex}
|
|
591
|
+
onClick={(e) => navigate(result.page.slug, e)}
|
|
592
|
+
onMouseEnter={() => setActiveIndex(index)}
|
|
593
|
+
>
|
|
594
|
+
<StyledResultTitle>{result.page.title}</StyledResultTitle>
|
|
595
|
+
<StyledResultMeta>
|
|
596
|
+
{result.page.section
|
|
597
|
+
? \`\${sectionLabels[result.page.section] || result.page.section} / \`
|
|
598
|
+
: ""}
|
|
599
|
+
{result.page.category}
|
|
600
|
+
</StyledResultMeta>
|
|
601
|
+
{result.snippet && (
|
|
602
|
+
<StyledSnippet
|
|
603
|
+
dangerouslySetInnerHTML={{
|
|
604
|
+
__html: highlightMatch(result.snippet, query),
|
|
605
|
+
}}
|
|
606
|
+
/>
|
|
607
|
+
)}
|
|
608
|
+
</StyledResultItem>
|
|
609
|
+
))}
|
|
610
|
+
</StyledResults>
|
|
611
|
+
{merged.length === 0 && (
|
|
612
|
+
<StyledEmpty aria-hidden="true">
|
|
613
|
+
{isSearching ? (
|
|
614
|
+
<>
|
|
615
|
+
<Spinner size={18} /> Searching documentation...
|
|
616
|
+
</>
|
|
617
|
+
) : (
|
|
618
|
+
"No results found"
|
|
450
619
|
)}
|
|
451
|
-
{merged.map((result, index) => (
|
|
452
|
-
<StyledResultItem
|
|
453
|
-
key={result.page.slug + result.page.section}
|
|
454
|
-
$isActive={index === activeIndex}
|
|
455
|
-
onClick={(e) => navigate(result.page.slug, e)}
|
|
456
|
-
onMouseEnter={() => setActiveIndex(index)}
|
|
457
|
-
>
|
|
458
|
-
<StyledResultTitle>{result.page.title}</StyledResultTitle>
|
|
459
|
-
<StyledResultMeta>
|
|
460
|
-
{result.page.section
|
|
461
|
-
? \`\${sectionLabels[result.page.section] || result.page.section} / \`
|
|
462
|
-
: ""}
|
|
463
|
-
{result.page.category}
|
|
464
|
-
</StyledResultMeta>
|
|
465
|
-
{result.snippet && (
|
|
466
|
-
<StyledSnippet
|
|
467
|
-
dangerouslySetInnerHTML={{
|
|
468
|
-
__html: highlightMatch(result.snippet, query),
|
|
469
|
-
}}
|
|
470
|
-
/>
|
|
471
|
-
)}
|
|
472
|
-
</StyledResultItem>
|
|
473
|
-
))}
|
|
474
|
-
</StyledResults>
|
|
475
|
-
) : (
|
|
476
|
-
<StyledEmpty>
|
|
477
|
-
{isSearching ? <Spinner size={18} /> : "No results found"}
|
|
478
620
|
</StyledEmpty>
|
|
479
621
|
)}
|
|
480
622
|
</StyledModal>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const sideBarTemplate = "\"use client\";\nimport { useContext, useEffect, useRef, useState } from \"react\";\nimport { usePathname } from \"next/navigation\";\nimport { Flex, Space, ThemeToggle } from \"cherry-styled-components\";\nimport { httpMethodBadgeColor } from \"@/components/layout/Badge\";\nimport {\n DocsSidebar,\n SectionBarContext,\n StyledSidebar,\n StyledSidebarList,\n StyledSidebarListItem,\n StyledStrong,\n StyledSidebarListItemLink,\n StyledSidebarMethodTag,\n StyledSidebarGroupButton,\n StyledSidebarGroupRow,\n StyledSidebarGroupLink,\n StyledSidebarGroupChevron,\n StyledSidebarGroupContent,\n StyledSidebarFooter,\n StyleMobileBar,\n StyledMobileBurger,\n} from \"@/components/layout/DocsComponents\";\nimport { FocusModeToggle } from \"@/components/layout/FocusModeToggle\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { useLockBodyScroll } from \"@/components/LockBodyScroll\";\n\n// A link can be a leaf (slug + title) or a group with nested children. Both the\n// category icon and the per-link icon are optional Lucide names.\ntype NavItemLink = {\n slug?: string;\n title: string;\n icon?: string;\n httpMethod?: string;\n links?: NavItemLink[];\n};\n\ntype NavItem = {\n label: string;\n icon?: string;\n links: NavItemLink[];\n};\n\ninterface SideBarProps {\n result: NavItem[];\n}\n\nfunction linkContainsActivePath(link: NavItemLink, pathname: string): boolean {\n if (link.slug !== undefined && pathname === `/${link.slug}`) {\n return true;\n }\n return (link.links ?? []).some((child) =>\n linkContainsActivePath(child, pathname),\n );\n}\n\nfunction SidebarNavLink({\n link,\n depth,\n pathname,\n onNavigate,\n}: {\n link: NavItemLink;\n depth: number;\n pathname: string;\n onNavigate: () => void;\n}) {\n const children = link.links ?? [];\n const hasChildren = children.length > 0;\n const href = link.slug !== undefined ? `/${link.slug}` : undefined;\n const isActive = href !== undefined && pathname === href;\n const indent = { paddingLeft: `${20 + depth * 14}px` };\n\n // Open collapsible groups that contain the active page so deep links land\n // with their ancestors already expanded.\n const [isOpen, setIsOpen] = useState(\n hasChildren\n ? children.some((child) => linkContainsActivePath(child, pathname))\n : false,\n );\n\n if (!hasChildren) {\n return (\n <StyledSidebarListItem>\n <StyledSidebarListItemLink\n href={href ?? \"#\"}\n $isActive={isActive}\n aria-current={isActive ? \"page\" : undefined}\n onClick={onNavigate}\n style={indent}\n >\n {link.httpMethod && (\n <StyledSidebarMethodTag\n mono\n solid={isActive}\n size=\"xs\"\n color={httpMethodBadgeColor(link.httpMethod)}\n >\n {link.httpMethod}\n </StyledSidebarMethodTag>\n )}\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n </StyledSidebarListItemLink>\n </StyledSidebarListItem>\n );\n }\n\n const toggle = () => setIsOpen((prev) => !prev);\n const toggleLabel = isOpen\n ? `Collapse ${link.title}`\n : `Expand ${link.title}`;\n const groupActive = linkContainsActivePath(link, pathname);\n\n return (\n <li>\n {href !== undefined ? (\n <StyledSidebarGroupRow\n $isActive={groupActive}\n $isOpen={isOpen}\n style={indent}\n >\n <StyledSidebarGroupLink\n href={href}\n aria-current={pathname === href ? \"page\" : undefined}\n onClick={onNavigate}\n >\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n </StyledSidebarGroupLink>\n <StyledSidebarGroupChevron\n type=\"button\"\n onClick={toggle}\n aria-expanded={isOpen}\n aria-label={toggleLabel}\n >\n <Icon name=\"chevron-right\" size={16} />\n </StyledSidebarGroupChevron>\n </StyledSidebarGroupRow>\n ) : (\n <StyledSidebarGroupButton\n type=\"button\"\n onClick={toggle}\n $isActive={groupActive}\n $isOpen={isOpen}\n style={indent}\n aria-expanded={isOpen}\n aria-label={toggleLabel}\n >\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n <Icon name=\"chevron-right\" size={16} />\n </StyledSidebarGroupButton>\n )}\n <StyledSidebarGroupContent $isOpen={isOpen}>\n {children.map((child: NavItemLink, index: number) => (\n <SidebarNavLink\n key={index}\n link={child}\n depth={depth + 1}\n pathname={pathname}\n onNavigate={onNavigate}\n />\n ))}\n </StyledSidebarGroupContent>\n </li>\n );\n}\n\nfunction SideBar({ result }: SideBarProps) {\n const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);\n const hasSectionBar = useContext(SectionBarContext);\n const pathname = usePathname();\n const navRef = useRef<HTMLElement>(null);\n const footerRef = useRef<HTMLDivElement>(null);\n\n useLockBodyScroll(isMobileMenuOpen);\n\n // Bring the current page's link into view within the sidebar's own scroll\n // area when it starts off-screen (deep pages, in-content links, search).\n // Scoped to the nav via scrollTo so the main document never jumps.\n useEffect(() => {\n const nav = navRef.current;\n if (!nav) return;\n const active = nav.querySelector<HTMLElement>('[aria-current=\"page\"]');\n if (!active) return;\n\n const navRect = nav.getBoundingClientRect();\n const activeRect = active.getBoundingClientRect();\n\n // The theme-toggle footer is sticky over the bottom of the scroll area\n // (~60px tall), so links underneath it are covered rather than visible.\n // Clamp the visible bottom to the footer's top edge when it's pinned.\n const footerRect = footerRef.current?.getBoundingClientRect();\n const visibleBottom = footerRect\n ? Math.min(navRect.bottom, footerRect.top)\n : navRect.bottom;\n\n const isOutOfView =\n activeRect.top < navRect.top || activeRect.bottom > visibleBottom;\n if (!isOutOfView) return;\n\n // Center within the visible band (nav top .. footer top), not the full\n // nav height, so the link never settles behind the footer.\n const visibleHeight = visibleBottom - navRect.top;\n const target =\n nav.scrollTop +\n (activeRect.top - navRect.top) -\n (visibleHeight - active.clientHeight) / 2;\n\n // Animate the scroll, but honor users who opt out of motion.\n const prefersReducedMotion = window.matchMedia(\n \"(prefers-reduced-motion: reduce)\",\n ).matches;\n nav.scrollTo({\n top: Math.max(0, target),\n behavior: prefersReducedMotion ? \"auto\" : \"smooth\",\n });\n }, [pathname]);\n\n return (\n <DocsSidebar>\n <StyleMobileBar\n onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}\n $isActive={isMobileMenuOpen}\n aria-label={\n isMobileMenuOpen ? \"Close navigation menu\" : \"Open navigation menu\"\n }\n aria-expanded={isMobileMenuOpen}\n >\n <StyledMobileBurger $isActive={isMobileMenuOpen} />\n </StyleMobileBar>\n\n <StyledSidebar\n ref={navRef}\n $isActive={isMobileMenuOpen}\n $hasSectionBar={hasSectionBar}\n >\n {result &&\n result.map((item: NavItem, index: number) => {\n return (\n <StyledSidebarList key={index}>\n <StyledSidebarListItem>\n <StyledStrong>\n {item.icon && <Icon name={item.icon} size={16} />}\n {item.label}\n </StyledStrong>{\" \"}\n </StyledSidebarListItem>\n <li>\n <Space $size={20} />\n </li>\n {item.links &&\n item.links.map((link: NavItemLink, indexChild: number) => (\n <SidebarNavLink\n key={indexChild}\n link={link}\n depth={0}\n pathname={pathname}\n onNavigate={() => setIsMobileMenuOpen(false)}\n />\n ))}\n <li aria-hidden=\"true\">\n <Space $size={20} />\n </li>\n </StyledSidebarList>\n );\n })}\n <StyledSidebarFooter ref={footerRef}>\n <Flex $xsJustifyContent=\"flex-start\" $lgJustifyContent=\"flex-end\">\n <ThemeToggle $shortcut />\n </Flex>\n </StyledSidebarFooter>\n </StyledSidebar>\n\n {/* Outside StyledSidebar on purpose: focus mode slides that whole\n column away, and the toggle has to survive it. */}\n <FocusModeToggle />\n </DocsSidebar>\n );\n}\n\nexport { SideBar };\n";
|
|
1
|
+
export declare const sideBarTemplate = "\"use client\";\nimport { useContext, useEffect, useId, useRef, useState } from \"react\";\nimport { usePathname } from \"next/navigation\";\nimport { Flex, Space, ThemeToggle } from \"cherry-styled-components\";\nimport { httpMethodBadgeColor } from \"@/components/layout/Badge\";\nimport {\n DocsSidebar,\n SectionBarContext,\n StyledSidebar,\n StyledSidebarList,\n StyledSidebarListItem,\n StyledStrong,\n StyledSidebarListItemLink,\n StyledSidebarMethodTag,\n StyledSidebarGroupButton,\n StyledSidebarGroupRow,\n StyledSidebarGroupLink,\n StyledSidebarGroupChevron,\n StyledSidebarGroupContent,\n StyledSidebarFooter,\n StyleMobileBar,\n StyledMobileBurger,\n} from \"@/components/layout/DocsComponents\";\nimport { FocusModeToggle } from \"@/components/layout/FocusModeToggle\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { useLockBodyScroll } from \"@/components/LockBodyScroll\";\n\n// A link can be a leaf (slug + title) or a group with nested children. Both the\n// category icon and the per-link icon are optional Lucide names.\ntype NavItemLink = {\n slug?: string;\n title: string;\n icon?: string;\n httpMethod?: string;\n links?: NavItemLink[];\n};\n\ntype NavItem = {\n label: string;\n icon?: string;\n links: NavItemLink[];\n};\n\ninterface SideBarProps {\n result: NavItem[];\n}\n\nfunction linkContainsActivePath(link: NavItemLink, pathname: string): boolean {\n if (link.slug !== undefined && pathname === `/${link.slug}`) {\n return true;\n }\n return (link.links ?? []).some((child) =>\n linkContainsActivePath(child, pathname),\n );\n}\n\nfunction SidebarNavLink({\n link,\n depth,\n pathname,\n onNavigate,\n}: {\n link: NavItemLink;\n depth: number;\n pathname: string;\n onNavigate: () => void;\n}) {\n const children = link.links ?? [];\n const hasChildren = children.length > 0;\n const href = link.slug !== undefined ? `/${link.slug}` : undefined;\n const isActive = href !== undefined && pathname === href;\n const indent = { paddingLeft: `${20 + depth * 14}px` };\n const groupContentId = useId();\n\n // Open collapsible groups that contain the active page so deep links land\n // with their ancestors already expanded.\n const [isOpen, setIsOpen] = useState(\n hasChildren\n ? children.some((child) => linkContainsActivePath(child, pathname))\n : false,\n );\n\n if (!hasChildren) {\n return (\n <StyledSidebarListItem>\n <StyledSidebarListItemLink\n href={href ?? \"#\"}\n $isActive={isActive}\n aria-current={isActive ? \"page\" : undefined}\n onClick={onNavigate}\n style={indent}\n >\n {link.httpMethod && (\n <StyledSidebarMethodTag\n mono\n solid={isActive}\n size=\"xs\"\n color={httpMethodBadgeColor(link.httpMethod)}\n >\n {link.httpMethod}\n </StyledSidebarMethodTag>\n )}\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n </StyledSidebarListItemLink>\n </StyledSidebarListItem>\n );\n }\n\n const toggle = () => setIsOpen((prev) => !prev);\n const toggleLabel = isOpen\n ? `Collapse ${link.title}`\n : `Expand ${link.title}`;\n const groupActive = linkContainsActivePath(link, pathname);\n\n return (\n <li>\n {href !== undefined ? (\n <StyledSidebarGroupRow\n $isActive={groupActive}\n $isOpen={isOpen}\n style={indent}\n >\n <StyledSidebarGroupLink\n href={href}\n aria-current={pathname === href ? \"page\" : undefined}\n onClick={onNavigate}\n >\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n </StyledSidebarGroupLink>\n <StyledSidebarGroupChevron\n type=\"button\"\n onClick={toggle}\n aria-expanded={isOpen}\n aria-controls={groupContentId}\n aria-label={toggleLabel}\n >\n <Icon name=\"chevron-right\" size={16} />\n </StyledSidebarGroupChevron>\n </StyledSidebarGroupRow>\n ) : (\n <StyledSidebarGroupButton\n type=\"button\"\n onClick={toggle}\n $isActive={groupActive}\n $isOpen={isOpen}\n style={indent}\n aria-expanded={isOpen}\n aria-controls={groupContentId}\n aria-label={toggleLabel}\n >\n {link.icon && <Icon name={link.icon} size={16} />}\n {link.title}\n <Icon name=\"chevron-right\" size={16} />\n </StyledSidebarGroupButton>\n )}\n <StyledSidebarGroupContent id={groupContentId} $isOpen={isOpen}>\n {children.map((child: NavItemLink, index: number) => (\n <SidebarNavLink\n key={index}\n link={child}\n depth={depth + 1}\n pathname={pathname}\n onNavigate={onNavigate}\n />\n ))}\n </StyledSidebarGroupContent>\n </li>\n );\n}\n\nfunction SideBar({ result }: SideBarProps) {\n const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);\n const hasSectionBar = useContext(SectionBarContext);\n const pathname = usePathname();\n const sidebarId = useId();\n const navRef = useRef<HTMLElement>(null);\n const footerRef = useRef<HTMLDivElement>(null);\n\n useLockBodyScroll(isMobileMenuOpen);\n\n // Bring the current page's link into view within the sidebar's own scroll\n // area when it starts off-screen (deep pages, in-content links, search).\n // Scoped to the nav via scrollTo so the main document never jumps.\n useEffect(() => {\n const nav = navRef.current;\n if (!nav) return;\n const active = nav.querySelector<HTMLElement>('[aria-current=\"page\"]');\n if (!active) return;\n\n const navRect = nav.getBoundingClientRect();\n const activeRect = active.getBoundingClientRect();\n\n // The theme-toggle footer is sticky over the bottom of the scroll area\n // (~60px tall), so links underneath it are covered rather than visible.\n // Clamp the visible bottom to the footer's top edge when it's pinned.\n const footerRect = footerRef.current?.getBoundingClientRect();\n const visibleBottom = footerRect\n ? Math.min(navRect.bottom, footerRect.top)\n : navRect.bottom;\n\n const isOutOfView =\n activeRect.top < navRect.top || activeRect.bottom > visibleBottom;\n if (!isOutOfView) return;\n\n // Center within the visible band (nav top .. footer top), not the full\n // nav height, so the link never settles behind the footer.\n const visibleHeight = visibleBottom - navRect.top;\n const target =\n nav.scrollTop +\n (activeRect.top - navRect.top) -\n (visibleHeight - active.clientHeight) / 2;\n\n // Animate the scroll, but honor users who opt out of motion.\n const prefersReducedMotion = window.matchMedia(\n \"(prefers-reduced-motion: reduce)\",\n ).matches;\n nav.scrollTo({\n top: Math.max(0, target),\n behavior: prefersReducedMotion ? \"auto\" : \"smooth\",\n });\n }, [pathname]);\n\n return (\n <DocsSidebar>\n <StyleMobileBar\n onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}\n $isActive={isMobileMenuOpen}\n aria-label={\n isMobileMenuOpen ? \"Close navigation menu\" : \"Open navigation menu\"\n }\n aria-expanded={isMobileMenuOpen}\n aria-controls={sidebarId}\n >\n <StyledMobileBurger $isActive={isMobileMenuOpen} />\n </StyleMobileBar>\n\n <StyledSidebar\n id={sidebarId}\n ref={navRef}\n $isActive={isMobileMenuOpen}\n $hasSectionBar={hasSectionBar}\n >\n {result &&\n result.map((item: NavItem, index: number) => {\n return (\n <StyledSidebarList key={index}>\n <StyledSidebarListItem>\n <StyledStrong>\n {item.icon && <Icon name={item.icon} size={16} />}\n {item.label}\n </StyledStrong>{\" \"}\n </StyledSidebarListItem>\n <li>\n <Space $size={20} />\n </li>\n {item.links &&\n item.links.map((link: NavItemLink, indexChild: number) => (\n <SidebarNavLink\n key={indexChild}\n link={link}\n depth={0}\n pathname={pathname}\n onNavigate={() => setIsMobileMenuOpen(false)}\n />\n ))}\n <li aria-hidden=\"true\">\n <Space $size={20} />\n </li>\n </StyledSidebarList>\n );\n })}\n <StyledSidebarFooter ref={footerRef}>\n <Flex $xsJustifyContent=\"flex-start\" $lgJustifyContent=\"flex-end\">\n <ThemeToggle $shortcut />\n </Flex>\n </StyledSidebarFooter>\n </StyledSidebar>\n\n {/* Outside StyledSidebar on purpose: focus mode slides that whole\n column away, and the toggle has to survive it. */}\n <FocusModeToggle />\n </DocsSidebar>\n );\n}\n\nexport { SideBar };\n";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const sideBarTemplate = `"use client";
|
|
2
|
-
import { useContext, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useContext, useEffect, useId, useRef, useState } from "react";
|
|
3
3
|
import { usePathname } from "next/navigation";
|
|
4
4
|
import { Flex, Space, ThemeToggle } from "cherry-styled-components";
|
|
5
5
|
import { httpMethodBadgeColor } from "@/components/layout/Badge";
|
|
@@ -70,6 +70,7 @@ function SidebarNavLink({
|
|
|
70
70
|
const href = link.slug !== undefined ? \`/\${link.slug}\` : undefined;
|
|
71
71
|
const isActive = href !== undefined && pathname === href;
|
|
72
72
|
const indent = { paddingLeft: \`\${20 + depth * 14}px\` };
|
|
73
|
+
const groupContentId = useId();
|
|
73
74
|
|
|
74
75
|
// Open collapsible groups that contain the active page so deep links land
|
|
75
76
|
// with their ancestors already expanded.
|
|
@@ -132,6 +133,7 @@ function SidebarNavLink({
|
|
|
132
133
|
type="button"
|
|
133
134
|
onClick={toggle}
|
|
134
135
|
aria-expanded={isOpen}
|
|
136
|
+
aria-controls={groupContentId}
|
|
135
137
|
aria-label={toggleLabel}
|
|
136
138
|
>
|
|
137
139
|
<Icon name="chevron-right" size={16} />
|
|
@@ -145,6 +147,7 @@ function SidebarNavLink({
|
|
|
145
147
|
$isOpen={isOpen}
|
|
146
148
|
style={indent}
|
|
147
149
|
aria-expanded={isOpen}
|
|
150
|
+
aria-controls={groupContentId}
|
|
148
151
|
aria-label={toggleLabel}
|
|
149
152
|
>
|
|
150
153
|
{link.icon && <Icon name={link.icon} size={16} />}
|
|
@@ -152,7 +155,7 @@ function SidebarNavLink({
|
|
|
152
155
|
<Icon name="chevron-right" size={16} />
|
|
153
156
|
</StyledSidebarGroupButton>
|
|
154
157
|
)}
|
|
155
|
-
<StyledSidebarGroupContent $isOpen={isOpen}>
|
|
158
|
+
<StyledSidebarGroupContent id={groupContentId} $isOpen={isOpen}>
|
|
156
159
|
{children.map((child: NavItemLink, index: number) => (
|
|
157
160
|
<SidebarNavLink
|
|
158
161
|
key={index}
|
|
@@ -171,6 +174,7 @@ function SideBar({ result }: SideBarProps) {
|
|
|
171
174
|
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
|
|
172
175
|
const hasSectionBar = useContext(SectionBarContext);
|
|
173
176
|
const pathname = usePathname();
|
|
177
|
+
const sidebarId = useId();
|
|
174
178
|
const navRef = useRef<HTMLElement>(null);
|
|
175
179
|
const footerRef = useRef<HTMLDivElement>(null);
|
|
176
180
|
|
|
@@ -227,11 +231,13 @@ function SideBar({ result }: SideBarProps) {
|
|
|
227
231
|
isMobileMenuOpen ? "Close navigation menu" : "Open navigation menu"
|
|
228
232
|
}
|
|
229
233
|
aria-expanded={isMobileMenuOpen}
|
|
234
|
+
aria-controls={sidebarId}
|
|
230
235
|
>
|
|
231
236
|
<StyledMobileBurger $isActive={isMobileMenuOpen} />
|
|
232
237
|
</StyleMobileBar>
|
|
233
238
|
|
|
234
239
|
<StyledSidebar
|
|
240
|
+
id={sidebarId}
|
|
235
241
|
ref={navRef}
|
|
236
242
|
$isActive={isMobileMenuOpen}
|
|
237
243
|
$hasSectionBar={hasSectionBar}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const accordionTemplate = "\"use client\";\nimport { useId, useState } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport { styledText } from \"cherry-styled-components\";\nimport { Theme } from \"@/app/theme\";\nimport { Icon } from \"@/components/layout/Icon\";\n\nconst StyledAccordion = styled.div<{ theme: Theme }>`\n background: ${({ theme }) => theme.colors.light};\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n padding: 20px;\n margin: 0;\n ${({ theme }) => styledText(theme)};\n width: 100%;\n`;\n\nconst StyledAccordionTitle = styled
|
|
1
|
+
export declare const accordionTemplate = "\"use client\";\nimport { useId, useState } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport { Button, resetButton, styledText } from \"cherry-styled-components\";\nimport { Theme } from \"@/app/theme\";\nimport { Icon } from \"@/components/layout/Icon\";\n\nconst StyledAccordion = styled.div<{ theme: Theme }>`\n background: ${({ theme }) => theme.colors.light};\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n padding: 20px;\n margin: 0;\n ${({ theme }) => styledText(theme)};\n width: 100%;\n`;\n\nconst StyledAccordionTitle = styled(Button)<{\n theme: Theme;\n $isOpen: boolean;\n}>`\n ${resetButton};\n appearance: none;\n display: block;\n width: 100%;\n border: none;\n background: none;\n text-align: left;\n font: inherit;\n cursor: pointer;\n margin: 0;\n padding: 0 40px 0 0;\n ${({ theme }) => styledText(theme)};\n font-weight: 700;\n color: ${({ theme }) => theme.colors.primary};\n transition: color 0.3s ease;\n position: relative;\n\n &:hover {\n color: ${({ theme }) => theme.colors.primaryDark};\n }\n\n &:focus-visible {\n outline: none;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n box-shadow: 0 0 0 2px ${({ theme }) => theme.colors.primaryLight};\n }\n\n & .lucide-chevron-down {\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n right: 0;\n transition: transform 0.3s ease;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n transform: translateY(-50%) rotate(180deg);\n `}\n }\n`;\n\nconst StyledAccordionContent = styled.div<{ theme: Theme; $isOpen: boolean }>`\n ${({ theme }) => styledText(theme)};\n color: ${({ theme }) => theme.colors.grayDark};\n height: 0;\n overflow: clip;\n transition: all 0.3s ease;\n display: flex;\n flex-direction: column;\n gap: 20px;\n flex-wrap: wrap;\n flex: 1;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n margin: 20px 0 0;\n height: auto;\n `}\n\n @media (prefers-reduced-motion: reduce) {\n transition: none;\n }\n`;\n\ninterface AccordionProps extends React.HTMLAttributes<HTMLDivElement> {\n children: React.ReactNode;\n title: string;\n defaultOpen?: boolean;\n}\n\nfunction Accordion({ children, title, defaultOpen = false }: AccordionProps) {\n const [isOpen, setIsOpen] = useState(defaultOpen);\n const contentId = useId();\n const titleId = useId();\n\n return (\n <StyledAccordion>\n <StyledAccordionTitle\n id={titleId}\n type=\"button\"\n onClick={() => setIsOpen(!isOpen)}\n $isOpen={isOpen}\n aria-expanded={isOpen}\n aria-controls={contentId}\n >\n {title} <Icon name=\"ChevronDown\" />\n </StyledAccordionTitle>\n <StyledAccordionContent\n id={contentId}\n role=\"region\"\n aria-labelledby={titleId}\n aria-hidden={!isOpen}\n inert={!isOpen}\n $isOpen={isOpen}\n >\n {children}\n </StyledAccordionContent>\n </StyledAccordion>\n );\n}\n\nexport { Accordion };\n";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const accordionTemplate = `"use client";
|
|
2
2
|
import { useId, useState } from "react";
|
|
3
3
|
import styled, { css } from "styled-components";
|
|
4
|
-
import { styledText } from "cherry-styled-components";
|
|
4
|
+
import { Button, resetButton, styledText } from "cherry-styled-components";
|
|
5
5
|
import { Theme } from "@/app/theme";
|
|
6
6
|
import { Icon } from "@/components/layout/Icon";
|
|
7
7
|
|
|
@@ -15,7 +15,11 @@ const StyledAccordion = styled.div<{ theme: Theme }>\`
|
|
|
15
15
|
width: 100%;
|
|
16
16
|
\`;
|
|
17
17
|
|
|
18
|
-
const StyledAccordionTitle = styled
|
|
18
|
+
const StyledAccordionTitle = styled(Button)<{
|
|
19
|
+
theme: Theme;
|
|
20
|
+
$isOpen: boolean;
|
|
21
|
+
}>\`
|
|
22
|
+
\${resetButton};
|
|
19
23
|
appearance: none;
|
|
20
24
|
display: block;
|
|
21
25
|
width: 100%;
|
|
@@ -36,6 +40,12 @@ const StyledAccordionTitle = styled.button<{ theme: Theme; $isOpen: boolean }>\`
|
|
|
36
40
|
color: \${({ theme }) => theme.colors.primaryDark};
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
&:focus-visible {
|
|
44
|
+
outline: none;
|
|
45
|
+
border-radius: \${({ theme }) => theme.spacing.radius.xs};
|
|
46
|
+
box-shadow: 0 0 0 2px \${({ theme }) => theme.colors.primaryLight};
|
|
47
|
+
}
|
|
48
|
+
|
|
39
49
|
& .lucide-chevron-down {
|
|
40
50
|
position: absolute;
|
|
41
51
|
top: 50%;
|
|
@@ -69,6 +79,10 @@ const StyledAccordionContent = styled.div<{ theme: Theme; $isOpen: boolean }>\`
|
|
|
69
79
|
margin: 20px 0 0;
|
|
70
80
|
height: auto;
|
|
71
81
|
\`}
|
|
82
|
+
|
|
83
|
+
@media (prefers-reduced-motion: reduce) {
|
|
84
|
+
transition: none;
|
|
85
|
+
}
|
|
72
86
|
\`;
|
|
73
87
|
|
|
74
88
|
interface AccordionProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
@@ -80,10 +94,12 @@ interface AccordionProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
80
94
|
function Accordion({ children, title, defaultOpen = false }: AccordionProps) {
|
|
81
95
|
const [isOpen, setIsOpen] = useState(defaultOpen);
|
|
82
96
|
const contentId = useId();
|
|
97
|
+
const titleId = useId();
|
|
83
98
|
|
|
84
99
|
return (
|
|
85
100
|
<StyledAccordion>
|
|
86
101
|
<StyledAccordionTitle
|
|
102
|
+
id={titleId}
|
|
87
103
|
type="button"
|
|
88
104
|
onClick={() => setIsOpen(!isOpen)}
|
|
89
105
|
$isOpen={isOpen}
|
|
@@ -92,7 +108,14 @@ function Accordion({ children, title, defaultOpen = false }: AccordionProps) {
|
|
|
92
108
|
>
|
|
93
109
|
{title} <Icon name="ChevronDown" />
|
|
94
110
|
</StyledAccordionTitle>
|
|
95
|
-
<StyledAccordionContent
|
|
111
|
+
<StyledAccordionContent
|
|
112
|
+
id={contentId}
|
|
113
|
+
role="region"
|
|
114
|
+
aria-labelledby={titleId}
|
|
115
|
+
aria-hidden={!isOpen}
|
|
116
|
+
inert={!isOpen}
|
|
117
|
+
$isOpen={isOpen}
|
|
118
|
+
>
|
|
96
119
|
{children}
|
|
97
120
|
</StyledAccordionContent>
|
|
98
121
|
</StyledAccordion>
|