react-groundwork 0.0.0-stage → 0.1.0

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.
Files changed (93) hide show
  1. package/.env.example +6 -0
  2. package/.gitattributes +2 -0
  3. package/.prettierignore +7 -0
  4. package/.prettierrc.json +12 -0
  5. package/README.md +24 -2
  6. package/cli/index.js +119 -0
  7. package/components.json +25 -0
  8. package/eslint.config.js +17 -0
  9. package/index.html +13 -0
  10. package/jsconfig.json +8 -0
  11. package/package.json +111 -4
  12. package/public/.htaccess +11 -0
  13. package/public/logo.png +0 -0
  14. package/src/App.jsx +14 -0
  15. package/src/api/api.routes.js +12 -0
  16. package/src/api/api.services.js +8 -0
  17. package/src/api/apiCall.js +128 -0
  18. package/src/api/apiHelpers.js +20 -0
  19. package/src/assets/css/index.css +173 -0
  20. package/src/assets/images/placeholders/placeholder-170x166.png +0 -0
  21. package/src/assets/images/placeholders/placeholder-360x260.png +0 -0
  22. package/src/assets/images/placeholders/placeholder-372x225.png +0 -0
  23. package/src/assets/images/placeholders/placeholder-40x40.png +0 -0
  24. package/src/assets/images/placeholders/placeholder-451x392.png +0 -0
  25. package/src/components/common/AppChart.jsx +56 -0
  26. package/src/components/common/Breadcrumbs.jsx +90 -0
  27. package/src/components/common/DataTable.jsx +203 -0
  28. package/src/components/common/DatePicker.jsx +275 -0
  29. package/src/components/common/DialogComponent.jsx +308 -0
  30. package/src/components/common/ErrorStateComponent.jsx +46 -0
  31. package/src/components/common/FullscreenToggle.jsx +54 -0
  32. package/src/components/common/HeadingComponent.jsx +29 -0
  33. package/src/components/common/LoadingComponent.jsx +33 -0
  34. package/src/components/common/NetworkStatus.jsx +103 -0
  35. package/src/components/common/NoDataComponent.jsx +45 -0
  36. package/src/components/common/Pagination.jsx +128 -0
  37. package/src/components/common/ParagraphComponent.jsx +14 -0
  38. package/src/components/common/PhoneInputComponent.jsx +242 -0
  39. package/src/components/common/ReactSelect.jsx +145 -0
  40. package/src/components/common/SearchSelect.jsx +176 -0
  41. package/src/components/common/SeeMore.jsx +26 -0
  42. package/src/components/common/SortableHeader.jsx +23 -0
  43. package/src/components/common/theme-toggle.jsx +39 -0
  44. package/src/components/layout/AuthLayout.jsx +90 -0
  45. package/src/components/layout/PageLayout.jsx +32 -0
  46. package/src/components/layout/SidebarLayout.jsx +233 -0
  47. package/src/components/ui/avatar.jsx +84 -0
  48. package/src/components/ui/badge.jsx +43 -0
  49. package/src/components/ui/button.jsx +44 -0
  50. package/src/components/ui/card.jsx +69 -0
  51. package/src/components/ui/checkbox.jsx +25 -0
  52. package/src/components/ui/dialog.jsx +149 -0
  53. package/src/components/ui/empty.jsx +82 -0
  54. package/src/components/ui/input.jsx +19 -0
  55. package/src/components/ui/label.jsx +19 -0
  56. package/src/components/ui/select.jsx +156 -0
  57. package/src/components/ui/skeleton.jsx +7 -0
  58. package/src/components/ui/sonner.jsx +37 -0
  59. package/src/components/ui/switch.jsx +23 -0
  60. package/src/components/ui/table.jsx +74 -0
  61. package/src/components/ui/textarea.jsx +16 -0
  62. package/src/constants/constant.js +16 -0
  63. package/src/context/theme-provider.jsx +48 -0
  64. package/src/features/components/ComponentFormDialog.jsx +162 -0
  65. package/src/features/components/ComponentsTable.jsx +219 -0
  66. package/src/features/components/componentStyles.js +16 -0
  67. package/src/features/components/mockData.js +407 -0
  68. package/src/features/playground/BasicsSection.jsx +122 -0
  69. package/src/features/playground/DataSection.jsx +210 -0
  70. package/src/features/playground/DemoCard.jsx +21 -0
  71. package/src/features/playground/FeedbackSection.jsx +309 -0
  72. package/src/features/playground/FormsSection.jsx +188 -0
  73. package/src/features/playground/UtilitiesSection.jsx +200 -0
  74. package/src/hooks/useApiHandler.jsx +82 -0
  75. package/src/hooks/useDebounce.js +12 -0
  76. package/src/lib/utils.js +1 -0
  77. package/src/main.jsx +16 -0
  78. package/src/pages/auth/ForgotPasswordPage.jsx +101 -0
  79. package/src/pages/auth/LoginPage.jsx +120 -0
  80. package/src/pages/auth/SignupPage.jsx +135 -0
  81. package/src/pages/views/ComponentsPage.jsx +316 -0
  82. package/src/pages/views/DashboardPage.jsx +260 -0
  83. package/src/pages/views/LandingPage.jsx +772 -0
  84. package/src/pages/views/NotFoundPage.jsx +30 -0
  85. package/src/pages/views/PlaygroundPage.jsx +50 -0
  86. package/src/routes/AppRoutes.jsx +29 -0
  87. package/src/routes/ProtectedRoute.jsx +18 -0
  88. package/src/utils/exportCsv.js +17 -0
  89. package/src/utils/formatCurrency.js +19 -0
  90. package/src/utils/formatDateTime.js +34 -0
  91. package/src/utils/handleSessionExpire.js +22 -0
  92. package/src/utils/logger.js +34 -0
  93. package/vite.config.js +23 -0
@@ -0,0 +1,275 @@
1
+ import { useState } from "react";
2
+ import { Popover } from "@base-ui/react/popover";
3
+ import { CalendarDays, ChevronLeft, ChevronRight } from "lucide-react";
4
+ import { cn } from "@/lib/utils";
5
+
6
+ const WEEKDAYS = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
7
+ const MONTHS = Array.from({ length: 12 }, (_, i) => new Date(2000, i, 1).toLocaleString("en-US", { month: "short" }));
8
+ const GRID_DAYS = 42;
9
+ const DECADE = 10;
10
+
11
+ const decadeStart = (year) => Math.floor(year / DECADE) * DECADE;
12
+ const NEXT_MODE = { days: "months", months: "years", years: "years" };
13
+
14
+ const pad = (n) => String(n).padStart(2, "0");
15
+ const toKey = (date) => `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
16
+ const fromKey = (key) => {
17
+ if (!key) return null;
18
+ const [y, m, d] = key.split("-").map(Number);
19
+ return new Date(y, m - 1, d);
20
+ };
21
+
22
+ const formatLabel = (key) =>
23
+ fromKey(key).toLocaleDateString("en-US", { month: "short", day: "2-digit", year: "numeric" });
24
+
25
+ const buildDays = (year, month) => {
26
+ const start = new Date(year, month, 1 - new Date(year, month, 1).getDay());
27
+ return Array.from(
28
+ { length: GRID_DAYS },
29
+ (_, i) => new Date(start.getFullYear(), start.getMonth(), start.getDate() + i),
30
+ );
31
+ };
32
+
33
+ const NavButton = ({ label, onClick, children }) => (
34
+ <button
35
+ type="button"
36
+ onClick={onClick}
37
+ aria-label={label}
38
+ className="flex size-8 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
39
+ >
40
+ {children}
41
+ </button>
42
+ );
43
+
44
+ const DayGrid = ({ view, value, todayKey, onSelect }) => (
45
+ <div className="grid grid-cols-7 gap-1">
46
+ {WEEKDAYS.map((day) => (
47
+ <span key={day} className="flex h-8 items-center justify-center text-[11px] font-medium text-muted-foreground">
48
+ {day}
49
+ </span>
50
+ ))}
51
+ {buildDays(view.year, view.month).map((date) => {
52
+ const key = toKey(date);
53
+ const isSelected = key === value;
54
+ const isToday = key === todayKey;
55
+ const isOutside = date.getMonth() !== view.month;
56
+ return (
57
+ <button
58
+ key={key}
59
+ type="button"
60
+ onClick={() => onSelect(key)}
61
+ aria-label={formatLabel(key)}
62
+ aria-pressed={isSelected}
63
+ className={cn(
64
+ "relative flex size-9 items-center justify-center rounded-lg text-sm tabular-nums transition-colors",
65
+ isSelected ? "bg-primary font-semibold text-primary-foreground" : "hover:bg-muted",
66
+ !isSelected && isOutside && "text-muted-foreground/50",
67
+ !isSelected && isToday && "font-semibold text-primary ring-1 ring-primary/30 ring-inset",
68
+ )}
69
+ >
70
+ {date.getDate()}
71
+ </button>
72
+ );
73
+ })}
74
+ </div>
75
+ );
76
+
77
+ const MonthGrid = ({ view, value, onSelect }) => {
78
+ const selected = fromKey(value);
79
+ return (
80
+ <div className="grid grid-cols-3 gap-2 py-1">
81
+ {MONTHS.map((label, month) => {
82
+ const isSelected = selected?.getFullYear() === view.year && selected?.getMonth() === month;
83
+ return (
84
+ <button
85
+ key={label}
86
+ type="button"
87
+ onClick={() => onSelect(month)}
88
+ className={cn(
89
+ "h-10 rounded-lg text-sm transition-colors",
90
+ isSelected ? "bg-primary font-semibold text-primary-foreground" : "hover:bg-muted",
91
+ !isSelected && month === view.month && "font-semibold text-primary",
92
+ )}
93
+ >
94
+ {label}
95
+ </button>
96
+ );
97
+ })}
98
+ </div>
99
+ );
100
+ };
101
+
102
+ const YearGrid = ({ view, value, onSelect }) => {
103
+ const start = decadeStart(view.year);
104
+ const selectedYear = fromKey(value)?.getFullYear();
105
+ const currentYear = new Date().getFullYear();
106
+ const years = Array.from({ length: DECADE + 2 }, (_, i) => start - 1 + i);
107
+
108
+ return (
109
+ <div className="grid grid-cols-3 gap-2 py-1">
110
+ {years.map((year) => {
111
+ const isSelected = year === selectedYear;
112
+ const isOutside = year < start || year >= start + DECADE;
113
+ return (
114
+ <button
115
+ key={year}
116
+ type="button"
117
+ onClick={() => onSelect(year)}
118
+ className={cn(
119
+ "h-10 rounded-lg text-sm tabular-nums transition-colors",
120
+ isSelected ? "bg-primary font-semibold text-primary-foreground" : "hover:bg-muted",
121
+ !isSelected && isOutside && "text-muted-foreground/50",
122
+ !isSelected && year === currentYear && "font-semibold text-primary",
123
+ )}
124
+ >
125
+ {year}
126
+ </button>
127
+ );
128
+ })}
129
+ </div>
130
+ );
131
+ };
132
+
133
+ const DatePicker = ({
134
+ id,
135
+ value = "",
136
+ onValueChange,
137
+ placeholder = "Select a date",
138
+ disabled = false,
139
+ invalid = false,
140
+ className,
141
+ }) => {
142
+ const todayKey = toKey(new Date());
143
+ const [open, setOpen] = useState(false);
144
+ const [mode, setMode] = useState("days");
145
+ const [view, setView] = useState(() => {
146
+ const date = fromKey(value) ?? new Date();
147
+ return { year: date.getFullYear(), month: date.getMonth() };
148
+ });
149
+
150
+ const handleOpenChange = (next) => {
151
+ if (next) {
152
+ const date = fromKey(value) ?? new Date();
153
+ setView({ year: date.getFullYear(), month: date.getMonth() });
154
+ setMode("days");
155
+ }
156
+ setOpen(next);
157
+ };
158
+
159
+ const shift = (step) =>
160
+ setView((prev) => {
161
+ if (mode === "years") return { ...prev, year: prev.year + step * DECADE };
162
+ if (mode === "months") return { ...prev, year: prev.year + step };
163
+ const date = new Date(prev.year, prev.month + step, 1);
164
+ return { year: date.getFullYear(), month: date.getMonth() };
165
+ });
166
+
167
+ const select = (key) => {
168
+ onValueChange?.(key);
169
+ setOpen(false);
170
+ };
171
+
172
+ const titles = {
173
+ days: new Date(view.year, view.month, 1).toLocaleString("en-US", { month: "long", year: "numeric" }),
174
+ months: String(view.year),
175
+ years: `${decadeStart(view.year)} – ${decadeStart(view.year) + DECADE - 1}`,
176
+ };
177
+ const navLabels = {
178
+ days: ["Previous month", "Next month"],
179
+ months: ["Previous year", "Next year"],
180
+ years: ["Previous decade", "Next decade"],
181
+ };
182
+
183
+ return (
184
+ <Popover.Root open={open} onOpenChange={handleOpenChange}>
185
+ <Popover.Trigger
186
+ id={id}
187
+ disabled={disabled}
188
+ aria-invalid={invalid || undefined}
189
+ className={cn(
190
+ "flex h-9 w-full items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-3 text-left text-sm transition-colors outline-none",
191
+ "hover:border-foreground/20 focus-visible:border-primary focus-visible:ring-3 focus-visible:ring-primary/12",
192
+ "data-popup-open:border-primary data-popup-open:ring-3 data-popup-open:ring-primary/12",
193
+ "disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:bg-input/30",
194
+ className,
195
+ )}
196
+ >
197
+ {value ? (
198
+ <span className="truncate">{formatLabel(value)}</span>
199
+ ) : (
200
+ <span className="truncate text-muted-foreground">{placeholder}</span>
201
+ )}
202
+ <CalendarDays className="size-4 shrink-0 text-muted-foreground" />
203
+ </Popover.Trigger>
204
+
205
+ <Popover.Portal>
206
+ <Popover.Positioner sideOffset={6} align="start" className="isolate z-50 outline-none">
207
+ <Popover.Popup
208
+ className={cn(
209
+ "w-72 origin-(--transform-origin) rounded-xl bg-popover p-3 text-popover-foreground shadow-lg shadow-black/8 ring-1 ring-foreground/10 outline-none",
210
+ "duration-150 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
211
+ )}
212
+ >
213
+ <div className="mb-2 flex items-center justify-between">
214
+ <NavButton label={navLabels[mode][0]} onClick={() => shift(-1)}>
215
+ <ChevronLeft className="size-4" />
216
+ </NavButton>
217
+ <button
218
+ type="button"
219
+ onClick={() => setMode((prev) => NEXT_MODE[prev])}
220
+ disabled={mode === "years"}
221
+ className="rounded-lg px-2.5 py-1 text-sm font-semibold transition-colors hover:bg-muted disabled:pointer-events-none"
222
+ >
223
+ {titles[mode]}
224
+ </button>
225
+ <NavButton label={navLabels[mode][1]} onClick={() => shift(1)}>
226
+ <ChevronRight className="size-4" />
227
+ </NavButton>
228
+ </div>
229
+
230
+ {mode === "days" && <DayGrid view={view} value={value} todayKey={todayKey} onSelect={select} />}
231
+ {mode === "years" && (
232
+ <YearGrid
233
+ view={view}
234
+ value={value}
235
+ onSelect={(year) => {
236
+ setView((prev) => ({ ...prev, year }));
237
+ setMode("months");
238
+ }}
239
+ />
240
+ )}
241
+ {mode === "months" && (
242
+ <MonthGrid
243
+ view={view}
244
+ value={value}
245
+ onSelect={(month) => {
246
+ setView((prev) => ({ ...prev, month }));
247
+ setMode("days");
248
+ }}
249
+ />
250
+ )}
251
+
252
+ <div className="mt-3 flex items-center justify-between border-t border-border pt-3">
253
+ <button
254
+ type="button"
255
+ onClick={() => select("")}
256
+ className="rounded-md px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
257
+ >
258
+ Clear
259
+ </button>
260
+ <button
261
+ type="button"
262
+ onClick={() => select(todayKey)}
263
+ className="rounded-md px-2 py-1 text-xs font-medium text-primary transition-colors hover:bg-primary/10"
264
+ >
265
+ Today
266
+ </button>
267
+ </div>
268
+ </Popover.Popup>
269
+ </Popover.Positioner>
270
+ </Popover.Portal>
271
+ </Popover.Root>
272
+ );
273
+ };
274
+
275
+ export default DatePicker;
@@ -0,0 +1,308 @@
1
+ import React from "react";
2
+ import { Loader2, Trash2 } from "lucide-react";
3
+
4
+ import { cn } from "@/lib/utils";
5
+ import {
6
+ Dialog,
7
+ DialogContent,
8
+ DialogHeader,
9
+ DialogTitle,
10
+ DialogDescription,
11
+ DialogFooter,
12
+ } from "@/components/ui/dialog";
13
+ import { Button } from "@/components/ui/button";
14
+ import { Input } from "@/components/ui/input";
15
+ import { Textarea } from "@/components/ui/textarea";
16
+ import { Label } from "@/components/ui/label";
17
+ import { Switch } from "@/components/ui/switch";
18
+ import ReactSelect from "@/components/common/ReactSelect";
19
+ import SearchSelect from "@/components/common/SearchSelect";
20
+ import DatePicker from "@/components/common/DatePicker";
21
+
22
+ const SIZE_CLASSES = {
23
+ sm: "sm:max-w-sm",
24
+ md: "sm:max-w-md",
25
+ lg: "sm:max-w-lg",
26
+ xl: "sm:max-w-2xl",
27
+ };
28
+
29
+ const COLUMN_CLASSES = {
30
+ 1: "sm:grid-cols-1",
31
+ 2: "sm:grid-cols-2",
32
+ 3: "sm:grid-cols-2 lg:grid-cols-3",
33
+ };
34
+
35
+ function Field({
36
+ type = "text",
37
+ label,
38
+ name,
39
+ value,
40
+ onChange,
41
+ onValueChange,
42
+ checked,
43
+ onCheckedChange,
44
+ error,
45
+ required,
46
+ placeholder,
47
+ options = [],
48
+ isLoading,
49
+ disabled,
50
+ description,
51
+ className,
52
+ children,
53
+ ...rest
54
+ }) {
55
+ if (type === "switch") {
56
+ return (
57
+ <div
58
+ className={cn(
59
+ "flex items-center justify-between gap-4 rounded-lg border border-input p-4 transition-colors",
60
+ checked && "border-primary/30 bg-primary/5",
61
+ className,
62
+ )}
63
+ >
64
+ <div className="space-y-0.5">
65
+ {label && (
66
+ <Label htmlFor={name} className="text-xs font-medium">
67
+ {label}
68
+ </Label>
69
+ )}
70
+ {description && <p className="text-[11px] text-muted-foreground">{description}</p>}
71
+ </div>
72
+
73
+ <Switch id={name} checked={checked} onCheckedChange={onCheckedChange} disabled={disabled} {...rest} />
74
+ </div>
75
+ );
76
+ }
77
+
78
+ return (
79
+ <div className={cn("space-y-1.5", className)}>
80
+ {label && (
81
+ <Label htmlFor={name} className="text-xs font-medium">
82
+ {label}
83
+ {required && <span className="text-destructive"> *</span>}
84
+ </Label>
85
+ )}
86
+
87
+ {children ? (
88
+ children
89
+ ) : type === "select" ? (
90
+ <SearchSelect
91
+ id={name}
92
+ options={options}
93
+ value={value}
94
+ onValueChange={onValueChange}
95
+ placeholder={placeholder}
96
+ disabled={disabled}
97
+ invalid={!!error}
98
+ />
99
+ ) : type === "date" ? (
100
+ <DatePicker
101
+ id={name}
102
+ value={value}
103
+ onValueChange={onValueChange}
104
+ placeholder={placeholder}
105
+ disabled={disabled}
106
+ invalid={!!error}
107
+ />
108
+ ) : type === "select-list" ? (
109
+ <ReactSelect
110
+ inputId={name}
111
+ options={options}
112
+ value={options.find((opt) => String(opt.value) === String(value)) ?? null}
113
+ onChange={(opt) => onValueChange?.(opt ? opt.value : "")}
114
+ placeholder={placeholder}
115
+ isDisabled={disabled}
116
+ isLoading={isLoading}
117
+ isInvalid={!!error}
118
+ />
119
+ ) : type === "multi-select" ? (
120
+ <SearchSelect
121
+ id={name}
122
+ multiple
123
+ options={options}
124
+ value={value}
125
+ onValueChange={onValueChange}
126
+ placeholder={placeholder}
127
+ disabled={disabled}
128
+ invalid={!!error}
129
+ />
130
+ ) : type === "textarea" ? (
131
+ <Textarea
132
+ id={name}
133
+ name={name}
134
+ value={value}
135
+ onChange={onChange}
136
+ placeholder={placeholder}
137
+ aria-invalid={!!error}
138
+ disabled={disabled}
139
+ className="text-sm"
140
+ {...rest}
141
+ />
142
+ ) : (
143
+ <Input
144
+ id={name}
145
+ name={name}
146
+ type={type}
147
+ value={value}
148
+ onChange={onChange}
149
+ placeholder={placeholder}
150
+ aria-invalid={!!error}
151
+ disabled={disabled}
152
+ className="h-9 text-sm"
153
+ {...rest}
154
+ />
155
+ )}
156
+
157
+ {error && <p className="text-xs text-destructive">{error}</p>}
158
+ </div>
159
+ );
160
+ }
161
+
162
+ function Section({ title, columns = 1, className, children }) {
163
+ return (
164
+ <div className={className}>
165
+ {title && (
166
+ <h3 className="mb-3 flex items-center gap-2 text-xs font-semibold text-foreground">
167
+ <span className="h-3 w-1 rounded-full bg-primary" />
168
+ {title}
169
+ </h3>
170
+ )}
171
+
172
+ <div className={cn("grid grid-cols-1 gap-4", COLUMN_CLASSES[columns])}>{children}</div>
173
+ </div>
174
+ );
175
+ }
176
+
177
+ function Footer({
178
+ onCancel,
179
+ cancelLabel = "Cancel",
180
+ submitLabel = "Save",
181
+ loadingLabel = submitLabel,
182
+ loading = false,
183
+ disabled = false,
184
+ }) {
185
+ return (
186
+ <DialogFooter className="mx-0 mb-0 shrink-0 gap-3 rounded-none border-t border-border bg-muted/40 px-6 py-4">
187
+ <Button type="button" variant="outline" className="h-9 min-w-24" onClick={onCancel} disabled={loading}>
188
+ {cancelLabel}
189
+ </Button>
190
+
191
+ <Button type="submit" className="h-9 min-w-28" disabled={loading || disabled}>
192
+ {loading && <Loader2 className="size-4 animate-spin" />}
193
+ {loading ? loadingLabel : submitLabel}
194
+ </Button>
195
+ </DialogFooter>
196
+ );
197
+ }
198
+
199
+ function DialogComponent({
200
+ open,
201
+ onOpenChange,
202
+ title,
203
+ description,
204
+ icon: Icon,
205
+ size = "md",
206
+ loading = false,
207
+ onSubmit,
208
+ className,
209
+ children,
210
+ }) {
211
+ const items = React.Children.toArray(children);
212
+ const footer = items.find((child) => child.type === Footer);
213
+ const body = items.filter((child) => child.type !== Footer);
214
+ const popupRef = React.useRef(null);
215
+
216
+ return (
217
+ <Dialog
218
+ open={open}
219
+ onOpenChange={(next) => {
220
+ if (loading) return;
221
+ onOpenChange?.(next);
222
+ }}
223
+ >
224
+ <DialogContent
225
+ ref={popupRef}
226
+ initialFocus={popupRef}
227
+ className={cn("flex max-h-[90vh] flex-col gap-0 overflow-hidden p-0", SIZE_CLASSES[size], className)}
228
+ >
229
+ <DialogHeader className="flex-row items-center gap-3 border-b border-border px-6 py-4 pr-12 text-left sm:text-left">
230
+ {Icon && (
231
+ <div className="flex size-10 shrink-0 items-center justify-center rounded-xl bg-primary/10 text-primary">
232
+ <Icon className="size-5" />
233
+ </div>
234
+ )}
235
+ <div className="flex min-w-0 flex-col gap-0.5">
236
+ <DialogTitle className="text-base leading-tight font-semibold">{title}</DialogTitle>
237
+ {description && <DialogDescription className="text-xs leading-snug">{description}</DialogDescription>}
238
+ </div>
239
+ </DialogHeader>
240
+
241
+ <form onSubmit={onSubmit} noValidate className="flex min-h-0 flex-1 flex-col">
242
+ <div className="scrollbar-thin min-h-0 flex-1 space-y-5 overflow-y-auto px-6 py-5">{body}</div>
243
+
244
+ {footer}
245
+ </form>
246
+ </DialogContent>
247
+ </Dialog>
248
+ );
249
+ }
250
+
251
+ function Confirm({
252
+ open,
253
+ onOpenChange,
254
+ title = "Are you sure?",
255
+ description,
256
+ onConfirm,
257
+ loading = false,
258
+ confirmLabel = "Delete",
259
+ loadingLabel = confirmLabel,
260
+ cancelLabel = "Cancel",
261
+ icon: Icon = Trash2,
262
+ }) {
263
+ return (
264
+ <Dialog
265
+ open={open}
266
+ onOpenChange={(next) => {
267
+ if (loading) return;
268
+ onOpenChange?.(next);
269
+ }}
270
+ >
271
+ <DialogContent className="gap-0 overflow-hidden p-0 sm:max-w-sm">
272
+ <DialogHeader className="items-center gap-3 px-6 pt-7 pb-5 text-center sm:text-center">
273
+ <div className="flex size-12 items-center justify-center rounded-full bg-destructive/10 text-destructive ring-8 ring-destructive/5">
274
+ <Icon className="size-5" />
275
+ </div>
276
+ <div className="flex flex-col gap-1">
277
+ <DialogTitle className="text-base leading-tight font-semibold">{title}</DialogTitle>
278
+ {description && <DialogDescription className="text-xs leading-snug">{description}</DialogDescription>}
279
+ </div>
280
+ </DialogHeader>
281
+
282
+ <DialogFooter className="mx-0 mb-0 grid grid-cols-2 gap-3 rounded-none border-t border-border bg-muted/40 px-6 py-4">
283
+ <Button
284
+ type="button"
285
+ variant="outline"
286
+ className="h-9 w-full"
287
+ onClick={() => onOpenChange?.(false)}
288
+ disabled={loading}
289
+ >
290
+ {cancelLabel}
291
+ </Button>
292
+
293
+ <Button type="button" variant="destructive" className="h-9 w-full" onClick={onConfirm} disabled={loading}>
294
+ {loading ? <Loader2 className="size-4 animate-spin" /> : <Icon className="size-4" />}
295
+ {loading ? loadingLabel : confirmLabel}
296
+ </Button>
297
+ </DialogFooter>
298
+ </DialogContent>
299
+ </Dialog>
300
+ );
301
+ }
302
+
303
+ DialogComponent.Field = Field;
304
+ DialogComponent.Section = Section;
305
+ DialogComponent.Footer = Footer;
306
+ DialogComponent.Confirm = Confirm;
307
+
308
+ export default DialogComponent;
@@ -0,0 +1,46 @@
1
+ import { AlertTriangle, RotateCw } from "lucide-react";
2
+ import { cn } from "@/lib/utils";
3
+ import { Button } from "@/components/ui/button";
4
+ import { Empty, EmptyHeader, EmptyMedia, EmptyTitle, EmptyDescription, EmptyContent } from "@/components/ui/empty";
5
+
6
+ const VARIANT_CLASSES = {
7
+ inline: "w-full py-10",
8
+ page: "w-full min-h-[70vh]",
9
+ overlay: "fixed inset-0 z-50 bg-background",
10
+ };
11
+
12
+ const ErrorStateComponent = ({
13
+ variant = "inline",
14
+ title = "Something went wrong",
15
+ description = "We couldn't load this data. Please try again.",
16
+ onRetry,
17
+ retryLabel = "Try again",
18
+ className,
19
+ }) => {
20
+ return (
21
+ <div
22
+ role="alert"
23
+ className={cn("flex items-center justify-center", VARIANT_CLASSES[variant] ?? VARIANT_CLASSES.inline, className)}
24
+ >
25
+ <Empty className="border-none p-0">
26
+ <EmptyHeader>
27
+ <EmptyMedia variant="icon" className="bg-destructive/10 text-destructive">
28
+ <AlertTriangle />
29
+ </EmptyMedia>
30
+ <EmptyTitle>{title}</EmptyTitle>
31
+ {description && <EmptyDescription>{description}</EmptyDescription>}
32
+ </EmptyHeader>
33
+ {onRetry && (
34
+ <EmptyContent>
35
+ <Button variant="outline" size="sm" onClick={onRetry}>
36
+ <RotateCw />
37
+ {retryLabel}
38
+ </Button>
39
+ </EmptyContent>
40
+ )}
41
+ </Empty>
42
+ </div>
43
+ );
44
+ };
45
+
46
+ export default ErrorStateComponent;
@@ -0,0 +1,54 @@
1
+ import { useSyncExternalStore } from "react";
2
+ import { AnimatePresence, motion } from "framer-motion";
3
+ import { Maximize, Minimize } from "lucide-react";
4
+ import { toast } from "sonner";
5
+ import { Button } from "@/components/ui/button";
6
+
7
+ const subscribe = (callback) => {
8
+ document.addEventListener("fullscreenchange", callback);
9
+ return () => document.removeEventListener("fullscreenchange", callback);
10
+ };
11
+
12
+ const getIsFullscreen = () => Boolean(document.fullscreenElement);
13
+
14
+ const FullscreenToggle = ({ variant = "ghost", size = "icon-sm", className }) => {
15
+ const isFullscreen = useSyncExternalStore(subscribe, getIsFullscreen, () => false);
16
+ const Icon = isFullscreen ? Minimize : Maximize;
17
+
18
+ if (!document.fullscreenEnabled) return null;
19
+
20
+ const toggleFullscreen = async () => {
21
+ try {
22
+ if (isFullscreen) await document.exitFullscreen();
23
+ else await document.documentElement.requestFullscreen();
24
+ } catch {
25
+ toast.error("Fullscreen is not available in this browser");
26
+ }
27
+ };
28
+
29
+ return (
30
+ <Button
31
+ variant={variant}
32
+ size={size}
33
+ className={className}
34
+ onClick={toggleFullscreen}
35
+ title={isFullscreen ? "Exit full screen" : "Full screen"}
36
+ >
37
+ <AnimatePresence mode="wait" initial={false}>
38
+ <motion.span
39
+ key={isFullscreen ? "exit" : "enter"}
40
+ className="flex"
41
+ initial={{ opacity: 0, scale: 0.6 }}
42
+ animate={{ opacity: 1, scale: 1 }}
43
+ exit={{ opacity: 0, scale: 0.6 }}
44
+ transition={{ duration: 0.15, ease: "easeOut" }}
45
+ >
46
+ <Icon className="h-4 w-4" />
47
+ </motion.span>
48
+ </AnimatePresence>
49
+ <span className="sr-only">{isFullscreen ? "Exit full screen" : "Full screen"}</span>
50
+ </Button>
51
+ );
52
+ };
53
+
54
+ export default FullscreenToggle;