Spaces:
Sleeping
Sleeping
Sync from GitHub via hub-sync
Browse files12345630 unmodified lines3738394041424344454647484950515253545556575859606162636442 unmodified lines107108109"use client";import React from "react";import { useAuth } from "@/context/auth-context";const SIGNIN_BADGE_URL =30 unmodified linesconst name =oauth.userInfo?.preferred_username ?? oauth.userInfo?.name ?? "signed in";const avatar = oauth.userInfo?.picture;return (<div className="inline-flex items-center h-6 gap-1.5 panel-raised bg-[var(--surface-0)]/85 backdrop-blur px-1.5 text-[11px] text-slate-300">{avatar && (// eslint-disable-next-line @next/next/no-img-element<imgsrc={avatar}alt=""width={20}height={20}className="rounded-full ring-1 ring-white/10"/>)}<span className="tabular max-w-[8rem] truncate">{name}</span><buttononClick={signOut}className="cursor-pointer rounded px-1 text-[9px] uppercase tracking-wide text-slate-400 hover:text-slate-100 hover:bg-white/5 transition-colors"title="Sign out of Hugging Face">Sign out</button></div>);}if (variant === "ghost") {42 unmodified lines</button>);}12345630 unmodified lines3738394041424342 unmodified lines8687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173"use client";import React, { useEffect, useRef, useState } from "react";import { useAuth } from "@/context/auth-context";const SIGNIN_BADGE_URL =30 unmodified linesconst name =oauth.userInfo?.preferred_username ?? oauth.userInfo?.name ?? "signed in";const avatar = oauth.userInfo?.picture;return <SignedInMenu name={name} avatar={avatar} onSignOut={signOut} />;}if (variant === "ghost") {42 unmodified lines</button>);}function SignedInMenu({name,avatar,onSignOut,}: {name: string;avatar?: string;onSignOut: () => void;}) {const [open, setOpen] = useState(false);const wrapperRef = useRef<HTMLDivElement>(null);useEffect(() => {if (!open) return;const onDown = (e: MouseEvent) => {if (wrapperRef.current &&!wrapperRef.current.contains(e.target as Node)) {setOpen(false);}};const onKey = (e: KeyboardEvent) => {if (e.key === "Escape") setOpen(false);};document.addEventListener("mousedown", onDown);document.addEventListener("keydown", onKey);return () => {document.removeEventListener("mousedown", onDown);document.removeEventListener("keydown", onKey);};}, [open]);return (<div ref={wrapperRef} className="relative inline-flex"><buttononClick={() => setOpen((v) => !v)}aria-haspopup="menu"aria-expanded={open}className="cursor-pointer inline-flex items-center h-6 gap-1.5 panel-raised bg-[var(--surface-0)]/85 backdrop-blur px-1.5 text-[11px] text-slate-300 hover:bg-white/[0.04] transition-colors"title={`Signed in as ${name}`}>{avatar && (// eslint-disable-next-line @next/next/no-img-element<imgsrc={avatar}alt=""width={20}height={20}className="rounded-full ring-1 ring-white/10"/>)}<span className="tabular max-w-[8rem] truncate">{name}</span><svgaria-hiddenwidth="8"height="8"viewBox="0 0 8 8"className={`text-slate-500 transition-transform ${open ? "rotate-180" : ""}`}><path d="M1 2.5l3 3 3-3" stroke="currentColor" fill="none" /></svg></button>{open && (<divrole="menu"className="absolute right-0 top-full mt-1.5 min-w-[10rem] panel-raised bg-[var(--surface-1)]/98 backdrop-blur shadow-xl p-1 z-50 text-[11px]"><buttonrole="menuitem"onClick={() => {setOpen(false);onSignOut();}}className="cursor-pointer w-full text-left px-2 py-1.5 rounded text-slate-300 hover:bg-white/5 hover:text-slate-100 transition-colors">Sign out</button></div>)}</div>);}
src/components/hf-auth-button.tsx+87-23