@open-elements/ui 0.2.0 → 0.3.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/README.md +30 -0
- package/dist/components/delete-confirm-dialog.d.ts +14 -0
- package/dist/components/delete-confirm-dialog.d.ts.map +1 -0
- package/dist/components/delete-confirm-dialog.js +22 -0
- package/dist/components/delete-confirm-dialog.js.map +1 -0
- package/dist/components/detail-field.d.ts +21 -0
- package/dist/components/detail-field.d.ts.map +1 -0
- package/dist/components/detail-field.js +47 -0
- package/dist/components/detail-field.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/delete-confirm-dialog.tsx +80 -0
- package/src/components/detail-field.tsx +156 -0
- package/src/index.ts +4 -0
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-elements/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Shared UI component library for Open Elements applications",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/
|
|
8
|
+
"url": "https://github.com/OpenElementsLabs/open-elements-ui.git"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"main": "./dist/index.js",
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Loader2 } from "lucide-react";
|
|
5
|
+
import {
|
|
6
|
+
AlertDialog,
|
|
7
|
+
AlertDialogCancel,
|
|
8
|
+
AlertDialogContent,
|
|
9
|
+
AlertDialogDescription,
|
|
10
|
+
AlertDialogFooter,
|
|
11
|
+
AlertDialogHeader,
|
|
12
|
+
AlertDialogTitle,
|
|
13
|
+
} from "./alert-dialog.tsx";
|
|
14
|
+
import { Button } from "./button.tsx";
|
|
15
|
+
|
|
16
|
+
interface DeleteConfirmDialogProps {
|
|
17
|
+
readonly open: boolean;
|
|
18
|
+
readonly onOpenChange: (open: boolean) => void;
|
|
19
|
+
readonly title: string;
|
|
20
|
+
readonly description: string;
|
|
21
|
+
readonly confirmLabel: string;
|
|
22
|
+
readonly cancelLabel: string;
|
|
23
|
+
readonly onConfirm: () => Promise<void>;
|
|
24
|
+
readonly error?: string | null;
|
|
25
|
+
readonly errorTitle?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function DeleteConfirmDialog({
|
|
29
|
+
open,
|
|
30
|
+
onOpenChange,
|
|
31
|
+
title,
|
|
32
|
+
description,
|
|
33
|
+
confirmLabel,
|
|
34
|
+
cancelLabel,
|
|
35
|
+
onConfirm,
|
|
36
|
+
error,
|
|
37
|
+
errorTitle,
|
|
38
|
+
}: DeleteConfirmDialogProps) {
|
|
39
|
+
const [loading, setLoading] = useState(false);
|
|
40
|
+
|
|
41
|
+
const handleConfirm = async () => {
|
|
42
|
+
if (loading) return;
|
|
43
|
+
setLoading(true);
|
|
44
|
+
try {
|
|
45
|
+
await onConfirm();
|
|
46
|
+
} finally {
|
|
47
|
+
setLoading(false);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<AlertDialog open={open} onOpenChange={onOpenChange}>
|
|
53
|
+
<AlertDialogContent>
|
|
54
|
+
<AlertDialogHeader>
|
|
55
|
+
<AlertDialogTitle>{error ? (errorTitle ?? title) : title}</AlertDialogTitle>
|
|
56
|
+
<AlertDialogDescription>{error ?? description}</AlertDialogDescription>
|
|
57
|
+
</AlertDialogHeader>
|
|
58
|
+
<AlertDialogFooter>
|
|
59
|
+
{error ? (
|
|
60
|
+
<AlertDialogCancel>{cancelLabel}</AlertDialogCancel>
|
|
61
|
+
) : (
|
|
62
|
+
<>
|
|
63
|
+
<AlertDialogCancel>{cancelLabel}</AlertDialogCancel>
|
|
64
|
+
<Button
|
|
65
|
+
onClick={handleConfirm}
|
|
66
|
+
disabled={loading}
|
|
67
|
+
className="bg-oe-red hover:bg-oe-red-dark text-white"
|
|
68
|
+
>
|
|
69
|
+
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
|
70
|
+
{confirmLabel}
|
|
71
|
+
</Button>
|
|
72
|
+
</>
|
|
73
|
+
)}
|
|
74
|
+
</AlertDialogFooter>
|
|
75
|
+
</AlertDialogContent>
|
|
76
|
+
</AlertDialog>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type { DeleteConfirmDialogProps };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Copy, Check, ExternalLink, Mail, Phone } from "lucide-react";
|
|
5
|
+
import { Tooltip, TooltipTrigger, TooltipContent } from "./tooltip.tsx";
|
|
6
|
+
|
|
7
|
+
interface DetailFieldTranslations {
|
|
8
|
+
readonly copy: string;
|
|
9
|
+
readonly copied: string;
|
|
10
|
+
readonly open: string;
|
|
11
|
+
readonly email: string;
|
|
12
|
+
readonly call: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const defaultTranslations: DetailFieldTranslations = {
|
|
16
|
+
copy: "Copy",
|
|
17
|
+
copied: "Copied",
|
|
18
|
+
open: "Open",
|
|
19
|
+
email: "Email",
|
|
20
|
+
call: "Call",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
interface DetailFieldProps {
|
|
24
|
+
readonly label: string;
|
|
25
|
+
readonly value: string | null;
|
|
26
|
+
readonly copyable?: boolean;
|
|
27
|
+
readonly linkable?: boolean;
|
|
28
|
+
readonly mailable?: boolean;
|
|
29
|
+
readonly callable?: boolean;
|
|
30
|
+
readonly multiline?: boolean;
|
|
31
|
+
readonly children?: React.ReactNode;
|
|
32
|
+
readonly translations?: DetailFieldTranslations;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function normalizeUrl(url: string): string {
|
|
36
|
+
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
37
|
+
return url;
|
|
38
|
+
}
|
|
39
|
+
return `https://${url}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function DetailField({
|
|
43
|
+
label,
|
|
44
|
+
value,
|
|
45
|
+
copyable,
|
|
46
|
+
linkable,
|
|
47
|
+
mailable,
|
|
48
|
+
callable,
|
|
49
|
+
multiline,
|
|
50
|
+
children,
|
|
51
|
+
translations = defaultTranslations,
|
|
52
|
+
}: DetailFieldProps) {
|
|
53
|
+
const [copied, setCopied] = useState(false);
|
|
54
|
+
|
|
55
|
+
const hasValue = value !== null && value !== "";
|
|
56
|
+
const hasActions = hasValue && (copyable || linkable || mailable || callable);
|
|
57
|
+
|
|
58
|
+
const handleCopy = () => {
|
|
59
|
+
if (!value) return;
|
|
60
|
+
navigator.clipboard.writeText(value);
|
|
61
|
+
setCopied(true);
|
|
62
|
+
setTimeout(() => setCopied(false), 2000);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const handleOpenUrl = () => {
|
|
66
|
+
if (!value) return;
|
|
67
|
+
window.open(normalizeUrl(value), "_blank");
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const handleMailto = () => {
|
|
71
|
+
if (!value) return;
|
|
72
|
+
window.location.href = `mailto:${value}`;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const handleTel = () => {
|
|
76
|
+
if (!value) return;
|
|
77
|
+
window.location.href = `tel:${value}`;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div>
|
|
82
|
+
<dt className="text-sm font-medium text-oe-gray-mid">{label}</dt>
|
|
83
|
+
<dd className="mt-1 text-sm text-oe-black flex items-start gap-1">
|
|
84
|
+
<span className={multiline ? "whitespace-pre-line" : ""}>
|
|
85
|
+
{children ?? (hasValue ? value : "—")}
|
|
86
|
+
</span>
|
|
87
|
+
{hasActions && (
|
|
88
|
+
<span className="inline-flex gap-0.5 shrink-0 mt-0.5">
|
|
89
|
+
{copyable && (
|
|
90
|
+
<Tooltip>
|
|
91
|
+
<TooltipTrigger asChild>
|
|
92
|
+
<button
|
|
93
|
+
type="button"
|
|
94
|
+
onClick={handleCopy}
|
|
95
|
+
className="text-oe-gray-light hover:text-oe-dark [@media(pointer:coarse)]:text-oe-dark"
|
|
96
|
+
>
|
|
97
|
+
{copied ? (
|
|
98
|
+
<Check className="h-3.5 w-3.5 text-oe-green" />
|
|
99
|
+
) : (
|
|
100
|
+
<Copy className="h-3.5 w-3.5" />
|
|
101
|
+
)}
|
|
102
|
+
</button>
|
|
103
|
+
</TooltipTrigger>
|
|
104
|
+
<TooltipContent>{copied ? translations.copied : translations.copy}</TooltipContent>
|
|
105
|
+
</Tooltip>
|
|
106
|
+
)}
|
|
107
|
+
{linkable && (
|
|
108
|
+
<Tooltip>
|
|
109
|
+
<TooltipTrigger asChild>
|
|
110
|
+
<button
|
|
111
|
+
type="button"
|
|
112
|
+
onClick={handleOpenUrl}
|
|
113
|
+
className="text-oe-gray-light hover:text-oe-dark [@media(pointer:coarse)]:text-oe-dark"
|
|
114
|
+
>
|
|
115
|
+
<ExternalLink className="h-3.5 w-3.5" />
|
|
116
|
+
</button>
|
|
117
|
+
</TooltipTrigger>
|
|
118
|
+
<TooltipContent>{translations.open}</TooltipContent>
|
|
119
|
+
</Tooltip>
|
|
120
|
+
)}
|
|
121
|
+
{mailable && (
|
|
122
|
+
<Tooltip>
|
|
123
|
+
<TooltipTrigger asChild>
|
|
124
|
+
<button
|
|
125
|
+
type="button"
|
|
126
|
+
onClick={handleMailto}
|
|
127
|
+
className="text-oe-gray-light hover:text-oe-dark [@media(pointer:coarse)]:text-oe-dark"
|
|
128
|
+
>
|
|
129
|
+
<Mail className="h-3.5 w-3.5" />
|
|
130
|
+
</button>
|
|
131
|
+
</TooltipTrigger>
|
|
132
|
+
<TooltipContent>{translations.email}</TooltipContent>
|
|
133
|
+
</Tooltip>
|
|
134
|
+
)}
|
|
135
|
+
{callable && (
|
|
136
|
+
<Tooltip>
|
|
137
|
+
<TooltipTrigger asChild>
|
|
138
|
+
<button
|
|
139
|
+
type="button"
|
|
140
|
+
onClick={handleTel}
|
|
141
|
+
className="text-oe-gray-light hover:text-oe-dark [@media(pointer:coarse)]:text-oe-dark"
|
|
142
|
+
>
|
|
143
|
+
<Phone className="h-3.5 w-3.5" />
|
|
144
|
+
</button>
|
|
145
|
+
</TooltipTrigger>
|
|
146
|
+
<TooltipContent>{translations.call}</TooltipContent>
|
|
147
|
+
</Tooltip>
|
|
148
|
+
)}
|
|
149
|
+
</span>
|
|
150
|
+
)}
|
|
151
|
+
</dd>
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export type { DetailFieldProps, DetailFieldTranslations };
|
package/src/index.ts
CHANGED
|
@@ -120,6 +120,10 @@ export {
|
|
|
120
120
|
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } from "./components/tooltip.tsx";
|
|
121
121
|
|
|
122
122
|
// App-level components
|
|
123
|
+
export { DeleteConfirmDialog } from "./components/delete-confirm-dialog.tsx";
|
|
124
|
+
export type { DeleteConfirmDialogProps } from "./components/delete-confirm-dialog.tsx";
|
|
125
|
+
export { DetailField } from "./components/detail-field.tsx";
|
|
126
|
+
export type { DetailFieldProps, DetailFieldTranslations } from "./components/detail-field.tsx";
|
|
123
127
|
export { LanguageSwitch } from "./components/language-switch.tsx";
|
|
124
128
|
export { HealthStatus } from "./components/health-status.tsx";
|
|
125
129
|
export type { HealthStatusProps, HealthStatusTranslations } from "./components/health-status.tsx";
|