"use client"; import { Button } from "@suphark/ui/components/shared/button/button"; import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, } from "@suphark/ui/components/ui/input-group"; import { Spinner } from "@suphark/ui/components/ui/spinner"; import { cn } from "@suphark/ui/lib/utils"; import { EyeIcon, EyeOffIcon } from "lucide-react"; import { type ComponentProps, type ReactNode, useState } from "react"; import { useUiText } from "./ui-text"; /** เส้นคั่น "หรือ" ระหว่างปุ่ม provider กับฟอร์มอีเมล */ export function AuthDivider({ children, className }: { children?: ReactNode; className?: string }) { const text = useUiText().auth; return (
{children ?? text?.or ?? "หรือ"}
); } export interface AuthProvider { id: string; /** ชื่อ provider เช่น "Google" — ปุ่มแสดง "ดำเนินการต่อด้วย Google" (UiText.auth.continueWith) */ label: string; /** ข้อความเต็มของปุ่มแทน "ดำเนินการต่อด้วย {label}" (ทุก layout) เช่น "Estar (Microsoft 365)" */ text?: ReactNode; /** โลโก้ของ provider (svg) */ icon?: ReactNode; onClick?: () => void; /** ลิงก์แทน onClick (เช่น /api/auth/sign-in/google) */ href?: string; /** ป้ายท้ายปุ่ม เช่น "ใช้ล่าสุด" */ badge?: ReactNode; disabled?: boolean; } /** * ปุ่มเข้าสู่ระบบด้วย provider (Google / Microsoft / SSO ขององค์กร) * 1 ตัว = ปุ่มเต็มกว้างพร้อมข้อความ · 2 ตัวขึ้นไป = ตาราง 2 คอลัมน์ (`layout="list"` บังคับเรียงลงพร้อมข้อความเต็ม) * `pendingId` = ตัวที่กำลังพาไป (ปุ่มนั้นหมุน ตัวอื่นปิด กันกดซ้ำ) * ปุ่มเต็มกว้าง (1 ตัว / list) ข้อความยาวขึ้นบรรทัดใหม่ได้ ไม่ตัดทิ้ง · ตาราง 2 คอลัมน์ตัดด้วย … (ชื่อเต็มอยู่ใน aria-label/title) */ export function ProviderButtons({ providers, pendingId, layout = "auto", badgePlacement = "corner", className, }: { providers: ReadonlyArray; pendingId?: string | null; layout?: "auto" | "list"; /** ตำแหน่ง badge: corner = ป้ายเล็กทับขอบบนขวาแบบ Clerk "Last used" (ไม่กินที่ข้อความ) · inline = ท้ายข้อความ */ badgePlacement?: "corner" | "inline"; className?: string; }) { const text = useUiText().auth; const grid = layout === "auto" && providers.length >= 2; return (
{providers.map((p) => { const full = (text?.continueWith ?? "ดำเนินการต่อด้วย {provider}").replace( "{provider}", p.label, ); const label = p.text ?? (grid ? p.label : full); const busy = pendingId === p.id; const content = ( <> {busy ? : p.icon} {label} {p.badge && (badgePlacement === "corner" ? ( {p.badge} ) : ( {p.badge} ))} ); // ปุ่มเต็มกว้าง: ให้ข้อความยาวขึ้นบรรทัดใหม่ได้ (Button ตั้ง whitespace-nowrap + h-8) const buttonClass = cn( "w-full", !grid && "h-auto min-h-8 py-2 whitespace-normal", p.badge && badgePlacement === "corner" && "relative", ); const a11y = grid ? { "aria-label": full, title: full } : {}; const disabled = p.disabled || (pendingId != null && !busy); return p.href ? ( ) : ( ); })}
); } /** * ช่องรหัสผ่านพร้อมปุ่มแสดง/ซ่อน (แนวทาง web.dev: ให้ผู้ใช้ตรวจสิ่งที่พิมพ์ได้) * `autoComplete` ค่าเริ่มต้น "current-password" — หน้าสมัคร/ตั้งรหัสใหม่ส่ง "new-password" */ export function PasswordInput({ autoComplete = "current-password", className, ...props }: Omit, "type">) { const text = useUiText().auth; const [visible, setVisible] = useState(false); return ( setVisible((v) => !v)} > {visible ? : } ); }