mishig HF Staff commited on
Commit
d18f742
·
verified ·
1 Parent(s): db57454

Sync from GitHub via hub-sync

Browse files
Files changed (1) hide show
  1. src/components/hf-auth-button.tsx +24 -15
src/components/hf-auth-button.tsx CHANGED
@@ -4,7 +4,7 @@ import React, { useEffect, useRef, useState } from "react";
4
  import { useAuth } from "@/context/auth-context";
5
 
6
  const SIGNIN_BADGE_URL =
7
- "https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-sm-dark.svg";
8
 
9
  // `badge` — the official HF brand badge. Use as a strong invitation when the
10
  // auth path is itself the page's headline action.
@@ -23,8 +23,8 @@ type Variant = "badge" | "ghost" | "tab";
23
  // in the episode tab bar and needs to align with the `text-xs px-5 py-3`
24
  // tab buttons (~40px implicit height).
25
  const SLOT_HEIGHT: Record<Variant, string> = {
26
- badge: "h-6",
27
- ghost: "h-6",
28
  tab: "h-10",
29
  };
30
 
@@ -49,7 +49,14 @@ export default function HfAuthButton({ variant = "badge" }: HfAuthButtonProps) {
49
  const name =
50
  oauth.userInfo?.preferred_username ?? oauth.userInfo?.name ?? "signed in";
51
  const avatar = oauth.userInfo?.picture;
52
- return <SignedInMenu name={name} avatar={avatar} onSignOut={signOut} />;
 
 
 
 
 
 
 
53
  }
54
 
55
  if (variant === "ghost") {
@@ -57,7 +64,7 @@ export default function HfAuthButton({ variant = "badge" }: HfAuthButtonProps) {
57
  <button
58
  onClick={signIn}
59
  title="Sign in to access your private datasets"
60
- className="cursor-pointer inline-flex items-center h-6 gap-1.5 text-[11px] tracking-wide text-cyan-300/80 hover:text-cyan-200 transition-colors rounded focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-cyan-400/60"
61
  >
62
  <span aria-hidden>🤗</span>
63
  <span>Sign in for private datasets</span>
@@ -86,14 +93,14 @@ export default function HfAuthButton({ variant = "badge" }: HfAuthButtonProps) {
86
  onClick={signIn}
87
  title="Sign in with Hugging Face to access your private datasets"
88
  aria-label="Sign in with Hugging Face to access your private datasets"
89
- className="cursor-pointer inline-flex items-center h-6 rounded-md transition-all duration-150 hover:opacity-90 motion-safe:hover:-translate-y-px focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-cyan-400/60"
90
  >
91
  {/* eslint-disable-next-line @next/next/no-img-element */}
92
  <img
93
  src={SIGNIN_BADGE_URL}
94
  alt="Sign in with Hugging Face"
95
- height={24}
96
- className="h-6 w-auto"
97
  />
98
  </button>
99
  );
@@ -103,10 +110,12 @@ function SignedInMenu({
103
  name,
104
  avatar,
105
  onSignOut,
 
106
  }: {
107
  name: string;
108
  avatar?: string;
109
  onSignOut: () => void;
 
110
  }) {
111
  const [open, setOpen] = useState(false);
112
  const wrapperRef = useRef<HTMLDivElement>(null);
@@ -138,7 +147,7 @@ function SignedInMenu({
138
  onClick={() => setOpen((v) => !v)}
139
  aria-haspopup="menu"
140
  aria-expanded={open}
141
- 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 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-cyan-400/60"
142
  title={`Signed in as ${name}`}
143
  >
144
  {avatar && (
@@ -146,16 +155,16 @@ function SignedInMenu({
146
  <img
147
  src={avatar}
148
  alt=""
149
- width={20}
150
- height={20}
151
  className="rounded-full ring-1 ring-white/10"
152
  />
153
  )}
154
- <span className="tabular max-w-[8rem] truncate">{name}</span>
155
  <svg
156
  aria-hidden
157
- width="8"
158
- height="8"
159
  viewBox="0 0 8 8"
160
  className={`text-slate-500 transition-transform ${open ? "rotate-180" : ""}`}
161
  >
@@ -166,7 +175,7 @@ function SignedInMenu({
166
  {open && (
167
  <div
168
  role="menu"
169
- 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] animate-menu-pop"
170
  >
171
  <button
172
  role="menuitem"
 
4
  import { useAuth } from "@/context/auth-context";
5
 
6
  const SIGNIN_BADGE_URL =
7
+ "https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-md-dark.svg";
8
 
9
  // `badge` — the official HF brand badge. Use as a strong invitation when the
10
  // auth path is itself the page's headline action.
 
23
  // in the episode tab bar and needs to align with the `text-xs px-5 py-3`
24
  // tab buttons (~40px implicit height).
25
  const SLOT_HEIGHT: Record<Variant, string> = {
26
+ badge: "h-8",
27
+ ghost: "h-7",
28
  tab: "h-10",
29
  };
30
 
 
49
  const name =
50
  oauth.userInfo?.preferred_username ?? oauth.userInfo?.name ?? "signed in";
51
  const avatar = oauth.userInfo?.picture;
52
+ return (
53
+ <SignedInMenu
54
+ name={name}
55
+ avatar={avatar}
56
+ onSignOut={signOut}
57
+ variant={variant}
58
+ />
59
+ );
60
  }
61
 
62
  if (variant === "ghost") {
 
64
  <button
65
  onClick={signIn}
66
  title="Sign in to access your private datasets"
67
+ className="cursor-pointer inline-flex items-center h-7 gap-1.5 text-sm tracking-wide text-cyan-300/85 hover:text-cyan-200 transition-colors rounded focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-cyan-400/60"
68
  >
69
  <span aria-hidden>🤗</span>
70
  <span>Sign in for private datasets</span>
 
93
  onClick={signIn}
94
  title="Sign in with Hugging Face to access your private datasets"
95
  aria-label="Sign in with Hugging Face to access your private datasets"
96
+ className="cursor-pointer inline-flex items-center h-8 rounded-md transition-all duration-150 hover:opacity-90 motion-safe:hover:-translate-y-px focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-cyan-400/60"
97
  >
98
  {/* eslint-disable-next-line @next/next/no-img-element */}
99
  <img
100
  src={SIGNIN_BADGE_URL}
101
  alt="Sign in with Hugging Face"
102
+ height={32}
103
+ className="h-8 w-auto"
104
  />
105
  </button>
106
  );
 
110
  name,
111
  avatar,
112
  onSignOut,
113
+ variant,
114
  }: {
115
  name: string;
116
  avatar?: string;
117
  onSignOut: () => void;
118
+ variant: Variant;
119
  }) {
120
  const [open, setOpen] = useState(false);
121
  const wrapperRef = useRef<HTMLDivElement>(null);
 
147
  onClick={() => setOpen((v) => !v)}
148
  aria-haspopup="menu"
149
  aria-expanded={open}
150
+ className={`cursor-pointer inline-flex items-center ${SLOT_HEIGHT[variant]} gap-2 panel-raised bg-[var(--surface-0)]/85 backdrop-blur px-2 text-xs text-slate-300 hover:bg-white/[0.04] transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-cyan-400/60`}
151
  title={`Signed in as ${name}`}
152
  >
153
  {avatar && (
 
155
  <img
156
  src={avatar}
157
  alt=""
158
+ width={22}
159
+ height={22}
160
  className="rounded-full ring-1 ring-white/10"
161
  />
162
  )}
163
+ <span className="tabular max-w-[10rem] truncate">{name}</span>
164
  <svg
165
  aria-hidden
166
+ width="9"
167
+ height="9"
168
  viewBox="0 0 8 8"
169
  className={`text-slate-500 transition-transform ${open ? "rotate-180" : ""}`}
170
  >
 
175
  {open && (
176
  <div
177
  role="menu"
178
+ 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-xs animate-menu-pop"
179
  >
180
  <button
181
  role="menuitem"