47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { Check, X } from 'lucide-react'
|
|
import { cn } from '../../lib/utils'
|
|
import type { AttendanceChoice } from './utils'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
export function AttendanceToggle({
|
|
choice,
|
|
disabled,
|
|
onToggle,
|
|
fullName,
|
|
}: {
|
|
choice: AttendanceChoice
|
|
disabled?: boolean
|
|
onToggle: () => void
|
|
fullName: string
|
|
}) {
|
|
const isPresent = choice === 'PRESENT'
|
|
const { t } = useTranslation('classAttendance')
|
|
|
|
return (
|
|
<button
|
|
type="button"
|
|
role="switch"
|
|
aria-checked={isPresent}
|
|
aria-label={t(`toggle.${choice}`, { name: fullName })}
|
|
disabled={disabled}
|
|
onClick={onToggle}
|
|
className={cn(
|
|
'relative inline-flex h-11 w-14 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface disabled:cursor-not-allowed disabled:opacity-70',
|
|
isPresent ? 'bg-success' : 'bg-danger',
|
|
)}
|
|
>
|
|
<span
|
|
className={cn(
|
|
'inline-flex size-9 items-center justify-center rounded-full bg-white shadow-sm transition-transform duration-150',
|
|
isPresent ? 'translate-x-3' : 'translate-x-1',
|
|
)}
|
|
>
|
|
{isPresent ? (
|
|
<Check className="size-5 text-success" aria-hidden />
|
|
) : (
|
|
<X className="size-5 text-danger" aria-hidden />
|
|
)}
|
|
</span>
|
|
</button>
|
|
)
|
|
} |