feat: add distance value object and ci workflows

This commit is contained in:
Bernard Ngandu
2025-10-10 16:13:48 +02:00
parent d3338e8901
commit 2ed7a48d36
44 changed files with 4263 additions and 1370 deletions
+40 -43
View File
@@ -1,28 +1,28 @@
import { ChevronDown, ChevronUp, Flame, Focus, LocateFixed, MapPin, RefreshCw } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { ChevronDown, ChevronUp, Flame, Focus, LocateFixed, MapPin, RefreshCw } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { LanguageToggle } from '@/components/layout/LanguageToggle'
import { ThemeToggle } from '@/components/layout/ThemeToggle'
import { cn } from '@/lib/utils'
import type { FeedStatus } from '@/types/api'
import { LanguageToggle } from "@/components/layout/LanguageToggle";
import { ThemeToggle } from "@/components/layout/ThemeToggle";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import type { FeedStatus } from "@/types/api";
interface AppHeaderProps {
status: FeedStatus
statusLabel: string
lastUpdatedLabel: string
onRefresh: () => void
onFocusHeat: () => void
onLocateUser: () => void
onFocusMySignal: () => void
disableRefresh: boolean
disableHeat: boolean
disableLocate: boolean
disableMySignal: boolean
collapsed: boolean
onToggleCollapse: () => void
className?: string
status: FeedStatus;
statusLabel: string;
lastUpdatedLabel: string;
onRefresh: () => void;
onFocusHeat: () => void;
onLocateUser: () => void;
onFocusMySignal: () => void;
disableRefresh: boolean;
disableHeat: boolean;
disableLocate: boolean;
disableMySignal: boolean;
collapsed: boolean;
onToggleCollapse: () => void;
className?: string;
}
export function AppHeader({
@@ -41,21 +41,18 @@ export function AppHeader({
onToggleCollapse,
className,
}: AppHeaderProps) {
const { t } = useTranslation()
const isError = status === 'error'
const { t } = useTranslation();
const isError = status === "error";
const statusBadge = (
<Badge
variant="secondary"
className={cn(
'inline-flex items-center gap-2 rounded-full border border-border/60 bg-muted/60 px-3 py-1 text-xs font-medium uppercase tracking-wide',
collapsed && 'px-2 py-1 text-[11px] font-semibold',
"inline-flex items-center gap-2 rounded-full border border-border/60 bg-muted/60 px-3 py-1 text-xs font-medium uppercase tracking-wide",
collapsed && "px-2 py-1 text-[11px] font-semibold"
)}
>
<span
className={`flex items-center gap-2 ${isError ? 'text-destructive' : 'text-primary'}`}
aria-live="polite"
>
<span className={`flex items-center gap-2 ${isError ? "text-destructive" : "text-primary"}`} aria-live="polite">
<span className="relative block h-2.5 w-2.5 rounded-full bg-current">
<span className="absolute inset-[-0.35rem] rounded-full border border-current opacity-40 animate-status-pulse" />
</span>
@@ -63,18 +60,18 @@ export function AppHeader({
</span>
{!collapsed && (
<span className="text-[10px] uppercase text-muted-foreground">
{t('header.badge.updated', { time: lastUpdatedLabel })}
{t("header.badge.updated", { time: lastUpdatedLabel })}
</span>
)}
</Badge>
)
);
return (
<header
className={cn(
'flex w-full max-w-[420px] flex-col gap-3 rounded-3xl border border-border/60 bg-background/90 p-4 text-sm shadow-xl backdrop-blur transition-all',
collapsed && 'max-w-[240px] bg-background/80 p-3',
className,
"flex w-full max-w-[420px] flex-col gap-3 rounded-3xl border border-border/60 bg-background/90 p-4 text-sm shadow-xl backdrop-blur transition-all",
collapsed && "max-w-[240px] bg-background/80 p-3",
className
)}
>
<div className="flex items-center justify-between gap-3">
@@ -83,15 +80,15 @@ export function AppHeader({
<Flame className="h-5 w-5" />
</span>
<div className="flex flex-col">
<span className="text-base font-semibold sm:text-lg">{t('app.name')}</span>
{!collapsed && <span className="text-xs text-muted-foreground sm:text-sm">{t('app.tagline')}</span>}
<span className="text-base font-semibold sm:text-lg">{t("app.name")}</span>
{!collapsed && <span className="text-xs text-muted-foreground sm:text-sm">{t("app.tagline")}</span>}
</div>
</div>
<Button
variant="ghost"
size="icon"
onClick={onToggleCollapse}
aria-label={collapsed ? t('header.actions.expand') : t('header.actions.collapse')}
aria-label={collapsed ? t("header.actions.expand") : t("header.actions.collapse")}
className="h-9 w-9 rounded-full border border-border/50 bg-muted/60 backdrop-blur hover:bg-muted"
>
{collapsed ? <ChevronDown className="h-4 w-4" /> : <ChevronUp className="h-4 w-4" />}
@@ -105,7 +102,7 @@ export function AppHeader({
size="icon"
onClick={onRefresh}
disabled={disableRefresh}
aria-label={t('header.actions.refresh')}
aria-label={t("header.actions.refresh")}
>
<RefreshCw className="h-4 w-4" />
</Button>
@@ -114,7 +111,7 @@ export function AppHeader({
size="icon"
onClick={onFocusHeat}
disabled={disableHeat}
aria-label={t('header.actions.focusHeat')}
aria-label={t("header.actions.focusHeat")}
>
<Focus className="h-4 w-4" />
</Button>
@@ -123,7 +120,7 @@ export function AppHeader({
size="icon"
onClick={onLocateUser}
disabled={disableLocate}
aria-label={t('header.actions.locate')}
aria-label={t("header.actions.locate")}
>
<LocateFixed className="h-4 w-4" />
</Button>
@@ -132,7 +129,7 @@ export function AppHeader({
size="icon"
onClick={onFocusMySignal}
disabled={disableMySignal}
aria-label={t('header.actions.mySignal')}
aria-label={t("header.actions.mySignal")}
>
<MapPin className="h-4 w-4" />
</Button>
@@ -141,5 +138,5 @@ export function AppHeader({
</div>
)}
</header>
)
);
}
+11 -12
View File
@@ -1,28 +1,27 @@
import { Globe } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { Globe } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Button } from '@/components/ui/button'
import { Button } from "@/components/ui/button";
export function LanguageToggle() {
const { i18n, t } = useTranslation()
const current = i18n.language === 'fr' ? 'fr' : 'en'
const next = current === 'en' ? 'fr' : 'en'
const nextLabel = t(next === 'en' ? 'language.english' : 'language.french')
const { i18n, t } = useTranslation();
const current = i18n.language === "fr" ? "fr" : "en";
const next = current === "en" ? "fr" : "en";
const nextLabel = t(next === "en" ? "language.english" : "language.french");
return (
<Button
variant="ghost"
size="sm"
onClick={() => {
i18n.changeLanguage(next).catch(() => undefined)
i18n.changeLanguage(next).catch(() => undefined);
}}
aria-label={t('common.aria.language', { language: nextLabel })}
aria-label={t("common.aria.language", { language: nextLabel })}
className="h-9 rounded-full border border-border/60 bg-background/80 px-3 backdrop-blur"
>
<span className="sr-only">{t('language.label')}</span>
<span className="sr-only">{t("language.label")}</span>
<Globe className="h-4 w-4" />
<span className="ml-2 text-xs font-semibold uppercase text-muted-foreground">{current.toUpperCase()}</span>
</Button>
)
);
}
+8 -8
View File
@@ -1,22 +1,22 @@
import { Moon, Sun } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { Moon, Sun } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Button } from '@/components/ui/button'
import { useTheme } from '@/hooks/useTheme'
import { Button } from "@/components/ui/button";
import { useTheme } from "@/hooks/useTheme";
export function ThemeToggle() {
const { toggleTheme, isDark } = useTheme()
const { t } = useTranslation()
const { toggleTheme, isDark } = useTheme();
const { t } = useTranslation();
return (
<Button
variant="ghost"
size="icon"
onClick={toggleTheme}
aria-label={isDark ? t('common.aria.theme.light') : t('common.aria.theme.dark')}
aria-label={isDark ? t("common.aria.theme.light") : t("common.aria.theme.dark")}
className="rounded-full border border-border/60 bg-background/80 backdrop-blur"
>
{isDark ? <Sun className="h-4 w-4" /> : <Moon className="h-4 w-4" />}
</Button>
)
);
}
+15 -25
View File
@@ -1,39 +1,29 @@
import type { MutableRefObject } from 'react'
import { useTranslation } from 'react-i18next'
import type { MutableRefObject } from "react";
import { cn } from '@/lib/utils'
import { useTranslation } from "react-i18next";
import { cn } from "@/lib/utils";
interface MapViewportProps {
containerRef: MutableRefObject<HTMLDivElement | null>
isPosting: boolean
isLoading: boolean
confirmationHint?: string | null
className?: string
containerRef: MutableRefObject<HTMLDivElement | null>;
isPosting: boolean;
isLoading: boolean;
confirmationHint?: string | null;
className?: string;
}
export function MapViewport({
containerRef,
isPosting,
isLoading,
confirmationHint,
className,
}: MapViewportProps) {
const { t } = useTranslation()
export function MapViewport({ containerRef, isPosting, isLoading, confirmationHint, className }: MapViewportProps) {
const { t } = useTranslation();
return (
<div
className={cn(
'relative h-full min-h-screen w-full overflow-hidden bg-muted/40 shadow-inner',
className,
)}
>
<div ref={containerRef} className={cn('absolute inset-0 z-0', 'leaflet-wrapper')} />
<div className={cn("relative h-full min-h-screen w-full overflow-hidden bg-muted/40 shadow-inner", className)}>
<div ref={containerRef} className={cn("absolute inset-0 z-0", "leaflet-wrapper")} />
<div className="pointer-events-none absolute inset-x-0 top-0 z-10 h-24 bg-gradient-to-b from-background/70 to-transparent" />
<div className="pointer-events-none absolute inset-x-0 bottom-0 z-10 h-24 bg-gradient-to-t from-background/70 to-transparent" />
{(isPosting || isLoading) && (
<div className="pointer-events-none absolute inset-0 z-20 flex items-center justify-center">
<span className="rounded-full border border-border/60 bg-background/80 px-4 py-2 text-xs font-medium uppercase tracking-wide text-muted-foreground backdrop-blur">
{isPosting ? t('map.posting') : t('map.loading')}
{isPosting ? t("map.posting") : t("map.loading")}
</span>
</div>
)}
@@ -43,5 +33,5 @@ export function MapViewport({
</div>
)}
</div>
)
);
}
+20 -20
View File
@@ -1,43 +1,43 @@
import { Activity, ArrowRight } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { Activity, ArrowRight } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { ScrollArea } from '@/components/ui/scroll-area'
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { ScrollArea } from "@/components/ui/scroll-area";
interface ActivityItem {
id: string | number
title: string
subtitle: string
timestampLabel: string
distanceLabel: string
onFocus: () => void
id: string | number;
title: string;
subtitle: string;
timestampLabel: string;
distanceLabel: string;
onFocus: () => void;
}
interface ActivityPanelProps {
items: ActivityItem[]
emptyMessage: string
items: ActivityItem[];
emptyMessage: string;
}
export function ActivityPanel({ items, emptyMessage }: ActivityPanelProps) {
const { t } = useTranslation()
const { t } = useTranslation();
return (
<Card className="h-full">
<CardHeader className="space-y-1">
<CardTitle className="flex items-center gap-2">
<Activity className="h-5 w-5 text-primary" />
{t('activity.title')}
{t("activity.title")}
</CardTitle>
<CardDescription>{t('activity.description')}</CardDescription>
<CardDescription>{t("activity.description")}</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
{items.length === 0 && <p className="text-sm text-muted-foreground">{emptyMessage}</p>}
{items.length > 0 && (
<ScrollArea className="max-h-[280px] pr-2">
<ul className="space-y-3">
{items.map((item) => (
{items.map(item => (
<li key={item.id} className="rounded-2xl border border-border/60 bg-muted/50 p-3">
<div className="flex items-center justify-between gap-3">
<div className="flex flex-col">
@@ -51,7 +51,7 @@ export function ActivityPanel({ items, emptyMessage }: ActivityPanelProps) {
<div className="mt-2 flex items-center justify-between text-xs text-muted-foreground">
<span>{item.distanceLabel}</span>
<Button variant="ghost" size="sm" className="h-8 gap-2 text-xs" onClick={item.onFocus}>
{t('activity.view')}
{t("activity.view")}
<ArrowRight className="h-3.5 w-3.5" />
</Button>
</div>
@@ -62,5 +62,5 @@ export function ActivityPanel({ items, emptyMessage }: ActivityPanelProps) {
)}
</CardContent>
</Card>
)
);
}
@@ -1,47 +1,45 @@
import { Flame, MapPin } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { Flame, MapPin } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { ScrollArea } from '@/components/ui/scroll-area'
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { ScrollArea } from "@/components/ui/scroll-area";
interface HotspotCellInfo {
id: string
title: string
subtitle: string
intensity: number
onFocus: () => void
id: string;
title: string;
subtitle: string;
intensity: number;
onFocus: () => void;
}
interface HotspotStatsPanelProps {
hasLocation: boolean
radiusKm: number
locationHint: string
cells: HotspotCellInfo[]
hasLocation: boolean;
radiusKm: number;
locationHint: string;
cells: HotspotCellInfo[];
}
export function HotspotStatsPanel({ hasLocation, radiusKm, locationHint, cells }: HotspotStatsPanelProps) {
const { t } = useTranslation()
const { t } = useTranslation();
return (
<Card className="h-full">
<CardHeader className="space-y-1">
<CardTitle className="flex items-center gap-2">
<Flame className="h-5 w-5 text-primary" />
{t('hotspots.title')}
{t("hotspots.title")}
</CardTitle>
<CardDescription>{t('hotspots.description', { radius: radiusKm })}</CardDescription>
<CardDescription>{t("hotspots.description", { radius: radiusKm })}</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
{!hasLocation && <p className="text-sm text-muted-foreground">{locationHint}</p>}
{hasLocation && cells.length === 0 && (
<p className="text-sm text-muted-foreground">{t('hotspots.empty')}</p>
)}
{hasLocation && cells.length === 0 && <p className="text-sm text-muted-foreground">{t("hotspots.empty")}</p>}
{cells.length > 0 && (
<ScrollArea className="max-h-[280px] pr-2">
<ul className="space-y-3">
{cells.map((cell) => (
{cells.map(cell => (
<li key={cell.id} className="rounded-2xl border border-border/60 bg-muted/50 p-3">
<div className="flex items-center justify-between gap-3">
<div className="flex flex-col">
@@ -58,7 +56,7 @@ export function HotspotStatsPanel({ hasLocation, radiusKm, locationHint, cells }
className="mt-2 w-full justify-center gap-2 text-xs"
onClick={cell.onFocus}
>
<MapPin className="h-3.5 w-3.5" /> {t('hotspots.focus')}
<MapPin className="h-3.5 w-3.5" /> {t("hotspots.focus")}
</Button>
</li>
))}
@@ -67,5 +65,5 @@ export function HotspotStatsPanel({ hasLocation, radiusKm, locationHint, cells }
)}
</CardContent>
</Card>
)
);
}
+31 -33
View File
@@ -1,23 +1,23 @@
import { AlertCircle, Radio } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { AlertCircle, Radio } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import type { FeedError } from '@/hooks/useHotspotFeed'
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import type { FeedError } from "@/hooks/useHotspotFeed";
interface OverviewPanelProps {
nearbySignals: number
uniqueContributors: number
lastUpdatedLabel: string
mySignalLabel: string | null
error: FeedError | null
onReport: () => void
onRetry: () => void
isPosting: boolean
locationHint: string
showLocationCta: boolean
disableReport: boolean
nearbySignals: number;
uniqueContributors: number;
lastUpdatedLabel: string;
mySignalLabel: string | null;
error: FeedError | null;
onReport: () => void;
onRetry: () => void;
isPosting: boolean;
locationHint: string;
showLocationCta: boolean;
disableReport: boolean;
}
export function OverviewPanel({
@@ -33,32 +33,32 @@ export function OverviewPanel({
showLocationCta,
disableReport,
}: OverviewPanelProps) {
const { t } = useTranslation()
const errorMessage = error ? t(error.key, error.values) : null
const { t } = useTranslation();
const errorMessage = error ? t(error.key, error.values) : null;
return (
<Card>
<CardHeader className="space-y-1">
<CardTitle className="flex items-center gap-2">
<Radio className="h-5 w-5 text-primary" />
{t('overview.title')}
{t("overview.title")}
</CardTitle>
<CardDescription>{t('overview.description')}</CardDescription>
<CardDescription>{t("overview.description")}</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid grid-cols-2 gap-3">
<div className="rounded-2xl border border-border/60 bg-muted/50 p-3">
<span className="text-xs uppercase text-muted-foreground">{t('overview.stats.signals')}</span>
<span className="text-xs uppercase text-muted-foreground">{t("overview.stats.signals")}</span>
<p className="text-xl font-semibold">{nearbySignals}</p>
</div>
<div className="rounded-2xl border border-border/60 bg-muted/50 p-3">
<span className="text-xs uppercase text-muted-foreground">{t('overview.stats.contributors')}</span>
<span className="text-xs uppercase text-muted-foreground">{t("overview.stats.contributors")}</span>
<p className="text-xl font-semibold">{uniqueContributors}</p>
</div>
</div>
{mySignalLabel && (
<Badge variant="secondary" className="w-full justify-center rounded-full py-2 text-xs uppercase">
{t('overview.badge', { time: mySignalLabel })}
{t("overview.badge", { time: mySignalLabel })}
</Badge>
)}
{errorMessage ? (
@@ -67,7 +67,7 @@ export function OverviewPanel({
<div className="space-y-2">
<p>{errorMessage}</p>
<Button variant="outline" size="sm" className="text-xs" onClick={onRetry}>
{t('overview.error.action')}
{t("overview.error.action")}
</Button>
</div>
</div>
@@ -75,17 +75,15 @@ export function OverviewPanel({
<p className="text-sm text-muted-foreground">{locationHint}</p>
)}
<Button className="w-full" onClick={onReport} disabled={isPosting || disableReport}>
{isPosting
? t('overview.cta.sending')
: disableReport
? t('overview.cta.waiting')
: t('overview.cta.send')}
{isPosting ? t("overview.cta.sending") : disableReport ? t("overview.cta.waiting") : t("overview.cta.send")}
</Button>
{showLocationCta && !errorMessage && (
<p className="text-xs text-muted-foreground">{t('overview.locationPermission')}</p>
<p className="text-xs text-muted-foreground">{t("overview.locationPermission")}</p>
)}
<p className="text-[11px] uppercase text-muted-foreground">{t('overview.lastSynced', { time: lastUpdatedLabel })}</p>
<p className="text-[11px] uppercase text-muted-foreground">
{t("overview.lastSynced", { time: lastUpdatedLabel })}
</p>
</CardContent>
</Card>
)
);
}
+40 -37
View File
@@ -1,13 +1,14 @@
import * as React from 'react'
import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog'
import * as React from "react";
import { cn } from '@/lib/utils'
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";
const AlertDialog = AlertDialogPrimitive.Root
import { cn } from "@/lib/utils";
const AlertDialogTrigger = AlertDialogPrimitive.Trigger
const AlertDialog = AlertDialogPrimitive.Root;
const AlertDialogPortal = AlertDialogPrimitive.Portal
const AlertDialogTrigger = AlertDialogPrimitive.Trigger;
const AlertDialogPortal = AlertDialogPrimitive.Portal;
const AlertDialogOverlay = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
@@ -16,13 +17,13 @@ const AlertDialogOverlay = React.forwardRef<
<AlertDialogPrimitive.Overlay
ref={ref}
className={cn(
'fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
className,
"fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}
/>
))
AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName
));
AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName;
const AlertDialogContent = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Content>,
@@ -33,44 +34,40 @@ const AlertDialogContent = React.forwardRef<
<AlertDialogPrimitive.Content
ref={ref}
className={cn(
'fixed left-[50%] top-[50%] z-50 grid w-full max-w-md translate-x-[-50%] translate-y-[-50%] gap-4 border border-border/70 bg-background p-6 shadow-sm duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg',
className,
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-md translate-x-[-50%] translate-y-[-50%] gap-4 border border-border/70 bg-background p-6 shadow-sm duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className
)}
{...props}
/>
</AlertDialogPortal>
))
AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName
));
AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName;
const AlertDialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn('flex flex-col space-y-2 text-center sm:text-left', className)} {...props} />
)
AlertDialogHeader.displayName = 'AlertDialogHeader'
<div className={cn("flex flex-col space-y-2 text-center sm:text-left", className)} {...props} />
);
AlertDialogHeader.displayName = "AlertDialogHeader";
const AlertDialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn('flex flex-col-reverse gap-2 sm:flex-row sm:justify-end', className)} {...props} />
)
AlertDialogFooter.displayName = 'AlertDialogFooter'
<div className={cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className)} {...props} />
);
AlertDialogFooter.displayName = "AlertDialogFooter";
const AlertDialogTitle = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Title ref={ref} className={cn('text-lg font-semibold', className)} {...props} />
))
AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName
<AlertDialogPrimitive.Title ref={ref} className={cn("text-lg font-semibold", className)} {...props} />
));
AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName;
const AlertDialogDescription = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Description
ref={ref}
className={cn('text-sm text-muted-foreground', className)}
{...props}
/>
))
AlertDialogDescription.displayName = AlertDialogPrimitive.Description.displayName
<AlertDialogPrimitive.Description ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
));
AlertDialogDescription.displayName = AlertDialogPrimitive.Description.displayName;
const AlertDialogAction = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Action>,
@@ -78,11 +75,14 @@ const AlertDialogAction = React.forwardRef<
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Action
ref={ref}
className={cn('inline-flex h-10 items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background disabled:pointer-events-none disabled:opacity-50', className)}
className={cn(
"inline-flex h-10 items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background disabled:pointer-events-none disabled:opacity-50",
className
)}
{...props}
/>
))
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName
));
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName;
const AlertDialogCancel = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
@@ -90,11 +90,14 @@ const AlertDialogCancel = React.forwardRef<
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Cancel
ref={ref}
className={cn('inline-flex h-10 items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-muted focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background disabled:pointer-events-none disabled:opacity-50 sm:mr-2', className)}
className={cn(
"inline-flex h-10 items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-muted focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background disabled:pointer-events-none disabled:opacity-50 sm:mr-2",
className
)}
{...props}
/>
))
AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName
));
AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName;
export {
AlertDialog,
@@ -106,4 +109,4 @@ export {
AlertDialogDescription,
AlertDialogAction,
AlertDialogCancel,
}
};
+20 -23
View File
@@ -1,36 +1,33 @@
import * as React from 'react'
import { cva, type VariantProps } from 'class-variance-authority'
import * as React from "react";
import { cn } from '@/lib/utils'
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
const badgeVariants = cva(
'inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
{
variants: {
variant: {
default: 'border-transparent bg-primary/15 text-primary',
secondary: 'border-transparent bg-secondary text-secondary-foreground',
destructive: 'border-transparent bg-destructive/15 text-destructive',
outline: 'text-foreground',
success: 'border-transparent bg-emerald-500/15 text-emerald-300',
muted: 'border-transparent bg-muted/60 text-muted-foreground',
default: "border-transparent bg-primary/15 text-primary",
secondary: "border-transparent bg-secondary text-secondary-foreground",
destructive: "border-transparent bg-destructive/15 text-destructive",
outline: "text-foreground",
success: "border-transparent bg-emerald-500/15 text-emerald-300",
muted: "border-transparent bg-muted/60 text-muted-foreground",
},
},
defaultVariants: {
variant: 'default',
variant: "default",
},
},
)
}
);
export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}
export interface BadgeProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof badgeVariants> {}
const Badge = React.forwardRef<HTMLDivElement, BadgeProps>(
({ className, variant, ...props }, ref) => (
<div ref={ref} className={cn(badgeVariants({ variant }), className)} {...props} />
),
)
Badge.displayName = 'Badge'
const Badge = React.forwardRef<HTMLDivElement, BadgeProps>(({ className, variant, ...props }, ref) => (
<div ref={ref} className={cn(badgeVariants({ variant }), className)} {...props} />
));
Badge.displayName = "Badge";
export { Badge }
export { Badge };
+25 -28
View File
@@ -1,48 +1,45 @@
import * as React from 'react'
import { Slot } from '@radix-ui/react-slot'
import { cva, type VariantProps } from 'class-variance-authority'
import * as React from "react";
import { cn } from '@/lib/utils'
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
const buttonVariants = cva(
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 focus-visible:ring-offset-background',
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 focus-visible:ring-offset-background",
{
variants: {
variant: {
default: 'bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm',
secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
ghost: 'hover:bg-accent hover:text-accent-foreground',
outline:
'border border-input bg-transparent hover:bg-accent hover:text-accent-foreground shadow-sm',
destructive:
'bg-destructive text-destructive-foreground hover:bg-destructive/90 shadow-sm',
default: "bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm",
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
outline: "border border-input bg-transparent hover:bg-accent hover:text-accent-foreground shadow-sm",
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90 shadow-sm",
},
size: {
default: 'h-10 px-4 py-2',
sm: 'h-9 rounded-md px-3',
lg: 'h-11 rounded-md px-5 text-base',
icon: 'h-10 w-10',
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
lg: "h-11 rounded-md px-5 text-base",
icon: "h-10 w-10",
},
},
defaultVariants: {
variant: 'default',
size: 'default',
variant: "default",
size: "default",
},
},
)
}
);
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
asChild?: boolean;
}
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : 'button'
return (
<Comp className={cn(buttonVariants({ variant, size }), className)} ref={ref} {...props} />
)
},
)
Button.displayName = 'Button'
const Comp = asChild ? Slot : "button";
return <Comp className={cn(buttonVariants({ variant, size }), className)} ref={ref} {...props} />;
}
);
Button.displayName = "Button";
+33 -37
View File
@@ -1,54 +1,50 @@
import * as React from 'react'
import * as React from "react";
import { cn } from '@/lib/utils'
import { cn } from "@/lib/utils";
const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
'rounded-xl border border-border/60 bg-card/80 text-card-foreground shadow-sm backdrop-blur',
className,
)}
{...props}
/>
),
)
Card.displayName = 'Card'
const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"rounded-xl border border-border/60 bg-card/80 text-card-foreground shadow-sm backdrop-blur",
className
)}
{...props}
/>
));
Card.displayName = "Card";
const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn('flex flex-col space-y-1.5 p-6', className)} {...props} />
),
)
CardHeader.displayName = 'CardHeader'
<div ref={ref} className={cn("flex flex-col space-y-1.5 p-6", className)} {...props} />
)
);
CardHeader.displayName = "CardHeader";
const CardTitle = React.forwardRef<HTMLHeadingElement, React.HTMLAttributes<HTMLHeadingElement>>(
({ className, ...props }, ref) => (
<h3 ref={ref} className={cn('text-lg font-semibold leading-none tracking-tight', className)} {...props} />
),
)
CardTitle.displayName = 'CardTitle'
<h3 ref={ref} className={cn("text-lg font-semibold leading-none tracking-tight", className)} {...props} />
)
);
CardTitle.displayName = "CardTitle";
const CardDescription = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
({ className, ...props }, ref) => (
<p ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
),
)
CardDescription.displayName = 'CardDescription'
<p ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
)
);
CardDescription.displayName = "CardDescription";
const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn('p-6 pt-0', className)} {...props} />
),
)
CardContent.displayName = 'CardContent'
({ className, ...props }, ref) => <div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
);
CardContent.displayName = "CardContent";
const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn('flex items-center p-6 pt-0 text-sm text-muted-foreground', className)} {...props} />
),
)
CardFooter.displayName = 'CardFooter'
<div ref={ref} className={cn("flex items-center p-6 pt-0 text-sm text-muted-foreground", className)} {...props} />
)
);
CardFooter.displayName = "CardFooter";
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle }
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle };
+16 -17
View File
@@ -1,40 +1,39 @@
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area'
import * as React from 'react'
import * as React from "react";
import { cn } from '@/lib/utils'
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
import { cn } from "@/lib/utils";
const ScrollArea = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
>(({ className, children, ...props }, ref) => (
<ScrollAreaPrimitive.Root ref={ref} className={cn('relative overflow-hidden', className)} {...props}>
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
{children}
</ScrollAreaPrimitive.Viewport>
<ScrollAreaPrimitive.Root ref={ref} className={cn("relative overflow-hidden", className)} {...props}>
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">{children}</ScrollAreaPrimitive.Viewport>
<ScrollBar />
<ScrollAreaPrimitive.Corner />
</ScrollAreaPrimitive.Root>
))
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName
));
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
const ScrollBar = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
>(({ className, orientation = 'vertical', ...props }, ref) => (
>(({ className, orientation = "vertical", ...props }, ref) => (
<ScrollAreaPrimitive.ScrollAreaScrollbar
ref={ref}
orientation={orientation}
className={cn(
'flex touch-none select-none transition-colors',
orientation === 'vertical' && 'h-full w-2 border-l border-l-transparent p-[1px]',
orientation === 'horizontal' && 'h-2 border-t border-t-transparent p-[1px]',
className,
"flex touch-none select-none transition-colors",
orientation === "vertical" && "h-full w-2 border-l border-l-transparent p-[1px]",
orientation === "horizontal" && "h-2 border-t border-t-transparent p-[1px]",
className
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border/60" />
</ScrollAreaPrimitive.ScrollAreaScrollbar>
))
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName
));
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName;
export { ScrollArea, ScrollBar }
export { ScrollArea, ScrollBar };
+8 -12
View File
@@ -1,22 +1,18 @@
import * as React from 'react'
import * as React from "react";
import { cn } from '@/lib/utils'
import { cn } from "@/lib/utils";
const Separator = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement> & { orientation?: 'horizontal' | 'vertical' }
>(({ className, orientation = 'horizontal', ...props }, ref) => (
React.HTMLAttributes<HTMLDivElement> & { orientation?: "horizontal" | "vertical" }
>(({ className, orientation = "horizontal", ...props }, ref) => (
<div
ref={ref}
className={cn(
'shrink-0 bg-border/60',
orientation === 'horizontal' ? 'h-px w-full' : 'h-full w-px',
className,
)}
className={cn("shrink-0 bg-border/60", orientation === "horizontal" ? "h-px w-full" : "h-full w-px", className)}
role="none"
{...props}
/>
))
Separator.displayName = 'Separator'
));
Separator.displayName = "Separator";
export { Separator }
export { Separator };
+58 -58
View File
@@ -1,16 +1,17 @@
import * as React from 'react'
import * as SheetPrimitive from '@radix-ui/react-dialog'
import { useTranslation } from 'react-i18next'
import * as React from "react";
import { cn } from '@/lib/utils'
import * as SheetPrimitive from "@radix-ui/react-dialog";
import { useTranslation } from "react-i18next";
const Sheet = SheetPrimitive.Root
import { cn } from "@/lib/utils";
const SheetTrigger = SheetPrimitive.Trigger
const Sheet = SheetPrimitive.Root;
const SheetClose = SheetPrimitive.Close
const SheetTrigger = SheetPrimitive.Trigger;
const SheetPortal = SheetPrimitive.Portal
const SheetClose = SheetPrimitive.Close;
const SheetPortal = SheetPrimitive.Portal;
const SheetOverlay = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Overlay>,
@@ -18,79 +19,78 @@ const SheetOverlay = React.forwardRef<
>(({ className, ...props }, ref) => (
<SheetPrimitive.Overlay
className={cn(
'fixed inset-0 z-40 bg-background/60 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
className,
"fixed inset-0 z-40 bg-background/60 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}
ref={ref}
/>
))
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName
));
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;
type SheetSide = 'top' | 'bottom' | 'left' | 'right'
type SheetSide = "top" | "bottom" | "left" | "right";
interface SheetContentProps extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content> {
side?: SheetSide
side?: SheetSide;
}
const SheetContent = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Content>,
SheetContentProps
>(({ side = 'bottom', className, children, ...props }, ref) => {
const { t } = useTranslation()
const SheetContent = React.forwardRef<React.ElementRef<typeof SheetPrimitive.Content>, SheetContentProps>(
({ side = "bottom", className, children, ...props }, ref) => {
const { t } = useTranslation();
return (
<SheetPortal>
<SheetOverlay />
<SheetPrimitive.Content
ref={ref}
className={cn(
'fixed z-50 grid gap-4 bg-background p-6 shadow-sm transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out',
side === 'bottom' && 'inset-x-0 bottom-0 rounded-t-2xl border-t',
side === 'top' && 'inset-x-0 top-0 rounded-b-2xl border-b',
side === 'left' && 'inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm',
side === 'right' && 'inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm',
className,
)}
data-side={side}
{...props}
>
{children}
<SheetPrimitive.Close className="absolute right-6 top-6 rounded-full border border-border/50 bg-background/60 px-3 py-1 text-xs font-medium text-muted-foreground transition hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background">
{t('common.actions.close')}
<span className="sr-only">{t('common.aria.sheet.close')}</span>
</SheetPrimitive.Close>
</SheetPrimitive.Content>
</SheetPortal>
)
})
SheetContent.displayName = SheetPrimitive.Content.displayName
return (
<SheetPortal>
<SheetOverlay />
<SheetPrimitive.Content
ref={ref}
className={cn(
"fixed z-50 grid gap-4 bg-background p-6 shadow-sm transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out",
side === "bottom" && "inset-x-0 bottom-0 rounded-t-2xl border-t",
side === "top" && "inset-x-0 top-0 rounded-b-2xl border-b",
side === "left" && "inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",
side === "right" && "inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",
className
)}
data-side={side}
{...props}
>
{children}
<SheetPrimitive.Close className="absolute right-6 top-6 rounded-full border border-border/50 bg-background/60 px-3 py-1 text-xs font-medium text-muted-foreground transition hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background">
{t("common.actions.close")}
<span className="sr-only">{t("common.aria.sheet.close")}</span>
</SheetPrimitive.Close>
</SheetPrimitive.Content>
</SheetPortal>
);
}
);
SheetContent.displayName = SheetPrimitive.Content.displayName;
const SheetHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn('flex flex-col space-y-2 text-center sm:text-left', className)} {...props} />
)
SheetHeader.displayName = 'SheetHeader'
<div className={cn("flex flex-col space-y-2 text-center sm:text-left", className)} {...props} />
);
SheetHeader.displayName = "SheetHeader";
const SheetFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn('flex flex-col-reverse gap-2 sm:flex-row sm:justify-end', className)} {...props} />
)
SheetFooter.displayName = 'SheetFooter'
<div className={cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className)} {...props} />
);
SheetFooter.displayName = "SheetFooter";
const SheetTitle = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Title ref={ref} className={cn('text-lg font-semibold', className)} {...props} />
))
SheetTitle.displayName = SheetPrimitive.Title.displayName
<SheetPrimitive.Title ref={ref} className={cn("text-lg font-semibold", className)} {...props} />
));
SheetTitle.displayName = SheetPrimitive.Title.displayName;
const SheetDescription = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
))
SheetDescription.displayName = SheetPrimitive.Description.displayName
<SheetPrimitive.Description ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
));
SheetDescription.displayName = SheetPrimitive.Description.displayName;
export {
Sheet,
@@ -103,4 +103,4 @@ export {
SheetFooter,
SheetTitle,
SheetDescription,
}
};
+20 -16
View File
@@ -1,9 +1,10 @@
import * as TabsPrimitive from '@radix-ui/react-tabs'
import * as React from 'react'
import * as React from "react";
import { cn } from '@/lib/utils'
import * as TabsPrimitive from "@radix-ui/react-tabs";
const Tabs = TabsPrimitive.Root
import { cn } from "@/lib/utils";
const Tabs = TabsPrimitive.Root;
const TabsList = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.List>,
@@ -11,11 +12,14 @@ const TabsList = React.forwardRef<
>(({ className, ...props }, ref) => (
<TabsPrimitive.List
ref={ref}
className={cn('inline-flex h-10 items-center justify-center rounded-full bg-muted p-1 text-muted-foreground', className)}
className={cn(
"inline-flex h-10 items-center justify-center rounded-full bg-muted p-1 text-muted-foreground",
className
)}
{...props}
/>
))
TabsList.displayName = TabsPrimitive.List.displayName
));
TabsList.displayName = TabsPrimitive.List.displayName;
const TabsTrigger = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Trigger>,
@@ -24,13 +28,13 @@ const TabsTrigger = React.forwardRef<
<TabsPrimitive.Trigger
ref={ref}
className={cn(
'inline-flex min-w-[120px] items-center justify-center whitespace-nowrap rounded-full px-4 py-1.5 text-sm font-medium transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=inactive]:opacity-70',
className,
"inline-flex min-w-[120px] items-center justify-center whitespace-nowrap rounded-full px-4 py-1.5 text-sm font-medium transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=inactive]:opacity-70",
className
)}
{...props}
/>
))
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
));
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName;
const TabsContent = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Content>,
@@ -39,12 +43,12 @@ const TabsContent = React.forwardRef<
<TabsPrimitive.Content
ref={ref}
className={cn(
'mt-4 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
className,
"mt-4 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
className
)}
{...props}
/>
))
TabsContent.displayName = TabsPrimitive.Content.displayName
));
TabsContent.displayName = TabsPrimitive.Content.displayName;
export { Tabs, TabsList, TabsTrigger, TabsContent }
export { Tabs, TabsList, TabsTrigger, TabsContent };
+41 -48
View File
@@ -1,11 +1,12 @@
import * as React from 'react'
import * as ToastPrimitives from '@radix-ui/react-toast'
import { cva, type VariantProps } from 'class-variance-authority'
import { X } from 'lucide-react'
import * as React from "react";
import { cn } from '@/lib/utils'
import * as ToastPrimitives from "@radix-ui/react-toast";
import { cva, type VariantProps } from "class-variance-authority";
import { X } from "lucide-react";
const ToastProvider = ToastPrimitives.Provider
import { cn } from "@/lib/utils";
const ToastProvider = ToastPrimitives.Provider;
const ToastViewport = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Viewport>,
@@ -14,28 +15,28 @@ const ToastViewport = React.forwardRef<
<ToastPrimitives.Viewport
ref={ref}
className={cn(
'fixed inset-x-0 top-4 z-[1000] mx-auto flex w-full max-w-sm flex-col gap-2 px-4 sm:right-4 sm:left-auto sm:mx-0 sm:w-96',
className,
"fixed inset-x-0 top-4 z-[1000] mx-auto flex w-full max-w-sm flex-col gap-2 px-4 sm:right-4 sm:left-auto sm:mx-0 sm:w-96",
className
)}
{...props}
/>
))
ToastViewport.displayName = ToastPrimitives.Viewport.displayName
));
ToastViewport.displayName = ToastPrimitives.Viewport.displayName;
const toastVariants = cva(
'group pointer-events-auto relative flex w-full items-start gap-3 overflow-hidden rounded-2xl border border-border bg-background p-4 shadow-lg transition-all',
"group pointer-events-auto relative flex w-full items-start gap-3 overflow-hidden rounded-2xl border border-border bg-background p-4 shadow-lg transition-all",
{
variants: {
variant: {
default: 'bg-background text-foreground',
destructive: 'border-destructive/60 bg-destructive text-destructive-foreground',
default: "bg-background text-foreground",
destructive: "border-destructive/60 bg-destructive text-destructive-foreground",
},
},
defaultVariants: {
variant: 'default',
variant: "default",
},
},
)
}
);
const Toast = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Root>,
@@ -45,9 +46,9 @@ const Toast = React.forwardRef<
<ToastPrimitives.Root ref={ref} className={cn(toastVariants({ variant }), className)} {...props}>
{props.children}
</ToastPrimitives.Root>
)
})
Toast.displayName = ToastPrimitives.Root.displayName
);
});
Toast.displayName = ToastPrimitives.Root.displayName;
const ToastAction = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Action>,
@@ -56,13 +57,13 @@ const ToastAction = React.forwardRef<
<ToastPrimitives.Action
ref={ref}
className={cn(
'inline-flex h-8 shrink-0 items-center justify-center rounded-full border border-border/60 bg-background px-3 text-xs font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
className,
"inline-flex h-8 shrink-0 items-center justify-center rounded-full border border-border/60 bg-background px-3 text-xs font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
className
)}
{...props}
/>
))
ToastAction.displayName = ToastPrimitives.Action.displayName
));
ToastAction.displayName = ToastPrimitives.Action.displayName;
const ToastClose = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Close>,
@@ -71,46 +72,38 @@ const ToastClose = React.forwardRef<
<ToastPrimitives.Close
ref={ref}
className={cn(
'absolute right-3 top-3 rounded-full p-1 text-foreground/70 transition-colors hover:bg-foreground/10 hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
className,
"absolute right-3 top-3 rounded-full p-1 text-foreground/70 transition-colors hover:bg-foreground/10 hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
className
)}
toast-close=""
{...props}
>
<X className="h-4 w-4" />
</ToastPrimitives.Close>
))
ToastClose.displayName = ToastPrimitives.Close.displayName
));
ToastClose.displayName = ToastPrimitives.Close.displayName;
const ToastTitle = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Title>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Title ref={ref} className={cn('text-sm font-semibold leading-none tracking-tight', className)} {...props} />
))
ToastTitle.displayName = ToastPrimitives.Title.displayName
<ToastPrimitives.Title
ref={ref}
className={cn("text-sm font-semibold leading-none tracking-tight", className)}
{...props}
/>
));
ToastTitle.displayName = ToastPrimitives.Title.displayName;
const ToastDescription = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Description>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Description
ref={ref}
className={cn('text-sm text-muted-foreground', className)}
{...props}
/>
))
ToastDescription.displayName = ToastPrimitives.Description.displayName
<ToastPrimitives.Description ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
));
ToastDescription.displayName = ToastPrimitives.Description.displayName;
export type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
export type ToastActionElement = React.ReactElement<typeof ToastAction>
export type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;
export type ToastActionElement = React.ReactElement<typeof ToastAction>;
export {
ToastProvider,
ToastViewport,
Toast,
ToastTitle,
ToastDescription,
ToastClose,
ToastAction,
}
export { ToastProvider, ToastViewport, Toast, ToastTitle, ToastDescription, ToastClose, ToastAction };
+6 -13
View File
@@ -1,15 +1,8 @@
import {
Toast,
ToastClose,
ToastDescription,
ToastProvider,
ToastTitle,
ToastViewport,
} from '@/components/ui/toast'
import { useToast } from '@/components/ui/use-toast'
import { Toast, ToastClose, ToastDescription, ToastProvider, ToastTitle, ToastViewport } from "@/components/ui/toast";
import { useToast } from "@/components/ui/use-toast";
export function Toaster() {
const { toasts, dismiss } = useToast()
const { toasts, dismiss } = useToast();
return (
<ToastProvider>
@@ -17,9 +10,9 @@ export function Toaster() {
<Toast
key={id}
{...props}
onOpenChange={(open) => {
onOpenChange={open => {
if (!open) {
dismiss(id)
dismiss(id);
}
}}
>
@@ -33,5 +26,5 @@ export function Toaster() {
))}
<ToastViewport />
</ToastProvider>
)
);
}
+63 -67
View File
@@ -1,129 +1,125 @@
import * as React from 'react'
import * as React from "react";
import type { ToastActionElement, ToastProps } from '@/components/ui/toast'
import type { ToastActionElement, ToastProps } from "@/components/ui/toast";
type ToasterToast = ToastProps & {
id: string
title?: React.ReactNode
description?: React.ReactNode
action?: ToastActionElement
}
id: string;
title?: React.ReactNode;
description?: React.ReactNode;
action?: ToastActionElement;
};
type ToastState = {
toasts: ToasterToast[]
}
toasts: ToasterToast[];
};
type ToastAction =
| { type: 'ADD_TOAST'; toast: ToasterToast }
| { type: 'UPDATE_TOAST'; toast: Partial<ToasterToast> & { id: string } }
| { type: 'DISMISS_TOAST'; toastId?: string }
| { type: 'REMOVE_TOAST'; toastId?: string }
| { type: "ADD_TOAST"; toast: ToasterToast }
| { type: "UPDATE_TOAST"; toast: Partial<ToasterToast> & { id: string } }
| { type: "DISMISS_TOAST"; toastId?: string }
| { type: "REMOVE_TOAST"; toastId?: string };
const TOAST_LIMIT = 5
const TOAST_REMOVE_DELAY = 1000
const TOAST_LIMIT = 5;
const TOAST_REMOVE_DELAY = 1000;
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>();
const listeners = new Set<(state: ToastState) => void>()
const listeners = new Set<(state: ToastState) => void>();
let memoryState: ToastState = { toasts: [] }
let memoryState: ToastState = { toasts: [] };
function dispatch(action: ToastAction) {
memoryState = reducer(memoryState, action)
listeners.forEach((listener) => {
listener(memoryState)
})
memoryState = reducer(memoryState, action);
listeners.forEach(listener => {
listener(memoryState);
});
}
function reducer(state: ToastState, action: ToastAction): ToastState {
switch (action.type) {
case 'ADD_TOAST': {
case "ADD_TOAST": {
return {
...state,
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
}
};
}
case 'UPDATE_TOAST': {
case "UPDATE_TOAST": {
return {
...state,
toasts: state.toasts.map((toast) =>
toast.id === action.toast.id ? { ...toast, ...action.toast } : toast,
),
}
toasts: state.toasts.map(toast => (toast.id === action.toast.id ? { ...toast, ...action.toast } : toast)),
};
}
case 'DISMISS_TOAST': {
const { toastId } = action
case "DISMISS_TOAST": {
const { toastId } = action;
if (toastId) {
addToRemoveQueue(toastId)
addToRemoveQueue(toastId);
} else {
state.toasts.forEach((toast) => {
addToRemoveQueue(toast.id)
})
state.toasts.forEach(toast => {
addToRemoveQueue(toast.id);
});
}
return {
...state,
toasts: state.toasts.map((toast) =>
toast.id === toastId || toastId === undefined
? { ...toast, open: false }
: toast,
toasts: state.toasts.map(toast =>
toast.id === toastId || toastId === undefined ? { ...toast, open: false } : toast
),
}
};
}
case 'REMOVE_TOAST': {
case "REMOVE_TOAST": {
if (action.toastId === undefined) {
return { ...state, toasts: [] }
return { ...state, toasts: [] };
}
return {
...state,
toasts: state.toasts.filter((toast) => toast.id !== action.toastId),
}
toasts: state.toasts.filter(toast => toast.id !== action.toastId),
};
}
default:
return state
return state;
}
}
function addToRemoveQueue(toastId: string) {
if (toastTimeouts.has(toastId)) {
return
return;
}
const timeout = setTimeout(() => {
toastTimeouts.delete(toastId)
dispatch({ type: 'REMOVE_TOAST', toastId })
}, TOAST_REMOVE_DELAY)
toastTimeouts.delete(toastId);
dispatch({ type: "REMOVE_TOAST", toastId });
}, TOAST_REMOVE_DELAY);
toastTimeouts.set(toastId, timeout)
toastTimeouts.set(toastId, timeout);
}
function genId() {
return Math.random().toString(36).slice(2, 10)
return Math.random().toString(36).slice(2, 10);
}
export function useToast() {
const [state, setState] = React.useState<ToastState>(memoryState)
const [state, setState] = React.useState<ToastState>(memoryState);
React.useEffect(() => {
listeners.add(setState)
listeners.add(setState);
return () => {
listeners.delete(setState)
}
}, [])
listeners.delete(setState);
};
}, []);
return {
...state,
toast: (props: Omit<ToasterToast, 'id'>) => {
const id = genId()
dispatch({ type: 'ADD_TOAST', toast: { ...props, id, open: true } })
return id
toast: (props: Omit<ToasterToast, "id">) => {
const id = genId();
dispatch({ type: "ADD_TOAST", toast: { ...props, id, open: true } });
return id;
},
dismiss: (toastId?: string) => dispatch({ type: 'DISMISS_TOAST', toastId }),
}
dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
};
}
export const toast = (props: Omit<ToasterToast, 'id'>) => {
const id = genId()
dispatch({ type: 'ADD_TOAST', toast: { ...props, id, open: true } })
return id
}
export const toast = (props: Omit<ToasterToast, "id">) => {
const id = genId();
dispatch({ type: "ADD_TOAST", toast: { ...props, id, open: true } });
return id;
};