@open-elements/ui 0.7.0 → 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/dist/components/capability-status.d.ts +10 -0
- package/dist/components/capability-status.d.ts.map +1 -0
- package/dist/components/capability-status.js +12 -0
- package/dist/components/capability-status.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -1
- package/src/components/__tests__/capability-status.test.tsx +82 -0
- package/src/components/capability-status.tsx +63 -0
- package/src/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-elements/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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
8
|
"url": "https://github.com/OpenElementsLabs/open-elements-ui.git"
|
|
9
9
|
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=20"
|
|
12
|
+
},
|
|
10
13
|
"type": "module",
|
|
11
14
|
"main": "./dist/index.js",
|
|
12
15
|
"module": "./dist/index.js",
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from "vitest";
|
|
2
|
+
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { CapabilityStatus } from "../capability-status.tsx";
|
|
4
|
+
import { TooltipProvider } from "../tooltip.tsx";
|
|
5
|
+
|
|
6
|
+
function renderWithTooltip(ui: React.ReactElement) {
|
|
7
|
+
return render(<TooltipProvider delayDuration={0}>{ui}</TooltipProvider>);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
cleanup();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe("CapabilityStatus", () => {
|
|
15
|
+
it("renders a green indicator and the available text when available", () => {
|
|
16
|
+
const { container } = renderWithTooltip(
|
|
17
|
+
<CapabilityStatus
|
|
18
|
+
available
|
|
19
|
+
label="HEIC image decoding"
|
|
20
|
+
availableText="Available"
|
|
21
|
+
unavailableText="Not available"
|
|
22
|
+
/>,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
expect(screen.getByText("HEIC image decoding")).toBeInTheDocument();
|
|
26
|
+
expect(screen.getByText("Available")).toBeInTheDocument();
|
|
27
|
+
|
|
28
|
+
const icon = container.querySelector("svg.lucide-circle-check");
|
|
29
|
+
expect(icon).toBeInTheDocument();
|
|
30
|
+
expect(icon?.getAttribute("class")).toContain("text-oe-green");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("renders a red warning indicator and the unavailable text when not available", () => {
|
|
34
|
+
const { container } = renderWithTooltip(
|
|
35
|
+
<CapabilityStatus
|
|
36
|
+
available={false}
|
|
37
|
+
label="HEIC image decoding"
|
|
38
|
+
availableText="Available"
|
|
39
|
+
unavailableText="Not available"
|
|
40
|
+
hint="HEIC uploads will be rejected with 415 — check Dockerfile"
|
|
41
|
+
/>,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(screen.getByText("Not available")).toBeInTheDocument();
|
|
45
|
+
|
|
46
|
+
const icon = container.querySelector("svg.lucide-triangle-alert");
|
|
47
|
+
expect(icon).toBeInTheDocument();
|
|
48
|
+
expect(icon?.getAttribute("class")).toContain("text-oe-red");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("exposes the hint as a tooltip when a hint is provided", async () => {
|
|
52
|
+
renderWithTooltip(
|
|
53
|
+
<CapabilityStatus
|
|
54
|
+
available={false}
|
|
55
|
+
label="HEIC image decoding"
|
|
56
|
+
availableText="Available"
|
|
57
|
+
unavailableText="Not available"
|
|
58
|
+
hint="HEIC uploads will be rejected with 415 — check Dockerfile"
|
|
59
|
+
/>,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const trigger = screen.getByRole("note");
|
|
63
|
+
fireEvent.focus(trigger);
|
|
64
|
+
|
|
65
|
+
const tooltip = await screen.findByRole("tooltip");
|
|
66
|
+
expect(tooltip).toHaveTextContent("HEIC uploads will be rejected with 415 — check Dockerfile");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("renders without a tooltip trigger and does not error when no hint is provided", () => {
|
|
70
|
+
renderWithTooltip(
|
|
71
|
+
<CapabilityStatus
|
|
72
|
+
available
|
|
73
|
+
label="HEIC image decoding"
|
|
74
|
+
availableText="Available"
|
|
75
|
+
unavailableText="Not available"
|
|
76
|
+
/>,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(screen.queryByRole("note")).not.toBeInTheDocument();
|
|
80
|
+
expect(screen.getByText("HEIC image decoding")).toBeInTheDocument();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { CircleCheck, TriangleAlert } from "lucide-react";
|
|
4
|
+
import { Card, CardContent } from "./card.tsx";
|
|
5
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.tsx";
|
|
6
|
+
|
|
7
|
+
interface CapabilityStatusProps {
|
|
8
|
+
readonly available: boolean;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly availableText: string;
|
|
11
|
+
readonly unavailableText: string;
|
|
12
|
+
readonly hint?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function CapabilityStatus({
|
|
16
|
+
available,
|
|
17
|
+
label,
|
|
18
|
+
availableText,
|
|
19
|
+
unavailableText,
|
|
20
|
+
hint,
|
|
21
|
+
}: CapabilityStatusProps) {
|
|
22
|
+
const statusText = available ? availableText : unavailableText;
|
|
23
|
+
const Icon = available ? CircleCheck : TriangleAlert;
|
|
24
|
+
|
|
25
|
+
const row = (
|
|
26
|
+
<div className="flex items-center gap-3">
|
|
27
|
+
<Icon
|
|
28
|
+
className={`h-5 w-5 shrink-0 ${available ? "text-oe-green" : "text-oe-red"}`}
|
|
29
|
+
aria-hidden="true"
|
|
30
|
+
/>
|
|
31
|
+
<div className="flex flex-col">
|
|
32
|
+
<span className="text-base font-medium text-oe-dark">{label}</span>
|
|
33
|
+
<span className="text-sm text-oe-gray-mid">{statusText}</span>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Card className="border-oe-gray-light">
|
|
40
|
+
<CardContent>
|
|
41
|
+
{hint ? (
|
|
42
|
+
<Tooltip>
|
|
43
|
+
<TooltipTrigger asChild>
|
|
44
|
+
<div
|
|
45
|
+
tabIndex={0}
|
|
46
|
+
role="note"
|
|
47
|
+
aria-label={`${label}: ${statusText}. ${hint}`}
|
|
48
|
+
className="cursor-help outline-none"
|
|
49
|
+
>
|
|
50
|
+
{row}
|
|
51
|
+
</div>
|
|
52
|
+
</TooltipTrigger>
|
|
53
|
+
<TooltipContent>{hint}</TooltipContent>
|
|
54
|
+
</Tooltip>
|
|
55
|
+
) : (
|
|
56
|
+
row
|
|
57
|
+
)}
|
|
58
|
+
</CardContent>
|
|
59
|
+
</Card>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type { CapabilityStatusProps };
|
package/src/index.ts
CHANGED
|
@@ -139,6 +139,8 @@ export type { DetailFieldProps, DetailFieldTranslations } from "./components/det
|
|
|
139
139
|
export { LanguageSwitch } from "./components/language-switch.tsx";
|
|
140
140
|
export { HealthStatus } from "./components/health-status.tsx";
|
|
141
141
|
export type { HealthStatusProps, HealthStatusTranslations } from "./components/health-status.tsx";
|
|
142
|
+
export { CapabilityStatus } from "./components/capability-status.tsx";
|
|
143
|
+
export type { CapabilityStatusProps } from "./components/capability-status.tsx";
|
|
142
144
|
export { TagChips } from "./components/tag-chips.tsx";
|
|
143
145
|
export type { TagChipsProps } from "./components/tag-chips.tsx";
|
|
144
146
|
export { TagForm } from "./components/tag-form.tsx";
|