Synertech Web/ui v0.57.5 Site Storybook

Documentation / Dashboards

ChartFilterBar

Client@synertech/uiOpen in Storybook

A dashboard’s filters, in a single row above everything they frame. It is not a chart, barely a component: a rule written down as a layout. A dashboard filtered card by card is a dashboard whose numbers stop agreeing; the row therefore applies to every panel below it, and the period picker never sits inside one of them.

It builds no control of its own: compose it with ChartPeriodPicker for the window, Select and Dropdown for the dimensions, and the actions slot (pushed to the far end) for an export, a refresh, a saved view.

A "use client" component: it reads the labels provider for its accessible name (role="group", “Filtres” in French), which label overrides.

Examples

Basic usage

A period and a dimension, side by side. Each filter stays controlled by the application, which reruns its queries when one changes.

Open in a tab
import { useState } from "react";
import { ChartFilterBar, ChartPeriodPicker, Select, createPeriod, type ChartPeriod } from "@synertech/ui";

const regions = [
  { value: "all", label: "Toutes les régions" },
  { value: "qc", label: "Québec" },
  { value: "on", label: "Ontario" },
  { value: "bc", label: "Colombie-Britannique" },
];

export function Basic() {
  const [period, setPeriod] = useState<ChartPeriod>(() => createPeriod("30d"));
  const [region, setRegion] = useState("all");

  return (
    <ChartFilterBar>
      <ChartPeriodPicker size="sm" value={period} onChange={setPeriod} locale="fr-CA" />
      <Select
        size="sm"
        options={regions}
        value={region}
        onValueChange={setRegion}
        triggerClassName="w-52"
      />
    </ChartFilterBar>
  );
}

Actions at the end of the row

Whatever is passed to actions is pushed to the right: an export of the filtered set, a reset of the filters.

Open in a tab
import { useState } from "react";
import { Button, ChartExportButton, ChartFilterBar, Select } from "@synertech/ui";

const months = ["Jan", "Fév", "Mar", "Avr", "Mai", "Juin"];

const series = [{ key: "sessions", label: "Sessions" }];

const regions = [
  { value: "all", label: "Toutes les régions" },
  { value: "qc", label: "Québec" },
  { value: "on", label: "Ontario" },
  { value: "bc", label: "Colombie-Britannique" },
];

export function WithActions() {
  const [region, setRegion] = useState("all");
  const rows = months.map((month, index) => ({ month, sessions: 18000 + index * 3200 }));

  return (
    <ChartFilterBar
      actions={
        <>
          <Button size="sm" onClick={() => setRegion("all")}>
            Réinitialiser
          </Button>
          <ChartExportButton data={rows} series={series} xKey="month" xLabel="Mois" size="sm" />
        </>
      }
    >
      <Select size="sm" options={regions} value={region} onValueChange={setRegion} />
    </ChartFilterBar>
  );
}

Multiple-choice filter

A multiple dimension is composed with Dropdown and its checkbox items; the row imposes no particular control.

Open in a tab
import { useState } from "react";
import { ChartFilterBar, ChartPeriodPicker, Dropdown, DropdownCheckboxItem, DropdownContent, DropdownTrigger } from "@synertech/ui";

const channelOptions = [
  { value: "direct", label: "Direct" },
  { value: "organique", label: "Organique" },
  { value: "payant", label: "Payant" },
];

export function MultiSelectFilter() {
  const [channels, setChannels] = useState(["direct", "organique"]);
  const toggle = (channel: string, checked: boolean) =>
    setChannels((current) =>
      checked ? [...current, channel] : current.filter((entry) => entry !== channel)
    );

  return (
    <ChartFilterBar size="sm" label="Filtres du rapport d’acquisition">
      <ChartPeriodPicker size="sm" defaultValue="90d" locale="fr-CA" />
      <Dropdown>
        <DropdownTrigger className="rounded-full border border-gray-300 px-3 py-1 text-xs">
          Canaux ({channels.length})
        </DropdownTrigger>
        <DropdownContent>
          {channelOptions.map((channel) => (
            <DropdownCheckboxItem
              key={channel.value}
              checked={channels.includes(channel.value)}
              onCheckedChange={(checked) => toggle(channel.value, checked)}
              closeOnChange={false}
            >
              {channel.label}
            </DropdownCheckboxItem>
          ))}
        </DropdownContent>
      </Dropdown>
    </ChartFilterBar>
  );
}

A complete dashboard

One row, two charts reading the same filters. sticky keeps it on screen while scrolling; the French provider translates the labels.

Open in a tab
import { useMemo, useState } from "react";
import { BarChart, ChartFilterBar, ChartPeriodPicker, LineChart, Select, UILabelsProvider, createPeriod, formatPeriodRange, frenchUILabels, type ChartPeriod } from "@synertech/ui";

const months = ["Jan", "Fév", "Mar", "Avr", "Mai", "Juin"];

const regions = [
  { value: "all", label: "Toutes les régions" },
  { value: "qc", label: "Québec" },
  { value: "on", label: "Ontario" },
  { value: "bc", label: "Colombie-Britannique" },
];

const series = [{ key: "sessions", label: "Sessions" }];

export function Dashboard() {
  const [period, setPeriod] = useState<ChartPeriod>(() => createPeriod("12m"));
  const [region, setRegion] = useState("all");

  // Remplace la requête d’une vraie application : les deux graphiques lisent les mêmes filtres.
  const data = useMemo(() => {
    const weight = region === "all" ? 1 : 0.35;
    return months.map((month, index) => ({
      month,
      sessions: Math.round((18000 + index * 3200) * weight),
      conversions: Math.round((620 + index * 140) * weight),
    }));
  }, [region]);

  return (
    <UILabelsProvider labels={frenchUILabels}>
      <div className="flex flex-col gap-6">
        <ChartFilterBar sticky>
          <ChartPeriodPicker size="sm" value={period} onChange={setPeriod} locale="fr-CA" />
          <Select size="sm" options={regions} value={region} onValueChange={setRegion} />
          <span className="text-xs text-gray-500 dark:text-gray-400">
            {formatPeriodRange(period.from, period.to, "fr-CA")}
          </span>
        </ChartFilterBar>

        <div className="grid grid-cols-1 gap-6 md:grid-cols-2">
          <LineChart data={data} series={series} x={{ key: "month" }} title="Sessions" />
          <BarChart
            data={data}
            series={[{ key: "conversions", label: "Conversions" }]}
            x={{ key: "month" }}
            title="Conversions"
          />
        </div>
      </div>
    </UILabelsProvider>
  );
}

API reference

Components

ChartFilterBar

ComponentClient

The filters, in one row above everything they frame.

Not a chart and barely a component — a rule written down as a layout. A dashboard filtered per card is a dashboard whose numbers stop agreeing: two panels answer two questions and nothing on screen says so. One row, above the charts, applying to all of them, is the only arrangement where a reader can trust that two figures are comparable.

It composes what the library already has — ChartPeriodPicker for the window, Select and Dropdown for the dimensions — rather than growing controls of its own.

<ChartFilterBar actions={<Button size="sm">Export</Button>}>
  <ChartPeriodPicker value={period} onChange={setPeriod} />
  <Select size="sm" options={regions} value={region} onValueChange={setRegion} />
</ChartFilterBar>
import { ChartFilterBar } from "@synertech/ui";

Props — ChartFilterBarProps

PropTypeDefaultDescription
children• ReactNode —
actions ReactNode —

Pushed to the far end of the row: an export, a refresh, a saved view.

bordered boolean true

The rule under the row, which is what makes it read as a frame.

label string —

Names the row for assistive technology. Defaults to the translated "Filters".

size ChartSize "md"
sticky boolean false

Keeps the row on screen while a long dashboard scrolls under it.

+ 277 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).