Skip to content

Commit fc6033b

Browse files
committed
feat(ui): adds ExpandCollapseButtons shared component
1 parent 378e818 commit fc6033b

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
export interface ExpandCollapseButtonsProps {
2+
onExpandAll: () => void;
3+
onCollapseAll: () => void;
4+
}
5+
6+
export default function ExpandCollapseButtons(props: ExpandCollapseButtonsProps) {
7+
return (
8+
<div class="flex items-center gap-1">
9+
<button
10+
class="btn btn-ghost btn-xs"
11+
title="Expand all"
12+
aria-label="Expand all"
13+
onClick={() => props.onExpandAll()}
14+
>
15+
<svg
16+
xmlns="http://www.w3.org/2000/svg"
17+
fill="none"
18+
viewBox="0 0 24 24"
19+
stroke-width={1.5}
20+
stroke="currentColor"
21+
class="h-4 w-4"
22+
>
23+
<path
24+
stroke-linecap="round"
25+
stroke-linejoin="round"
26+
d="m4.5 5.25 7.5 7.5 7.5-7.5m-15 6 7.5 7.5 7.5-7.5"
27+
/>
28+
</svg>
29+
</button>
30+
<button
31+
class="btn btn-ghost btn-xs"
32+
title="Collapse all"
33+
aria-label="Collapse all"
34+
onClick={() => props.onCollapseAll()}
35+
>
36+
<svg
37+
xmlns="http://www.w3.org/2000/svg"
38+
fill="none"
39+
viewBox="0 0 24 24"
40+
stroke-width={1.5}
41+
stroke="currentColor"
42+
class="h-4 w-4"
43+
>
44+
<path
45+
stroke-linecap="round"
46+
stroke-linejoin="round"
47+
d="m4.5 18.75 7.5-7.5 7.5 7.5m-15-6 7.5-7.5 7.5 7.5"
48+
/>
49+
</svg>
50+
</button>
51+
</div>
52+
);
53+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { describe, it, expect, vi } from "vitest";
2+
import { render, screen, fireEvent } from "@solidjs/testing-library";
3+
import ExpandCollapseButtons from "../../src/app/components/shared/ExpandCollapseButtons";
4+
5+
describe("ExpandCollapseButtons", () => {
6+
it("renders both buttons with correct aria-labels", () => {
7+
render(() => <ExpandCollapseButtons onExpandAll={() => {}} onCollapseAll={() => {}} />);
8+
expect(screen.getByRole("button", { name: "Expand all" })).toBeTruthy();
9+
expect(screen.getByRole("button", { name: "Collapse all" })).toBeTruthy();
10+
});
11+
12+
it("calls onExpandAll when expand button is clicked", () => {
13+
const onExpandAll = vi.fn();
14+
render(() => <ExpandCollapseButtons onExpandAll={onExpandAll} onCollapseAll={() => {}} />);
15+
fireEvent.click(screen.getByRole("button", { name: "Expand all" }));
16+
expect(onExpandAll).toHaveBeenCalledTimes(1);
17+
});
18+
19+
it("calls onCollapseAll when collapse button is clicked", () => {
20+
const onCollapseAll = vi.fn();
21+
render(() => <ExpandCollapseButtons onExpandAll={() => {}} onCollapseAll={onCollapseAll} />);
22+
fireEvent.click(screen.getByRole("button", { name: "Collapse all" }));
23+
expect(onCollapseAll).toHaveBeenCalledTimes(1);
24+
});
25+
});

0 commit comments

Comments
 (0)