mirror of
https://github.com/vercel/workflow.git
synced 2026-09-14 19:59:43 +08:00
32ac8e73fd
* Fix Biome lint violations and add Biome CI check Biome was not configured to respect .gitignore, so ~92% of the 13,355 reported diagnostics came from gitignored build artifacts. Enable VCS integration (useIgnoreFile), apply safe auto-fixes across the repo, fix the remaining mechanical errors by hand, downgrade judgment-call a11y / dangerouslySetInnerHTML rules to warnings, and add a 'biome ci' job to the Lint workflow so violations block PRs going forward. * Use an empty changeset (no behavior change, no release needed)
99 lines
2.9 KiB
TypeScript
99 lines
2.9 KiB
TypeScript
'use client';
|
|
|
|
import { ChevronDownIcon } from 'lucide-react';
|
|
import { Accordion as AccordionPrimitive } from 'radix-ui';
|
|
import type * as React from 'react';
|
|
import { useEffect, useRef } from 'react';
|
|
|
|
import { cn } from '@/lib/utils';
|
|
|
|
function Accordion({
|
|
...props
|
|
}: React.ComponentProps<typeof AccordionPrimitive.Root>) {
|
|
const ref = useRef<HTMLDivElement | null>(null);
|
|
|
|
useEffect(() => {
|
|
const syncHashTarget = () => {
|
|
const hash = window.location.hash.slice(1);
|
|
if (!hash || !ref.current) return;
|
|
|
|
const target = document.getElementById(decodeURIComponent(hash));
|
|
if (!target || !ref.current.contains(target)) return;
|
|
|
|
const item = target.closest<HTMLElement>('[data-slot="accordion-item"]');
|
|
const trigger = item?.querySelector<HTMLElement>(
|
|
'[data-slot="accordion-trigger"]'
|
|
);
|
|
|
|
if (item?.dataset.state !== 'open') {
|
|
trigger?.click();
|
|
}
|
|
|
|
requestAnimationFrame(() => {
|
|
target.scrollIntoView({ block: 'start' });
|
|
});
|
|
};
|
|
|
|
syncHashTarget();
|
|
window.addEventListener('hashchange', syncHashTarget);
|
|
return () => {
|
|
window.removeEventListener('hashchange', syncHashTarget);
|
|
};
|
|
}, []);
|
|
|
|
return <AccordionPrimitive.Root data-slot="accordion" ref={ref} {...props} />;
|
|
}
|
|
|
|
function AccordionItem({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof AccordionPrimitive.Item>) {
|
|
return (
|
|
<AccordionPrimitive.Item
|
|
data-slot="accordion-item"
|
|
className={cn('border-b last:border-b-0', className)}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function AccordionTrigger({
|
|
className,
|
|
children,
|
|
...props
|
|
}: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {
|
|
return (
|
|
<AccordionPrimitive.Header className="flex">
|
|
<AccordionPrimitive.Trigger
|
|
data-slot="accordion-trigger"
|
|
className={cn(
|
|
'focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180',
|
|
className
|
|
)}
|
|
{...props}
|
|
>
|
|
{children}
|
|
<ChevronDownIcon className="text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200" />
|
|
</AccordionPrimitive.Trigger>
|
|
</AccordionPrimitive.Header>
|
|
);
|
|
}
|
|
|
|
function AccordionContent({
|
|
className,
|
|
children,
|
|
...props
|
|
}: React.ComponentProps<typeof AccordionPrimitive.Content>) {
|
|
return (
|
|
<AccordionPrimitive.Content
|
|
data-slot="accordion-content"
|
|
className="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm"
|
|
{...props}
|
|
>
|
|
<div className={cn('pt-0 pb-4', className)}>{children}</div>
|
|
</AccordionPrimitive.Content>
|
|
);
|
|
}
|
|
|
|
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };
|