@open-elements/ui 0.2.0 → 0.4.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 (45) hide show
  1. package/README.md +31 -0
  2. package/dist/components/delete-confirm-dialog.d.ts +14 -0
  3. package/dist/components/delete-confirm-dialog.d.ts.map +1 -0
  4. package/dist/components/delete-confirm-dialog.js +22 -0
  5. package/dist/components/delete-confirm-dialog.js.map +1 -0
  6. package/dist/components/detail-field.d.ts +21 -0
  7. package/dist/components/detail-field.d.ts.map +1 -0
  8. package/dist/components/detail-field.js +47 -0
  9. package/dist/components/detail-field.js.map +1 -0
  10. package/dist/components/markdown-editor.d.ts +3 -0
  11. package/dist/components/markdown-editor.d.ts.map +1 -0
  12. package/dist/components/markdown-editor.js +77 -0
  13. package/dist/components/markdown-editor.js.map +1 -0
  14. package/dist/components/markdown-view.d.ts +3 -0
  15. package/dist/components/markdown-view.d.ts.map +1 -0
  16. package/dist/components/markdown-view.js +46 -0
  17. package/dist/components/markdown-view.js.map +1 -0
  18. package/dist/components/user-avatar.d.ts +3 -0
  19. package/dist/components/user-avatar.d.ts.map +1 -0
  20. package/dist/components/user-avatar.js +38 -0
  21. package/dist/components/user-avatar.js.map +1 -0
  22. package/dist/components/user-multi-select.d.ts +3 -0
  23. package/dist/components/user-multi-select.d.ts.map +1 -0
  24. package/dist/components/user-multi-select.js +46 -0
  25. package/dist/components/user-multi-select.js.map +1 -0
  26. package/dist/index.d.ts +9 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +8 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/tsconfig.build.tsbuildinfo +1 -1
  31. package/dist/types/index.d.ts +30 -0
  32. package/dist/types/index.d.ts.map +1 -1
  33. package/package.json +16 -4
  34. package/src/components/__tests__/markdown-editor.test.tsx +35 -0
  35. package/src/components/__tests__/markdown-view.test.tsx +32 -0
  36. package/src/components/__tests__/user-avatar.test.tsx +68 -0
  37. package/src/components/__tests__/user-multi-select.test.tsx +97 -0
  38. package/src/components/delete-confirm-dialog.tsx +80 -0
  39. package/src/components/detail-field.tsx +156 -0
  40. package/src/components/markdown-editor.tsx +143 -0
  41. package/src/components/markdown-view.tsx +49 -0
  42. package/src/components/user-avatar.tsx +60 -0
  43. package/src/components/user-multi-select.tsx +134 -0
  44. package/src/index.ts +20 -0
  45. package/src/types/index.ts +36 -0
@@ -24,4 +24,34 @@ export interface TagMultiSelectProps {
24
24
  readonly loadTags: () => Promise<TagOption[]>;
25
25
  readonly translations: TagMultiSelectTranslations;
26
26
  }
27
+ export interface UserOption {
28
+ readonly id: string;
29
+ readonly name: string;
30
+ readonly email: string;
31
+ readonly avatarUrl?: string | null;
32
+ }
33
+ export interface UserAvatarProps {
34
+ readonly user: UserOption;
35
+ readonly size?: "sm" | "md";
36
+ }
37
+ export interface UserMultiSelectTranslations {
38
+ readonly placeholder: string;
39
+ readonly searchPlaceholder: string;
40
+ readonly empty: string;
41
+ }
42
+ export interface UserMultiSelectProps {
43
+ readonly users: readonly UserOption[];
44
+ readonly selectedIds: readonly string[];
45
+ readonly onChange: (ids: string[]) => void;
46
+ readonly disabledIds?: readonly string[];
47
+ readonly translations: UserMultiSelectTranslations;
48
+ }
49
+ export interface MarkdownEditorProps {
50
+ readonly value: string;
51
+ readonly onChange: (value: string) => void;
52
+ readonly placeholder?: string;
53
+ }
54
+ export interface MarkdownViewProps {
55
+ readonly content: string;
56
+ }
27
57
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ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W,oBAAoB;IACnC,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC3C,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAC;CACpD;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@open-elements/ui",
3
- "version": "0.2.0",
3
+ "version": "0.4.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/OpenElements/open-elements-ui.git"
8
+ "url": "https://github.com/OpenElementsLabs/open-elements-ui.git"
9
9
  },
10
10
  "type": "module",
11
11
  "main": "./dist/index.js",
@@ -35,7 +35,13 @@
35
35
  "clsx": "^2.1.0",
36
36
  "tailwind-merge": "^3.0.0",
37
37
  "react-day-picker": "^9.14.0",
38
- "date-fns": "^4.1.0"
38
+ "date-fns": "^4.1.0",
39
+ "@tiptap/core": "^3.22.0",
40
+ "@tiptap/react": "^3.22.0",
41
+ "@tiptap/starter-kit": "^3.22.0",
42
+ "@tiptap/extension-link": "^3.22.0",
43
+ "@tiptap/extension-placeholder": "^3.22.0",
44
+ "tiptap-markdown": "^0.9.0"
39
45
  },
40
46
  "devDependencies": {
41
47
  "@types/react": "^19.0.0",
@@ -59,7 +65,13 @@
59
65
  "clsx": "^2.1.0",
60
66
  "tailwind-merge": "^3.0.0",
61
67
  "react-day-picker": "^9.14.0",
62
- "date-fns": "^4.1.0"
68
+ "date-fns": "^4.1.0",
69
+ "@tiptap/core": "^3.22.0",
70
+ "@tiptap/react": "^3.22.0",
71
+ "@tiptap/starter-kit": "^3.22.0",
72
+ "@tiptap/extension-link": "^3.22.0",
73
+ "@tiptap/extension-placeholder": "^3.22.0",
74
+ "tiptap-markdown": "^0.9.0"
63
75
  },
64
76
  "scripts": {
65
77
  "build": "tsc -p tsconfig.build.json && pnpm run build:css",
@@ -0,0 +1,35 @@
1
+ import { describe, it, expect, vi, afterEach } from "vitest";
2
+ import { render, cleanup } from "@testing-library/react";
3
+
4
+ // Mock TipTap before importing the component
5
+ vi.mock("@tiptap/react", () => ({
6
+ useEditor: () => null,
7
+ EditorContent: () => <div data-testid="editor-content" />,
8
+ }));
9
+ vi.mock("@tiptap/starter-kit", () => ({ default: { configure: () => ({}) } }));
10
+ vi.mock("@tiptap/extension-link", () => ({ default: { configure: () => ({}) } }));
11
+ vi.mock("@tiptap/extension-placeholder", () => ({ default: { configure: () => ({}) } }));
12
+ vi.mock("tiptap-markdown", () => ({ Markdown: {} }));
13
+
14
+ import { MarkdownEditor } from "../markdown-editor.tsx";
15
+
16
+ afterEach(cleanup);
17
+
18
+ describe("MarkdownEditor", () => {
19
+ it("mounts without error", () => {
20
+ const { container } = render(<MarkdownEditor value="" onChange={() => {}} />);
21
+ expect(container).toBeTruthy();
22
+ });
23
+
24
+ it("renders editor content area", () => {
25
+ const { container } = render(<MarkdownEditor value="" onChange={() => {}} />);
26
+ expect(container.querySelector("[data-testid='editor-content']")).toBeTruthy();
27
+ });
28
+
29
+ it("accepts placeholder prop without error", () => {
30
+ const { container } = render(
31
+ <MarkdownEditor value="" onChange={() => {}} placeholder="Type here..." />,
32
+ );
33
+ expect(container).toBeTruthy();
34
+ });
35
+ });
@@ -0,0 +1,32 @@
1
+ import { describe, it, expect, vi, afterEach } from "vitest";
2
+ import { render, cleanup } from "@testing-library/react";
3
+
4
+ // Mock TipTap before importing the component
5
+ vi.mock("@tiptap/react", () => ({
6
+ useEditor: () => null,
7
+ EditorContent: () => <div data-testid="editor-content" />,
8
+ }));
9
+ vi.mock("@tiptap/starter-kit", () => ({ default: { configure: () => ({}) } }));
10
+ vi.mock("@tiptap/extension-link", () => ({ default: { configure: () => ({}) } }));
11
+ vi.mock("tiptap-markdown", () => ({ Markdown: {} }));
12
+
13
+ import { MarkdownView } from "../markdown-view.tsx";
14
+
15
+ afterEach(cleanup);
16
+
17
+ describe("MarkdownView", () => {
18
+ it("mounts without error", () => {
19
+ const { container } = render(<MarkdownView content="" />);
20
+ expect(container).toBeTruthy();
21
+ });
22
+
23
+ it("renders editor content area", () => {
24
+ const { container } = render(<MarkdownView content="Hello world" />);
25
+ expect(container.querySelector("[data-testid='editor-content']")).toBeTruthy();
26
+ });
27
+
28
+ it("accepts markdown content without error", () => {
29
+ const { container } = render(<MarkdownView content="Hello **bold** and *italic*" />);
30
+ expect(container).toBeTruthy();
31
+ });
32
+ });
@@ -0,0 +1,68 @@
1
+ import { describe, it, expect, afterEach } from "vitest";
2
+ import { render, cleanup } from "@testing-library/react";
3
+ import { UserAvatar } from "../user-avatar.tsx";
4
+ import type { UserOption } from "../../types/index.ts";
5
+
6
+ afterEach(cleanup);
7
+
8
+ const userWithAvatar: UserOption = {
9
+ id: "user-1",
10
+ name: "Hendrik Ebbers",
11
+ email: "hendrik@example.com",
12
+ avatarUrl: "https://example.com/avatar.jpg",
13
+ };
14
+
15
+ const userWithoutAvatar: UserOption = {
16
+ id: "user-2",
17
+ name: "Hendrik Ebbers",
18
+ email: "hendrik@example.com",
19
+ };
20
+
21
+ const singleNameUser: UserOption = {
22
+ id: "user-3",
23
+ name: "Admin",
24
+ email: "admin@example.com",
25
+ };
26
+
27
+ describe("UserAvatar", () => {
28
+ it("renders initials when no avatar URL", () => {
29
+ const { container } = render(<UserAvatar user={userWithoutAvatar} />);
30
+ expect(container.querySelector("span")?.textContent).toBe("HE");
31
+ });
32
+
33
+ it("renders single initial for single-name user", () => {
34
+ const { container } = render(<UserAvatar user={singleNameUser} />);
35
+ expect(container.querySelector("span")?.textContent).toBe("A");
36
+ });
37
+
38
+ it("renders avatar image when URL is provided", () => {
39
+ const { container } = render(<UserAvatar user={userWithAvatar} />);
40
+ const img = container.querySelector("img");
41
+ expect(img).not.toBeNull();
42
+ expect(img?.getAttribute("src")).toBe("https://example.com/avatar.jpg");
43
+ expect(img?.getAttribute("alt")).toBe("Hendrik Ebbers");
44
+ });
45
+
46
+ it("renders small size by default", () => {
47
+ const { container } = render(<UserAvatar user={userWithoutAvatar} size="sm" />);
48
+ const el = container.querySelector("span");
49
+ expect(el?.className).toContain("h-6");
50
+ expect(el?.className).toContain("w-6");
51
+ });
52
+
53
+ it("renders medium size when specified", () => {
54
+ const { container } = render(<UserAvatar user={userWithoutAvatar} size="md" />);
55
+ const el = container.querySelector("span");
56
+ expect(el?.className).toContain("h-8");
57
+ expect(el?.className).toContain("w-8");
58
+ });
59
+
60
+ it("assigns deterministic color based on user id", () => {
61
+ const { container: c1 } = render(<UserAvatar user={userWithoutAvatar} />);
62
+ const class1 = c1.querySelector("span")?.className;
63
+ cleanup();
64
+ const { container: c2 } = render(<UserAvatar user={userWithoutAvatar} />);
65
+ const class2 = c2.querySelector("span")?.className;
66
+ expect(class1).toBe(class2);
67
+ });
68
+ });
@@ -0,0 +1,97 @@
1
+ import { describe, it, expect, vi } from "vitest";
2
+ import { render } from "@testing-library/react";
3
+ import { UserMultiSelect } from "../user-multi-select.tsx";
4
+ import type { UserOption, UserMultiSelectTranslations } from "../../types/index.ts";
5
+
6
+ const mockTranslations: UserMultiSelectTranslations = {
7
+ placeholder: "Select members...",
8
+ searchPlaceholder: "Search...",
9
+ empty: "No users found",
10
+ };
11
+
12
+ const mockUsers: UserOption[] = [
13
+ { id: "1", name: "Alice Adams", email: "alice@example.com" },
14
+ { id: "2", name: "Bob Baker", email: "bob@example.com" },
15
+ { id: "3", name: "Charlie Clark", email: "charlie@example.com" },
16
+ ];
17
+
18
+ describe("UserMultiSelect", () => {
19
+ it("renders with empty user list showing placeholder", () => {
20
+ const { getByText } = render(
21
+ <UserMultiSelect
22
+ users={[]}
23
+ selectedIds={[]}
24
+ onChange={() => {}}
25
+ translations={mockTranslations}
26
+ />,
27
+ );
28
+
29
+ expect(getByText("Select members...")).toBeInTheDocument();
30
+ });
31
+
32
+ it("shows selected user chips", () => {
33
+ const { getAllByText } = render(
34
+ <UserMultiSelect
35
+ users={mockUsers}
36
+ selectedIds={["1", "2"]}
37
+ onChange={() => {}}
38
+ translations={mockTranslations}
39
+ />,
40
+ );
41
+
42
+ expect(getAllByText("Alice Adams").length).toBeGreaterThanOrEqual(1);
43
+ expect(getAllByText("Bob Baker").length).toBeGreaterThanOrEqual(1);
44
+ });
45
+
46
+ it("does not show remove button for disabled users in chips", () => {
47
+ const { container } = render(
48
+ <UserMultiSelect
49
+ users={mockUsers}
50
+ selectedIds={["1"]}
51
+ onChange={() => {}}
52
+ disabledIds={["1"]}
53
+ translations={mockTranslations}
54
+ />,
55
+ );
56
+
57
+ // The trigger button contains chips; disabled user chips should not have a role="button" remove element
58
+ const trigger = container.querySelector("[data-slot='popover-trigger']");
59
+ const removeBtn = trigger?.querySelector("[role='button']");
60
+ expect(removeBtn).toBeNull();
61
+ });
62
+
63
+ it("uses placeholder from translations", () => {
64
+ const deTranslations: UserMultiSelectTranslations = {
65
+ placeholder: "Mitglieder auswählen...",
66
+ searchPlaceholder: "Suchen...",
67
+ empty: "Keine Benutzer gefunden",
68
+ };
69
+
70
+ const { getByText } = render(
71
+ <UserMultiSelect
72
+ users={[]}
73
+ selectedIds={[]}
74
+ onChange={() => {}}
75
+ translations={deTranslations}
76
+ />,
77
+ );
78
+
79
+ expect(getByText("Mitglieder auswählen...")).toBeInTheDocument();
80
+ });
81
+
82
+ it("calls onChange is provided as callback prop", () => {
83
+ const onChange = vi.fn();
84
+
85
+ const { container } = render(
86
+ <UserMultiSelect
87
+ users={mockUsers}
88
+ selectedIds={["1"]}
89
+ onChange={onChange}
90
+ translations={mockTranslations}
91
+ />,
92
+ );
93
+
94
+ // Verify component renders with the callback without crashing
95
+ expect(container).toBeTruthy();
96
+ });
97
+ });
@@ -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 };