Add diagram and pattern glyphs as currentColor SVG components so a parent text class can recolor them.

This commit is contained in:
adilallo committed 2026-11-12 17:50:45 -07:00
1 parent 9a9358ad46
commit bf9ee79c9f
44 files changed
+995

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
import "@testing-library/jest-dom/vitest";
import { describe, expect, it } from "vitest";
import { render, screen } from "@testing-library/react";
import DiagramGlyph, {
DIAGRAM_GLYPH_OPTIONS,
} from "../../app/components/asset/DiagramGlyph";
describe("DiagramGlyph", () => {
it("renders every glyph at 48 and 24", () => {
const { rerender } = render(
<DiagramGlyph glyph="group" size={48} />,
);
expect(document.querySelector("svg")).toHaveAttribute("width", "48");
expect(document.querySelector("svg")).toHaveAttribute("height", "48");
expect(document.querySelector("svg")).toHaveAttribute("aria-hidden");
rerender(<DiagramGlyph glyph="group" size={24} />);
expect(document.querySelector("svg")).toHaveAttribute("width", "24");
expect(document.querySelector("svg")).toHaveAttribute("height", "24");
for (const glyph of DIAGRAM_GLYPH_OPTIONS) {
rerender(<DiagramGlyph glyph={glyph} />);
expect(document.querySelector("svg")).toBeInTheDocument();
}
});
it("names a diagram glyph and keeps a decorative glyph unlabeled", () => {
const { rerender } = render(
<DiagramGlyph
glyph="rotation"
title="Rotation"
description="Roles move on a set schedule."
/>,
);
expect(
screen.getByRole("img", {
name: "Rotation. Roles move on a set schedule.",
}),
).toBeInTheDocument();
rerender(<DiagramGlyph glyph="rotation" />);
expect(screen.queryByRole("img")).not.toBeInTheDocument();
expect(document.querySelector("svg")).toHaveAttribute("aria-hidden");
});
it("recolors with one text class", () => {
render(
<DiagramGlyph
glyph="consensus"
className="text-[var(--color-content-default-brand-primary)]"
/>,
);
expect(document.querySelector("svg")).toHaveClass(
"text-[var(--color-content-default-brand-primary)]",
);
});
});
+55
View File
@@ -0,0 +1,55 @@
import "@testing-library/jest-dom/vitest";
import { describe, expect, it } from "vitest";
import { render, screen } from "@testing-library/react";
import PatternGlyph, {
PATTERN_GLYPH_OPTIONS,
} from "../../app/components/asset/PatternGlyph";
describe("PatternGlyph", () => {
it("renders every glyph at 48 and 24", () => {
const { rerender } = render(
<PatternGlyph glyph="lazy-consensus" size={48} />,
);
expect(document.querySelector("svg")).toHaveAttribute("width", "48");
expect(document.querySelector("svg")).toHaveAttribute("aria-hidden");
rerender(<PatternGlyph glyph="lazy-consensus" size={24} />);
expect(document.querySelector("svg")).toHaveAttribute("width", "24");
for (const glyph of PATTERN_GLYPH_OPTIONS) {
rerender(<PatternGlyph glyph={glyph} />);
expect(document.querySelector("svg")).toBeInTheDocument();
}
});
it("names a diagram glyph and keeps a decorative glyph unlabeled", () => {
const { rerender } = render(
<PatternGlyph
glyph="conflict-council"
title="Conflict council"
description="Named members hear what the first steps could not settle."
/>,
);
expect(
screen.getByRole("img", {
name: "Conflict council. Named members hear what the first steps could not settle.",
}),
).toBeInTheDocument();
rerender(<PatternGlyph glyph="conflict-council" />);
expect(screen.queryByRole("img")).not.toBeInTheDocument();
expect(document.querySelector("svg")).toHaveAttribute("aria-hidden");
});
it("recolors with one text class", () => {
render(
<PatternGlyph
glyph="full-consensus"
className="text-[var(--color-content-default-brand-primary)]"
/>,
);
expect(document.querySelector("svg")).toHaveClass(
"text-[var(--color-content-default-brand-primary)]",
);
});
});