@dinachi/cli 0.8.1 → 0.9.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.
- package/CHANGELOG.md +87 -0
- package/README.md +2 -0
- package/dist/index.js +131 -4
- package/package.json +14 -10
- package/templates/accordion/accordion.tsx +5 -8
- package/templates/badge/badge.tsx +4 -4
- package/templates/json-render/catalog.ts +483 -0
- package/templates/json-render/components.tsx +958 -0
- package/templates/json-render/index.ts +36 -0
- package/templates/json-render/registry.ts +21 -0
- package/templates/link/index.ts +2 -0
- package/templates/link/link.tsx +94 -0
- package/templates/otp-field/index.ts +1 -0
- package/templates/otp-field/otp-field.tsx +72 -0
- package/templates/select/select.tsx +4 -2
- package/templates/slider/slider.tsx +1 -1
- package/templates/text/index.ts +2 -0
- package/templates/text/text.tsx +70 -0
- package/templates/tsconfig.json +2 -1
- package/LICENSE +0 -21
|
@@ -0,0 +1,958 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useBoundProp,
|
|
5
|
+
useFieldValidation,
|
|
6
|
+
type SetState,
|
|
7
|
+
type StateModel,
|
|
8
|
+
} from "@json-render/react";
|
|
9
|
+
import type { ReactNode } from "react";
|
|
10
|
+
import type { z } from "zod";
|
|
11
|
+
|
|
12
|
+
// DinachiUI component imports
|
|
13
|
+
import {
|
|
14
|
+
Accordion as AccordionRoot,
|
|
15
|
+
AccordionItem,
|
|
16
|
+
AccordionHeader,
|
|
17
|
+
AccordionTrigger,
|
|
18
|
+
AccordionPanel,
|
|
19
|
+
} from "@/components/ui/accordion";
|
|
20
|
+
import {
|
|
21
|
+
AlertDialog as AlertDialogRoot,
|
|
22
|
+
AlertDialogPortal,
|
|
23
|
+
AlertDialogBackdrop,
|
|
24
|
+
AlertDialogPopup,
|
|
25
|
+
AlertDialogHeader,
|
|
26
|
+
AlertDialogTitle,
|
|
27
|
+
AlertDialogDescription,
|
|
28
|
+
AlertDialogFooter,
|
|
29
|
+
AlertDialogAction,
|
|
30
|
+
AlertDialogCancel,
|
|
31
|
+
} from "@/components/ui/alert-dialog";
|
|
32
|
+
import {
|
|
33
|
+
Avatar as AvatarRoot,
|
|
34
|
+
AvatarImage,
|
|
35
|
+
AvatarFallback,
|
|
36
|
+
} from "@/components/ui/avatar";
|
|
37
|
+
import { Badge } from "@/components/ui/badge";
|
|
38
|
+
import { Button } from "@/components/ui/button";
|
|
39
|
+
import {
|
|
40
|
+
Card,
|
|
41
|
+
CardHeader,
|
|
42
|
+
CardTitle,
|
|
43
|
+
CardDescription,
|
|
44
|
+
CardContent,
|
|
45
|
+
} from "@/components/ui/card";
|
|
46
|
+
import { Checkbox as DinachiCheckbox } from "@/components/ui/checkbox";
|
|
47
|
+
import {
|
|
48
|
+
Collapsible as CollapsibleRoot,
|
|
49
|
+
CollapsibleTrigger,
|
|
50
|
+
CollapsiblePanel,
|
|
51
|
+
} from "@/components/ui/collapsible";
|
|
52
|
+
import {
|
|
53
|
+
Dialog as DialogRoot,
|
|
54
|
+
DialogContent,
|
|
55
|
+
DialogHeader,
|
|
56
|
+
DialogTitle,
|
|
57
|
+
DialogDescription,
|
|
58
|
+
DialogClose,
|
|
59
|
+
DialogFooter,
|
|
60
|
+
} from "@/components/ui/dialog";
|
|
61
|
+
import {
|
|
62
|
+
Drawer as DrawerRoot,
|
|
63
|
+
DrawerContent,
|
|
64
|
+
DrawerTitle,
|
|
65
|
+
DrawerDescription,
|
|
66
|
+
DrawerClose,
|
|
67
|
+
DrawerHeader,
|
|
68
|
+
DrawerFooter,
|
|
69
|
+
} from "@/components/ui/drawer";
|
|
70
|
+
import { Fieldset as FieldsetRoot, FieldsetLegend } from "@/components/ui/fieldset";
|
|
71
|
+
import { Input } from "@/components/ui/input";
|
|
72
|
+
import {
|
|
73
|
+
NumberField as NumberFieldRoot,
|
|
74
|
+
NumberFieldGroup,
|
|
75
|
+
NumberFieldInput,
|
|
76
|
+
NumberFieldIncrement,
|
|
77
|
+
NumberFieldDecrement,
|
|
78
|
+
} from "@/components/ui/number-field";
|
|
79
|
+
import {
|
|
80
|
+
Popover as PopoverRoot,
|
|
81
|
+
PopoverTrigger,
|
|
82
|
+
PopoverContent,
|
|
83
|
+
} from "@/components/ui/popover";
|
|
84
|
+
import {
|
|
85
|
+
Progress,
|
|
86
|
+
ProgressTrack,
|
|
87
|
+
ProgressIndicator,
|
|
88
|
+
} from "@/components/ui/progress";
|
|
89
|
+
import {
|
|
90
|
+
RadioGroup,
|
|
91
|
+
Radio,
|
|
92
|
+
RadioIndicator,
|
|
93
|
+
} from "@/components/ui/radio";
|
|
94
|
+
import { ScrollArea as ScrollAreaComponent } from "@/components/ui/scroll-area";
|
|
95
|
+
import {
|
|
96
|
+
Select as SelectRoot,
|
|
97
|
+
SelectTrigger,
|
|
98
|
+
SelectValue,
|
|
99
|
+
SelectContent,
|
|
100
|
+
SelectItem,
|
|
101
|
+
} from "@/components/ui/select";
|
|
102
|
+
import { Separator } from "@/components/ui/separator";
|
|
103
|
+
import {
|
|
104
|
+
Slider as DinachiSlider,
|
|
105
|
+
SliderControl,
|
|
106
|
+
SliderTrack,
|
|
107
|
+
SliderRange,
|
|
108
|
+
SliderThumb,
|
|
109
|
+
} from "@/components/ui/slider";
|
|
110
|
+
import { Switch as DinachiSwitch, SwitchThumb } from "@/components/ui/switch";
|
|
111
|
+
import {
|
|
112
|
+
Tabs as TabsRoot,
|
|
113
|
+
TabsList,
|
|
114
|
+
TabsTrigger,
|
|
115
|
+
TabsContent,
|
|
116
|
+
} from "@/components/ui/tabs";
|
|
117
|
+
import { Text } from "@/components/ui/text";
|
|
118
|
+
import { Textarea } from "@/components/ui/textarea";
|
|
119
|
+
import { createToastManager } from "@/components/ui/toast";
|
|
120
|
+
import { Toggle } from "@/components/ui/toggle";
|
|
121
|
+
import { ToggleGroup as ToggleGroupRoot, ToggleGroupItem } from "@/components/ui/toggle-group";
|
|
122
|
+
import {
|
|
123
|
+
TooltipProvider,
|
|
124
|
+
Tooltip as TooltipRoot,
|
|
125
|
+
TooltipTrigger,
|
|
126
|
+
TooltipContent,
|
|
127
|
+
} from "@/components/ui/tooltip";
|
|
128
|
+
import { dinachiComponentDefinitions } from "./catalog";
|
|
129
|
+
|
|
130
|
+
// =============================================================================
|
|
131
|
+
// Toast Manager (singleton for action-based toast triggering)
|
|
132
|
+
// =============================================================================
|
|
133
|
+
|
|
134
|
+
export const toastManager = createToastManager();
|
|
135
|
+
|
|
136
|
+
// =============================================================================
|
|
137
|
+
// Component type helper
|
|
138
|
+
// =============================================================================
|
|
139
|
+
|
|
140
|
+
type Props<K extends keyof typeof dinachiComponentDefinitions> =
|
|
141
|
+
z.infer<(typeof dinachiComponentDefinitions)[K]["props"]>;
|
|
142
|
+
|
|
143
|
+
interface Ctx<K extends keyof typeof dinachiComponentDefinitions> {
|
|
144
|
+
props: Props<K>;
|
|
145
|
+
children?: ReactNode;
|
|
146
|
+
emit?: (event: string) => void;
|
|
147
|
+
bindings?: Record<string, string>;
|
|
148
|
+
loading?: boolean;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// =============================================================================
|
|
152
|
+
// Layout Components
|
|
153
|
+
// =============================================================================
|
|
154
|
+
|
|
155
|
+
const gapMap: Record<string, string> = {
|
|
156
|
+
none: "gap-0", xs: "gap-1", sm: "gap-2", md: "gap-4", lg: "gap-6", xl: "gap-8",
|
|
157
|
+
};
|
|
158
|
+
const paddingMap: Record<string, string> = {
|
|
159
|
+
none: "p-0", xs: "p-1", sm: "p-2", md: "p-4", lg: "p-6", xl: "p-8",
|
|
160
|
+
};
|
|
161
|
+
const alignMap: Record<string, string> = {
|
|
162
|
+
start: "items-start", center: "items-center", end: "items-end",
|
|
163
|
+
stretch: "items-stretch", baseline: "items-baseline",
|
|
164
|
+
};
|
|
165
|
+
const justifyMap: Record<string, string> = {
|
|
166
|
+
start: "justify-start", center: "justify-center", end: "justify-end",
|
|
167
|
+
between: "justify-between", around: "justify-around", evenly: "justify-evenly",
|
|
168
|
+
};
|
|
169
|
+
const columnsMap: Record<string, string> = {
|
|
170
|
+
"1": "grid-cols-1",
|
|
171
|
+
"2": "grid-cols-1 sm:grid-cols-2",
|
|
172
|
+
"3": "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",
|
|
173
|
+
"4": "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4",
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
function BoxComponent({ props, children }: Ctx<"Box">) {
|
|
177
|
+
const isGrid = props.display === "grid";
|
|
178
|
+
const classes = [
|
|
179
|
+
isGrid ? "grid w-full" : "flex",
|
|
180
|
+
isGrid
|
|
181
|
+
? columnsMap[props.columns ?? "1"] ?? "grid-cols-1"
|
|
182
|
+
: props.direction === "row" ? "flex-row" : "flex-col",
|
|
183
|
+
gapMap[props.gap ?? "none"] ?? "",
|
|
184
|
+
!isGrid ? (alignMap[props.align ?? "stretch"] ?? "") : "",
|
|
185
|
+
!isGrid ? (justifyMap[props.justify ?? "start"] ?? "") : "",
|
|
186
|
+
!isGrid && props.wrap ? "flex-wrap" : "",
|
|
187
|
+
paddingMap[props.padding ?? "none"] ?? "",
|
|
188
|
+
].filter(Boolean).join(" ");
|
|
189
|
+
|
|
190
|
+
return <div className={classes}>{children}</div>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function TextComponent({ props }: Ctx<"Text">) {
|
|
194
|
+
return <Text variant={props.variant ?? "p"}>{props.content}</Text>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// =============================================================================
|
|
198
|
+
// Simple Components
|
|
199
|
+
// =============================================================================
|
|
200
|
+
|
|
201
|
+
function ButtonComponent({ props, emit }: Ctx<"Button">) {
|
|
202
|
+
return (
|
|
203
|
+
<Button
|
|
204
|
+
variant={props.variant ?? "default"}
|
|
205
|
+
size={props.size ?? "default"}
|
|
206
|
+
disabled={props.disabled ?? false}
|
|
207
|
+
onClick={() => emit?.("press")}
|
|
208
|
+
>
|
|
209
|
+
{props.label}
|
|
210
|
+
</Button>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function InputComponent({ props, bindings, emit }: Ctx<"Input">) {
|
|
215
|
+
const [value, setValue] = useBoundProp<string>(props.value, bindings?.value);
|
|
216
|
+
|
|
217
|
+
const hasValidation = !!(bindings?.value && props.checks?.length);
|
|
218
|
+
const validateOn = props.validateOn ?? "blur";
|
|
219
|
+
const { errors, validate } = useFieldValidation(
|
|
220
|
+
bindings?.value ?? "",
|
|
221
|
+
hasValidation ? { checks: props.checks, validateOn } : undefined,
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
return (
|
|
225
|
+
<div className="space-y-2">
|
|
226
|
+
{props.label && (
|
|
227
|
+
<label className="block text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70">
|
|
228
|
+
{props.label}
|
|
229
|
+
</label>
|
|
230
|
+
)}
|
|
231
|
+
<Input
|
|
232
|
+
id={props.name ?? undefined}
|
|
233
|
+
name={props.name ?? undefined}
|
|
234
|
+
type={props.type ?? "text"}
|
|
235
|
+
placeholder={props.placeholder ?? ""}
|
|
236
|
+
value={value ?? ""}
|
|
237
|
+
disabled={props.disabled ?? false}
|
|
238
|
+
required={props.required ?? false}
|
|
239
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
240
|
+
setValue(e.target.value);
|
|
241
|
+
if (hasValidation && validateOn === "change") validate();
|
|
242
|
+
emit?.("change");
|
|
243
|
+
}}
|
|
244
|
+
onBlur={() => {
|
|
245
|
+
if (hasValidation && validateOn === "blur") validate();
|
|
246
|
+
}}
|
|
247
|
+
onKeyDown={(e: React.KeyboardEvent) => {
|
|
248
|
+
if (e.key === "Enter") {
|
|
249
|
+
if (hasValidation && validateOn === "submit") validate();
|
|
250
|
+
emit?.("submit");
|
|
251
|
+
}
|
|
252
|
+
}}
|
|
253
|
+
/>
|
|
254
|
+
{errors.length > 0 && (
|
|
255
|
+
<p className="text-sm text-destructive">{errors[0]}</p>
|
|
256
|
+
)}
|
|
257
|
+
</div>
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function TextareaComponent({ props, bindings, emit }: Ctx<"Textarea">) {
|
|
262
|
+
const [value, setValue] = useBoundProp<string>(props.value, bindings?.value);
|
|
263
|
+
|
|
264
|
+
const hasValidation = !!(bindings?.value && props.checks?.length);
|
|
265
|
+
const validateOn = props.validateOn ?? "blur";
|
|
266
|
+
const { errors, validate } = useFieldValidation(
|
|
267
|
+
bindings?.value ?? "",
|
|
268
|
+
hasValidation ? { checks: props.checks, validateOn } : undefined,
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
return (
|
|
272
|
+
<div className="space-y-2">
|
|
273
|
+
{props.label && (
|
|
274
|
+
<label className="block text-sm font-medium leading-none">
|
|
275
|
+
{props.label}
|
|
276
|
+
</label>
|
|
277
|
+
)}
|
|
278
|
+
<Textarea
|
|
279
|
+
name={props.name ?? undefined}
|
|
280
|
+
placeholder={props.placeholder ?? ""}
|
|
281
|
+
rows={props.rows ?? 3}
|
|
282
|
+
value={value ?? ""}
|
|
283
|
+
disabled={props.disabled ?? false}
|
|
284
|
+
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
285
|
+
setValue(e.target.value);
|
|
286
|
+
if (hasValidation && validateOn === "change") validate();
|
|
287
|
+
emit?.("change");
|
|
288
|
+
}}
|
|
289
|
+
onBlur={() => {
|
|
290
|
+
if (hasValidation && validateOn === "blur") validate();
|
|
291
|
+
}}
|
|
292
|
+
/>
|
|
293
|
+
{errors.length > 0 && (
|
|
294
|
+
<p className="text-sm text-destructive">{errors[0]}</p>
|
|
295
|
+
)}
|
|
296
|
+
</div>
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function CheckboxComponent({ props, bindings, emit }: Ctx<"Checkbox">) {
|
|
301
|
+
const [checked, setChecked] = useBoundProp<boolean>(props.checked, bindings?.checked);
|
|
302
|
+
|
|
303
|
+
const hasValidation = !!(bindings?.checked && props.checks?.length);
|
|
304
|
+
const validateOn = props.validateOn ?? "change";
|
|
305
|
+
const { errors, validate } = useFieldValidation(
|
|
306
|
+
bindings?.checked ?? "",
|
|
307
|
+
hasValidation ? { checks: props.checks, validateOn } : undefined,
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
return (
|
|
311
|
+
<div className="space-y-1">
|
|
312
|
+
<div className="flex items-center gap-2">
|
|
313
|
+
<DinachiCheckbox
|
|
314
|
+
name={props.name ?? undefined}
|
|
315
|
+
checked={checked ?? false}
|
|
316
|
+
disabled={props.disabled ?? false}
|
|
317
|
+
required={props.required ?? false}
|
|
318
|
+
onCheckedChange={(val: boolean) => {
|
|
319
|
+
setChecked(val);
|
|
320
|
+
if (hasValidation && validateOn === "change") validate();
|
|
321
|
+
emit?.("change");
|
|
322
|
+
}}
|
|
323
|
+
/>
|
|
324
|
+
<label className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70">
|
|
325
|
+
{props.label}
|
|
326
|
+
</label>
|
|
327
|
+
</div>
|
|
328
|
+
{errors.length > 0 && (
|
|
329
|
+
<p className="text-sm text-destructive">{errors[0]}</p>
|
|
330
|
+
)}
|
|
331
|
+
</div>
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function SwitchComponent({ props, bindings, emit }: Ctx<"Switch">) {
|
|
336
|
+
const [checked, setChecked] = useBoundProp<boolean>(props.checked, bindings?.checked);
|
|
337
|
+
|
|
338
|
+
return (
|
|
339
|
+
<div className="flex items-center gap-2">
|
|
340
|
+
<DinachiSwitch
|
|
341
|
+
name={props.name ?? undefined}
|
|
342
|
+
checked={checked ?? false}
|
|
343
|
+
disabled={props.disabled ?? false}
|
|
344
|
+
onCheckedChange={(val: boolean) => {
|
|
345
|
+
setChecked(val);
|
|
346
|
+
emit?.("change");
|
|
347
|
+
}}
|
|
348
|
+
>
|
|
349
|
+
<SwitchThumb />
|
|
350
|
+
</DinachiSwitch>
|
|
351
|
+
<label className="text-sm font-medium leading-none">
|
|
352
|
+
{props.label}
|
|
353
|
+
</label>
|
|
354
|
+
</div>
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function RadioComponent({ props, bindings, emit }: Ctx<"Radio">) {
|
|
359
|
+
const [value, setValue] = useBoundProp<string>(props.value, bindings?.value);
|
|
360
|
+
const options = props.options ?? [];
|
|
361
|
+
|
|
362
|
+
const hasValidation = !!(bindings?.value && props.checks?.length);
|
|
363
|
+
const validateOn = props.validateOn ?? "change";
|
|
364
|
+
const { errors, validate } = useFieldValidation(
|
|
365
|
+
bindings?.value ?? "",
|
|
366
|
+
hasValidation ? { checks: props.checks, validateOn } : undefined,
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
return (
|
|
370
|
+
<div className="space-y-2">
|
|
371
|
+
{props.label && (
|
|
372
|
+
<label className="block text-sm font-medium leading-none">
|
|
373
|
+
{props.label}
|
|
374
|
+
</label>
|
|
375
|
+
)}
|
|
376
|
+
<RadioGroup
|
|
377
|
+
name={props.name ?? undefined}
|
|
378
|
+
value={value ?? ""}
|
|
379
|
+
onValueChange={(val: unknown) => {
|
|
380
|
+
setValue(String(val));
|
|
381
|
+
if (hasValidation && validateOn === "change") validate();
|
|
382
|
+
emit?.("change");
|
|
383
|
+
}}
|
|
384
|
+
>
|
|
385
|
+
{options.map((opt: { label: string; value: string; disabled?: boolean }) => (
|
|
386
|
+
<div key={opt.value} className="flex items-center gap-2">
|
|
387
|
+
<Radio value={opt.value} disabled={opt.disabled ?? false}>
|
|
388
|
+
<RadioIndicator />
|
|
389
|
+
</Radio>
|
|
390
|
+
<label className="text-sm">{opt.label}</label>
|
|
391
|
+
</div>
|
|
392
|
+
))}
|
|
393
|
+
</RadioGroup>
|
|
394
|
+
{errors.length > 0 && (
|
|
395
|
+
<p className="text-sm text-destructive">{errors[0]}</p>
|
|
396
|
+
)}
|
|
397
|
+
</div>
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function SelectComponent({ props, bindings, emit }: Ctx<"Select">) {
|
|
402
|
+
const [value, setValue] = useBoundProp<string>(props.value, bindings?.value);
|
|
403
|
+
const options = props.options ?? [];
|
|
404
|
+
|
|
405
|
+
const hasValidation = !!(bindings?.value && props.checks?.length);
|
|
406
|
+
const validateOn = props.validateOn ?? "change";
|
|
407
|
+
const { errors, validate } = useFieldValidation(
|
|
408
|
+
bindings?.value ?? "",
|
|
409
|
+
hasValidation ? { checks: props.checks, validateOn } : undefined,
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
return (
|
|
413
|
+
<div className="space-y-2">
|
|
414
|
+
{props.label && (
|
|
415
|
+
<label className="block text-sm font-medium leading-none">
|
|
416
|
+
{props.label}
|
|
417
|
+
</label>
|
|
418
|
+
)}
|
|
419
|
+
<SelectRoot
|
|
420
|
+
value={value ?? ""}
|
|
421
|
+
onValueChange={(val: string | null) => {
|
|
422
|
+
setValue(val ?? "");
|
|
423
|
+
if (hasValidation && validateOn === "change") validate();
|
|
424
|
+
emit?.("change");
|
|
425
|
+
}}
|
|
426
|
+
disabled={props.disabled ?? false}
|
|
427
|
+
>
|
|
428
|
+
<SelectTrigger>
|
|
429
|
+
<SelectValue placeholder={props.placeholder ?? "Select..."} />
|
|
430
|
+
</SelectTrigger>
|
|
431
|
+
<SelectContent>
|
|
432
|
+
{options.map((opt: { label: string; value: string; disabled?: boolean }) => (
|
|
433
|
+
<SelectItem
|
|
434
|
+
key={opt.value}
|
|
435
|
+
value={opt.value}
|
|
436
|
+
disabled={opt.disabled ?? false}
|
|
437
|
+
>
|
|
438
|
+
{opt.label}
|
|
439
|
+
</SelectItem>
|
|
440
|
+
))}
|
|
441
|
+
</SelectContent>
|
|
442
|
+
</SelectRoot>
|
|
443
|
+
{errors.length > 0 && (
|
|
444
|
+
<p className="text-sm text-destructive">{errors[0]}</p>
|
|
445
|
+
)}
|
|
446
|
+
</div>
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function SliderComponent({ props, bindings, emit }: Ctx<"Slider">) {
|
|
451
|
+
const [value, setValue] = useBoundProp<number>(props.value, bindings?.value);
|
|
452
|
+
|
|
453
|
+
return (
|
|
454
|
+
<div className="space-y-2">
|
|
455
|
+
{props.label && (
|
|
456
|
+
<label className="block text-sm font-medium leading-none">
|
|
457
|
+
{props.label}
|
|
458
|
+
</label>
|
|
459
|
+
)}
|
|
460
|
+
<DinachiSlider
|
|
461
|
+
value={value ?? 0}
|
|
462
|
+
onValueChange={(val: number | readonly number[]) => {
|
|
463
|
+
const numVal = typeof val === "number" ? val : val[0] ?? 0;
|
|
464
|
+
setValue(numVal);
|
|
465
|
+
emit?.("change");
|
|
466
|
+
}}
|
|
467
|
+
min={props.min ?? 0}
|
|
468
|
+
max={props.max ?? 100}
|
|
469
|
+
step={props.step ?? 1}
|
|
470
|
+
disabled={props.disabled ?? false}
|
|
471
|
+
>
|
|
472
|
+
<SliderControl>
|
|
473
|
+
<SliderTrack>
|
|
474
|
+
<SliderRange />
|
|
475
|
+
</SliderTrack>
|
|
476
|
+
<SliderThumb />
|
|
477
|
+
</SliderControl>
|
|
478
|
+
</DinachiSlider>
|
|
479
|
+
</div>
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function ToggleComponent({ props, bindings, emit }: Ctx<"Toggle">) {
|
|
484
|
+
const [pressed, setPressed] = useBoundProp<boolean>(props.pressed, bindings?.pressed);
|
|
485
|
+
|
|
486
|
+
return (
|
|
487
|
+
<Toggle
|
|
488
|
+
variant={props.variant ?? "default"}
|
|
489
|
+
size={props.size ?? "default"}
|
|
490
|
+
pressed={pressed ?? false}
|
|
491
|
+
onPressedChange={(val: boolean) => {
|
|
492
|
+
setPressed(val);
|
|
493
|
+
emit?.("change");
|
|
494
|
+
}}
|
|
495
|
+
>
|
|
496
|
+
{props.label}
|
|
497
|
+
</Toggle>
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function LabelComponent({ props }: Ctx<"Label">) {
|
|
502
|
+
return (
|
|
503
|
+
<label
|
|
504
|
+
htmlFor={props.htmlFor ?? undefined}
|
|
505
|
+
className="block text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
|
506
|
+
>
|
|
507
|
+
{props.text}
|
|
508
|
+
</label>
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function BadgeComponent({ props }: Ctx<"Badge">) {
|
|
513
|
+
return (
|
|
514
|
+
<Badge
|
|
515
|
+
variant={props.variant ?? "default"}
|
|
516
|
+
size={props.size ?? "default"}
|
|
517
|
+
rounded={props.rounded ?? "default"}
|
|
518
|
+
>
|
|
519
|
+
{props.text}
|
|
520
|
+
</Badge>
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function SeparatorComponent({ props }: Ctx<"Separator">) {
|
|
525
|
+
return <Separator orientation={props.orientation ?? "horizontal"} />;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
function SkeletonComponent({ props }: Ctx<"Skeleton">) {
|
|
529
|
+
return (
|
|
530
|
+
<div
|
|
531
|
+
className="animate-pulse rounded-md bg-muted"
|
|
532
|
+
style={{
|
|
533
|
+
width: props.width ?? undefined,
|
|
534
|
+
height: props.height ?? "1rem",
|
|
535
|
+
}}
|
|
536
|
+
/>
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function ProgressComponent({ props }: Ctx<"Progress">) {
|
|
541
|
+
return (
|
|
542
|
+
<div className="space-y-1">
|
|
543
|
+
{props.label && (
|
|
544
|
+
<div className="flex justify-between text-sm">
|
|
545
|
+
<label className="font-medium leading-none">{props.label}</label>
|
|
546
|
+
<span className="text-muted-foreground">{props.value}%</span>
|
|
547
|
+
</div>
|
|
548
|
+
)}
|
|
549
|
+
<Progress value={props.value}>
|
|
550
|
+
<ProgressTrack>
|
|
551
|
+
<ProgressIndicator />
|
|
552
|
+
</ProgressTrack>
|
|
553
|
+
</Progress>
|
|
554
|
+
</div>
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// =============================================================================
|
|
559
|
+
// Compound Components (flattened wrappers)
|
|
560
|
+
// =============================================================================
|
|
561
|
+
|
|
562
|
+
function CardComponent({ props, children }: Ctx<"Card">) {
|
|
563
|
+
return (
|
|
564
|
+
<Card>
|
|
565
|
+
{(props.title || props.description) && (
|
|
566
|
+
<CardHeader>
|
|
567
|
+
{props.title && <CardTitle>{props.title}</CardTitle>}
|
|
568
|
+
{props.description && (
|
|
569
|
+
<CardDescription>{props.description}</CardDescription>
|
|
570
|
+
)}
|
|
571
|
+
</CardHeader>
|
|
572
|
+
)}
|
|
573
|
+
<CardContent>{children}</CardContent>
|
|
574
|
+
</Card>
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function TabsComponent({ props, bindings, children, emit }: Ctx<"Tabs">) {
|
|
579
|
+
const tabs = props.tabs ?? [];
|
|
580
|
+
const [value, setValue] = useBoundProp<string>(props.value, bindings?.value);
|
|
581
|
+
const activeValue = (bindings?.value ? value : null) || props.defaultValue || tabs[0]?.value || "";
|
|
582
|
+
|
|
583
|
+
return (
|
|
584
|
+
<TabsRoot
|
|
585
|
+
value={activeValue}
|
|
586
|
+
onValueChange={(val: unknown) => {
|
|
587
|
+
setValue(String(val));
|
|
588
|
+
emit?.("change");
|
|
589
|
+
}}
|
|
590
|
+
>
|
|
591
|
+
<TabsList>
|
|
592
|
+
{tabs.map((tab: { label: string; value: string; disabled?: boolean }) => (
|
|
593
|
+
<TabsTrigger
|
|
594
|
+
key={tab.value}
|
|
595
|
+
value={tab.value}
|
|
596
|
+
disabled={tab.disabled ?? false}
|
|
597
|
+
>
|
|
598
|
+
{tab.label}
|
|
599
|
+
</TabsTrigger>
|
|
600
|
+
))}
|
|
601
|
+
</TabsList>
|
|
602
|
+
<TabsContent value={activeValue}>{children}</TabsContent>
|
|
603
|
+
</TabsRoot>
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
function AccordionComponent({ props }: Ctx<"Accordion">) {
|
|
608
|
+
const items = props.items ?? [];
|
|
609
|
+
|
|
610
|
+
return (
|
|
611
|
+
<AccordionRoot
|
|
612
|
+
multiple={props.multiple ?? false}
|
|
613
|
+
className="w-full"
|
|
614
|
+
>
|
|
615
|
+
{items.map((item: { title: string; content: string; value: string; disabled?: boolean }, idx: number) => (
|
|
616
|
+
<AccordionItem key={item.value || idx} value={item.value || String(idx)}>
|
|
617
|
+
<AccordionHeader>
|
|
618
|
+
<AccordionTrigger disabled={item.disabled ?? false}>
|
|
619
|
+
{item.title}
|
|
620
|
+
</AccordionTrigger>
|
|
621
|
+
</AccordionHeader>
|
|
622
|
+
<AccordionPanel>{item.content}</AccordionPanel>
|
|
623
|
+
</AccordionItem>
|
|
624
|
+
))}
|
|
625
|
+
</AccordionRoot>
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
function DialogComponent({ props, bindings, children }: Ctx<"Dialog">) {
|
|
630
|
+
const [open, setOpen] = useBoundProp<boolean>(props.open, bindings?.open);
|
|
631
|
+
|
|
632
|
+
return (
|
|
633
|
+
<DialogRoot open={open ?? false} onOpenChange={setOpen}>
|
|
634
|
+
<DialogContent>
|
|
635
|
+
<DialogHeader>
|
|
636
|
+
<DialogTitle>{props.title}</DialogTitle>
|
|
637
|
+
{props.description && (
|
|
638
|
+
<DialogDescription>{props.description}</DialogDescription>
|
|
639
|
+
)}
|
|
640
|
+
</DialogHeader>
|
|
641
|
+
<div className="py-4">{children}</div>
|
|
642
|
+
<DialogFooter>
|
|
643
|
+
<DialogClose>Close</DialogClose>
|
|
644
|
+
</DialogFooter>
|
|
645
|
+
</DialogContent>
|
|
646
|
+
</DialogRoot>
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
function AlertDialogComponent({ props, bindings, children, emit }: Ctx<"AlertDialog">) {
|
|
651
|
+
const [open, setOpen] = useBoundProp<boolean>(props.open, bindings?.open);
|
|
652
|
+
|
|
653
|
+
return (
|
|
654
|
+
<AlertDialogRoot open={open ?? false} onOpenChange={setOpen}>
|
|
655
|
+
<AlertDialogPortal>
|
|
656
|
+
<AlertDialogBackdrop />
|
|
657
|
+
<div className="fixed inset-0 z-50 flex items-center justify-center overflow-auto">
|
|
658
|
+
<AlertDialogPopup>
|
|
659
|
+
<AlertDialogHeader>
|
|
660
|
+
<AlertDialogTitle>{props.title}</AlertDialogTitle>
|
|
661
|
+
{props.description && (
|
|
662
|
+
<AlertDialogDescription>
|
|
663
|
+
{props.description}
|
|
664
|
+
</AlertDialogDescription>
|
|
665
|
+
)}
|
|
666
|
+
</AlertDialogHeader>
|
|
667
|
+
{children}
|
|
668
|
+
<AlertDialogFooter>
|
|
669
|
+
<AlertDialogCancel
|
|
670
|
+
onClick={() => {
|
|
671
|
+
setOpen(false);
|
|
672
|
+
emit?.("cancel");
|
|
673
|
+
}}
|
|
674
|
+
>
|
|
675
|
+
{props.cancelLabel ?? "Cancel"}
|
|
676
|
+
</AlertDialogCancel>
|
|
677
|
+
<AlertDialogAction
|
|
678
|
+
onClick={() => {
|
|
679
|
+
setOpen(false);
|
|
680
|
+
emit?.("confirm");
|
|
681
|
+
}}
|
|
682
|
+
>
|
|
683
|
+
{props.actionLabel ?? "Continue"}
|
|
684
|
+
</AlertDialogAction>
|
|
685
|
+
</AlertDialogFooter>
|
|
686
|
+
</AlertDialogPopup>
|
|
687
|
+
</div>
|
|
688
|
+
</AlertDialogPortal>
|
|
689
|
+
</AlertDialogRoot>
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
function TooltipComponent({ props }: Ctx<"Tooltip">) {
|
|
694
|
+
return (
|
|
695
|
+
<TooltipProvider>
|
|
696
|
+
<TooltipRoot>
|
|
697
|
+
<TooltipTrigger>
|
|
698
|
+
<span className="underline decoration-dotted cursor-help">
|
|
699
|
+
{props.text}
|
|
700
|
+
</span>
|
|
701
|
+
</TooltipTrigger>
|
|
702
|
+
<TooltipContent
|
|
703
|
+
side={props.side ?? "top"}
|
|
704
|
+
align={props.align ?? "center"}
|
|
705
|
+
>
|
|
706
|
+
{props.content}
|
|
707
|
+
</TooltipContent>
|
|
708
|
+
</TooltipRoot>
|
|
709
|
+
</TooltipProvider>
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// =============================================================================
|
|
714
|
+
// Additional Components (Avatar, Drawer, Popover, NumberField, ToggleGroup,
|
|
715
|
+
// Collapsible, ScrollArea, Fieldset)
|
|
716
|
+
// =============================================================================
|
|
717
|
+
|
|
718
|
+
function AvatarComponent({ props }: Ctx<"Avatar">) {
|
|
719
|
+
return (
|
|
720
|
+
<AvatarRoot size={props.size ?? "md"}>
|
|
721
|
+
{props.src && <AvatarImage src={props.src} alt={props.alt ?? ""} />}
|
|
722
|
+
<AvatarFallback>{props.fallback ?? "?"}</AvatarFallback>
|
|
723
|
+
</AvatarRoot>
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function DrawerComponent({ props, bindings, children }: Ctx<"Drawer">) {
|
|
728
|
+
const [open, setOpen] = useBoundProp<boolean>(props.open, bindings?.open);
|
|
729
|
+
|
|
730
|
+
return (
|
|
731
|
+
<DrawerRoot open={open ?? false} onOpenChange={setOpen}>
|
|
732
|
+
<DrawerContent side={props.side ?? "right"}>
|
|
733
|
+
<DrawerHeader>
|
|
734
|
+
<DrawerTitle>{props.title}</DrawerTitle>
|
|
735
|
+
{props.description && (
|
|
736
|
+
<DrawerDescription>{props.description}</DrawerDescription>
|
|
737
|
+
)}
|
|
738
|
+
</DrawerHeader>
|
|
739
|
+
<div className="py-4">{children}</div>
|
|
740
|
+
<DrawerFooter>
|
|
741
|
+
<DrawerClose>Close</DrawerClose>
|
|
742
|
+
</DrawerFooter>
|
|
743
|
+
</DrawerContent>
|
|
744
|
+
</DrawerRoot>
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
function PopoverComponent({ props, children }: Ctx<"Popover">) {
|
|
749
|
+
return (
|
|
750
|
+
<PopoverRoot>
|
|
751
|
+
<PopoverTrigger className="cursor-pointer underline decoration-dotted underline-offset-4 text-sm">
|
|
752
|
+
{props.triggerText}
|
|
753
|
+
</PopoverTrigger>
|
|
754
|
+
<PopoverContent
|
|
755
|
+
side={props.side ?? "bottom"}
|
|
756
|
+
align={props.align ?? "center"}
|
|
757
|
+
>
|
|
758
|
+
{children}
|
|
759
|
+
</PopoverContent>
|
|
760
|
+
</PopoverRoot>
|
|
761
|
+
);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
function NumberFieldComponent({ props, bindings, emit }: Ctx<"NumberField">) {
|
|
765
|
+
const [value, setValue] = useBoundProp<number>(props.value, bindings?.value);
|
|
766
|
+
|
|
767
|
+
const hasValidation = !!(bindings?.value && props.checks?.length);
|
|
768
|
+
const validateOn = props.validateOn ?? "change";
|
|
769
|
+
const { errors, validate } = useFieldValidation(
|
|
770
|
+
bindings?.value ?? "",
|
|
771
|
+
hasValidation ? { checks: props.checks, validateOn } : undefined,
|
|
772
|
+
);
|
|
773
|
+
|
|
774
|
+
return (
|
|
775
|
+
<div className="space-y-2">
|
|
776
|
+
{props.label && (
|
|
777
|
+
<label className="block text-sm font-medium leading-none">
|
|
778
|
+
{props.label}
|
|
779
|
+
</label>
|
|
780
|
+
)}
|
|
781
|
+
<NumberFieldRoot
|
|
782
|
+
value={value ?? 0}
|
|
783
|
+
onValueChange={(val: number | null) => {
|
|
784
|
+
setValue(val ?? 0);
|
|
785
|
+
if (hasValidation && validateOn === "change") validate();
|
|
786
|
+
emit?.("change");
|
|
787
|
+
}}
|
|
788
|
+
min={props.min}
|
|
789
|
+
max={props.max}
|
|
790
|
+
step={props.step ?? 1}
|
|
791
|
+
disabled={props.disabled ?? false}
|
|
792
|
+
>
|
|
793
|
+
<NumberFieldGroup>
|
|
794
|
+
<NumberFieldDecrement />
|
|
795
|
+
<NumberFieldInput />
|
|
796
|
+
<NumberFieldIncrement />
|
|
797
|
+
</NumberFieldGroup>
|
|
798
|
+
</NumberFieldRoot>
|
|
799
|
+
{errors.length > 0 && (
|
|
800
|
+
<p className="text-sm text-destructive">{errors[0]}</p>
|
|
801
|
+
)}
|
|
802
|
+
</div>
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
function ToggleGroupComponent({ props, bindings, emit }: Ctx<"ToggleGroup">) {
|
|
807
|
+
const [value, setValue] = useBoundProp<string>(props.value, bindings?.value);
|
|
808
|
+
const options = props.options ?? [];
|
|
809
|
+
|
|
810
|
+
return (
|
|
811
|
+
<ToggleGroupRoot
|
|
812
|
+
value={value ? [value] : []}
|
|
813
|
+
onValueChange={(newValue: unknown) => {
|
|
814
|
+
const arr = newValue as string[];
|
|
815
|
+
const selected = arr[arr.length - 1] ?? "";
|
|
816
|
+
setValue(selected);
|
|
817
|
+
emit?.("change");
|
|
818
|
+
}}
|
|
819
|
+
>
|
|
820
|
+
{options.map((opt: { label: string; value: string }) => (
|
|
821
|
+
<ToggleGroupItem
|
|
822
|
+
key={opt.value}
|
|
823
|
+
value={opt.value}
|
|
824
|
+
variant={props.variant ?? "outline"}
|
|
825
|
+
size={props.size ?? "default"}
|
|
826
|
+
>
|
|
827
|
+
{opt.label}
|
|
828
|
+
</ToggleGroupItem>
|
|
829
|
+
))}
|
|
830
|
+
</ToggleGroupRoot>
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
function CollapsibleComponent({ props, children }: Ctx<"Collapsible">) {
|
|
835
|
+
return (
|
|
836
|
+
<CollapsibleRoot defaultOpen={props.defaultOpen ?? false}>
|
|
837
|
+
<CollapsibleTrigger>{props.triggerText}</CollapsibleTrigger>
|
|
838
|
+
<CollapsiblePanel>
|
|
839
|
+
<div className="px-4 pb-4">{children}</div>
|
|
840
|
+
</CollapsiblePanel>
|
|
841
|
+
</CollapsibleRoot>
|
|
842
|
+
);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
function ScrollAreaContainerComponent({ props, children }: Ctx<"ScrollArea">) {
|
|
846
|
+
return (
|
|
847
|
+
<ScrollAreaComponent
|
|
848
|
+
orientation={props.orientation ?? "vertical"}
|
|
849
|
+
style={{ maxHeight: props.maxHeight ?? undefined }}
|
|
850
|
+
>
|
|
851
|
+
{children}
|
|
852
|
+
</ScrollAreaComponent>
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
function FieldsetComponent({ props, children }: Ctx<"Fieldset">) {
|
|
857
|
+
return (
|
|
858
|
+
<FieldsetRoot disabled={props.disabled ?? false}>
|
|
859
|
+
{props.legend && <FieldsetLegend>{props.legend}</FieldsetLegend>}
|
|
860
|
+
{children}
|
|
861
|
+
</FieldsetRoot>
|
|
862
|
+
);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// =============================================================================
|
|
866
|
+
// Component Registry Map
|
|
867
|
+
// =============================================================================
|
|
868
|
+
|
|
869
|
+
export const dinachiComponents = {
|
|
870
|
+
Box: BoxComponent,
|
|
871
|
+
Text: TextComponent,
|
|
872
|
+
Button: ButtonComponent,
|
|
873
|
+
Input: InputComponent,
|
|
874
|
+
Textarea: TextareaComponent,
|
|
875
|
+
Checkbox: CheckboxComponent,
|
|
876
|
+
Switch: SwitchComponent,
|
|
877
|
+
Radio: RadioComponent,
|
|
878
|
+
Select: SelectComponent,
|
|
879
|
+
Slider: SliderComponent,
|
|
880
|
+
Toggle: ToggleComponent,
|
|
881
|
+
Label: LabelComponent,
|
|
882
|
+
Badge: BadgeComponent,
|
|
883
|
+
Separator: SeparatorComponent,
|
|
884
|
+
Skeleton: SkeletonComponent,
|
|
885
|
+
Progress: ProgressComponent,
|
|
886
|
+
Card: CardComponent,
|
|
887
|
+
Tabs: TabsComponent,
|
|
888
|
+
Accordion: AccordionComponent,
|
|
889
|
+
Dialog: DialogComponent,
|
|
890
|
+
AlertDialog: AlertDialogComponent,
|
|
891
|
+
Tooltip: TooltipComponent,
|
|
892
|
+
Avatar: AvatarComponent,
|
|
893
|
+
Drawer: DrawerComponent,
|
|
894
|
+
Popover: PopoverComponent,
|
|
895
|
+
NumberField: NumberFieldComponent,
|
|
896
|
+
ToggleGroup: ToggleGroupComponent,
|
|
897
|
+
Collapsible: CollapsibleComponent,
|
|
898
|
+
ScrollArea: ScrollAreaContainerComponent,
|
|
899
|
+
Fieldset: FieldsetComponent,
|
|
900
|
+
};
|
|
901
|
+
|
|
902
|
+
// =============================================================================
|
|
903
|
+
// Action Handlers
|
|
904
|
+
// =============================================================================
|
|
905
|
+
|
|
906
|
+
type ToastVariant = "default" | "success" | "error" | "warning";
|
|
907
|
+
|
|
908
|
+
const toastTypeMap: Record<ToastVariant, string> = {
|
|
909
|
+
default: "default",
|
|
910
|
+
success: "success",
|
|
911
|
+
error: "error",
|
|
912
|
+
warning: "warning",
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
export const dinachiActionHandlers = {
|
|
916
|
+
navigate: async (
|
|
917
|
+
params: { url: string; target?: string } | undefined,
|
|
918
|
+
_setState: SetState,
|
|
919
|
+
_state: StateModel,
|
|
920
|
+
) => {
|
|
921
|
+
if (!params?.url) return;
|
|
922
|
+
if (params.target === "_blank") {
|
|
923
|
+
window.open(params.url, "_blank");
|
|
924
|
+
} else {
|
|
925
|
+
window.location.href = params.url;
|
|
926
|
+
}
|
|
927
|
+
},
|
|
928
|
+
|
|
929
|
+
submit: async (
|
|
930
|
+
params: { formId?: string } | undefined,
|
|
931
|
+
_setState: SetState,
|
|
932
|
+
_state: StateModel,
|
|
933
|
+
) => {
|
|
934
|
+
if (params?.formId) {
|
|
935
|
+
const form = document.getElementById(params.formId) as HTMLFormElement | null;
|
|
936
|
+
form?.requestSubmit();
|
|
937
|
+
}
|
|
938
|
+
},
|
|
939
|
+
|
|
940
|
+
showToast: async (
|
|
941
|
+
params: {
|
|
942
|
+
title: string;
|
|
943
|
+
description?: string;
|
|
944
|
+
variant?: string;
|
|
945
|
+
timeout?: number;
|
|
946
|
+
} | undefined,
|
|
947
|
+
_setState: SetState,
|
|
948
|
+
_state: StateModel,
|
|
949
|
+
) => {
|
|
950
|
+
if (!params?.title) return;
|
|
951
|
+
toastManager.add({
|
|
952
|
+
title: params.title,
|
|
953
|
+
description: params.description ?? undefined,
|
|
954
|
+
type: toastTypeMap[(params.variant as ToastVariant) ?? "default"] ?? "default",
|
|
955
|
+
timeout: params.timeout ?? 5000,
|
|
956
|
+
});
|
|
957
|
+
},
|
|
958
|
+
};
|