mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 10:25:06 +03:00
34 lines
800 B
TypeScript
34 lines
800 B
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { cn } from 'ui'
|
|
|
|
export interface LoadingBeamProps {
|
|
isActive: boolean
|
|
direction?: 'forward' | 'backward'
|
|
className?: string
|
|
}
|
|
|
|
export const LoadingBeam = ({ isActive, direction = 'forward', className }: LoadingBeamProps) => {
|
|
const [run, setRun] = useState(0)
|
|
const [runDirection, setRunDirection] = useState(direction)
|
|
const [wasActive, setWasActive] = useState(isActive)
|
|
if (isActive !== wasActive) {
|
|
setWasActive(isActive)
|
|
if (isActive) {
|
|
setRun((current) => current + 1)
|
|
setRunDirection(direction)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div
|
|
key={run}
|
|
aria-hidden
|
|
data-active={isActive ? '' : undefined}
|
|
data-direction={runDirection}
|
|
className={cn('loading-beam', className)}
|
|
/>
|
|
)
|
|
}
|