- 拆分品牌色「文字/底色」双通道:新增 --color-brand-ink(-rgb)(深色 #F87171) 与 tailwind brand.ink;text-brand → text-brand-ink 迁移 247 处; bg-brand/border-brand 保持 --color-brand-rgb 不翻转(红底白字 5.58:1 不能动) - dark 块补齐 --color-brand-bg: #2A1418(修复深色白字压浅粉底 1.04:1) - hero 徽章新增 --badge-accent-text 桥接:accentColor 直用作深底文字不可读 (#1e3a5f 深底 1.65:1),浅色取原色 / 深色 color-mix 提亮 - 硬编码颜色 token 化:bg-white/text-gray-*/border-gray-* → bg-bg-*/text-text-*/border-border-* - 可访问性:触控目标 <24px 归零(footer 链接列 [&_a]:min-h-6 收口 377 处等)、 news 搜索框补 aria-label、标题跳级 h2→h4 修正为 h3、装饰 blur 光斑容器补 overflow-hidden 消除伪文本裁剪 - 验证:tsc 0 / eslint 0 error / jest 0 失败用例 / dogfood 33 路由 × 双主题 P1-P3 全零
204 lines
7.6 KiB
TypeScript
204 lines
7.6 KiB
TypeScript
'use client';
|
|
|
|
import * as React from 'react';
|
|
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
|
|
import { Check, ChevronRight, Circle } from 'lucide-react';
|
|
import { cn } from '@/lib/utils';
|
|
|
|
/**
|
|
* 标准 shadcn/ui DropdownMenu 组件
|
|
* 基于 @radix-ui/react-dropdown-menu
|
|
*/
|
|
const DropdownMenu = DropdownMenuPrimitive.Root;
|
|
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
|
|
const DropdownMenuGroup = DropdownMenuPrimitive.Group;
|
|
const DropdownMenuPortal = DropdownMenuPrimitive.Portal;
|
|
const DropdownMenuSub = DropdownMenuPrimitive.Sub;
|
|
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
|
|
|
const DropdownMenuSubTrigger = React.forwardRef<
|
|
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & { inset?: boolean }
|
|
>(({ className, inset, children, ...props }, ref) => (
|
|
<DropdownMenuPrimitive.SubTrigger
|
|
ref={ref}
|
|
data-slot="dropdown-menu-sub-trigger"
|
|
className={cn(
|
|
'flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none',
|
|
'focus:bg-bg-secondary data-[state=open]:bg-bg-secondary',
|
|
inset && 'pl-8',
|
|
className
|
|
)}
|
|
{...props}
|
|
>
|
|
{children}
|
|
<ChevronRight className="ml-auto size-4" />
|
|
</DropdownMenuPrimitive.SubTrigger>
|
|
));
|
|
DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName;
|
|
|
|
const DropdownMenuSubContent = React.forwardRef<
|
|
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
|
|
>(({ className, ...props }, ref) => (
|
|
<DropdownMenuPrimitive.SubContent
|
|
ref={ref}
|
|
data-slot="dropdown-menu-sub-content"
|
|
className={cn(
|
|
'z-50 min-w-[8rem] overflow-hidden rounded-md border border-border-primary bg-bg-primary p-1 text-text-primary shadow-lg',
|
|
'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
));
|
|
DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName;
|
|
|
|
const DropdownMenuContent = React.forwardRef<
|
|
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
|
|
>(({ className, sideOffset = 4, ...props }, ref) => (
|
|
<DropdownMenuPrimitive.Portal>
|
|
<DropdownMenuPrimitive.Content
|
|
ref={ref}
|
|
data-slot="dropdown-menu-content"
|
|
sideOffset={sideOffset}
|
|
className={cn(
|
|
'z-50 min-w-[8rem] overflow-hidden rounded-md border border-border-primary bg-bg-primary p-1 text-text-primary shadow-md',
|
|
'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',
|
|
'data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
</DropdownMenuPrimitive.Portal>
|
|
));
|
|
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
|
|
|
|
const DropdownMenuItem = React.forwardRef<
|
|
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & { inset?: boolean }
|
|
>(({ className, inset, ...props }, ref) => (
|
|
<DropdownMenuPrimitive.Item
|
|
ref={ref}
|
|
data-slot="dropdown-menu-item"
|
|
className={cn(
|
|
'relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors',
|
|
'focus:bg-bg-secondary focus:text-text-primary',
|
|
'data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
'[&>svg]:size-4 [&>svg]:shrink-0',
|
|
inset && 'pl-8',
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
));
|
|
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
|
|
|
|
const DropdownMenuCheckboxItem = React.forwardRef<
|
|
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
|
|
>(({ className, children, checked, ...props }, ref) => (
|
|
<DropdownMenuPrimitive.CheckboxItem
|
|
ref={ref}
|
|
data-slot="dropdown-menu-checkbox-item"
|
|
className={cn(
|
|
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors',
|
|
'focus:bg-bg-secondary focus:text-text-primary',
|
|
'data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
className
|
|
)}
|
|
checked={checked}
|
|
{...props}
|
|
>
|
|
<span className="absolute left-2 flex size-3.5 items-center justify-center">
|
|
<DropdownMenuPrimitive.ItemIndicator>
|
|
<Check className="size-4 text-brand-ink" />
|
|
</DropdownMenuPrimitive.ItemIndicator>
|
|
</span>
|
|
{children}
|
|
</DropdownMenuPrimitive.CheckboxItem>
|
|
));
|
|
DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName;
|
|
|
|
const DropdownMenuRadioItem = React.forwardRef<
|
|
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
|
|
>(({ className, children, ...props }, ref) => (
|
|
<DropdownMenuPrimitive.RadioItem
|
|
ref={ref}
|
|
data-slot="dropdown-menu-radio-item"
|
|
className={cn(
|
|
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors',
|
|
'focus:bg-bg-secondary focus:text-text-primary',
|
|
'data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
className
|
|
)}
|
|
{...props}
|
|
>
|
|
<span className="absolute left-2 flex size-3.5 items-center justify-center">
|
|
<DropdownMenuPrimitive.ItemIndicator>
|
|
<Circle className="size-2 fill-brand text-brand-ink" />
|
|
</DropdownMenuPrimitive.ItemIndicator>
|
|
</span>
|
|
{children}
|
|
</DropdownMenuPrimitive.RadioItem>
|
|
));
|
|
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;
|
|
|
|
const DropdownMenuLabel = React.forwardRef<
|
|
React.ElementRef<typeof DropdownMenuPrimitive.Label>,
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & { inset?: boolean }
|
|
>(({ className, inset, ...props }, ref) => (
|
|
<DropdownMenuPrimitive.Label
|
|
ref={ref}
|
|
data-slot="dropdown-menu-label"
|
|
className={cn('px-2 py-1.5 text-xs font-medium text-text-muted', inset && 'pl-8', className)}
|
|
{...props}
|
|
/>
|
|
));
|
|
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;
|
|
|
|
const DropdownMenuSeparator = React.forwardRef<
|
|
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
|
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
|
|
>(({ className, ...props }, ref) => (
|
|
<DropdownMenuPrimitive.Separator
|
|
ref={ref}
|
|
data-slot="dropdown-menu-separator"
|
|
className={cn('-mx-1 my-1 h-px bg-border-primary', className)}
|
|
{...props}
|
|
/>
|
|
));
|
|
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;
|
|
|
|
const DropdownMenuShortcut = ({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<'span'>) => (
|
|
<span
|
|
data-slot="dropdown-menu-shortcut"
|
|
className={cn('ml-auto text-xs tracking-widest text-text-muted', className)}
|
|
{...props}
|
|
/>
|
|
);
|
|
DropdownMenuShortcut.displayName = 'DropdownMenuShortcut';
|
|
|
|
export {
|
|
DropdownMenu,
|
|
DropdownMenuTrigger,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuCheckboxItem,
|
|
DropdownMenuRadioItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuShortcut,
|
|
DropdownMenuGroup,
|
|
DropdownMenuPortal,
|
|
DropdownMenuSub,
|
|
DropdownMenuSubContent,
|
|
DropdownMenuSubTrigger,
|
|
DropdownMenuRadioGroup,
|
|
};
|