Skip to content

docs: update tracker to reflect FileEditor completion #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions app/demo/file-editor/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"use client";

import { useState } from "react";
import { FileEditor, FileData } from "@/components/ui/file-editor";
import { Button } from "@/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";

export default function FileEditorDemo() {
const [files, setFiles] = useState<FileData[]>([
{
id: "1",
name: "hello.js",
content: `// A simple JavaScript function
function greet(name) {
return \`Hello, \${name}!\`;
}

console.log(greet("World"));`,
language: "javascript",
},
{
id: "2",
name: "styles.css",
content: `/* Main styles */
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
line-height: 1.6;
color: #333;
}

.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}`,
language: "css",
},
]);

const [readOnly, setReadOnly] = useState(false);

const handleChange = (id: string, updates: Partial<FileData>) => {
setFiles((prev) =>
prev.map((file) => (file.id === id ? { ...file, ...updates } : file))
);
};

const handleDelete = (id: string) => {
setFiles((prev) => prev.filter((file) => file.id !== id));
};

const addNewFile = () => {
const newId = Date.now().toString();
const existingCount = files.length;
setFiles((prev) => [
...prev,
{
id: newId,
name: `file${existingCount + 1}.txt`,
content: "",
language: "text",
},
]);
};

const getAllFilenames = () => files.map((f) => f.name);

return (
<div className="container mx-auto max-w-6xl p-8">
<Card className="mb-8">
<CardHeader>
<CardTitle>FileEditor Component Demo</CardTitle>
<CardDescription>
Test the FileEditor component with filename validation, language
detection, and code editing features.
</CardDescription>
</CardHeader>
<CardContent>
<div className="mb-4 flex gap-4">
<Button onClick={addNewFile} disabled={files.length >= 20}>
Add New File
</Button>
<Button variant="outline" onClick={() => setReadOnly(!readOnly)}>
{readOnly ? "Enable Editing" : "Disable Editing"}
</Button>
</div>

<p className="text-muted-foreground mb-4 text-sm">
Files: {files.length} / 20
</p>
</CardContent>
</Card>

{/* File Editors */}
<div className="space-y-8">
{files.map((file, index) => (
<Card key={file.id}>
<CardHeader>
<CardTitle className="text-lg">File {index + 1}</CardTitle>
</CardHeader>
<CardContent>
<FileEditor
file={file}
onChange={handleChange}
onDelete={handleDelete}
showDelete={files.length > 1}
existingFilenames={getAllFilenames()}
readOnly={readOnly}
/>
</CardContent>
</Card>
))}
</div>

{/* Features to Test */}
<Card className="mt-8">
<CardHeader>
<CardTitle>Testing Guide</CardTitle>
</CardHeader>
<CardContent className="space-y-2 text-sm">
<p>• Try changing filenames and see language auto-detection</p>
<p>• Test filename validation (empty, duplicates, invalid chars)</p>
<p>• Switch languages manually using the dropdown</p>
<p>• Add content to see file size indicators</p>
<p>
• Test the delete button (with confirmation for non-empty files)
</p>
<p>• Toggle read-only mode to disable editing</p>
<p>• Add large content (400KB+) to see size warnings</p>
</CardContent>
</Card>
</div>
);
}
92 changes: 92 additions & 0 deletions components/ui/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import * as React from "react";

import { cn } from "@/lib/utils";

function Card({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card"
className={cn(
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
className
)}
{...props}
/>
);
}

function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-header"
className={cn(
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
className
)}
{...props}
/>
);
}

function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-title"
className={cn("leading-none font-semibold", className)}
{...props}
/>
);
}

function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-description"
className={cn("text-muted-foreground text-sm", className)}
{...props}
/>
);
}

function CardAction({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-action"
className={cn(
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
className
)}
{...props}
/>
);
}

function CardContent({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-content"
className={cn("px-6", className)}
{...props}
/>
);
}

function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-footer"
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
{...props}
/>
);
}

export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardAction,
CardDescription,
CardContent,
};
Loading