feat: pages
This commit is contained in:
@@ -17,8 +17,6 @@ import { Spinner } from "@/components/ui/spinner";
|
||||
|
||||
type Draft = { id: string; title: string; slug: string; updatedAt: Date };
|
||||
|
||||
|
||||
|
||||
export default function DraftsDialog({ drafts }: { drafts: Draft[]}) {
|
||||
const [isDeletingId, setIsDeletingId] = useState("");
|
||||
|
||||
|
||||
+464
-210
@@ -1,23 +1,19 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Field,
|
||||
FieldGroup,
|
||||
FieldLabel,
|
||||
FieldSet,
|
||||
} from "@/components/ui/field";
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupAddon,
|
||||
InputGroupButton,
|
||||
InputGroupInput,
|
||||
} from "@/components/ui/input-group";
|
||||
import { Field, FieldGroup, FieldLabel, FieldSet } from "@/components/ui/field";
|
||||
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/input-group";
|
||||
import { Block, BlockType, Page, PageMeta, PageType } from "@/lib/pages/types";
|
||||
import { Globe2, Plus, Trash2, X } from "lucide-react";
|
||||
import { Globe2Icon, PlusIcon, Trash2Icon, XIcon, GripVerticalIcon, ChevronDownIcon, ImageIcon, QuoteIcon, AlertCircleIcon, MinusIcon, ListIcon, TableIcon, TypeIcon, AlignLeftIcon, InfoIcon, DotIcon, ListOrderedIcon, LinkIcon } from "lucide-react";
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "./ui/select";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Input } from "./ui/input";
|
||||
import { Separator } from "./ui/separator";
|
||||
import { Alert } from "./ui/alert";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
|
||||
export type EditorData = {
|
||||
title: string;
|
||||
@@ -35,20 +31,42 @@ type EditorProps = {
|
||||
onChange: (data: EditorData) => void;
|
||||
};
|
||||
|
||||
export default function Editor({
|
||||
page,
|
||||
initialBlocks = [],
|
||||
onChange,
|
||||
}: EditorProps) {
|
||||
const BLOCK_ICONS: Record<BlockType, React.ReactNode> = {
|
||||
PARAGRAPH: <AlignLeftIcon size={14} />,
|
||||
HEADING: <TypeIcon size={14} />,
|
||||
IMAGE: <ImageIcon size={14} />,
|
||||
QUOTE: <QuoteIcon size={14} />,
|
||||
CALLOUT: <AlertCircleIcon size={14} />,
|
||||
DIVIDER: <MinusIcon size={14} />,
|
||||
LIST: <ListIcon size={14} />,
|
||||
TABLE: <TableIcon size={14} />,
|
||||
LINK: <LinkIcon size={14} />
|
||||
};
|
||||
|
||||
const BLOCK_LABELS: Record<BlockType, string> = {
|
||||
PARAGRAPH: "Text",
|
||||
HEADING: "Heading",
|
||||
IMAGE: "Image",
|
||||
QUOTE: "Quote",
|
||||
CALLOUT: "Callout",
|
||||
DIVIDER: "Divider",
|
||||
LIST: "List",
|
||||
TABLE: "Table",
|
||||
LINK: "Link"
|
||||
};
|
||||
|
||||
export default function Editor({ page, initialBlocks = [], onChange }: EditorProps) {
|
||||
const meta = (page?.meta as PageMeta) ?? {};
|
||||
|
||||
const [title, setTitle] = useState(page?.title ?? "");
|
||||
const [type, setType] = useState(page?.type ?? "NEWS");
|
||||
const [type, setType] = useState<PageType>(page?.type ?? "NEWS");
|
||||
const [slug, setSlug] = useState(page?.slug ?? "");
|
||||
const [location, setLocation] = useState(meta.location ?? "");
|
||||
const [tags, setTags] = useState<string[]>(meta.tags ?? []);
|
||||
const [tagInput, setTagInput] = useState("");
|
||||
const [blocks, setBlocks] = useState<Block[]>(initialBlocks);
|
||||
const [dragIndex, setDragIndex] = useState<number | null>(null);
|
||||
const [dropIndex, setDropIndex] = useState<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
onChange({
|
||||
@@ -72,16 +90,16 @@ export default function Editor({
|
||||
setTags(tags.filter((t) => t !== tag));
|
||||
}
|
||||
|
||||
function addBlock(type: BlockType) {
|
||||
function addBlock(blockType: BlockType) {
|
||||
setBlocks([
|
||||
...blocks,
|
||||
{
|
||||
id: crypto.randomUUID(),
|
||||
pageId: page?.id ?? "",
|
||||
parentId: null,
|
||||
type,
|
||||
type: blockType,
|
||||
position: blocks.length,
|
||||
content: getDefaultContent(type),
|
||||
content: getDefaultContent(blockType),
|
||||
},
|
||||
]);
|
||||
}
|
||||
@@ -94,10 +112,32 @@ export default function Editor({
|
||||
setBlocks(blocks.map((b) => (b.id === id ? { ...b, content } : b)));
|
||||
}
|
||||
|
||||
function moveBlock(from: number, to: number) {
|
||||
const updated = [...blocks];
|
||||
const [moved] = updated.splice(from, 1);
|
||||
updated.splice(to, 0, moved);
|
||||
setBlocks(updated.map((b, i) => ({ ...b, position: i })));
|
||||
}
|
||||
|
||||
function handleDragStart(index: number) {
|
||||
setDragIndex(index);
|
||||
}
|
||||
|
||||
function handleDragOver(e: React.DragEvent, index: number) {
|
||||
e.preventDefault();
|
||||
setDropIndex(index);
|
||||
}
|
||||
|
||||
function handleDrop(index: number) {
|
||||
if (dragIndex !== null && dragIndex !== index) moveBlock(dragIndex, index);
|
||||
setDragIndex(null);
|
||||
setDropIndex(null);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-10">
|
||||
<FieldSet>
|
||||
<h2 className="underline underline-offset-8 decoration-2 mb-4">Meta</h2>
|
||||
<h2 className="underline underline-offset-8 decoration-2 mb-6">Meta</h2>
|
||||
<FieldGroup>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="title">Title</FieldLabel>
|
||||
@@ -105,21 +145,17 @@ export default function Editor({
|
||||
<InputGroupInput
|
||||
id="title"
|
||||
value={title}
|
||||
placeholder="Enter page title"
|
||||
onChange={(e) => {
|
||||
setTitle(e.target.value);
|
||||
if (!page) {
|
||||
setSlug(
|
||||
e.target.value.toLowerCase().replace(/\s+/g, "-")
|
||||
);
|
||||
}
|
||||
if (!page) setSlug(e.target.value.toLowerCase().replace(/\s+/g, "-"));
|
||||
}}
|
||||
placeholder="Enter page title"
|
||||
/>
|
||||
</InputGroup>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="type">Page type</FieldLabel>
|
||||
<Select defaultValue={type} onValueChange={(e) => setType(e)} disabled={true}>
|
||||
<Select defaultValue={type} onValueChange={(e) => setType(e as PageType)}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Type" />
|
||||
</SelectTrigger>
|
||||
@@ -134,122 +170,105 @@ export default function Editor({
|
||||
<Field>
|
||||
<FieldLabel htmlFor="slug">Slug</FieldLabel>
|
||||
<InputGroup>
|
||||
<InputGroupInput
|
||||
id="slug"
|
||||
value={slug}
|
||||
onChange={(e) => setSlug(e.target.value)}
|
||||
placeholder="page-slug"
|
||||
disabled={true}
|
||||
/>
|
||||
<InputGroupInput id="slug" value={slug} placeholder="page-slug" onChange={(e) => setSlug(e.target.value)} />
|
||||
</InputGroup>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="location">Location</FieldLabel>
|
||||
<InputGroup>
|
||||
<InputGroupAddon align="inline-start">
|
||||
<Globe2 size={14} className="text-muted-foreground" />
|
||||
</InputGroupAddon>
|
||||
<InputGroupInput
|
||||
id="location"
|
||||
value={location}
|
||||
onChange={(e) => setLocation(e.target.value)}
|
||||
placeholder="Liberty City, European Federation"
|
||||
/>
|
||||
</InputGroup>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="tags">Tags</FieldLabel>
|
||||
<InputGroup>
|
||||
<InputGroupInput
|
||||
id="tags"
|
||||
value={tagInput}
|
||||
onChange={(e) => setTagInput(e.target.value)}
|
||||
onKeyDown={(e) => e.key === "Enter" && addTag()}
|
||||
placeholder="Add a tag and press Enter"
|
||||
/>
|
||||
<InputGroupAddon align="inline-end">
|
||||
<InputGroupButton onClick={addTag}>Add</InputGroupButton>
|
||||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
{tags.length > 0 && (
|
||||
<div className="flex flex-row gap-2 flex-wrap mt-3">
|
||||
{tags.map((tag) => (
|
||||
<Badge
|
||||
key={tag}
|
||||
variant="secondary"
|
||||
className="flex gap-1 items-center cursor-pointer"
|
||||
onClick={() => removeTag(tag)}
|
||||
>
|
||||
{tag}
|
||||
<X size={11} />
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Field>
|
||||
{type === "NEWS" && (
|
||||
<Field>
|
||||
<FieldLabel htmlFor="location">Location</FieldLabel>
|
||||
<InputGroup>
|
||||
<InputGroupAddon align="inline-start">
|
||||
<Globe2Icon size={14} className="text-muted-foreground" />
|
||||
</InputGroupAddon>
|
||||
<InputGroupInput id="location" value={location} placeholder="Liberty City, European Federation" onChange={(e) => setLocation(e.target.value)} />
|
||||
</InputGroup>
|
||||
</Field>
|
||||
)}
|
||||
{type === "NEWS" && (
|
||||
<Field>
|
||||
<FieldLabel htmlFor="tags">Tags</FieldLabel>
|
||||
<InputGroup>
|
||||
<InputGroupInput
|
||||
id="tags"
|
||||
value={tagInput}
|
||||
placeholder="Add a tag and press Enter"
|
||||
onChange={(e) => setTagInput(e.target.value)}
|
||||
onKeyDown={(e) => e.key === "Enter" && addTag()}
|
||||
/>
|
||||
<InputGroupAddon align="inline-end">
|
||||
<InputGroupButton onClick={addTag}>Add</InputGroupButton>
|
||||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
{tags.length > 0 && (
|
||||
<div className="flex flex-row gap-2 flex-wrap mt-3">
|
||||
{tags.map((tag) => (
|
||||
<Badge key={tag} variant="secondary" className="flex gap-1 items-center cursor-pointer" onClick={() => removeTag(tag)}>
|
||||
{tag}
|
||||
<XIcon size={11} />
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Field>
|
||||
)}
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
|
||||
<FieldSet>
|
||||
<h2 className="underline underline-offset-8 decoration-2 mb-4">Content</h2>
|
||||
<div className="flex flex-col gap-3">
|
||||
{blocks.length === 0 && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
No blocks yet. Add one below.
|
||||
</p>
|
||||
)}
|
||||
{blocks.map((block) => (
|
||||
<BlockEditor
|
||||
<div className="flex flex-col gap-1">
|
||||
<h2 className="underline underline-offset-8 decoration-2 mb-6">Content</h2>
|
||||
{blocks.length === 0 && (
|
||||
<p className="text-sm text-muted-foreground">No blocks yet. Add one below.</p>
|
||||
)}
|
||||
<div className="flex flex-col gap-6">
|
||||
{blocks.map((block, index) => (
|
||||
<div
|
||||
key={block.id}
|
||||
block={block}
|
||||
onChange={(content) => updateBlock(block.id, content)}
|
||||
onRemove={() => removeBlock(block.id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex flex-row gap-2 flex-wrap mt-6">
|
||||
{(
|
||||
[
|
||||
"PARAGRAPH",
|
||||
"HEADING",
|
||||
"IMAGE",
|
||||
"QUOTE",
|
||||
"CALLOUT",
|
||||
"DIVIDER",
|
||||
"LIST",
|
||||
"TABLE",
|
||||
] as BlockType[]
|
||||
).map((t) => (
|
||||
<Button
|
||||
key={t}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => addBlock(t)}
|
||||
draggable
|
||||
onDragStart={() => handleDragStart(index)}
|
||||
onDragOver={(e) => handleDragOver(e, index)}
|
||||
onDrop={() => handleDrop(index)}
|
||||
onDragEnd={() => { setDragIndex(null); setDropIndex(null); }}
|
||||
className={cn(
|
||||
"group relative flex flex-row gap-4 items-start py-1 transition-opacity",
|
||||
dragIndex === index && "opacity-30",
|
||||
dropIndex === index && dragIndex !== index && "border-t-2 border-primary"
|
||||
)}
|
||||
>
|
||||
<Plus size={12} />
|
||||
{t.charAt(0) + t.slice(1).toLowerCase()}
|
||||
</Button>
|
||||
<div className="flex-1 min-w-0">
|
||||
<BlockInput block={block} onChange={(content) => updateBlock(block.id, content)} />
|
||||
</div>
|
||||
<div className="flex flex-col gap-2 items-center opacity-0 group-hover:opacity-100 transition-opacity shrink-0">
|
||||
<Button variant="ghost" className="cursor-grab active:cursor-grabbing" size="icon-sm" >
|
||||
<GripVerticalIcon />
|
||||
</Button>
|
||||
<Button variant="ghost" onClick={() => removeBlock(block.id)} size="icon-sm" >
|
||||
<Trash2Icon />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</FieldSet>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function BlockEditor({ block, onChange, onRemove }: { block: Block; onChange: (content: Block["content"]) => void; onRemove: () => void }) {
|
||||
return (
|
||||
<div className="flex flex-row gap-3 items-start group">
|
||||
<div className="flex-1 rounded-md border bg-background p-4">
|
||||
<BlockInput block={block} onChange={onChange} />
|
||||
<div className="mt-4">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="gap-1.5 text-muted-foreground">
|
||||
<PlusIcon size={14} />
|
||||
<p>Add block</p>
|
||||
<ChevronDownIcon size={12} />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="w-44">
|
||||
{(["PARAGRAPH", "HEADING", "IMAGE", "QUOTE", "CALLOUT", "DIVIDER", "LIST", "TABLE", "LINK"] as BlockType[]).map((t) => (
|
||||
<DropdownMenuItem key={t} onClick={() => addBlock(t)} className="gap-2">
|
||||
<p className="text-muted-foreground">{BLOCK_ICONS[t]}</p>
|
||||
<p>{BLOCK_LABELS[t]}</p>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={onRemove}
|
||||
className="opacity-0 group-hover:opacity-100 transition-opacity mt-1 shrink-0"
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -258,111 +277,346 @@ function BlockInput({ block, onChange }: { block: Block; onChange: (c: Block["co
|
||||
switch (block.type) {
|
||||
case "PARAGRAPH":
|
||||
return (
|
||||
<textarea
|
||||
className="w-full bg-transparent resize-none outline-none text-sm leading-relaxed"
|
||||
rows={3}
|
||||
<AutoResizeTextarea
|
||||
className="w-full bg-transparent resize-none outline-none leading-relaxed placeholder:text-muted-foreground"
|
||||
placeholder="Start writing..."
|
||||
value={(block.content as any).text ?? ""}
|
||||
onChange={(e) =>
|
||||
onChange({ type: "PARAGRAPH", text: e.target.value })
|
||||
}
|
||||
onChange={(e) => onChange({ type: "PARAGRAPH", text: e.target.value })}
|
||||
/>
|
||||
);
|
||||
|
||||
case "HEADING":
|
||||
return (
|
||||
<input
|
||||
className="w-full bg-transparent outline-none text-lg tracking-tight"
|
||||
placeholder="Heading"
|
||||
value={(block.content as any).text ?? ""}
|
||||
onChange={(e) =>
|
||||
onChange({ type: "HEADING", text: e.target.value, level: 2 })
|
||||
}
|
||||
/>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
className="flex-1 bg-transparent outline-none tracking-tight placeholder:text-muted-foreground"
|
||||
placeholder="Heading"
|
||||
value={(block.content as any).text ?? ""}
|
||||
onChange={(e) => onChange({ type: "HEADING", text: e.target.value, level: (block.content as any).level ?? 2 })}
|
||||
/>
|
||||
<Select
|
||||
value={String((block.content as any).level ?? 2)}
|
||||
onValueChange={(v) => onChange({ type: "HEADING", text: (block.content as any).text ?? "", level: Number(v) as 1 | 2 | 3 })}
|
||||
>
|
||||
<SelectTrigger className="w-16 h-7 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="1">H1</SelectItem>
|
||||
<SelectItem value="2">H2</SelectItem>
|
||||
<SelectItem value="3">H3</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
);
|
||||
|
||||
case "QUOTE":
|
||||
return (
|
||||
<div className="flex flex-col gap-2 border-l-2 pl-4">
|
||||
<textarea
|
||||
className="w-full bg-transparent resize-none outline-none text-sm italic leading-relaxed"
|
||||
rows={2}
|
||||
<div className="flex flex-col gap-2 border-l-2 border-muted-foreground pl-4">
|
||||
<AutoResizeTextarea
|
||||
className="w-full bg-transparent resize-none outline-none leading-relaxed placeholder:text-muted-foreground"
|
||||
placeholder="Quote text..."
|
||||
value={(block.content as any).text ?? ""}
|
||||
onChange={(e) =>
|
||||
onChange({
|
||||
type: "QUOTE",
|
||||
text: e.target.value,
|
||||
author: (block.content as any).author,
|
||||
})
|
||||
}
|
||||
onChange={(e) => onChange({ type: "QUOTE", text: e.target.value, author: (block.content as any).author })}
|
||||
/>
|
||||
<input
|
||||
className="w-full bg-transparent outline-none text-xs text-muted-foreground"
|
||||
placeholder="Author"
|
||||
className="w-full bg-transparent outline-none text-sm text-muted-foreground placeholder:text-muted-foreground/60"
|
||||
placeholder="— Author"
|
||||
value={(block.content as any).author ?? ""}
|
||||
onChange={(e) =>
|
||||
onChange({
|
||||
type: "QUOTE",
|
||||
text: (block.content as any).text,
|
||||
author: e.target.value,
|
||||
})
|
||||
}
|
||||
onChange={(e) => onChange({ type: "QUOTE", text: (block.content as any).text, author: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
case "DIVIDER":
|
||||
return <hr className="border-border" />;
|
||||
|
||||
case "CALLOUT":
|
||||
return (
|
||||
<div className="flex flex-row gap-3 items-start rounded-md bg-muted p-3">
|
||||
<span className="text-base leading-none mt-0.5">⚠️</span>
|
||||
<textarea
|
||||
className="w-full bg-transparent resize-none outline-none text-sm leading-relaxed"
|
||||
rows={2}
|
||||
<Alert>
|
||||
<InfoIcon />
|
||||
<input
|
||||
className="w-full bg-transparent outline-none text-sm font-medium placeholder:text-muted-foreground"
|
||||
placeholder="Callout title"
|
||||
value={(block.content as any).title ?? ""}
|
||||
onChange={(e) => onChange({ type: "CALLOUT", title: e.target.value, text: (block.content as any).text ?? "" })}
|
||||
/>
|
||||
<AutoResizeTextarea
|
||||
className="w-full bg-transparent resize-none outline-none text-sm leading-relaxed text-muted-foreground placeholder:text-muted-foreground/60"
|
||||
placeholder="Callout text..."
|
||||
value={(block.content as any).text ?? ""}
|
||||
onChange={(e) =>
|
||||
onChange({ type: "CALLOUT", text: e.target.value })
|
||||
}
|
||||
onChange={(e) => onChange({ type: "CALLOUT", title: (block.content as any).title ?? "", text: e.target.value })}
|
||||
/>
|
||||
</Alert>
|
||||
);
|
||||
|
||||
case "IMAGE":
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<input
|
||||
className="w-full bg-transparent outline-none text-muted-foreground placeholder:text-muted-foreground py-1.5 border-b border-dashed border-muted-foreground/30 focus:border-muted-foreground/60 transition-colors"
|
||||
placeholder="https://example.com/image.jpg"
|
||||
value={(block.content as any).url ?? ""}
|
||||
onChange={(e) => onChange({ type: "IMAGE", url: e.target.value })}
|
||||
/>
|
||||
{(block.content as any).url && (
|
||||
<div className="w-max relative rounded-md overflow-hidden border bg-muted/30">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={(block.content as any).url}
|
||||
alt="preview"
|
||||
className="max-h-64 w-auto object-contain"
|
||||
onError={(e) => { (e.target as HTMLImageElement).style.display = "none"; }}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<Input
|
||||
className="max-w-64"
|
||||
placeholder="Caption (optional)"
|
||||
value={(block.content as any).caption ?? ""}
|
||||
onChange={(e) => onChange({ type: "IMAGE", url: (block.content as any).url ?? "", caption: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
case "IMAGE":
|
||||
|
||||
case "DIVIDER":
|
||||
return <Separator />;
|
||||
|
||||
case "LIST":
|
||||
return <ListEditor content={block.content as any} onChange={(c) => onChange(c)} />;
|
||||
|
||||
case "TABLE":
|
||||
return <TableEditor content={block.content as any} onChange={(c) => onChange(c)} />;
|
||||
|
||||
case "LINK":
|
||||
return (
|
||||
<input
|
||||
className="w-full bg-transparent outline-none text-sm text-muted-foreground"
|
||||
placeholder="https://example.com/image.jpg"
|
||||
value={(block.content as any).url ?? ""}
|
||||
onChange={(e) => onChange({ type: "IMAGE", url: e.target.value })}
|
||||
/>
|
||||
<div className="flex flex-row gap-2.5">
|
||||
<LinkIcon size={16} />
|
||||
<div className="flex flex-col gap-2">
|
||||
<input
|
||||
className="w-full bg-transparent outline-none text-sm"
|
||||
placeholder="Link label"
|
||||
value={(block.content as any).label ?? ""}
|
||||
onChange={(e) =>
|
||||
onChange({
|
||||
type: "LINK",
|
||||
label: e.target.value,
|
||||
href: (block.content as any).href ?? "",
|
||||
})
|
||||
}
|
||||
/>
|
||||
|
||||
<input
|
||||
className="w-full bg-transparent outline-none text-sm text-muted-foreground"
|
||||
placeholder="URL"
|
||||
value={(block.content as any).href ?? ""}
|
||||
onChange={(e) =>
|
||||
onChange({
|
||||
type: "LINK",
|
||||
label: (block.content as any).label ?? "",
|
||||
href: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
default:
|
||||
return (
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{block.type} — editor coming soon
|
||||
</p>
|
||||
);
|
||||
return <p className="text-muted-foreground text-sm py-1.5">{block.type} — editor coming soon</p>;
|
||||
}
|
||||
}
|
||||
|
||||
function ListEditor({ content, onChange }: { content: { type: "LIST"; style: "BULLET" | "ORDERED"; items: string[] }; onChange: (c: any) => void }) {
|
||||
const items = content.items ?? [""];
|
||||
|
||||
function updateItem(index: number, value: string) {
|
||||
const updated = [...items];
|
||||
updated[index] = value;
|
||||
onChange({ ...content, items: updated });
|
||||
}
|
||||
|
||||
function addItem() {
|
||||
onChange({ ...content, items: [...items, ""] });
|
||||
}
|
||||
|
||||
function removeItem(index: number) {
|
||||
const updated = items.filter((_, i) => i !== index);
|
||||
onChange({ ...content, items: updated.length ? updated : [""] });
|
||||
}
|
||||
|
||||
function handleKeyDown(e: React.KeyboardEvent, index: number) {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
const updated = [...items];
|
||||
updated.splice(index + 1, 0, "");
|
||||
onChange({ ...content, items: updated });
|
||||
setTimeout(() => {
|
||||
const inputs = document.querySelectorAll(`[data-list-item]`);
|
||||
(inputs[index + 1] as HTMLInputElement)?.focus();
|
||||
}, 0);
|
||||
}
|
||||
if (e.key === "Backspace" && items[index] === "" && items.length > 1) {
|
||||
e.preventDefault();
|
||||
removeItem(index);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<Select value={content.style} onValueChange={(v) => onChange({ ...content, style: v })}>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="BULLET"><ListIcon />Bullet</SelectItem>
|
||||
<SelectItem value="ORDERED"><ListOrderedIcon /> Ordered</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
{items.map((item, index) => (
|
||||
<div key={index} className="flex items-center gap-2">
|
||||
<span className="text-muted-foreground w-4 shrink-0 text-right">
|
||||
{content.style === "ORDERED" ? `${index + 1}.` : <DotIcon />}
|
||||
</span>
|
||||
<input
|
||||
data-list-item
|
||||
className="w-64 bg-transparent outline-none py-0.5 placeholder:text-muted-foreground"
|
||||
placeholder="List item"
|
||||
value={item}
|
||||
onChange={(e) => updateItem(index, e.target.value)}
|
||||
onKeyDown={(e) => handleKeyDown(e, index)}
|
||||
/>
|
||||
{items.length > 1 && (
|
||||
<Button variant="ghost" onClick={() => removeItem(index)} size="icon-sm" >
|
||||
<XIcon />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<Button className="w-max mt-2 text-muted-foreground" variant="outline" onClick={addItem} size="sm">
|
||||
<PlusIcon />
|
||||
Add item
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TableEditor({ content, onChange }: { content: { type: "TABLE"; headers: string[]; rows: string[][] }; onChange: (c: any) => void }) {
|
||||
const headers = content.headers ?? ["Column 1"];
|
||||
const rows = content.rows ?? [];
|
||||
|
||||
function updateHeader(index: number, value: string) {
|
||||
const updated = [...headers];
|
||||
updated[index] = value;
|
||||
onChange({ ...content, headers: updated });
|
||||
}
|
||||
|
||||
function addColumn() {
|
||||
onChange({ ...content, headers: headers.concat(""), rows: rows.map((row) => [...row, ""]) });
|
||||
}
|
||||
|
||||
function removeColumn(colIndex: number) {
|
||||
if (headers.length <= 1) return;
|
||||
onChange({
|
||||
...content,
|
||||
headers: headers.filter((_, i) => i !== colIndex),
|
||||
rows: rows.map((row) => row.filter((_, i) => i !== colIndex)),
|
||||
});
|
||||
}
|
||||
|
||||
function addRow() {
|
||||
onChange({ ...content, rows: [...rows, headers.map(() => "")] });
|
||||
}
|
||||
|
||||
function removeRow(rowIndex: number) {
|
||||
onChange({ ...content, rows: rows.filter((_, i) => i !== rowIndex) });
|
||||
}
|
||||
|
||||
function updateCell(rowIndex: number, colIndex: number, value: string) {
|
||||
onChange({
|
||||
...content,
|
||||
rows: rows.map((row, ri) => ri === rowIndex ? row.map((cell, ci) => (ci === colIndex ? value : cell)) : row),
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2 py-1 overflow-x-auto">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
{headers.map((header, ci) => (
|
||||
<TableHead key={ci}>
|
||||
<div className="flex flex-row items-center">
|
||||
<input
|
||||
className="flex-1 bg-transparent outline-none placeholder:text-muted-foreground min-w-0"
|
||||
placeholder={`Column ${ci + 1}`}
|
||||
value={header}
|
||||
onChange={(e) => updateHeader(ci, e.target.value)}
|
||||
/>
|
||||
{headers.length > 1 && (
|
||||
<Button variant="ghost" onClick={() => removeColumn(ci)} size="icon-sm" >
|
||||
<XIcon />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</TableHead>
|
||||
))}
|
||||
<TableHead>
|
||||
<Button variant="ghost" onClick={addColumn} size="icon-sm" >
|
||||
<PlusIcon />
|
||||
</Button>
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{rows.map((row, ri) => (
|
||||
<TableRow key={ri}>
|
||||
{row.map((cell, ci) => (
|
||||
<TableCell key={ci}>
|
||||
<input className="w-full bg-transparent outline-none placeholder:text-muted-foreground min-w-0" placeholder="Value" value={cell} onChange={(e) => updateCell(ri, ci, e.target.value)} />
|
||||
</TableCell>
|
||||
))}
|
||||
<TableCell>
|
||||
<Button variant="ghost" onClick={() => removeRow(ri)} size="icon-sm" >
|
||||
<XIcon />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<Button className="w-max mt-2 text-muted-foreground" variant="outline" onClick={addRow} size="sm">
|
||||
<PlusIcon />
|
||||
Add row
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AutoResizeTextarea({ value, onChange, className, placeholder }: { value: string; onChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void; className?: string; placeholder?: string }) {
|
||||
const ref = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (ref.current) {
|
||||
ref.current.style.height = "auto";
|
||||
ref.current.style.height = `${ref.current.scrollHeight}px`;
|
||||
}
|
||||
}, [value]);
|
||||
|
||||
return <textarea ref={ref} rows={1} className={cn("overflow-hidden", className)} placeholder={placeholder} value={value} onChange={onChange} />;
|
||||
}
|
||||
|
||||
function getDefaultContent(type: BlockType): Block["content"] {
|
||||
switch (type) {
|
||||
case "PARAGRAPH":
|
||||
return { type: "PARAGRAPH", text: "" };
|
||||
case "HEADING":
|
||||
return { type: "HEADING", text: "", level: 2 };
|
||||
case "QUOTE":
|
||||
return { type: "QUOTE", text: "" };
|
||||
case "CALLOUT":
|
||||
return { type: "CALLOUT", text: "" };
|
||||
case "DIVIDER":
|
||||
return { type: "DIVIDER" };
|
||||
case "LIST":
|
||||
return { type: "LIST", style: "BULLET", items: [] };
|
||||
case "TABLE":
|
||||
return { type: "TABLE", headers: [], rows: [] };
|
||||
case "IMAGE":
|
||||
return { type: "IMAGE", url: "" };
|
||||
default:
|
||||
return { type: "PARAGRAPH", text: "" };
|
||||
case "PARAGRAPH": return { type: "PARAGRAPH", text: "" };
|
||||
case "HEADING": return { type: "HEADING", text: "", level: 2 };
|
||||
case "QUOTE": return { type: "QUOTE", text: "" };
|
||||
case "CALLOUT": return { type: "CALLOUT", title: "", text: "" };
|
||||
case "DIVIDER": return { type: "DIVIDER" };
|
||||
case "LIST": return { type: "LIST", style: "BULLET", items: [""] };
|
||||
case "TABLE": return { type: "TABLE", headers: ["", ""], rows: [["", ""]] };
|
||||
case "IMAGE": return { type: "IMAGE", url: "", caption: "" };
|
||||
default: return { type: "PARAGRAPH", text: "" };
|
||||
}
|
||||
}
|
||||
@@ -18,15 +18,15 @@ export default function Footer() {
|
||||
<div className="flex flex-col gap-2">
|
||||
<Link href="/" className="text-black/60 cursor-pointer hover:underline underline-offset-8 decoration-2">Main</Link>
|
||||
<Link href="/news" className="text-black/60 cursor-pointer hover:underline underline-offset-8 decoration-2">News</Link>
|
||||
<Link href="/congress" className="text-black/60 cursor-pointer hover:underline underline-offset-8 decoration-2">The Congress</Link>
|
||||
<Link href="/page/congress" className="text-black/60 cursor-pointer hover:underline underline-offset-8 decoration-2">The Congress</Link>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<Link href="/president" className="text-black/60 cursor-pointer hover:underline underline-offset-8 decoration-2">President</Link>
|
||||
<Link href="/vice-president" className="text-black/60 cursor-pointer hover:underline underline-offset-8 decoration-2">Vice-President</Link>
|
||||
<Link href="/government" className="text-black/60 cursor-pointer hover:underline underline-offset-8 decoration-2">Federal Government</Link>
|
||||
<Link href="/page/president" className="text-black/60 cursor-pointer hover:underline underline-offset-8 decoration-2">President</Link>
|
||||
<Link href="/page/vice-president" className="text-black/60 cursor-pointer hover:underline underline-offset-8 decoration-2">Vice President</Link>
|
||||
<Link href="/page/government" className="text-black/60 cursor-pointer hover:underline underline-offset-8 decoration-2">Federal Government</Link>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<Link href="/regions" className="text-black/60 cursor-pointer hover:underline underline-offset-8 decoration-2">Regions</Link>
|
||||
<Link href="/page/regions" className="text-black/60 cursor-pointer hover:underline underline-offset-8 decoration-2">Regions</Link>
|
||||
</div>
|
||||
</div>
|
||||
<p>© 2026 European Federation. All rights reserved.</p>
|
||||
|
||||
+10
-2
@@ -4,14 +4,15 @@ import login from "@/app/actions/login";
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import logout from "@/app/actions/logout";
|
||||
import Link from "next/link";
|
||||
import { getNavLinks } from "@/lib/navlinks/repository";
|
||||
|
||||
export default async function Header() {
|
||||
const user = await getCurrentUser();
|
||||
const links = await getNavLinks();
|
||||
|
||||
return (
|
||||
<header className="relative flex items-center justify-between w-full h-16 px-8 bg-gray-100">
|
||||
<div />
|
||||
<Link href="/" className="absolute left-1/2 -translate-x-1/2 flex items-center gap-4">
|
||||
<Link href="/" className="flex items-center gap-4">
|
||||
<Image
|
||||
src="/emblem.png"
|
||||
width={28}
|
||||
@@ -20,6 +21,13 @@ export default async function Header() {
|
||||
/>
|
||||
<h3>European Federation</h3>
|
||||
</Link>
|
||||
<div className="absolute left-1/2 -translate-x-1/2 flex items-center gap-6">
|
||||
{
|
||||
links.map((link) => (
|
||||
<Link className="hover:underline underline-offset-8 decoration-2 duration-200" key={link.id} href={link.href || `/${link.page.type.toLowerCase()}/${link.page.slug}`}><h3>{link.label ?? link.page?.title}</h3></Link>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
{
|
||||
user ? (
|
||||
<form action={logout}>
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { CheckIcon, ChevronRightIcon } from "lucide-react"
|
||||
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function DropdownMenu({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
||||
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Trigger
|
||||
data-slot="dropdown-menu-trigger"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuContent({
|
||||
className,
|
||||
align = "start",
|
||||
sideOffset = 4,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<DropdownMenuPrimitive.Content
|
||||
data-slot="dropdown-menu-content"
|
||||
sideOffset={sideOffset}
|
||||
align={align}
|
||||
className={cn("z-50 max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) min-w-32 origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 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 data-[state=closed]:overflow-hidden data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className )}
|
||||
{...props}
|
||||
/>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
||||
inset?: boolean
|
||||
variant?: "default" | "destructive"
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Item
|
||||
data-slot="dropdown-menu-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"group/dropdown-menu-item relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.CheckboxItem
|
||||
data-slot="dropdown-menu-checkbox-item"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span
|
||||
className="pointer-events-none absolute right-2 flex items-center justify-center"
|
||||
data-slot="dropdown-menu-checkbox-item-indicator"
|
||||
>
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.CheckboxItem>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuRadioGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioGroup
|
||||
data-slot="dropdown-menu-radio-group"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuRadioItem({
|
||||
className,
|
||||
children,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioItem
|
||||
data-slot="dropdown-menu-radio-item"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span
|
||||
className="pointer-events-none absolute right-2 flex items-center justify-center"
|
||||
data-slot="dropdown-menu-radio-item-indicator"
|
||||
>
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.RadioItem>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Label
|
||||
data-slot="dropdown-menu-label"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"px-1.5 py-1 text-xs font-medium text-muted-foreground data-inset:pl-7",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Separator
|
||||
data-slot="dropdown-menu-separator"
|
||||
className={cn("-mx-1 my-1 h-px bg-border", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="dropdown-menu-shortcut"
|
||||
className={cn(
|
||||
"ml-auto text-xs tracking-widest text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSub({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
||||
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubTrigger
|
||||
data-slot="dropdown-menu-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="cn-rtl-flip ml-auto" />
|
||||
</DropdownMenuPrimitive.SubTrigger>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSubContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubContent
|
||||
data-slot="dropdown-menu-sub-content"
|
||||
className={cn("z-50 min-w-[96px] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-lg bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 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 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className )}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
DropdownMenu,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuSubContent,
|
||||
}
|
||||
Reference in New Issue
Block a user