File size: 1,459 Bytes
f555806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use client';

import classNames from 'classnames';
import { useAuth } from '@/contexts/AuthContext';

interface Props {
  className?: string;
  size?: 'sm' | 'md' | 'lg';
}

const BUTTON_ASSETS: Record<'sm' | 'md' | 'lg', string> = {
  sm: 'https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-sm-dark.svg',
  md: 'https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-md-dark.svg',
  lg: 'https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-lg-dark.svg',
};

export default function HFLoginButton({ className, size = 'md' }: Props) {
  const { loginWithOAuth, oauthAvailable, status } = useAuth();

  if (!oauthAvailable) {
    return null;
  }

  const disabled = status === 'checking';

  return (
    <button
      type="button"
      onClick={loginWithOAuth}
      disabled={disabled}
      className={classNames(
        'border border-gray-700 rounded-md bg-gray-900 hover:bg-gray-800 transition-colors inline-flex items-center justify-center p-2 disabled:opacity-60 disabled:cursor-not-allowed',
        className,
      )}
      aria-label="Sign in with Hugging Face"
    >
      <img
        src={BUTTON_ASSETS[size]}
        alt="Sign in with Hugging Face"
        className={classNames('block', {
          'h-16': size === 'lg',
          'h-14': size === 'md',
          'h-12': size === 'sm',
        })}
      />
    </button>
  );
}