✨ Feat: add options
This commit is contained in:
parent
81cd2ed02c
commit
c62641f356
39
app/components/options/1/page.tsx
Normal file
39
app/components/options/1/page.tsx
Normal file
|
@ -0,0 +1,39 @@
|
|||
"use client";
|
||||
|
||||
import { Trash2 } from "lucide-react";
|
||||
import Option from "../Option";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { MenuItem } from "../types";
|
||||
|
||||
const menuItems: MenuItem[] = [
|
||||
{ name: "重命名" },
|
||||
{ name: "修改表单" },
|
||||
{ name: "创建副本" },
|
||||
{ name: "继续收集" },
|
||||
{ name: "设置" },
|
||||
{
|
||||
name: "添加标签",
|
||||
subs: [
|
||||
{ name: "设置" },
|
||||
{ name: "Message", separator: true },
|
||||
{ name: "More..." },
|
||||
],
|
||||
},
|
||||
{ name: "打印表单" },
|
||||
{ name: "模板分享" },
|
||||
{ name: "文件管理" },
|
||||
{ separator: true },
|
||||
{
|
||||
icon: <Trash2 className="text-red-500 mr-2 h-4 w-4" />,
|
||||
name: "删除",
|
||||
color: "text-red-500",
|
||||
},
|
||||
];
|
||||
|
||||
export default function Option1() {
|
||||
return (
|
||||
<Option menuItems={menuItems} title={""}>
|
||||
<Button variant="outline">Stop</Button>
|
||||
</Option>
|
||||
);
|
||||
}
|
37
app/components/options/2/page.tsx
Normal file
37
app/components/options/2/page.tsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
"use client";
|
||||
|
||||
import { Trash2 } from "lucide-react";
|
||||
import Option from "../Option";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { MenuItem } from "../types";
|
||||
|
||||
const menuItems: MenuItem[] = [
|
||||
{ name: "重命名" },
|
||||
{ name: "创建副本" },
|
||||
{
|
||||
name: "添加标签",
|
||||
subs: [
|
||||
{ name: "设置" },
|
||||
{ name: "Message" },
|
||||
{ separator: true },
|
||||
{ name: "More..." },
|
||||
],
|
||||
},
|
||||
{ name: "打印表单" },
|
||||
{ name: "模板分享" },
|
||||
{ name: "文件管理" },
|
||||
{ separator: true },
|
||||
{
|
||||
icon: <Trash2 className="text-red-500 mr-2 h-4 w-4" />,
|
||||
name: "删除",
|
||||
color: "text-red-500",
|
||||
},
|
||||
];
|
||||
|
||||
export default function Option2() {
|
||||
return (
|
||||
<Option menuItems={menuItems}>
|
||||
<Button variant="outline">Draft</Button>
|
||||
</Option>
|
||||
);
|
||||
}
|
40
app/components/options/3/page.tsx
Normal file
40
app/components/options/3/page.tsx
Normal file
|
@ -0,0 +1,40 @@
|
|||
"use client";
|
||||
|
||||
import { Trash2 } from "lucide-react";
|
||||
import Option from "../Option";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { MenuItem } from "../types";
|
||||
|
||||
const menuItems: MenuItem[] = [
|
||||
{ name: "重命名" },
|
||||
{ name: "填写接龙" },
|
||||
{ name: "修改接龙" },
|
||||
{ name: "创建副本" },
|
||||
{ name: "停止收集" },
|
||||
{ name: "设置" },
|
||||
{
|
||||
name: "添加标签",
|
||||
subs: [
|
||||
{ name: "设置" },
|
||||
{ name: "Message" },
|
||||
{ separator: true },
|
||||
{ name: "More..." },
|
||||
],
|
||||
},
|
||||
{ name: "打印接龙" },
|
||||
{ name: "模板分享" },
|
||||
{ name: "文件管理" },
|
||||
{ separator: true },
|
||||
{
|
||||
icon: <Trash2 className="text-red-500 mr-2 h-4 w-4" />,
|
||||
name: "删除",
|
||||
color: "text-red-500",
|
||||
},
|
||||
];
|
||||
export default function Option3() {
|
||||
return (
|
||||
<Option menuItems={menuItems} title="Release">
|
||||
<Button variant="outline">Release</Button>
|
||||
</Option>
|
||||
);
|
||||
}
|
25
app/components/options/4/page.tsx
Normal file
25
app/components/options/4/page.tsx
Normal file
|
@ -0,0 +1,25 @@
|
|||
"use client";
|
||||
|
||||
import Option from "../Option";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { MenuItem } from "../types";
|
||||
import { PlusIcon } from "lucide-react";
|
||||
|
||||
const menuItems: MenuItem[] = [
|
||||
{ name: "打印表单" },
|
||||
{ name: "模板分享" },
|
||||
{ name: "文件管理" },
|
||||
{ separator: true },
|
||||
{
|
||||
icon: <PlusIcon className="mr-2 h-4 w-4" />,
|
||||
name: "新建标签",
|
||||
},
|
||||
];
|
||||
|
||||
export default function Tag() {
|
||||
return (
|
||||
<Option menuItems={menuItems} title="取消标签">
|
||||
<Button variant="outline">Tag</Button>
|
||||
</Option>
|
||||
);
|
||||
}
|
97
app/components/options/Option.tsx
Normal file
97
app/components/options/Option.tsx
Normal file
|
@ -0,0 +1,97 @@
|
|||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuSubContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuLabel,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { MenuItem } from "./types";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
interface IOptionProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
title?: string;
|
||||
menuItems: MenuItem[];
|
||||
}
|
||||
|
||||
export default function Option({
|
||||
title,
|
||||
menuItems,
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: IOptionProps) {
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>{children}</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className={cn(" w-36 p-3", className)} {...props}>
|
||||
{title && (
|
||||
<>
|
||||
<DropdownMenuLabel>{title}</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
</>
|
||||
)}
|
||||
{/* save a origin item */}
|
||||
{/* <DropdownMenuItem>
|
||||
<User className="mr-2 h-4 w-4" />
|
||||
<span>Profile</span>
|
||||
<DropdownMenuShortcut>⇧⌘P</DropdownMenuShortcut>
|
||||
</DropdownMenuItem> */}
|
||||
{
|
||||
<DropdownMenuGroup>
|
||||
{menuItems.map((item) => (
|
||||
<>
|
||||
{item?.subs && (
|
||||
<DropdownMenuSub>
|
||||
<DropdownMenuSubTrigger>
|
||||
{item.icon}
|
||||
<span className={cn(item.color)}>{item.name}</span>
|
||||
{item.separator}
|
||||
</DropdownMenuSubTrigger>
|
||||
<DropdownMenuPortal>
|
||||
<DropdownMenuSubContent>
|
||||
{Array.isArray(item.subs) &&
|
||||
item?.subs.map((subItem) => (
|
||||
<>
|
||||
{subItem.name && (
|
||||
<DropdownMenuItem
|
||||
key={item?.name ?? "" + subItem?.name ?? ""}
|
||||
>
|
||||
{subItem.icon}
|
||||
<span className={cn(subItem.color)}>
|
||||
{subItem.name}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{subItem.separator && <DropdownMenuSeparator />}
|
||||
</>
|
||||
))}
|
||||
</DropdownMenuSubContent>
|
||||
</DropdownMenuPortal>
|
||||
</DropdownMenuSub>
|
||||
)}
|
||||
{!item?.subs && (
|
||||
<>
|
||||
{item.name && (
|
||||
<DropdownMenuItem key={item?.name ?? ""}>
|
||||
{item.icon}
|
||||
<span className={cn(item.color)}>{item.name}</span>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{item.separator && <DropdownMenuSeparator />}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
))}
|
||||
</DropdownMenuGroup>
|
||||
}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
15
app/components/options/page.tsx
Normal file
15
app/components/options/page.tsx
Normal file
|
@ -0,0 +1,15 @@
|
|||
import Option1 from "./1/page";
|
||||
import Option2 from "./2/page";
|
||||
import Option3 from "./3/page";
|
||||
import Tag from "./4/page";
|
||||
|
||||
export default function Options() {
|
||||
return (
|
||||
<div className="h-full flex space-x-4 justify-center mt-10">
|
||||
<Option1 />
|
||||
<Option2 />
|
||||
<Option3 />
|
||||
<Tag />
|
||||
</div>
|
||||
);
|
||||
}
|
18
app/components/options/types.ts
Normal file
18
app/components/options/types.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { ReactNode } from "react";
|
||||
|
||||
export type MenuItem = {
|
||||
name?: string;
|
||||
icon?: JSX.Element;
|
||||
color?: string;
|
||||
subs?: MenuItem[] | ReactNode;
|
||||
separator?: boolean;
|
||||
};
|
||||
|
||||
export interface IFormTag {
|
||||
modified_ts: number;
|
||||
color: string;
|
||||
user_id: string;
|
||||
tag_name: string;
|
||||
create_ts: number;
|
||||
tag_id: string;
|
||||
}
|
198
components/ui/dropdown-menu.tsx
Normal file
198
components/ui/dropdown-menu.tsx
Normal file
|
@ -0,0 +1,198 @@
|
|||
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"
|
||||
|
||||
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}
|
||||
className={cn(
|
||||
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",
|
||||
inset && "pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRight className="ml-auto h-4 w-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}
|
||||
className={cn(
|
||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground 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 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}
|
||||
/>
|
||||
))
|
||||
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}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground 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}
|
||||
className={cn(
|
||||
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
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}
|
||||
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-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<Check className="h-4 w-4" />
|
||||
</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}
|
||||
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-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<Circle className="h-2 w-2 fill-current" />
|
||||
</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}
|
||||
className={cn(
|
||||
"px-2 py-1.5 text-sm font-semibold",
|
||||
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}
|
||||
className={cn("-mx-1 my-1 h-px bg-muted", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName
|
||||
|
||||
const DropdownMenuShortcut = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
||||
return (
|
||||
<span
|
||||
className={cn("ml-auto text-xs tracking-widest opacity-60", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
DropdownMenuShortcut.displayName = "DropdownMenuShortcut"
|
||||
|
||||
export {
|
||||
DropdownMenu,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuRadioGroup,
|
||||
}
|
|
@ -11,6 +11,7 @@
|
|||
"dependencies": {
|
||||
"@headlessui/react": "^1.7.17",
|
||||
"@heroicons/react": "^2.0.18",
|
||||
"@radix-ui/react-dropdown-menu": "^2.0.5",
|
||||
"@radix-ui/react-icons": "^1.3.0",
|
||||
"@radix-ui/react-slot": "^1.0.2",
|
||||
"@types/node": "20.5.6",
|
||||
|
|
3731
pnpm-lock.yaml
3731
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user