@rovula/ui 0.1.14 → 0.1.16
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/dist/cjs/bundle.js +1545 -1545
- package/dist/cjs/bundle.js.map +1 -1
- package/dist/cjs/types/components/Form/Form.d.ts +1 -1
- package/dist/cjs/types/index.d.ts +2 -0
- package/dist/cjs/types/patterns/confirm-dialog/ConfirmDialog.d.ts +25 -0
- package/dist/cjs/types/patterns/confirm-dialog/ConfirmDialog.stories.d.ts +54 -0
- package/dist/cjs/types/patterns/form-dialog/FormDialog.d.ts +40 -0
- package/dist/cjs/types/patterns/form-dialog/FormDialog.stories.d.ts +63 -0
- package/dist/components/AlertDialog/AlertDialog.js +1 -1
- package/dist/components/Dialog/Dialog.js +1 -1
- package/dist/components/Form/Form.js +15 -4
- package/dist/esm/bundle.js +1545 -1545
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/types/components/Form/Form.d.ts +1 -1
- package/dist/esm/types/index.d.ts +2 -0
- package/dist/esm/types/patterns/confirm-dialog/ConfirmDialog.d.ts +25 -0
- package/dist/esm/types/patterns/confirm-dialog/ConfirmDialog.stories.d.ts +54 -0
- package/dist/esm/types/patterns/form-dialog/FormDialog.d.ts +40 -0
- package/dist/esm/types/patterns/form-dialog/FormDialog.stories.d.ts +63 -0
- package/dist/index.d.ts +67 -2
- package/dist/index.js +3 -0
- package/dist/patterns/confirm-dialog/ConfirmDialog.js +45 -0
- package/dist/patterns/confirm-dialog/ConfirmDialog.stories.js +103 -0
- package/dist/patterns/form-dialog/FormDialog.js +10 -0
- package/dist/patterns/form-dialog/FormDialog.stories.js +223 -0
- package/package.json +1 -1
- package/src/components/AlertDialog/AlertDialog.tsx +11 -13
- package/src/components/Dialog/Dialog.tsx +3 -9
- package/src/components/Form/Form.tsx +19 -4
- package/src/index.ts +4 -0
- package/src/patterns/confirm-dialog/ConfirmDialog.stories.tsx +193 -0
- package/src/patterns/confirm-dialog/ConfirmDialog.tsx +164 -0
- package/src/patterns/form-dialog/FormDialog.stories.tsx +437 -0
- package/src/patterns/form-dialog/FormDialog.tsx +144 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import {
|
|
5
|
+
Dialog,
|
|
6
|
+
DialogContent,
|
|
7
|
+
DialogHeader,
|
|
8
|
+
DialogTitle,
|
|
9
|
+
DialogDescription,
|
|
10
|
+
DialogBody,
|
|
11
|
+
DialogFooter,
|
|
12
|
+
DialogTrigger,
|
|
13
|
+
} from "@/components/Dialog/Dialog";
|
|
14
|
+
import Button from "@/components/Button/Button";
|
|
15
|
+
import Loading from "@/components/Loading/Loading";
|
|
16
|
+
|
|
17
|
+
export type FormDialogAction = {
|
|
18
|
+
label: string;
|
|
19
|
+
onClick?: () => void;
|
|
20
|
+
variant?: React.ComponentProps<typeof Button>["variant"];
|
|
21
|
+
color?: React.ComponentProps<typeof Button>["color"];
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
isLoading?: boolean;
|
|
24
|
+
type?: "button" | "submit" | "reset";
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type FormDialogProps = {
|
|
28
|
+
open?: boolean;
|
|
29
|
+
onOpenChange?: (open: boolean) => void;
|
|
30
|
+
title: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
children?: React.ReactNode;
|
|
33
|
+
trigger?: React.ReactNode;
|
|
34
|
+
/**
|
|
35
|
+
* Primary action (right side of footer).
|
|
36
|
+
*/
|
|
37
|
+
confirmAction?: FormDialogAction;
|
|
38
|
+
/**
|
|
39
|
+
* Secondary cancel action (right side of footer, outline style).
|
|
40
|
+
*/
|
|
41
|
+
cancelAction?: FormDialogAction;
|
|
42
|
+
/**
|
|
43
|
+
* Optional extra action placed on the left side of the footer.
|
|
44
|
+
*/
|
|
45
|
+
extraAction?: FormDialogAction;
|
|
46
|
+
scrollable?: boolean;
|
|
47
|
+
className?: string;
|
|
48
|
+
/**
|
|
49
|
+
* When provided, the confirm button becomes type="submit" and is linked to this form id.
|
|
50
|
+
* Use together with a <Form id={formId} .../> inside children.
|
|
51
|
+
*/
|
|
52
|
+
formId?: string;
|
|
53
|
+
testId?: string;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const FormDialog: React.FC<FormDialogProps> = ({
|
|
57
|
+
open,
|
|
58
|
+
onOpenChange,
|
|
59
|
+
title,
|
|
60
|
+
description,
|
|
61
|
+
children,
|
|
62
|
+
trigger,
|
|
63
|
+
confirmAction,
|
|
64
|
+
cancelAction,
|
|
65
|
+
extraAction,
|
|
66
|
+
scrollable = false,
|
|
67
|
+
className,
|
|
68
|
+
formId,
|
|
69
|
+
testId,
|
|
70
|
+
}) => {
|
|
71
|
+
const hasFooter = confirmAction || cancelAction || extraAction;
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
75
|
+
{trigger && <DialogTrigger asChild>{trigger}</DialogTrigger>}
|
|
76
|
+
<DialogContent className={className} data-testid={testId}>
|
|
77
|
+
<DialogHeader>
|
|
78
|
+
<DialogTitle data-testid={testId && `${testId}-title`}>{title}</DialogTitle>
|
|
79
|
+
{description && (
|
|
80
|
+
<DialogDescription data-testid={testId && `${testId}-description`}>
|
|
81
|
+
{description}
|
|
82
|
+
</DialogDescription>
|
|
83
|
+
)}
|
|
84
|
+
</DialogHeader>
|
|
85
|
+
|
|
86
|
+
{children && (
|
|
87
|
+
<DialogBody scrollable={scrollable}>{children}</DialogBody>
|
|
88
|
+
)}
|
|
89
|
+
|
|
90
|
+
{hasFooter && (
|
|
91
|
+
<DialogFooter className={extraAction ? "justify-between" : undefined}>
|
|
92
|
+
{extraAction && (
|
|
93
|
+
<Button
|
|
94
|
+
type={extraAction.type ?? "button"}
|
|
95
|
+
variant={extraAction.variant ?? "outline"}
|
|
96
|
+
color={extraAction.color ?? "secondary"}
|
|
97
|
+
fullwidth={false}
|
|
98
|
+
disabled={extraAction.disabled}
|
|
99
|
+
isLoading={extraAction.isLoading}
|
|
100
|
+
onClick={extraAction.onClick}
|
|
101
|
+
data-testid={testId && `${testId}-extra-button`}
|
|
102
|
+
>
|
|
103
|
+
{extraAction.label}
|
|
104
|
+
</Button>
|
|
105
|
+
)}
|
|
106
|
+
<div className="flex items-center gap-4">
|
|
107
|
+
{cancelAction && (
|
|
108
|
+
<Button
|
|
109
|
+
type={cancelAction.type ?? "button"}
|
|
110
|
+
variant={cancelAction.variant ?? "outline"}
|
|
111
|
+
color={cancelAction.color ?? "primary"}
|
|
112
|
+
fullwidth={false}
|
|
113
|
+
disabled={cancelAction.disabled}
|
|
114
|
+
isLoading={cancelAction.isLoading}
|
|
115
|
+
onClick={cancelAction.onClick}
|
|
116
|
+
data-testid={testId && `${testId}-cancel-button`}
|
|
117
|
+
>
|
|
118
|
+
{cancelAction.label}
|
|
119
|
+
</Button>
|
|
120
|
+
)}
|
|
121
|
+
{confirmAction && (
|
|
122
|
+
<Button
|
|
123
|
+
type={formId ? "submit" : confirmAction.type ?? "button"}
|
|
124
|
+
form={formId}
|
|
125
|
+
variant={confirmAction.variant ?? "solid"}
|
|
126
|
+
color={confirmAction.color ?? "primary"}
|
|
127
|
+
fullwidth={false}
|
|
128
|
+
disabled={confirmAction.disabled}
|
|
129
|
+
isLoading={confirmAction.isLoading}
|
|
130
|
+
onClick={confirmAction.onClick}
|
|
131
|
+
data-testid={testId && `${testId}-confirm-button`}
|
|
132
|
+
>
|
|
133
|
+
{confirmAction.label}
|
|
134
|
+
</Button>
|
|
135
|
+
)}
|
|
136
|
+
</div>
|
|
137
|
+
</DialogFooter>
|
|
138
|
+
)}
|
|
139
|
+
</DialogContent>
|
|
140
|
+
</Dialog>
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
FormDialog.displayName = "FormDialog";
|