Files
2026-06-10 19:59:27 +08:00

85 lines
2.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React, { createRef } from "react";
import clsx from "clsx";
import todayJson from "@/lib/data/today.json";
import { Button } from "@/components/ui/button";
import { Textarea } from "@/components/ui/textarea";
import Image from "next/image";
const todayData: string[] = todayJson;
function Question(props: { question: string; setQuestion: any }) {
const inputRef = createRef<HTMLTextAreaElement>();
function startClick() {
const value = inputRef.current?.value;
if (value === "") {
return;
}
props.setQuestion(value);
}
function todayClick(index: number) {
props.setQuestion(todayData[index]);
}
return (
<div
className={clsx(
"ignore-animate flex w-full max-w-md flex-col gap-4",
props.question || "pt-6",
)}
>
{props.question === "" ? (
<>
<label></label>
<Textarea
ref={inputRef}
placeholder="将使用 AI 为您解读"
className="resize-none"
rows={4}
/>
<div className="flex flex-row-reverse">
<Button size="sm" onClick={startClick}>
</Button>
</div>
<label className="mt-16 underline underline-offset-4">
🧐 西
</label>
<div className="flex flex-wrap gap-3">
{todayData.map(function (value, index) {
return (
<span
key={index}
onClick={() => {
todayClick(index);
}}
className="rounded-md border bg-secondary p-2 text-sm text-muted-foreground shadow transition hover:scale-[1.03] dark:border-0 dark:text-foreground/80 dark:shadow-none"
>
{value}
</span>
);
})}
</div>
</>
) : null}
{props.question && (
<div className="flex truncate rounded-md border bg-secondary p-2 shadow dark:border-0 dark:shadow-none">
<Image
width={24}
height={24}
className="mr-2"
src="/img/yin-yang.webp"
alt="yinyang"
/>
{props.question}
</div>
)}
</div>
);
}
export default Question;