@orsetra/shared-ui 1.0.22 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,131 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { cva, type VariantProps } from "class-variance-authority"
5
+ import { X, CheckCircle, AlertCircle, AlertTriangle, Info } from "lucide-react"
6
+ import { cn } from "../../lib/utils"
7
+
8
+ const alertBannerVariants = cva(
9
+ "relative w-full flex items-center gap-3 px-4 py-3 text-sm font-medium transition-all duration-300",
10
+ {
11
+ variants: {
12
+ variant: {
13
+ success: "bg-green-50 text-green-800 border-b border-green-200",
14
+ error: "bg-red-50 text-red-800 border-b border-red-200",
15
+ warning: "bg-amber-50 text-amber-800 border-b border-amber-200",
16
+ info: "bg-blue-50 text-blue-800 border-b border-blue-200",
17
+ },
18
+ },
19
+ defaultVariants: {
20
+ variant: "info",
21
+ },
22
+ }
23
+ )
24
+
25
+ const iconMap = {
26
+ success: CheckCircle,
27
+ error: AlertCircle,
28
+ warning: AlertTriangle,
29
+ info: Info,
30
+ }
31
+
32
+ export interface AlertBannerProps
33
+ extends React.HTMLAttributes<HTMLDivElement>,
34
+ VariantProps<typeof alertBannerVariants> {
35
+ message: string
36
+ onClose?: () => void
37
+ closable?: boolean
38
+ icon?: React.ReactNode
39
+ }
40
+
41
+ const AlertBanner = React.forwardRef<HTMLDivElement, AlertBannerProps>(
42
+ ({ className, variant = "info", message, onClose, closable = true, icon, ...props }, ref) => {
43
+ const Icon = iconMap[variant || "info"]
44
+
45
+ return (
46
+ <div
47
+ ref={ref}
48
+ role="alert"
49
+ className={cn(alertBannerVariants({ variant }), className)}
50
+ {...props}
51
+ >
52
+ {icon || <Icon className="h-5 w-5 flex-shrink-0" />}
53
+ <span className="flex-1">{message}</span>
54
+ {closable && onClose && (
55
+ <button
56
+ onClick={onClose}
57
+ className="flex-shrink-0 p-1 rounded-md hover:bg-black/5 transition-colors"
58
+ aria-label="Fermer"
59
+ >
60
+ <X className="h-4 w-4" />
61
+ </button>
62
+ )}
63
+ </div>
64
+ )
65
+ }
66
+ )
67
+ AlertBanner.displayName = "AlertBanner"
68
+
69
+ // Hook pour gérer les alertes
70
+ export interface AlertState {
71
+ show: boolean
72
+ variant: "success" | "error" | "warning" | "info"
73
+ message: string
74
+ }
75
+
76
+ export function useAlertBanner() {
77
+ const [alert, setAlert] = React.useState<AlertState>({
78
+ show: false,
79
+ variant: "info",
80
+ message: "",
81
+ })
82
+
83
+ const showAlert = React.useCallback(
84
+ (variant: AlertState["variant"], message: string, duration = 5000) => {
85
+ setAlert({ show: true, variant, message })
86
+
87
+ if (duration > 0) {
88
+ setTimeout(() => {
89
+ setAlert((prev) => ({ ...prev, show: false }))
90
+ }, duration)
91
+ }
92
+ },
93
+ []
94
+ )
95
+
96
+ const hideAlert = React.useCallback(() => {
97
+ setAlert((prev) => ({ ...prev, show: false }))
98
+ }, [])
99
+
100
+ const showSuccess = React.useCallback(
101
+ (message: string, duration?: number) => showAlert("success", message, duration),
102
+ [showAlert]
103
+ )
104
+
105
+ const showError = React.useCallback(
106
+ (message: string, duration?: number) => showAlert("error", message, duration),
107
+ [showAlert]
108
+ )
109
+
110
+ const showWarning = React.useCallback(
111
+ (message: string, duration?: number) => showAlert("warning", message, duration),
112
+ [showAlert]
113
+ )
114
+
115
+ const showInfo = React.useCallback(
116
+ (message: string, duration?: number) => showAlert("info", message, duration),
117
+ [showAlert]
118
+ )
119
+
120
+ return {
121
+ alert,
122
+ showAlert,
123
+ hideAlert,
124
+ showSuccess,
125
+ showError,
126
+ showWarning,
127
+ showInfo,
128
+ }
129
+ }
130
+
131
+ export { AlertBanner }
@@ -21,6 +21,7 @@ export { ImageCropDialog } from './image-crop-dialog'
21
21
  export { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from './accordion'
22
22
  export { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogAction, AlertDialogCancel } from './alert-dialog'
23
23
  export { Alert, AlertTitle, AlertDescription } from './alert'
24
+ export { AlertBanner, useAlertBanner, type AlertBannerProps, type AlertState } from './alert-banner'
24
25
  export { AspectRatio } from './aspect-ratio'
25
26
  export { Badge } from './badge'
26
27
  export { Breadcrumb, BreadcrumbList, BreadcrumbItem, BreadcrumbLink, BreadcrumbPage, BreadcrumbSeparator, BreadcrumbEllipsis } from './breadcrumb'
@@ -89,6 +89,14 @@ class HttpClient {
89
89
  });
90
90
  }
91
91
 
92
+ async patch<T>(url: string, body?: any, options: RequestInit = {}): Promise<T | null> {
93
+ return this.request<T>(url, {
94
+ ...options,
95
+ method: 'PATCH',
96
+ body: body ? JSON.stringify(body) : undefined
97
+ });
98
+ }
99
+
92
100
  async delete<T>(url: string, options: RequestInit = {}): Promise<T | null> {
93
101
  return this.request<T>(url, {
94
102
  ...options,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orsetra/shared-ui",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "Shared UI components for Orsetra platform",
5
5
  "main": "./index.ts",
6
6
  "types": "./index.ts",
@@ -92,4 +92,4 @@
92
92
  "next": "^16.0.7",
93
93
  "typescript": "^5"
94
94
  }
95
- }
95
+ }