跳至正文
获取 Pro
业务区块B.08

悬浮操作栏

FreeRegistry
components/linyi/floating-action-bar.tsx
lucide-reactmotion
"use client";
 
import * as React from "react";
import { motion, AnimatePresence } from "motion/react";
import { Copy, Archive, Trash2, X } from "lucide-react";
import { cn } from "@/lib/cn";
import { SPRING_SNAPPY } from "@/lib/motion";
 
export interface FloatingActionBarProps {
selectedCount: number;
onCopy?: () => void;
onArchive?: () => void;
onDelete?: () => void;
onClear?: () => void;
compact?: boolean;
className?: string;
}
 
export function FloatingActionBar({
selectedCount,
onCopy,
onArchive,
onDelete,
onClear,
compact = false,
className,
}: FloatingActionBarProps) {
return (
<AnimatePresence>
{selectedCount > 0 && (
<motion.div
role="toolbar"
aria-label="批量操作栏"
initial={{ opacity: 0, y: 14, scale: 0.96 }}
animate={{ opacity: 1, y: 0, scale: 1 }}
exit={{ opacity: 0, y: 12, scale: 0.96 }}
transition={SPRING_SNAPPY}
className={cn(
"lg-bar inline-flex items-center rounded-pill",
compact ? "gap-1.5 px-3 py-1.5" : "gap-2 px-3.5 py-2",
className
)}
>
<div className="flex items-center gap-1.5 pl-1 pr-1.5">
<span className="h-1.5 w-1.5 rounded-full bg-accent" aria-hidden="true" />
<span className="font-mono-num text-xs font-medium text-fg">
已选 {selectedCount} 项
</span>
</div>
 
<span className="h-4 w-px bg-line-strong" aria-hidden="true" />
 
<div className="flex items-center gap-1.5">
{onCopy && (
<button
type="button"
onClick={onCopy}
className={cn(
"ui-btn ui-btn-ghost text-xs",
compact ? "h-7 w-7 p-0" : "h-control-sm px-3"
)}
aria-label="复制选中项"
>
<Copy className="h-3.5 w-3.5" />
{!compact && <span>复制</span>}
</button>
)}
 
{onArchive && (
<button
type="button"
onClick={onArchive}
className={cn(
"ui-btn ui-btn-ghost text-xs",
compact ? "h-7 w-7 p-0" : "h-control-sm px-3"
)}
aria-label="归档选中项"
>
<Archive className="h-3.5 w-3.5" />
{!compact && <span>归档</span>}
</button>
)}
 
{onDelete && (
<button
type="button"
onClick={onDelete}
className={cn(
"lg-btn lg-accent btn-beam text-xs",
compact ? "h-7 w-7 p-0" : "h-control-sm px-3"
)}
aria-label="删除选中项"
>
<Trash2 className="h-3.5 w-3.5" />
{!compact && <span>删除</span>}
</button>
)}
</div>
 
{onClear && (
<button
type="button"
onClick={onClear}
aria-label="取消选择"
className="ml-0.5 flex h-7 w-7 cursor-pointer items-center justify-center rounded-pill text-fg-muted transition-colors hover:bg-well hover:text-fg"
>
<X className="h-3.5 w-3.5" />
</button>
)}
</motion.div>
)}
</AnimatePresence>
);
}