@contractspec/lib.ui-kit-web 3.4.0 → 3.4.2

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.
@@ -1,5 +1,190 @@
1
1
  // @bun
2
2
  var __require = import.meta.require;
3
+
4
+ // ui/button.tsx
5
+ import { Slot } from "@radix-ui/react-slot";
6
+ import { cva } from "class-variance-authority";
7
+ import { cn } from "@contractspec/lib.ui-kit-core/utils";
8
+ import { jsxDEV } from "react/jsx-dev-runtime";
9
+ var buttonVariants = cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-hidden focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive", {
10
+ variants: {
11
+ variant: {
12
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
13
+ destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
14
+ outline: "border bg-background shadow-2xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
15
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
16
+ ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
17
+ link: "text-primary underline-offset-4 hover:underline"
18
+ },
19
+ size: {
20
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
21
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
22
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
23
+ icon: "size-9"
24
+ }
25
+ },
26
+ defaultVariants: {
27
+ variant: "default",
28
+ size: "default"
29
+ }
30
+ });
31
+ function Button({
32
+ className,
33
+ variant,
34
+ size,
35
+ asChild = false,
36
+ ref,
37
+ ...props
38
+ }) {
39
+ if (asChild) {
40
+ return /* @__PURE__ */ jsxDEV(Slot, {
41
+ "data-slot": "button",
42
+ className: cn(buttonVariants({ variant, size, className })),
43
+ ...props
44
+ }, undefined, false, undefined, this);
45
+ }
46
+ return /* @__PURE__ */ jsxDEV("button", {
47
+ ref,
48
+ "data-slot": "button",
49
+ className: cn(buttonVariants({ variant, size, className })),
50
+ ...props
51
+ }, undefined, false, undefined, this);
52
+ }
53
+ // ui/organisms/ErrorBoundary/ErrorBoundary.tsx
54
+ import React from "react";
55
+ import { AlertTriangle, RefreshCw, Home } from "lucide-react";
56
+ import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
57
+ "use client";
58
+ var DefaultErrorFallback = ({
59
+ error,
60
+ errorId,
61
+ resetError
62
+ }) => {
63
+ const isDevelopment = true;
64
+ return /* @__PURE__ */ jsxDEV2("div", {
65
+ className: "flex min-h-screen items-center justify-center bg-gray-50 px-4",
66
+ children: /* @__PURE__ */ jsxDEV2("div", {
67
+ className: "w-full max-w-md rounded-lg bg-white p-6 text-center shadow-lg",
68
+ children: [
69
+ /* @__PURE__ */ jsxDEV2("div", {
70
+ className: "mb-4 flex justify-center",
71
+ children: /* @__PURE__ */ jsxDEV2(AlertTriangle, {
72
+ className: "h-12 w-12 text-red-500"
73
+ }, undefined, false, undefined, this)
74
+ }, undefined, false, undefined, this),
75
+ /* @__PURE__ */ jsxDEV2("h1", {
76
+ className: "mb-2 text-2xl font-semibold text-gray-900",
77
+ children: "Une erreur s'est produite"
78
+ }, undefined, false, undefined, this),
79
+ /* @__PURE__ */ jsxDEV2("p", {
80
+ className: "mb-6 text-gray-600",
81
+ children: "Nous nous excusons pour ce d\xE9sagr\xE9ment. Notre \xE9quipe a \xE9t\xE9 notifi\xE9e et travaille \xE0 r\xE9soudre le probl\xE8me."
82
+ }, undefined, false, undefined, this),
83
+ isDevelopment && /* @__PURE__ */ jsxDEV2("div", {
84
+ className: "mb-6 rounded-md bg-red-50 p-4 text-left",
85
+ children: [
86
+ /* @__PURE__ */ jsxDEV2("p", {
87
+ className: "mb-2 text-base font-medium text-red-800",
88
+ children: "Erreur de d\xE9veloppement:"
89
+ }, undefined, false, undefined, this),
90
+ /* @__PURE__ */ jsxDEV2("p", {
91
+ className: "font-mono text-sm break-all text-red-700",
92
+ children: error.message
93
+ }, undefined, false, undefined, this),
94
+ errorId && /* @__PURE__ */ jsxDEV2("p", {
95
+ className: "mt-2 text-sm text-red-600",
96
+ children: [
97
+ "ID: ",
98
+ errorId
99
+ ]
100
+ }, undefined, true, undefined, this)
101
+ ]
102
+ }, undefined, true, undefined, this),
103
+ /* @__PURE__ */ jsxDEV2("div", {
104
+ className: "flex flex-col justify-center gap-3 sm:flex-row",
105
+ children: [
106
+ /* @__PURE__ */ jsxDEV2(Button, {
107
+ onClick: resetError,
108
+ className: "flex items-center gap-2",
109
+ children: [
110
+ /* @__PURE__ */ jsxDEV2(RefreshCw, {
111
+ className: "h-4 w-4"
112
+ }, undefined, false, undefined, this),
113
+ "R\xE9essayer"
114
+ ]
115
+ }, undefined, true, undefined, this),
116
+ /* @__PURE__ */ jsxDEV2(Button, {
117
+ onClick: () => window.location.href = "/",
118
+ variant: "secondary",
119
+ className: "flex items-center gap-2",
120
+ children: [
121
+ /* @__PURE__ */ jsxDEV2(Home, {
122
+ className: "h-4 w-4"
123
+ }, undefined, false, undefined, this),
124
+ "Accueil"
125
+ ]
126
+ }, undefined, true, undefined, this)
127
+ ]
128
+ }, undefined, true, undefined, this),
129
+ !isDevelopment && errorId && /* @__PURE__ */ jsxDEV2("p", {
130
+ className: "mt-4 text-sm text-gray-500",
131
+ children: [
132
+ "Code d'erreur: ",
133
+ errorId
134
+ ]
135
+ }, undefined, true, undefined, this)
136
+ ]
137
+ }, undefined, true, undefined, this)
138
+ }, undefined, false, undefined, this);
139
+ };
140
+
141
+ class ErrorBoundary extends React.Component {
142
+ constructor(props) {
143
+ super(props);
144
+ this.state = {
145
+ hasError: false,
146
+ error: null,
147
+ errorId: null
148
+ };
149
+ }
150
+ static getDerivedStateFromError(error) {
151
+ return {
152
+ hasError: true,
153
+ error
154
+ };
155
+ }
156
+ componentDidCatch(error, errorInfo) {
157
+ const errorId = `err_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
158
+ this.setState({ errorId });
159
+ this.props.onError?.(error, errorInfo);
160
+ if (true) {
161
+ console.error("ErrorBoundary caught an error:", error, errorInfo);
162
+ }
163
+ }
164
+ resetError = () => {
165
+ this.setState({
166
+ hasError: false,
167
+ error: null,
168
+ errorId: null
169
+ });
170
+ };
171
+ render() {
172
+ if (this.state.hasError && this.state.error) {
173
+ const FallbackComponent = this.props.fallback || DefaultErrorFallback;
174
+ return /* @__PURE__ */ jsxDEV2(FallbackComponent, {
175
+ error: this.state.error,
176
+ errorId: this.state.errorId,
177
+ resetError: this.resetError
178
+ }, undefined, false, undefined, this);
179
+ }
180
+ return this.props.children;
181
+ }
182
+ }
183
+ var useErrorHandler = () => {
184
+ return React.useCallback((error) => {
185
+ throw error;
186
+ }, []);
187
+ };
3
188
  export {
4
189
  useErrorHandler,
5
190
  ErrorBoundary