@siyahi/ui 0.1.9-next.12 → 0.1.9-next.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,11 @@ function BarChartCard({ stacked = false, selected = null, onSelect, ...props })
11
11
  ...props,
12
12
  yDomain: props.yDomain ?? (props.data.some((row) => props.series.some(({ key }) => Number(row[key]) > 0)) ? void 0 : DOWN_FROM_ZERO),
13
13
  stackOffset: stacked ? "sign" : void 0,
14
+ onClick: onSelect ? ({ activeTooltipIndex, isTooltipActive }) => {
15
+ if (!isTooltipActive || activeTooltipIndex == null) return;
16
+ const row = props.data[Number(activeTooltipIndex)];
17
+ if (row) onSelect(row[props.xKey] === selected ? null : row[props.xKey]);
18
+ } : void 0,
14
19
  children: props.series.map((item, index) => {
15
20
  const { key, label, color, negativeColor } = item;
16
21
  return /* @__PURE__ */ jsx(Bar, {
@@ -29,11 +34,6 @@ function BarChartCard({ stacked = false, selected = null, onSelect, ...props })
29
34
  0,
30
35
  0
31
36
  ] : 0,
32
- className: onSelect ? "cursor-pointer" : void 0,
33
- onClick: onSelect && ((bar) => {
34
- const value = bar.payload?.[props.xKey];
35
- if (value !== void 0) onSelect(value === selected ? null : value);
36
- }),
37
37
  children: (negativeColor || selected !== null) && props.data.map((row, i) => /* @__PURE__ */ jsx(Cell, {
38
38
  fill: negativeColor && Number(row[key]) < 0 ? negativeColor : color,
39
39
  fillOpacity: selected === null || row[props.xKey] === selected ? 1 : .35
@@ -1,5 +1,5 @@
1
1
  import { ChartColor, ChartSeries, ChartSeriesItem, NumericXProps, SeriesChartProps } from "./chart-series.js";
2
- import { ReactNode } from "react";
2
+ import { ComponentProps, ReactNode } from "react";
3
3
  import { AreaChart, BarChart, LineChart, YAxisProps } from "recharts";
4
4
  //#region src/lib/chart-frame.d.ts
5
5
  interface ChartFrameProps<T extends object, K extends keyof T> extends Omit<SeriesChartProps<T, K>, "yDomain">, NumericXProps {
@@ -15,6 +15,7 @@ interface ChartFrameProps<T extends object, K extends keyof T> extends Omit<Seri
15
15
  horizontal?: boolean;
16
16
  /** "sign" stacks negative values below zero and positive ones above, rather than on one running total. */
17
17
  stackOffset?: "sign";
18
+ onClick?: ComponentProps<typeof BarChart>["onClick"];
18
19
  }
19
20
  /**
20
21
  * The colour a series' Bar takes, which its legend chip shows: the negative colour when every value drawn is below
@@ -31,6 +32,6 @@ export declare function seriesRow<T>(series: ChartSeries<T>, formatValue: (value
31
32
  * that gave its category axis its own id (dash#88) got a plot split in two
32
33
  * and every tooltip headed with the series name instead of the category.
33
34
  */
34
- export declare function ChartFrame<T extends object, K extends keyof T>({ chart: Chart, children, horizontal, stackOffset, title, description, action, data, xKey, series, xFormatter, xTooltipFormatter, valueFormatter, yTickFormatter, yDomain, yTicks, height, xTickDetail, xLabel, yLabel, referenceLines, placeholder, footer, xDomain, xTicks }: ChartFrameProps<T, K>): import("react").JSX.Element;
35
+ export declare function ChartFrame<T extends object, K extends keyof T>({ chart: Chart, children, horizontal, stackOffset, onClick, title, description, action, data, xKey, series, xFormatter, xTooltipFormatter, valueFormatter, yTickFormatter, yDomain, yTicks, height, xTickDetail, xLabel, yLabel, referenceLines, placeholder, footer, xDomain, xTicks }: ChartFrameProps<T, K>): import("react").JSX.Element;
35
36
  //#endregion
36
37
  export {};
@@ -93,7 +93,7 @@ function fittedTick(data, xKey, xFormatter, detailOf, beside) {
93
93
  * that gave its category axis its own id (dash#88) got a plot split in two
94
94
  * and every tooltip headed with the series name instead of the category.
95
95
  */
96
- function ChartFrame({ chart: Chart, children, horizontal = false, stackOffset, title, description, action, data, xKey, series, xFormatter = String, xTooltipFormatter = xFormatter, valueFormatter, yTickFormatter, yDomain, yTicks, height, xTickDetail, xLabel, yLabel, referenceLines = NO_LINES, placeholder, footer, xDomain, xTicks }) {
96
+ function ChartFrame({ chart: Chart, children, horizontal = false, stackOffset, onClick, title, description, action, data, xKey, series, xFormatter = String, xTooltipFormatter = xFormatter, valueFormatter, yTickFormatter, yDomain, yTicks, height, xTickDetail, xLabel, yLabel, referenceLines = NO_LINES, placeholder, footer, xDomain, xTicks }) {
97
97
  const { numberLocale } = useLocale();
98
98
  const formatValue = valueFormatter ?? new Intl.NumberFormat(numberLocale).format;
99
99
  const config = Object.fromEntries(series.map(({ key, label, color }) => [key, {
@@ -114,12 +114,14 @@ function ChartFrame({ chart: Chart, children, horizontal = false, stackOffset, t
114
114
  children: placeholder
115
115
  }) : /* @__PURE__ */ jsx(ChartContainer, {
116
116
  config,
117
- className: "aspect-auto w-full",
117
+ className: cn("aspect-auto w-full", onClick && "cursor-pointer"),
118
118
  style: { height },
119
119
  children: /* @__PURE__ */ jsxs(Chart, {
120
120
  data,
121
121
  layout: horizontal ? "vertical" : "horizontal",
122
122
  stackOffset,
123
+ onClick,
124
+ throttledEvents: onClick ? [] : void 0,
123
125
  margin: {
124
126
  left: 0,
125
127
  right: xTicks ? endRoom(xFormatter, xTicks) : 8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siyahi/ui",
3
- "version": "0.1.9-next.12",
3
+ "version": "0.1.9-next.13",
4
4
  "description": "Stock shadcn/ui on Base UI and Tailwind v4, a finance theme, a few compositions and formatters.",
5
5
  "keywords": [
6
6
  "base-ui",