Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/yummy-sites-sink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@cloudflare/kumo-docs-astro": minor
"@cloudflare/kumo": minor
---

Create Sankey Chart component
1 change: 1 addition & 0 deletions packages/kumo-docs-astro/src/components/SidebarNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const componentItems: NavItem[] = [
const chartItems: NavItem[] = [
{ label: "Charts", href: "/charts" },
{ label: "Timeseries", href: "/charts/timeseries" },
{ label: "Sankey", href: "/charts/sankey" },
{ label: "Custom Chart", href: "/charts/custom" },
];

Expand Down
53 changes: 2 additions & 51 deletions packages/kumo-docs-astro/src/components/demos/Chart/ChartDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
import * as echarts from "echarts/core";
import type { KumoChartOption } from "@cloudflare/kumo";
import { BarChart, LineChart, PieChart } from "echarts/charts";
import { useEffect, useMemo, useState } from "react";
import { useMemo } from "react";
import { useIsDarkMode } from "~/lib/use-is-dark-mode";
import {
AriaComponent,
AxisPointerComponent,
Expand Down Expand Up @@ -624,53 +625,3 @@ function buildSeriesData(
return [ts, value * timeScale];
});
}

function useIsDarkMode() {
const getIsDark = () => {
if (typeof document === "undefined") return false;

const root = document.documentElement;

const mode = root.getAttribute("data-mode");
if (mode === "dark") return true;
if (mode === "light") return false;

// 1) Prefer explicit html class contract (Tailwind-style)
if (root.classList.contains("dark")) return true;
if (root.classList.contains("light")) return false;

// 2) Otherwise fall back to system preference
return (
window.matchMedia?.("(prefers-color-scheme: dark)")?.matches ?? false
);
};

const [isDark, setIsDark] = useState(getIsDark);

useEffect(() => {
const root = document.documentElement;

const update = () => setIsDark(getIsDark());

// Watch html class changes
const mo = new MutationObserver(update);
mo.observe(root, {
attributes: true,
attributeFilter: ["data-mode", "class"],
});

const mql = window.matchMedia?.("(prefers-color-scheme: dark)");
if (mql) {
mql.addEventListener("change", update);
}

return () => {
if (mql) {
mql.removeEventListener("change", update);
}
mo.disconnect();
};
}, []);

return isDark;
}
Loading