|
| 1 | +import { Icon } from '@/shared/icons'; |
| 2 | +import { cn } from '@/shared/lib'; |
| 3 | +import { cva } from 'class-variance-authority'; |
| 4 | + |
| 5 | +interface ControlBarProps { |
| 6 | + isLoggedIn: boolean; |
| 7 | + onLogin: () => void; |
| 8 | + userName: string; |
| 9 | + className?: string; |
| 10 | +} |
| 11 | + |
| 12 | +const rightStyle = cva('flex items-center gap-[0.6rem] transition w-[7.8rem]', { |
| 13 | + variants: { |
| 14 | + state: { |
| 15 | + loggedIn: 'text-mint-600', |
| 16 | + guest: 'text-gray-400 hover:text-gray-600', |
| 17 | + }, |
| 18 | + }, |
| 19 | + defaultVariants: { state: 'guest' }, |
| 20 | +}); |
| 21 | + |
| 22 | +const ControlBar = ({ |
| 23 | + onLogin, |
| 24 | + isLoggedIn, |
| 25 | + userName = '글다', |
| 26 | + className, |
| 27 | +}: ControlBarProps) => { |
| 28 | + const rightState = isLoggedIn ? 'loggedIn' : ('guest' as const); |
| 29 | + const iconColor = isLoggedIn ? 'mint-600' : ('gray-400' as const); |
| 30 | + |
| 31 | + return ( |
| 32 | + <header className={cn('bg-none w-full h-[5.4rem]', className)} role='group'> |
| 33 | + <div className='h-full grid grid-cols-[auto_1fr_auto] items-center gap-[1.2rem]'> |
| 34 | + <div |
| 35 | + className='w-[7.8rem] h-[5.4rem] rounded-[0.6rem] bg-gray-200' |
| 36 | + aria-hidden |
| 37 | + /> |
| 38 | + |
| 39 | + <h1 className='justify-self-center text-headline-sm-serif font-[400] leading-[2.4rem] tracking-[0.015rem] text-gray-900'> |
| 40 | + 글다 |
| 41 | + </h1> |
| 42 | + {isLoggedIn ? ( |
| 43 | + <div className={cn(rightStyle({ state: rightState }), 'min-w-0')}> |
| 44 | + <Icon name='User' size={24} color={iconColor} /> |
| 45 | + <span |
| 46 | + className='text-body-md w-[5.3rem] truncate block' |
| 47 | + aria-label={`${userName}님`} |
| 48 | + > |
| 49 | + {userName}님 |
| 50 | + </span> |
| 51 | + </div> |
| 52 | + ) : ( |
| 53 | + <button |
| 54 | + type='button' |
| 55 | + onClick={(e) => { |
| 56 | + e.stopPropagation(); |
| 57 | + onLogin?.(); |
| 58 | + }} |
| 59 | + className={rightStyle({ state: rightState })} |
| 60 | + aria-label='Log In' |
| 61 | + > |
| 62 | + <Icon name='User' size={24} color={iconColor} /> |
| 63 | + <span className='text-body-md'>Log In</span> |
| 64 | + </button> |
| 65 | + )} |
| 66 | + </div> |
| 67 | + </header> |
| 68 | + ); |
| 69 | +}; |
| 70 | + |
| 71 | +export default ControlBar; |
0 commit comments