Skip to content

Commit 66cf619

Browse files
committed
Legend formatting
1 parent d2085ff commit 66cf619

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

apps/class-solid/src/components/plots/Legend.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { For } from "solid-js";
2-
import { cn } from "~/lib/utils";
3-
import { Checkbox } from "../ui/checkbox";
2+
import { createUniqueId } from "solid-js";
43
import type { ChartData } from "./ChartContainer";
54
import { useChartContext } from "./ChartContainer";
65

@@ -15,21 +14,29 @@ export function Legend<T>(props: LegendProps<T>) {
1514

1615
return (
1716
<div
18-
class={cn(
19-
"flex flex-wrap justify-end text-sm tracking-tight",
20-
`w-[${chart.width}px]`,
21-
)}
17+
class={"flex flex-wrap justify-end gap-2 text-sm tracking-tight"}
18+
style={`max-width: ${chart.width}px;`}
2219
>
2320
<For each={props.entries()}>
24-
{(d) => (
25-
<div class=" flex gap-1">
26-
<Checkbox
27-
checked={props.toggles[d.label]}
28-
onChange={(v) => props.onChange(d.label, v)}
29-
/>
30-
<p style={`color: ${d.color}`}>{d.label}</p>
31-
</div>
32-
)}
21+
{(d) => {
22+
const id = createUniqueId();
23+
return (
24+
<div
25+
class="flex items-center gap-1"
26+
style={`color: ${d.color}; accent-color: ${d.color}`}
27+
>
28+
<input
29+
type="checkbox"
30+
checked={props.toggles[d.label]}
31+
onChange={(v) =>
32+
props.onChange(d.label, v.currentTarget.checked)
33+
}
34+
id={id}
35+
/>
36+
<label for={id}>{d.label}</label>
37+
</div>
38+
);
39+
}}
3340
</For>
3441
</div>
3542
);

0 commit comments

Comments
 (0)