AI 与对话 · 助手与对话 · 公开
Ruixen Moon Chat
以紫蓝月球为背景的 AI 输入界面,包含自动伸缩文本框、附件入口和常用生成快捷操作。
#React#AI#聊天界面
Prompt 原文8,966 字符
You are given a task to integrate an existing React component in the codebase
The codebase should support:
- shadcn project structure
- Tailwind CSS
- Typescript
If it doesn't, provide instructions on how to setup project via shadcn CLI, install Tailwind or Typescript.
Determine the default path for components and styles.
If default path for components is not /components/ui, provide instructions on why it's important to create this folder
Copy-paste this component to /components/ui folder:
```tsx
ruixen-moon-chat.tsx
"use client";
import { useState, useRef, useEffect, useCallback } from "react";
import { Textarea } from "@/components/ui/textarea";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import {
ImageIcon,
FileUp,
MonitorIcon,
CircleUserRound,
ArrowUpIcon,
Paperclip,
PlusIcon,
Code2,
Palette,
Layers,
Rocket,
} from "lucide-react";
interface AutoResizeProps {
minHeight: number;
maxHeight?: number;
}
function useAutoResizeTextarea({ minHeight, maxHeight }: AutoResizeProps) {
const textareaRef = useRef<HTMLTextAreaElement>(null);
const adjustHeight = useCallback(
(reset?: boolean) => {
const textarea = textareaRef.current;
if (!textarea) return;
if (reset) {
textarea.style.height = `${minHeight}px`;
return;
}
textarea.style.height = `${minHeight}px`; // reset first
const newHeight = Math.max(
minHeight,
Math.min(textarea.scrollHeight, maxHeight ?? Infinity)
);
textarea.style.height = `${newHeight}px`;
},
[minHeight, maxHeight]
);
useEffect(() => {
if (textareaRef.current) textareaRef.current.style.height = `${minHeight}px`;
}, [minHeight]);
return { textareaRef, adjustHeight };
}
export default function RuixenMoonChat() {
const [message, setMessage] = useState("");
const { textareaRef, adjustHeight } = useAutoResizeTextarea({
minHeight: 48,
maxHeight: 150,
});
return (
<div
className="relative w-full h-screen bg-cover bg-center flex flex-col items-center"
style={{
backgroundImage:
"url('https://pub-940ccf6255b54fa799a9b01050e6c227.r2.dev/ruixen_moon_2.png')",
backgroundAttachment: "fixed",
}}
>
{/* Centered AI Title */}
<div className="flex-1 w-full flex flex-col items-center justify-center">
<div className="text-center">
<h1 className="text-4xl font-semibold text-white drop-shadow-sm">
Ruixen AI
</h1>
<p className="mt-2 text-neutral-200">
Build something amazing — just start typing below.
</p>
</div>
</div>
{/* Input Box Section */}
<div className="w-full max-w-3xl mb-[20vh]">
<div className="relative bg-black/60 backdrop-blur-md rounded-xl border border-neutral-700">
<Textarea
ref={textareaRef}
value={message}
onChange={(e) => {
setMessage(e.target.value);
adjustHeight();
}}
placeholder="Type your request..."
className={cn(
"w-full px-4 py-3 resize-none border-none",
"bg-transparent text-white text-sm",
"focus-visible:ring-0 focus-visible:ring-offset-0",
"placeholder:text-neutral-400 min-h-[48px]"
)}
style={{ overflow: "hidden" }}
/>
{/* Footer Buttons */}
<div className="flex items-center justify-between p-3">
<Button
variant="ghost"
size="icon"
className="text-white hover:bg-neutral-700"
>
<Paperclip className="w-4 h-4" />
</Button>
<div className="flex items-center gap-2">
<Button
disabled
className={cn(
"flex items-center gap-1 px-3 py-2 rounded-lg transition-colors",
"bg-neutral-700 text-neutral-400 cursor-not-allowed"
)}
>
<ArrowUpIcon className="w-4 h-4" />
<span className="sr-only">Send</span>
</Button>
</div>
</div>
</div>
{/* Quick Actions */}
<div className="flex items-center justify-center flex-wrap gap-3 mt-6">
<QuickAction icon={<Code2 className="w-4 h-4" />} label="Generate Code" />
<QuickAction icon={<Rocket className="w-4 h-4" />} label="Launch App" />
<QuickAction icon={<Layers className="w-4 h-4" />} label="UI Components" />
<QuickAction icon={<Palette className="w-4 h-4" />} label="Theme Ideas" />
<QuickAction icon={<CircleUserRound className="w-4 h-4" />} label="User Dashboard" />
<QuickAction icon={<MonitorIcon className="w-4 h-4" />} label="Landing Page" />
<QuickAction icon={<FileUp className="w-4 h-4" />} label="Upload Docs" />
<QuickAction icon={<ImageIcon className="w-4 h-4" />} label="Image Assets" />
</div>
</div>
</div>
);
}
interface QuickActionProps {
icon: React.ReactNode;
label: string;
}
function QuickAction({ icon, label }: QuickActionProps) {
return (
<Button
variant="outline"
className="flex items-center gap-2 rounded-full border-neutral-700 bg-black/50 text-neutral-300 hover:text-white hover:bg-neutral-700"
>
{icon}
<span className="text-xs">{label}</span>
</Button>
);
}
demo.tsx
"use client";
import React from "react";
import RuixenMoonChat from "@/components/ui/ruixen-moon-chat"; // adjust path if needed
export default function DemoPage() {
return (
<main className="min-h-screen w-full bg-black text-white">
{/* Chat Component */}
<section className="flex justify-center items-start w-full">
<RuixenMoonChat />
</section>
{/* Footer */}
<footer className="text-center text-neutral-500 py-2 mt-10 border-t border-neutral-800 text-sm">
© {new Date().getFullYear()} Ruixen Demo Page
</footer>
</main>
);
}
```
Copy-paste these files for dependencies:
```tsx
shadcn/textarea
import * as React from "react"
import { cn } from "@/lib/utils"
export interface TextareaProps
extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
({ className, ...props }, ref) => {
return (
<textarea
className={cn(
"flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className
)}
ref={ref}
{...props}
/>
)
}
)
Textarea.displayName = "Textarea"
export { Textarea }
```
```tsx
shadcn/button
import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const buttonVariants = cva(
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90",
destructive:
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
outline:
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
secondary:
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
lg: "h-11 rounded-md px-8",
icon: "h-10 w-10",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
},
)
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button"
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
)
},
)
Button.displayName = "Button"
export { Button, buttonVariants }
```
Install NPM dependencies:
```bash
lucide-react, @radix-ui/react-slot, class-variance-authority
```
最后更新于 2026/8/10 14:58:28