Files
kolaytercih/src/components/ui/prompt-suggestion.tsx
bilalgursen b61d5e825a
Some checks failed
Deploy / deploy (push) Has been cancelled
feat(danisman): hazır sorular konu haplarıyla, yazma kutusunun üstünde (prompt-kit kalıbı) (→ 2.1.1)
Boş durumdaki küçük cümle hapları kalktı. Konuya basınca soruları satır
satır açılır, ortak söz koyu yazılır; soru göndermez, kutuya yazılır.
Vurgu Türkçe küçük harfle aranır, uzun satır sarılır.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 17:07:51 +03:00

93 lines
2.4 KiB
TypeScript
Raw 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.
"use client"
import { Button, buttonVariants } from "@/components/ui/button"
import { cn } from "@/lib/utils"
import { VariantProps } from "class-variance-authority"
export type PromptSuggestionProps = {
children: React.ReactNode
variant?: VariantProps<typeof buttonVariants>["variant"]
size?: VariantProps<typeof buttonVariants>["size"]
className?: string
highlight?: string
} & React.ButtonHTMLAttributes<HTMLButtonElement>
function PromptSuggestion({
children,
variant,
size,
className,
highlight,
...props
}: PromptSuggestionProps) {
const isHighlightMode = highlight !== undefined && highlight.trim() !== ""
const content = typeof children === "string" ? children : ""
if (!isHighlightMode) {
return (
<Button
variant={variant || "outline"}
size={size || "lg"}
className={cn(className)}
{...props}
>
{children}
</Button>
)
}
if (!content) {
return (
<Button
variant={variant || "ghost"}
size={size || "sm"}
className={cn(
"w-full cursor-pointer justify-start py-2",
"hover:bg-accent",
className
)}
{...props}
>
{children}
</Button>
)
}
// Türkçe yerel küçültme: "İ" → "i" tek harf kalır, vurgu dizini kaymaz.
const trimmedHighlight = highlight.trim()
const contentLower = content.toLocaleLowerCase("tr")
const highlightLower = trimmedHighlight.toLocaleLowerCase("tr")
const index = contentLower.indexOf(highlightLower)
const bitis = index + highlightLower.length
return (
<Button
variant={variant || "ghost"}
size={size || "sm"}
className={cn(
"h-auto min-h-11 w-full cursor-pointer justify-start rounded-xl px-3 py-2 text-sm sm:min-h-9",
"hover:bg-slate-100",
className
)}
{...props}
>
{/* Tek metin kutusu: uzun cümle dar ekranda sarılır, vurgu satır içinde kalır. */}
<span className="min-w-0 text-left font-normal whitespace-normal text-slate-500">
{index === -1 ? (
content
) : (
<>
{content.substring(0, index)}
<span className="font-semibold text-slate-900">
{content.substring(index, bitis)}
</span>
{content.substring(bitis)}
</>
)}
</span>
</Button>
)
}
export { PromptSuggestion }