-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { cva, type VariantProps } from 'class-variance-authority'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
import { forwardRef } from 'react'; | ||
|
||
const alertVariants = cva( | ||
'relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7', | ||
{ | ||
variants: { | ||
variant: { | ||
default: 'bg-background text-foreground', | ||
destructive: 'border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive', | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: 'default', | ||
}, | ||
}, | ||
); | ||
|
||
export const Alert = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>>( | ||
({ className, variant, ...props }, ref) => ( | ||
<div ref={ref} role="alert" className={cn(alertVariants({ variant }), className)} {...props} /> | ||
), | ||
); | ||
Alert.displayName = 'Alert'; | ||
|
||
export const AlertTitle = forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>( | ||
({ className, ...props }, ref) => ( | ||
<h5 ref={ref} className={cn('mb-1 font-medium leading-none tracking-tight', className)} {...props} /> | ||
), | ||
); | ||
AlertTitle.displayName = 'AlertTitle'; | ||
|
||
export const AlertDescription = forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>( | ||
({ className, ...props }, ref) => <div ref={ref} className={cn('text-sm [&_p]:leading-relaxed', className)} {...props} />, | ||
); | ||
AlertDescription.displayName = 'AlertDescription'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { WifiOff } from 'lucide-react'; | ||
import { Alert, AlertDescription } from '@/components/ui/alert'; | ||
import { useOfflineStatus } from '@/hooks/useOfflineStatus'; | ||
|
||
export const OfflineBanner = () => { | ||
const isOffline = useOfflineStatus(); | ||
|
||
if (!isOffline) return null; | ||
|
||
return ( | ||
<Alert | ||
variant="destructive" | ||
className="sticky top-0 left-0 right-0 z-50 rounded-none flex items-center justify-center animate-in fade-in slide-in-from-top duration-300 bg-background" | ||
> | ||
<WifiOff className="h-4 w-4" /> | ||
<AlertDescription className="ml-2">{"You're currently offline. Some features may be unavailable."}</AlertDescription> | ||
</Alert> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useState, useEffect } from 'react'; | ||
|
||
export const useOfflineStatus = () => { | ||
const [isOffline, setIsOffline] = useState(!navigator.onLine); | ||
|
||
useEffect(() => { | ||
const handleOnline = () => setIsOffline(false); | ||
const handleOffline = () => setIsOffline(true); | ||
|
||
window.addEventListener('online', handleOnline); | ||
window.addEventListener('offline', handleOffline); | ||
|
||
return () => { | ||
window.removeEventListener('online', handleOnline); | ||
window.removeEventListener('offline', handleOffline); | ||
}; | ||
}, []); | ||
|
||
return isOffline; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters