@langchain/macaw-components 1.6.2 → 1.7.1
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.
- package/dist/catalog.json +724 -710
- package/dist/components/BarChart/BarChart.d.ts +1 -1
- package/dist/components/BarChart/BarChart.js +5 -3
- package/dist/components/BarChart/BarChart.js.map +1 -1
- package/dist/components/BarChart/BarChart.types.d.ts +6 -0
- package/dist/components/ChartLegend/ChartLegend.d.ts +17 -0
- package/dist/components/ChartLegend/ChartLegend.js +5 -2
- package/dist/components/ChartLegend/ChartLegend.js.map +1 -1
- package/dist/components/ChartLegend/ChartLegendItemRenderer.d.ts +4 -2
- package/dist/components/ChartLegend/ChartLegendItemRenderer.js +16 -11
- package/dist/components/ChartLegend/ChartLegendItemRenderer.js.map +1 -1
- package/dist/components/ChartLegend/index.d.ts +1 -1
- package/dist/components/ChatConversation/ChatConversation.d.ts +26 -0
- package/dist/components/ChatConversation/ChatConversation.js +115 -0
- package/dist/components/ChatConversation/ChatConversation.js.map +1 -0
- package/dist/components/ChatConversation/index.d.ts +2 -0
- package/dist/components/ChatConversation/index.js +2 -0
- package/dist/components/DonutChart/DonutChart.d.ts +8 -1
- package/dist/components/DonutChart/DonutChart.js +3 -2
- package/dist/components/DonutChart/DonutChart.js.map +1 -1
- package/dist/components/DonutChart/DonutChart.utils.d.ts +10 -7
- package/dist/components/DonutChart/DonutChart.utils.js +13 -11
- package/dist/components/DonutChart/DonutChart.utils.js.map +1 -1
- package/dist/components/LineChart/LineChart.d.ts +1 -1
- package/dist/components/LineChart/LineChart.js +4 -3
- package/dist/components/LineChart/LineChart.js.map +1 -1
- package/dist/components/LineChart/LineChart.types.d.ts +7 -0
- package/dist/components/RadarChart/RadarChart.d.ts +3 -0
- package/dist/components/RadarChart/RadarChart.js +3 -4
- package/dist/components/RadarChart/RadarChart.js.map +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -1
- package/dist/index.js +2 -1
- package/dist/utilities.css +1 -1
- package/docs/DESIGN.md +2 -0
- package/package.json +6 -2
|
@@ -22,4 +22,4 @@ import type { BarChartProps } from './BarChart.types.js';
|
|
|
22
22
|
* />
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
export declare const BarChart: ({ series, categoryAxis, valueAxes, mode, orientation, selectedIds, grid, valueBands, activeCategory, activeGuideBarId, activeBarId, activeLegendItemId, selectionRange, categoryPadding, plotPadding, minimumPlotWidth, groupPadding, minimumBarSize, shouldAnimate, slots, isRendering, showLegend, legendProps, className, "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, getBarAriaLabel, getCategoryAriaLabel, onDatumPointerDown, onDatumPointerMove, onDatumPointerOut, onDatumPointerUp, onDatumActivate, onDatumFocus, onDatumBlur, onBarPointerMove, onBarPointerOut, onBarActivate, onBarFocus, onBarBlur, ...rest }: BarChartProps) => import("react").JSX.Element;
|
|
25
|
+
export declare const BarChart: ({ series, categoryAxis, valueAxes, mode, orientation, selectedIds, excludedIds, grid, valueBands, activeCategory, activeGuideBarId, activeBarId, activeLegendItemId, selectionRange, categoryPadding, plotPadding, minimumPlotWidth, groupPadding, minimumBarSize, shouldAnimate, slots, isRendering, showLegend, legendProps, className, "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, getBarAriaLabel, getCategoryAriaLabel, onDatumPointerDown, onDatumPointerMove, onDatumPointerOut, onDatumPointerUp, onDatumActivate, onDatumFocus, onDatumBlur, onBarPointerMove, onBarPointerOut, onBarActivate, onBarFocus, onBarBlur, ...rest }: BarChartProps) => import("react").JSX.Element;
|
|
@@ -77,7 +77,7 @@ var resolveAxes = (configuredAxes, bars, orientation, innerWidth, innerHeight) =
|
|
|
77
77
|
* />
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
80
|
-
var BarChart = ({ series, categoryAxis, valueAxes, mode = "grouped", orientation = "vertical", selectedIds, grid, valueBands = [], activeCategory, activeGuideBarId, activeBarId, activeLegendItemId, selectionRange, categoryPadding, plotPadding, minimumPlotWidth = 160, groupPadding = BAR_CHART_DEFAULT_GROUP_PADDING, minimumBarSize = 1, shouldAnimate = true, slots, isRendering = true, showLegend, legendProps, className, "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, getBarAriaLabel, getCategoryAriaLabel, onDatumPointerDown, onDatumPointerMove, onDatumPointerOut, onDatumPointerUp, onDatumActivate, onDatumFocus, onDatumBlur, onBarPointerMove, onBarPointerOut, onBarActivate, onBarFocus, onBarBlur, ...rest }) => {
|
|
80
|
+
var BarChart = ({ series, categoryAxis, valueAxes, mode = "grouped", orientation = "vertical", selectedIds, excludedIds, grid, valueBands = [], activeCategory, activeGuideBarId, activeBarId, activeLegendItemId, selectionRange, categoryPadding, plotPadding, minimumPlotWidth = 160, groupPadding = BAR_CHART_DEFAULT_GROUP_PADDING, minimumBarSize = 1, shouldAnimate = true, slots, isRendering = true, showLegend, legendProps, className, "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, getBarAriaLabel, getCategoryAriaLabel, onDatumPointerDown, onDatumPointerMove, onDatumPointerOut, onDatumPointerUp, onDatumActivate, onDatumFocus, onDatumBlur, onBarPointerMove, onBarPointerOut, onBarActivate, onBarFocus, onBarBlur, ...rest }) => {
|
|
81
81
|
const [containerRef, dimensions] = useResizeObserver();
|
|
82
82
|
const [activeBuiltInLegendItemId, setActiveBuiltInLegendItemId] = useState(null);
|
|
83
83
|
const isVertical = orientation === "vertical";
|
|
@@ -90,7 +90,7 @@ var BarChart = ({ series, categoryAxis, valueAxes, mode = "grouped", orientation
|
|
|
90
90
|
valueAxisId: item.valueAxisId ?? defaultAxisId,
|
|
91
91
|
opacity: item.opacity == null || !Number.isFinite(item.opacity) ? 1 : clamp(item.opacity, 0, 1)
|
|
92
92
|
}));
|
|
93
|
-
const visible = selectedIds == null || selectedIds.size === 0
|
|
93
|
+
const visible = resolved.filter((item) => (selectedIds == null || selectedIds.size === 0 || selectedIds.has(item.id)) && !excludedIds?.has(item.id));
|
|
94
94
|
const allCategories = getBarChartCategories(resolved, categoryAxis?.domain);
|
|
95
95
|
return {
|
|
96
96
|
displaySeries: resolved,
|
|
@@ -103,6 +103,7 @@ var BarChart = ({ series, categoryAxis, valueAxes, mode = "grouped", orientation
|
|
|
103
103
|
series,
|
|
104
104
|
valueAxes,
|
|
105
105
|
selectedIds,
|
|
106
|
+
excludedIds,
|
|
106
107
|
categoryAxis?.domain,
|
|
107
108
|
mode
|
|
108
109
|
]);
|
|
@@ -161,7 +162,8 @@ var BarChart = ({ series, categoryAxis, valueAxes, mode = "grouped", orientation
|
|
|
161
162
|
id: item.id,
|
|
162
163
|
label: item.label,
|
|
163
164
|
markerColor: item.color,
|
|
164
|
-
selected: selectedIds?.has(item.id) ?? false
|
|
165
|
+
selected: selectedIds?.has(item.id) ?? false,
|
|
166
|
+
excluded: excludedIds?.has(item.id) ?? false
|
|
165
167
|
}));
|
|
166
168
|
const hasLegend = (showLegend ?? legendItems.length > 1) && legendItems.length > 0;
|
|
167
169
|
const legendLayout = legendProps?.layout ?? "inline";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BarChart.js","names":[],"sources":["../../../src/components/BarChart/BarChart.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\n\nimport { useResizeObserver } from '@mantine/hooks';\nimport { scaleLinear } from '@visx/scale';\nimport { getStringWidth } from '@visx/text';\n\nimport {\n CHART_SINGLE_FILL_COLOR,\n getCategoricalFillChartColor,\n} from '../../utils/chartColors';\nimport {\n CHART_AXIS_LABEL_THICKNESS,\n CHART_TICK_FONT_SIZE,\n CHART_VALUE_AXIS_TICK_LENGTH,\n} from '../../utils/chartConstants';\nimport { clamp } from '../../utils/clamp';\nimport { cn } from '../../utils/cn';\nimport { getYAxisLeftMargin } from '../../utils/getYAxisLeftMargin';\nimport { ChartLegend, type ChartLegendItem } from '../ChartLegend';\nimport type {\n BarChartDisplayAxis,\n BarChartDisplaySeries,\n BarChartLayoutBar,\n BarChartOrientation,\n BarChartProps,\n BarChartValueAxis,\n} from './BarChart.types';\nimport {\n formatBarChartValue,\n getBarChartCategories,\n getBarChartLayout,\n getBarChartValueDomain,\n normalizeBarChartSeries,\n} from './BarChart.utils';\nimport { BarChartPlot } from './BarChartPlot';\nimport {\n BAR_CHART_AXIS_THICKNESS,\n BAR_CHART_DEFAULT_AXIS_ID,\n BAR_CHART_DEFAULT_CATEGORY_PADDING_INNER,\n BAR_CHART_DEFAULT_CATEGORY_PADDING_OUTER,\n BAR_CHART_DEFAULT_GROUP_PADDING,\n BAR_CHART_DEFAULT_MINIMUM_BAR_SIZE,\n BAR_CHART_DEFAULT_TICK_COUNT,\n BAR_CHART_HORIZONTAL_CATEGORY_AXIS_THICKNESS,\n BAR_CHART_MARGIN_RIGHT,\n BAR_CHART_MARGIN_TOP,\n BAR_CHART_MINIMUM_PLOT_WIDTH,\n BAR_CHART_VALUE_AXIS_THICKNESS,\n} from './constants';\n\nconst HORIZONTAL_VALUE_TICK_LABEL_GAP = 8;\n\nconst getAxisIds = (\n configuredAxes: readonly BarChartValueAxis[] | undefined,\n series: readonly BarChartDisplaySeries[]\n): readonly string[] => {\n const axisIds = Array.from(\n new Set(configuredAxes?.map((axis) => axis.id) ?? [])\n );\n for (const item of series) {\n if (!axisIds.includes(item.valueAxisId)) axisIds.push(item.valueAxisId);\n }\n return axisIds.length === 0 ? [BAR_CHART_DEFAULT_AXIS_ID] : axisIds;\n};\n\nconst getHorizontalValueAxisEdgeMargin = (\n config: BarChartValueAxis,\n bars: readonly BarChartLayoutBar[]\n) => {\n const scale = scaleLinear<number>({\n domain: getBarChartValueDomain(bars, config.id, config.domain),\n range: [0, 1],\n nice: config.nice ?? config.domain == null,\n });\n const tickValues =\n config.tickValues ??\n scale.ticks(config.tickCount ?? BAR_CHART_DEFAULT_TICK_COUNT);\n const formatValue = config.formatValue ?? formatBarChartValue;\n const tickLabelStyle = { fontSize: `${CHART_TICK_FONT_SIZE}px` };\n const maximumTickLabelWidth = Math.max(\n 0,\n ...tickValues.map(\n (value) => getStringWidth(formatValue(value), tickLabelStyle) ?? 0\n )\n );\n return Math.ceil(maximumTickLabelWidth / 2);\n};\n\nconst getAutomaticHorizontalValueAxisTickCount = (\n config: BarChartValueAxis,\n bars: readonly BarChartLayoutBar[],\n innerWidth: number\n) => {\n const scale = scaleLinear<number>({\n domain: getBarChartValueDomain(bars, config.id, config.domain),\n range: [0, innerWidth],\n nice: config.nice ?? config.domain == null,\n });\n const formatValue = config.formatValue ?? formatBarChartValue;\n const tickLabelStyle = { fontSize: `${CHART_TICK_FONT_SIZE}px` };\n const maximumTickLabelWidth = Math.max(\n 0,\n ...scale\n .ticks(BAR_CHART_DEFAULT_TICK_COUNT)\n .map(\n (value) =>\n getStringWidth(formatValue(value), tickLabelStyle) ??\n formatValue(value).length * CHART_TICK_FONT_SIZE\n )\n );\n const minimumTickSpacing =\n maximumTickLabelWidth + HORIZONTAL_VALUE_TICK_LABEL_GAP;\n\n return Math.max(\n 1,\n Math.min(\n BAR_CHART_DEFAULT_TICK_COUNT,\n Math.floor(innerWidth / minimumTickSpacing)\n )\n );\n};\n\nconst resolveAxes = (\n configuredAxes: readonly Omit<BarChartDisplayAxis, 'scale'>[],\n bars: readonly BarChartLayoutBar[],\n orientation: BarChartOrientation,\n innerWidth: number,\n innerHeight: number\n): readonly BarChartDisplayAxis[] => {\n return configuredAxes.map((config) => {\n return {\n ...config,\n scale: scaleLinear<number>({\n domain: getBarChartValueDomain(bars, config.id, config.domain),\n range: orientation === 'vertical' ? [innerHeight, 0] : [0, innerWidth],\n nice: config.nice ?? config.domain == null,\n }),\n };\n });\n};\n\n/**\n * Responsive, presentational bars for categorical and time-bucket data. Supports\n * vertical or horizontal orientation, grouped or signed stacks, multiple value\n * axes, threshold bands, controlled legend filtering, selection and active\n * states, keyboard targets, and consumer-owned SVG slots. Bars always use\n * square corners in every orientation and mode.\n *\n * The component is deliberately presentational: consumers retain fetching,\n * sorting, Top-K/Other aggregation, formatting, tooltip content, links, frozen\n * interaction state, and the loading and empty states — pair it with\n * `ChartCard`, `ChartTooltip`, and `EmptyState`. Reach for `slots` before asking\n * for a new prop; each slot receives the resolved scales and geometry.\n *\n * @example\n * ```tsx\n * <BarChart\n * aria-label=\"Requests by environment\"\n * series={[{ id: 'prod', label: 'Production', data }]}\n * selectedIds={selectedIds}\n * legendProps={{ onItemClick: (item) => toggleId(item.id) }}\n * />\n * ```\n */\nexport const BarChart = ({\n series,\n categoryAxis,\n valueAxes,\n mode = 'grouped',\n orientation = 'vertical',\n selectedIds,\n grid,\n valueBands = [],\n activeCategory,\n activeGuideBarId,\n activeBarId,\n activeLegendItemId,\n selectionRange,\n categoryPadding,\n plotPadding,\n minimumPlotWidth = BAR_CHART_MINIMUM_PLOT_WIDTH,\n groupPadding = BAR_CHART_DEFAULT_GROUP_PADDING,\n minimumBarSize = BAR_CHART_DEFAULT_MINIMUM_BAR_SIZE,\n shouldAnimate = true,\n slots,\n isRendering = true,\n showLegend,\n legendProps,\n className,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n getBarAriaLabel,\n getCategoryAriaLabel,\n onDatumPointerDown,\n onDatumPointerMove,\n onDatumPointerOut,\n onDatumPointerUp,\n onDatumActivate,\n onDatumFocus,\n onDatumBlur,\n onBarPointerMove,\n onBarPointerOut,\n onBarActivate,\n onBarFocus,\n onBarBlur,\n ...rest\n}: BarChartProps) => {\n const [containerRef, dimensions] = useResizeObserver();\n const [activeBuiltInLegendItemId, setActiveBuiltInLegendItemId] = useState<\n string | null\n >(null);\n const isVertical = orientation === 'vertical';\n\n // The data half of the pipeline is independent of the measured size, and the\n // documented tooltip pattern re-renders this component on every pointermove.\n const { displaySeries, visibleSeries, categories, bars, axisIds } =\n useMemo(() => {\n const normalized = normalizeBarChartSeries(series);\n const defaultAxisId = valueAxes?.[0]?.id ?? BAR_CHART_DEFAULT_AXIS_ID;\n const resolved: readonly BarChartDisplaySeries[] = normalized.map(\n (item, index) => ({\n ...item,\n color:\n item.color ??\n (normalized.length === 1\n ? CHART_SINGLE_FILL_COLOR\n : getCategoricalFillChartColor(index)),\n valueAxisId: item.valueAxisId ?? defaultAxisId,\n opacity:\n item.opacity == null || !Number.isFinite(item.opacity)\n ? 1\n : clamp(item.opacity, 0, 1),\n })\n );\n const visible =\n selectedIds == null || selectedIds.size === 0\n ? resolved\n : resolved.filter((item) => selectedIds.has(item.id));\n const allCategories = getBarChartCategories(\n resolved,\n categoryAxis?.domain\n );\n return {\n displaySeries: resolved,\n visibleSeries: visible,\n categories: allCategories,\n bars: getBarChartLayout(visible, allCategories, mode),\n axisIds: getAxisIds(valueAxes, visible),\n };\n }, [series, valueAxes, selectedIds, categoryAxis?.domain, mode]);\n\n // A vertical value axis is only as wide as its widest tick label needs, so\n // currency and large counts are not clipped by a fixed gutter.\n const getValueAxisThickness = (config: BarChartValueAxis) => {\n if (config?.thickness != null) return Math.max(0, config.thickness);\n const labelThickness =\n config?.label == null ? 0 : CHART_AXIS_LABEL_THICKNESS;\n if (!isVertical) return BAR_CHART_AXIS_THICKNESS + labelThickness;\n return (\n Math.max(\n BAR_CHART_VALUE_AXIS_THICKNESS,\n getYAxisLeftMargin({\n yDomain: getBarChartValueDomain(bars, config.id, config.domain),\n formatTick: config?.formatValue ?? formatBarChartValue,\n fontSize: CHART_TICK_FONT_SIZE,\n numTicks: config?.tickCount ?? BAR_CHART_DEFAULT_TICK_COUNT,\n tickValues: config?.tickValues,\n tickLength: CHART_VALUE_AXIS_TICK_LENGTH,\n nice: config?.nice ?? config?.domain == null,\n })\n ) + labelThickness\n );\n };\n const configuredAxesById = new Map(\n valueAxes?.map((axis) => [axis.id, axis]) ?? []\n );\n const resolvedValueAxes: readonly Omit<BarChartDisplayAxis, 'scale'>[] =\n axisIds.map((axisId) => {\n const config = configuredAxesById.get(axisId) ?? { id: axisId };\n return {\n ...config,\n thickness: getValueAxisThickness(config),\n };\n });\n const primaryAxisThickness =\n resolvedValueAxes[0]?.thickness ?? BAR_CHART_VALUE_AXIS_THICKNESS;\n const secondaryAxisThickness = resolvedValueAxes\n .slice(1)\n .reduce((total, axis) => total + axis.thickness, 0);\n const padding = {\n top: Math.max(0, plotPadding?.top ?? 0),\n right: Math.max(0, plotPadding?.right ?? 0),\n bottom: Math.max(0, plotPadding?.bottom ?? 0),\n left: Math.max(0, plotPadding?.left ?? 0),\n };\n const defaultCategoryAxisThickness =\n (isVertical\n ? BAR_CHART_AXIS_THICKNESS\n : BAR_CHART_HORIZONTAL_CATEGORY_AXIS_THICKNESS) +\n (categoryAxis?.label == null ? 0 : CHART_AXIS_LABEL_THICKNESS);\n const categoryAxisThickness =\n categoryAxis?.thickness ?? defaultCategoryAxisThickness;\n const horizontalValueAxisEdgeMargin = isVertical\n ? 0\n : Math.max(\n 0,\n ...resolvedValueAxes.map((axis) =>\n getHorizontalValueAxisEdgeMargin(axis, bars)\n )\n );\n const chartMargin = isVertical\n ? {\n top: BAR_CHART_MARGIN_TOP + padding.top,\n right: BAR_CHART_MARGIN_RIGHT + secondaryAxisThickness + padding.right,\n bottom: categoryAxisThickness + padding.bottom,\n left: primaryAxisThickness + padding.left,\n }\n : {\n top: BAR_CHART_MARGIN_TOP + secondaryAxisThickness + padding.top,\n right:\n Math.max(BAR_CHART_MARGIN_RIGHT, horizontalValueAxisEdgeMargin) +\n padding.right,\n bottom: primaryAxisThickness + padding.bottom,\n left:\n Math.max(categoryAxisThickness, horizontalValueAxisEdgeMargin) +\n padding.left,\n };\n const chartWidth =\n dimensions.width === 0\n ? 0\n : Math.max(\n dimensions.width,\n chartMargin.left + chartMargin.right + Math.max(0, minimumPlotWidth)\n );\n const innerWidth = Math.max(\n 0,\n chartWidth - chartMargin.left - chartMargin.right\n );\n const innerHeight = Math.max(\n 0,\n dimensions.height - chartMargin.top - chartMargin.bottom\n );\n const sizedValueAxes = isVertical\n ? resolvedValueAxes\n : resolvedValueAxes.map((axis) =>\n axis.tickCount != null || axis.tickValues != null\n ? axis\n : {\n ...axis,\n tickCount: getAutomaticHorizontalValueAxisTickCount(\n axis,\n bars,\n innerWidth\n ),\n }\n );\n const axes = resolveAxes(\n sizedValueAxes,\n bars,\n orientation,\n innerWidth,\n innerHeight\n );\n const legendItems: readonly ChartLegendItem[] = displaySeries.map((item) => ({\n id: item.id,\n label: item.label,\n markerColor: item.color,\n selected: selectedIds?.has(item.id) ?? false,\n }));\n const hasLegend =\n (showLegend ?? legendItems.length > 1) && legendItems.length > 0;\n const legendLayout = legendProps?.layout ?? 'inline';\n\n const plot = (\n <div\n ref={containerRef}\n className={cn(\n 'relative size-full min-h-0 min-w-0 overflow-y-hidden',\n minimumPlotWidth <= 0 ? 'overflow-x-hidden' : 'overflow-x-auto'\n )}\n >\n <div className=\"h-full min-h-0\" style={{ width: chartWidth }}>\n <BarChartPlot\n width={chartWidth}\n height={dimensions.height}\n innerWidth={innerWidth}\n innerHeight={innerHeight}\n chartMargin={chartMargin}\n categories={categories}\n series={visibleSeries}\n bars={bars}\n axes={axes}\n orientation={orientation}\n categoryAxis={categoryAxis}\n categoryAxisThickness={categoryAxisThickness}\n categoryPadding={{\n inner: clamp(\n categoryPadding?.inner ??\n BAR_CHART_DEFAULT_CATEGORY_PADDING_INNER,\n 0,\n 1\n ),\n outer: clamp(\n categoryPadding?.outer ??\n BAR_CHART_DEFAULT_CATEGORY_PADDING_OUTER,\n 0,\n 1\n ),\n }}\n groupPadding={clamp(groupPadding, 0, 0.95)}\n minimumBarSize={Math.max(0, minimumBarSize)}\n shouldAnimate={shouldAnimate}\n grid={grid}\n valueBands={valueBands}\n activeCategory={activeCategory}\n activeGuideBarId={activeGuideBarId}\n activeBarId={activeBarId}\n activeBuiltInLegendItemId={\n hasLegend ? activeBuiltInLegendItemId : null\n }\n activeLegendItemId={activeLegendItemId}\n selectionRange={selectionRange}\n slots={slots}\n isRendering={isRendering}\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedBy}\n getBarAriaLabel={getBarAriaLabel}\n getCategoryAriaLabel={getCategoryAriaLabel}\n onDatumPointerDown={onDatumPointerDown}\n onDatumPointerMove={onDatumPointerMove}\n onDatumPointerOut={onDatumPointerOut}\n onDatumPointerUp={onDatumPointerUp}\n onDatumActivate={onDatumActivate}\n onDatumFocus={onDatumFocus}\n onDatumBlur={onDatumBlur}\n onBarPointerMove={onBarPointerMove}\n onBarPointerOut={onBarPointerOut}\n onBarActivate={onBarActivate}\n onBarFocus={onBarFocus}\n onBarBlur={onBarBlur}\n />\n </div>\n </div>\n );\n\n const legend = (\n <ChartLegend\n aria-label={`${ariaLabel} legend`}\n {...legendProps}\n layout={legendLayout}\n items={legendItems}\n onItemActiveChange={(item) => {\n setActiveBuiltInLegendItemId(item?.id ?? null);\n legendProps?.onItemActiveChange?.(item);\n }}\n />\n );\n\n return (\n <div\n className={cn('size-full min-h-0 min-w-0 @container', className)}\n {...rest}\n >\n {hasLegend ? (\n <div\n className={cn(\n 'grid size-full min-h-0 min-w-0 grid-cols-1',\n legendLayout === 'list'\n ? 'grid-rows-[minmax(0,1fr)_minmax(0,35%)] gap-space-3 @[560px]:grid-cols-[minmax(0,1fr)_minmax(10rem,30%)] @[560px]:grid-rows-1 @[560px]:gap-space-5'\n : 'grid-rows-[auto_minmax(0,1fr)] gap-space-2'\n )}\n >\n {legendLayout === 'list' ? (\n <>\n {plot}\n <div className=\"scroll-mask-t scroll-mask-b min-h-0 min-w-0 overflow-y-auto overflow-x-hidden\">\n {legend}\n </div>\n </>\n ) : (\n <>\n {legend}\n {plot}\n </>\n )}\n </div>\n ) : (\n plot\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AAkDA,IAAM,kCAAkC;AAExC,IAAM,cACJ,gBACA,WACsB;CACtB,MAAM,UAAU,MAAM,KACpB,IAAI,IAAI,gBAAgB,KAAK,SAAS,KAAK,EAAE,KAAK,CAAC,CAAC,CACtD;CACA,KAAK,MAAM,QAAQ,QACjB,IAAI,CAAC,QAAQ,SAAS,KAAK,WAAW,GAAG,QAAQ,KAAK,KAAK,WAAW;CAExE,OAA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ACzD,UAAA,oBAAC,cAAD;IACE,OAAO;IACP,QAAQ,WAAW;IACP;IACC;IACA;IACD;IACZ,QAAQ;IACF;IACA;IACO;IACC;IACS;IACvB,iBAAiB;KACf,OAAO,MACL,iBAAiB,SAAA,IAEjB,GACA,CACF;KACA,OAAO,MACL,iBAAiB,SAAA,IAEjB,GACA,CACF;IACF;IACA,cAAc,MAAM,cAAc,GAAG,GAAI;IACzC,gBAAgB,KAAK,IAAI,GAAG,cAAc;IAC3B;IACT;IACM;IACI;IACE;IACL;IACb,2BACE,YAAY,4BAA4B;IAEtB;IACJ;IACT;IACM;IACb,cAAY;IACZ,oBAAkB;IACD;IACK;IACF;IACA;IACD;IACD;IACD;IACH;IACD;IACK;IACD;IACF;IACH;IACD;GACZ,CAAA;EACE,CAAA;CACF,CAAA;CAGP,MAAM,SACJ,oBAAC,aAAD;EACE,cAAY,GAAG,UAAU;EACzB,GAAI;EACJ,QAAQ;EACR,OAAO;EACP,qBAAqB,SAAS;GAC5B,6BAA6B,MAAM,MAAM,IAAI;GAC7C,aAAa,qBAAqB,IAAI;EACxC;CACD,CAAA;CAGH,OACE,oBAAC,OAAD;EACE,WAAW,GAAG,wCAAwC,SAAS;EAC/D,GAAI;EAEH,UAAA,YACC,oBAAC,OAAD;GACE,WAAW,GACT,8CACA,iBAAiB,SACb,uJACA,4CACN;GAEC,UAAA,iBAAiB,SAChB,qBAAA,YAAA,EAAA,UAAA,CACG,MACD,oBAAC,OAAD;IAAK,WAAU;IACZ,UAAA;GACE,CAAA,CACL,EAAA,CAAA,IAEF,qBAAA,YAAA,EAAA,UAAA,CACG,QACA,IACD,EAAA,CAAA;EAED,CAAA,IAEL;CAEC,CAAA;AAET"}
|
|
1
|
+
{"version":3,"file":"BarChart.js","names":[],"sources":["../../../src/components/BarChart/BarChart.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\n\nimport { useResizeObserver } from '@mantine/hooks';\nimport { scaleLinear } from '@visx/scale';\nimport { getStringWidth } from '@visx/text';\n\nimport {\n CHART_SINGLE_FILL_COLOR,\n getCategoricalFillChartColor,\n} from '../../utils/chartColors';\nimport {\n CHART_AXIS_LABEL_THICKNESS,\n CHART_TICK_FONT_SIZE,\n CHART_VALUE_AXIS_TICK_LENGTH,\n} from '../../utils/chartConstants';\nimport { clamp } from '../../utils/clamp';\nimport { cn } from '../../utils/cn';\nimport { getYAxisLeftMargin } from '../../utils/getYAxisLeftMargin';\nimport { ChartLegend, type ChartLegendItem } from '../ChartLegend';\nimport type {\n BarChartDisplayAxis,\n BarChartDisplaySeries,\n BarChartLayoutBar,\n BarChartOrientation,\n BarChartProps,\n BarChartValueAxis,\n} from './BarChart.types';\nimport {\n formatBarChartValue,\n getBarChartCategories,\n getBarChartLayout,\n getBarChartValueDomain,\n normalizeBarChartSeries,\n} from './BarChart.utils';\nimport { BarChartPlot } from './BarChartPlot';\nimport {\n BAR_CHART_AXIS_THICKNESS,\n BAR_CHART_DEFAULT_AXIS_ID,\n BAR_CHART_DEFAULT_CATEGORY_PADDING_INNER,\n BAR_CHART_DEFAULT_CATEGORY_PADDING_OUTER,\n BAR_CHART_DEFAULT_GROUP_PADDING,\n BAR_CHART_DEFAULT_MINIMUM_BAR_SIZE,\n BAR_CHART_DEFAULT_TICK_COUNT,\n BAR_CHART_HORIZONTAL_CATEGORY_AXIS_THICKNESS,\n BAR_CHART_MARGIN_RIGHT,\n BAR_CHART_MARGIN_TOP,\n BAR_CHART_MINIMUM_PLOT_WIDTH,\n BAR_CHART_VALUE_AXIS_THICKNESS,\n} from './constants';\n\nconst HORIZONTAL_VALUE_TICK_LABEL_GAP = 8;\n\nconst getAxisIds = (\n configuredAxes: readonly BarChartValueAxis[] | undefined,\n series: readonly BarChartDisplaySeries[]\n): readonly string[] => {\n const axisIds = Array.from(\n new Set(configuredAxes?.map((axis) => axis.id) ?? [])\n );\n for (const item of series) {\n if (!axisIds.includes(item.valueAxisId)) axisIds.push(item.valueAxisId);\n }\n return axisIds.length === 0 ? [BAR_CHART_DEFAULT_AXIS_ID] : axisIds;\n};\n\nconst getHorizontalValueAxisEdgeMargin = (\n config: BarChartValueAxis,\n bars: readonly BarChartLayoutBar[]\n) => {\n const scale = scaleLinear<number>({\n domain: getBarChartValueDomain(bars, config.id, config.domain),\n range: [0, 1],\n nice: config.nice ?? config.domain == null,\n });\n const tickValues =\n config.tickValues ??\n scale.ticks(config.tickCount ?? BAR_CHART_DEFAULT_TICK_COUNT);\n const formatValue = config.formatValue ?? formatBarChartValue;\n const tickLabelStyle = { fontSize: `${CHART_TICK_FONT_SIZE}px` };\n const maximumTickLabelWidth = Math.max(\n 0,\n ...tickValues.map(\n (value) => getStringWidth(formatValue(value), tickLabelStyle) ?? 0\n )\n );\n return Math.ceil(maximumTickLabelWidth / 2);\n};\n\nconst getAutomaticHorizontalValueAxisTickCount = (\n config: BarChartValueAxis,\n bars: readonly BarChartLayoutBar[],\n innerWidth: number\n) => {\n const scale = scaleLinear<number>({\n domain: getBarChartValueDomain(bars, config.id, config.domain),\n range: [0, innerWidth],\n nice: config.nice ?? config.domain == null,\n });\n const formatValue = config.formatValue ?? formatBarChartValue;\n const tickLabelStyle = { fontSize: `${CHART_TICK_FONT_SIZE}px` };\n const maximumTickLabelWidth = Math.max(\n 0,\n ...scale\n .ticks(BAR_CHART_DEFAULT_TICK_COUNT)\n .map(\n (value) =>\n getStringWidth(formatValue(value), tickLabelStyle) ??\n formatValue(value).length * CHART_TICK_FONT_SIZE\n )\n );\n const minimumTickSpacing =\n maximumTickLabelWidth + HORIZONTAL_VALUE_TICK_LABEL_GAP;\n\n return Math.max(\n 1,\n Math.min(\n BAR_CHART_DEFAULT_TICK_COUNT,\n Math.floor(innerWidth / minimumTickSpacing)\n )\n );\n};\n\nconst resolveAxes = (\n configuredAxes: readonly Omit<BarChartDisplayAxis, 'scale'>[],\n bars: readonly BarChartLayoutBar[],\n orientation: BarChartOrientation,\n innerWidth: number,\n innerHeight: number\n): readonly BarChartDisplayAxis[] => {\n return configuredAxes.map((config) => {\n return {\n ...config,\n scale: scaleLinear<number>({\n domain: getBarChartValueDomain(bars, config.id, config.domain),\n range: orientation === 'vertical' ? [innerHeight, 0] : [0, innerWidth],\n nice: config.nice ?? config.domain == null,\n }),\n };\n });\n};\n\n/**\n * Responsive, presentational bars for categorical and time-bucket data. Supports\n * vertical or horizontal orientation, grouped or signed stacks, multiple value\n * axes, threshold bands, controlled legend filtering, selection and active\n * states, keyboard targets, and consumer-owned SVG slots. Bars always use\n * square corners in every orientation and mode.\n *\n * The component is deliberately presentational: consumers retain fetching,\n * sorting, Top-K/Other aggregation, formatting, tooltip content, links, frozen\n * interaction state, and the loading and empty states — pair it with\n * `ChartCard`, `ChartTooltip`, and `EmptyState`. Reach for `slots` before asking\n * for a new prop; each slot receives the resolved scales and geometry.\n *\n * @example\n * ```tsx\n * <BarChart\n * aria-label=\"Requests by environment\"\n * series={[{ id: 'prod', label: 'Production', data }]}\n * selectedIds={selectedIds}\n * legendProps={{ onItemClick: (item) => toggleId(item.id) }}\n * />\n * ```\n */\nexport const BarChart = ({\n series,\n categoryAxis,\n valueAxes,\n mode = 'grouped',\n orientation = 'vertical',\n selectedIds,\n excludedIds,\n grid,\n valueBands = [],\n activeCategory,\n activeGuideBarId,\n activeBarId,\n activeLegendItemId,\n selectionRange,\n categoryPadding,\n plotPadding,\n minimumPlotWidth = BAR_CHART_MINIMUM_PLOT_WIDTH,\n groupPadding = BAR_CHART_DEFAULT_GROUP_PADDING,\n minimumBarSize = BAR_CHART_DEFAULT_MINIMUM_BAR_SIZE,\n shouldAnimate = true,\n slots,\n isRendering = true,\n showLegend,\n legendProps,\n className,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n getBarAriaLabel,\n getCategoryAriaLabel,\n onDatumPointerDown,\n onDatumPointerMove,\n onDatumPointerOut,\n onDatumPointerUp,\n onDatumActivate,\n onDatumFocus,\n onDatumBlur,\n onBarPointerMove,\n onBarPointerOut,\n onBarActivate,\n onBarFocus,\n onBarBlur,\n ...rest\n}: BarChartProps) => {\n const [containerRef, dimensions] = useResizeObserver();\n const [activeBuiltInLegendItemId, setActiveBuiltInLegendItemId] = useState<\n string | null\n >(null);\n const isVertical = orientation === 'vertical';\n\n // The data half of the pipeline is independent of the measured size, and the\n // documented tooltip pattern re-renders this component on every pointermove.\n const { displaySeries, visibleSeries, categories, bars, axisIds } =\n useMemo(() => {\n const normalized = normalizeBarChartSeries(series);\n const defaultAxisId = valueAxes?.[0]?.id ?? BAR_CHART_DEFAULT_AXIS_ID;\n const resolved: readonly BarChartDisplaySeries[] = normalized.map(\n (item, index) => ({\n ...item,\n color:\n item.color ??\n (normalized.length === 1\n ? CHART_SINGLE_FILL_COLOR\n : getCategoricalFillChartColor(index)),\n valueAxisId: item.valueAxisId ?? defaultAxisId,\n opacity:\n item.opacity == null || !Number.isFinite(item.opacity)\n ? 1\n : clamp(item.opacity, 0, 1),\n })\n );\n const visible = resolved.filter(\n (item) =>\n (selectedIds == null ||\n selectedIds.size === 0 ||\n selectedIds.has(item.id)) &&\n !excludedIds?.has(item.id)\n );\n const allCategories = getBarChartCategories(\n resolved,\n categoryAxis?.domain\n );\n return {\n displaySeries: resolved,\n visibleSeries: visible,\n categories: allCategories,\n bars: getBarChartLayout(visible, allCategories, mode),\n axisIds: getAxisIds(valueAxes, visible),\n };\n }, [\n series,\n valueAxes,\n selectedIds,\n excludedIds,\n categoryAxis?.domain,\n mode,\n ]);\n\n // A vertical value axis is only as wide as its widest tick label needs, so\n // currency and large counts are not clipped by a fixed gutter.\n const getValueAxisThickness = (config: BarChartValueAxis) => {\n if (config?.thickness != null) return Math.max(0, config.thickness);\n const labelThickness =\n config?.label == null ? 0 : CHART_AXIS_LABEL_THICKNESS;\n if (!isVertical) return BAR_CHART_AXIS_THICKNESS + labelThickness;\n return (\n Math.max(\n BAR_CHART_VALUE_AXIS_THICKNESS,\n getYAxisLeftMargin({\n yDomain: getBarChartValueDomain(bars, config.id, config.domain),\n formatTick: config?.formatValue ?? formatBarChartValue,\n fontSize: CHART_TICK_FONT_SIZE,\n numTicks: config?.tickCount ?? BAR_CHART_DEFAULT_TICK_COUNT,\n tickValues: config?.tickValues,\n tickLength: CHART_VALUE_AXIS_TICK_LENGTH,\n nice: config?.nice ?? config?.domain == null,\n })\n ) + labelThickness\n );\n };\n const configuredAxesById = new Map(\n valueAxes?.map((axis) => [axis.id, axis]) ?? []\n );\n const resolvedValueAxes: readonly Omit<BarChartDisplayAxis, 'scale'>[] =\n axisIds.map((axisId) => {\n const config = configuredAxesById.get(axisId) ?? { id: axisId };\n return {\n ...config,\n thickness: getValueAxisThickness(config),\n };\n });\n const primaryAxisThickness =\n resolvedValueAxes[0]?.thickness ?? BAR_CHART_VALUE_AXIS_THICKNESS;\n const secondaryAxisThickness = resolvedValueAxes\n .slice(1)\n .reduce((total, axis) => total + axis.thickness, 0);\n const padding = {\n top: Math.max(0, plotPadding?.top ?? 0),\n right: Math.max(0, plotPadding?.right ?? 0),\n bottom: Math.max(0, plotPadding?.bottom ?? 0),\n left: Math.max(0, plotPadding?.left ?? 0),\n };\n const defaultCategoryAxisThickness =\n (isVertical\n ? BAR_CHART_AXIS_THICKNESS\n : BAR_CHART_HORIZONTAL_CATEGORY_AXIS_THICKNESS) +\n (categoryAxis?.label == null ? 0 : CHART_AXIS_LABEL_THICKNESS);\n const categoryAxisThickness =\n categoryAxis?.thickness ?? defaultCategoryAxisThickness;\n const horizontalValueAxisEdgeMargin = isVertical\n ? 0\n : Math.max(\n 0,\n ...resolvedValueAxes.map((axis) =>\n getHorizontalValueAxisEdgeMargin(axis, bars)\n )\n );\n const chartMargin = isVertical\n ? {\n top: BAR_CHART_MARGIN_TOP + padding.top,\n right: BAR_CHART_MARGIN_RIGHT + secondaryAxisThickness + padding.right,\n bottom: categoryAxisThickness + padding.bottom,\n left: primaryAxisThickness + padding.left,\n }\n : {\n top: BAR_CHART_MARGIN_TOP + secondaryAxisThickness + padding.top,\n right:\n Math.max(BAR_CHART_MARGIN_RIGHT, horizontalValueAxisEdgeMargin) +\n padding.right,\n bottom: primaryAxisThickness + padding.bottom,\n left:\n Math.max(categoryAxisThickness, horizontalValueAxisEdgeMargin) +\n padding.left,\n };\n const chartWidth =\n dimensions.width === 0\n ? 0\n : Math.max(\n dimensions.width,\n chartMargin.left + chartMargin.right + Math.max(0, minimumPlotWidth)\n );\n const innerWidth = Math.max(\n 0,\n chartWidth - chartMargin.left - chartMargin.right\n );\n const innerHeight = Math.max(\n 0,\n dimensions.height - chartMargin.top - chartMargin.bottom\n );\n const sizedValueAxes = isVertical\n ? resolvedValueAxes\n : resolvedValueAxes.map((axis) =>\n axis.tickCount != null || axis.tickValues != null\n ? axis\n : {\n ...axis,\n tickCount: getAutomaticHorizontalValueAxisTickCount(\n axis,\n bars,\n innerWidth\n ),\n }\n );\n const axes = resolveAxes(\n sizedValueAxes,\n bars,\n orientation,\n innerWidth,\n innerHeight\n );\n const legendItems: readonly ChartLegendItem[] = displaySeries.map((item) => ({\n id: item.id,\n label: item.label,\n markerColor: item.color,\n selected: selectedIds?.has(item.id) ?? false,\n excluded: excludedIds?.has(item.id) ?? false,\n }));\n const hasLegend =\n (showLegend ?? legendItems.length > 1) && legendItems.length > 0;\n const legendLayout = legendProps?.layout ?? 'inline';\n\n const plot = (\n <div\n ref={containerRef}\n className={cn(\n 'relative size-full min-h-0 min-w-0 overflow-y-hidden',\n minimumPlotWidth <= 0 ? 'overflow-x-hidden' : 'overflow-x-auto'\n )}\n >\n <div className=\"h-full min-h-0\" style={{ width: chartWidth }}>\n <BarChartPlot\n width={chartWidth}\n height={dimensions.height}\n innerWidth={innerWidth}\n innerHeight={innerHeight}\n chartMargin={chartMargin}\n categories={categories}\n series={visibleSeries}\n bars={bars}\n axes={axes}\n orientation={orientation}\n categoryAxis={categoryAxis}\n categoryAxisThickness={categoryAxisThickness}\n categoryPadding={{\n inner: clamp(\n categoryPadding?.inner ??\n BAR_CHART_DEFAULT_CATEGORY_PADDING_INNER,\n 0,\n 1\n ),\n outer: clamp(\n categoryPadding?.outer ??\n BAR_CHART_DEFAULT_CATEGORY_PADDING_OUTER,\n 0,\n 1\n ),\n }}\n groupPadding={clamp(groupPadding, 0, 0.95)}\n minimumBarSize={Math.max(0, minimumBarSize)}\n shouldAnimate={shouldAnimate}\n grid={grid}\n valueBands={valueBands}\n activeCategory={activeCategory}\n activeGuideBarId={activeGuideBarId}\n activeBarId={activeBarId}\n activeBuiltInLegendItemId={\n hasLegend ? activeBuiltInLegendItemId : null\n }\n activeLegendItemId={activeLegendItemId}\n selectionRange={selectionRange}\n slots={slots}\n isRendering={isRendering}\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedBy}\n getBarAriaLabel={getBarAriaLabel}\n getCategoryAriaLabel={getCategoryAriaLabel}\n onDatumPointerDown={onDatumPointerDown}\n onDatumPointerMove={onDatumPointerMove}\n onDatumPointerOut={onDatumPointerOut}\n onDatumPointerUp={onDatumPointerUp}\n onDatumActivate={onDatumActivate}\n onDatumFocus={onDatumFocus}\n onDatumBlur={onDatumBlur}\n onBarPointerMove={onBarPointerMove}\n onBarPointerOut={onBarPointerOut}\n onBarActivate={onBarActivate}\n onBarFocus={onBarFocus}\n onBarBlur={onBarBlur}\n />\n </div>\n </div>\n );\n\n const legend = (\n <ChartLegend\n aria-label={`${ariaLabel} legend`}\n {...legendProps}\n layout={legendLayout}\n items={legendItems}\n onItemActiveChange={(item) => {\n setActiveBuiltInLegendItemId(item?.id ?? null);\n legendProps?.onItemActiveChange?.(item);\n }}\n />\n );\n\n return (\n <div\n className={cn('size-full min-h-0 min-w-0 @container', className)}\n {...rest}\n >\n {hasLegend ? (\n <div\n className={cn(\n 'grid size-full min-h-0 min-w-0 grid-cols-1',\n legendLayout === 'list'\n ? 'grid-rows-[minmax(0,1fr)_minmax(0,35%)] gap-space-3 @[560px]:grid-cols-[minmax(0,1fr)_minmax(10rem,30%)] @[560px]:grid-rows-1 @[560px]:gap-space-5'\n : 'grid-rows-[auto_minmax(0,1fr)] gap-space-2'\n )}\n >\n {legendLayout === 'list' ? (\n <>\n {plot}\n <div className=\"scroll-mask-t scroll-mask-b min-h-0 min-w-0 overflow-y-auto overflow-x-hidden\">\n {legend}\n </div>\n </>\n ) : (\n <>\n {legend}\n {plot}\n </>\n )}\n </div>\n ) : (\n plot\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AAkDA,IAAM,kCAAkC;AAExC,IAAM,cACJ,gBACA,WACsB;CACtB,MAAM,UAAU,MAAM,KACpB,IAAI,IAAI,gBAAgB,KAAK,SAAS,KAAK,EAAE,KAAK,CAAC,CAAC,CACtD;CACA,KAAK,MAAM,QAAQ,QACjB,IAAI,CAAC,QAAQ,SAAS,KAAK,WAAW,GAAG,QAAQ,KAAK,KAAK,WAAW;CAExE,OAAO,QAAQ,WAAW,IAAI,CAAC,yBAAyB,IAAI;AAC9D;AAEA,IAAM,oCACJ,QACA,SACG;CACH,MAAM,QAAQ,YAAoB;EAChC,QAAQ,uBAAuB,MAAM,OAAO,IAAI,OAAO,MAAM;EAC7D,OAAO,CAAC,GAAG,CAAC;EACZ,MAAM,OAAO,QAAQ,OAAO,UAAU;CACxC,CAAC;CACD,MAAM,aACJ,OAAO,cACP,MAAM,MAAM,OAAO,aAAA,CAAyC;CAC9D,MAAM,cAAc,OAAO,eAAe;CAC1C,MAAM,iBAAiB,EAAE,UAAU,OAA4B;CAC/D,MAAM,wBAAwB,KAAK,IACjC,GACA,GAAG,WAAW,KACX,UAAU,eAAe,YAAY,KAAK,GAAG,cAAc,KAAK,CACnE,CACF;CACA,OAAO,KAAK,KAAK,wBAAwB,CAAC;AAC5C;AAEA,IAAM,4CACJ,QACA,MACA,eACG;CACH,MAAM,QAAQ,YAAoB;EAChC,QAAQ,uBAAuB,MAAM,OAAO,IAAI,OAAO,MAAM;EAC7D,OAAO,CAAC,GAAG,UAAU;EACrB,MAAM,OAAO,QAAQ,OAAO,UAAU;CACxC,CAAC;CACD,MAAM,cAAc,OAAO,eAAe;CAC1C,M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D,CAAA;CAGH,OACE,oBAAC,OAAD;EACE,WAAW,GAAG,wCAAwC,SAAS;EAC/D,GAAI;EAEH,UAAA,YACC,oBAAC,OAAD;GACE,WAAW,GACT,8CACA,iBAAiB,SACb,uJACA,4CACN;GAEC,UAAA,iBAAiB,SAChB,qBAAA,YAAA,EAAA,UAAA,CACG,MACD,oBAAC,OAAD;IAAK,WAAU;IACZ,UAAA;GACE,CAAA,CACL,EAAA,CAAA,IAEF,qBAAA,YAAA,EAAA,UAAA,CACG,QACA,IACD,EAAA,CAAA;EAED,CAAA,IAEL;CAEC,CAAA;AAET"}
|
|
@@ -201,6 +201,12 @@ export type BarChartProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'a
|
|
|
201
201
|
orientation?: BarChartOrientation;
|
|
202
202
|
/** Controlled legend filter. An empty set renders every series. */
|
|
203
203
|
selectedIds?: ReadonlySet<string>;
|
|
204
|
+
/**
|
|
205
|
+
* Series left out, whatever `selectedIds` holds. Their legend items stay,
|
|
206
|
+
* marked excluded; to toggle them from the legend, set
|
|
207
|
+
* `legendProps.itemClickAction` to `exclude` and wire `onItemClick`.
|
|
208
|
+
*/
|
|
209
|
+
excludedIds?: ReadonlySet<string>;
|
|
204
210
|
grid?: BarChartGrid;
|
|
205
211
|
valueBands?: readonly BarChartValueBand[];
|
|
206
212
|
/** Highlights one category band and draws a guide through its center. */
|
|
@@ -8,11 +8,28 @@ export type ChartLegendItem = {
|
|
|
8
8
|
markerColor?: string;
|
|
9
9
|
marker?: ReactNode;
|
|
10
10
|
selected?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Left out of the chart: the label is struck through and the color marker
|
|
13
|
+
* becomes an outline. Takes precedence over `selected`.
|
|
14
|
+
*/
|
|
15
|
+
excluded?: boolean;
|
|
11
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* What clicking a legend item does. `select` isolates the item, marking it
|
|
19
|
+
* with a funnel; `exclude` leaves the item out, marking it with an x — suited
|
|
20
|
+
* to charts where every series shows by default.
|
|
21
|
+
*/
|
|
22
|
+
export type ChartLegendItemClickAction = 'select' | 'exclude';
|
|
12
23
|
export type ChartLegendProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
|
|
13
24
|
items: readonly ChartLegendItem[];
|
|
14
25
|
layout?: 'inline' | 'list';
|
|
15
26
|
onItemClick?: (item: ChartLegendItem) => void;
|
|
27
|
+
/**
|
|
28
|
+
* What `onItemClick` toggles, which sets the item's affordance and pressed
|
|
29
|
+
* state. With `exclude`, pair `onItemClick` with a chart's `excludedIds`.
|
|
30
|
+
* Defaults to `select`.
|
|
31
|
+
*/
|
|
32
|
+
itemClickAction?: ChartLegendItemClickAction;
|
|
16
33
|
/** Reports the legend item under the pointer or keyboard focus. */
|
|
17
34
|
onItemActiveChange?: (item: ChartLegendItem | null) => void;
|
|
18
35
|
};
|
|
@@ -12,7 +12,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
12
12
|
//#region packages/components/src/components/ChartLegend/ChartLegend.tsx
|
|
13
13
|
var LEGEND_GAP_PX = SPACE_SCALE_PX[1];
|
|
14
14
|
var VIEW_HIDDEN_TOOLTIP = "Click to view hidden legends";
|
|
15
|
-
var ChartLegendList = ({ items, onItemClick, onItemActiveChange, className, role = "group", "aria-label": ariaLabel = "Chart legend", style, ...props }) => {
|
|
15
|
+
var ChartLegendList = ({ items, onItemClick, itemClickAction, onItemActiveChange, className, role = "group", "aria-label": ariaLabel = "Chart legend", style, ...props }) => {
|
|
16
16
|
const listColumns = getChartLegendListColumns(items, onItemClick != null);
|
|
17
17
|
const gridTemplateColumns = getChartLegendListGridTemplate(listColumns);
|
|
18
18
|
return /* @__PURE__ */ jsx("div", {
|
|
@@ -29,13 +29,14 @@ var ChartLegendList = ({ items, onItemClick, onItemActiveChange, className, role
|
|
|
29
29
|
layout: "list",
|
|
30
30
|
listColumns,
|
|
31
31
|
onActiveChange: onItemActiveChange,
|
|
32
|
+
clickAction: itemClickAction,
|
|
32
33
|
onClick: onItemClick == null ? void 0 : () => {
|
|
33
34
|
onItemClick(item);
|
|
34
35
|
}
|
|
35
36
|
}, item.id))
|
|
36
37
|
});
|
|
37
38
|
};
|
|
38
|
-
var ChartLegendInline = ({ items, onItemClick, onItemActiveChange, className, role = "group", "aria-label": ariaLabel = "Chart legend", ...props }) => {
|
|
39
|
+
var ChartLegendInline = ({ items, onItemClick, itemClickAction, onItemActiveChange, className, role = "group", "aria-label": ariaLabel = "Chart legend", ...props }) => {
|
|
39
40
|
const [popoverOpen, setPopoverOpen] = useState(false);
|
|
40
41
|
const [containerWidth, setContainerWidth] = useState(null);
|
|
41
42
|
const [itemWidths, setItemWidths] = useState({});
|
|
@@ -103,6 +104,7 @@ var ChartLegendInline = ({ items, onItemClick, onItemActiveChange, className, ro
|
|
|
103
104
|
const renderItem = (item) => /* @__PURE__ */ jsx(ChartLegendItemRenderer, {
|
|
104
105
|
item,
|
|
105
106
|
onActiveChange: onItemActiveChange,
|
|
107
|
+
clickAction: itemClickAction,
|
|
106
108
|
onClick: onItemClick == null ? void 0 : () => {
|
|
107
109
|
onItemClick(item);
|
|
108
110
|
}
|
|
@@ -147,6 +149,7 @@ var ChartLegendInline = ({ items, onItemClick, onItemActiveChange, className, ro
|
|
|
147
149
|
className: "shrink-0",
|
|
148
150
|
children: /* @__PURE__ */ jsx(ChartLegendItemRenderer, {
|
|
149
151
|
item,
|
|
152
|
+
clickAction: itemClickAction,
|
|
150
153
|
onClick: onItemClick == null ? void 0 : () => void 0,
|
|
151
154
|
tabIndex: -1
|
|
152
155
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartLegend.js","names":[],"sources":["../../../src/components/ChartLegend/ChartLegend.tsx"],"sourcesContent":["import {\n type HTMLAttributes,\n type ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { cn } from '../../utils/cn';\nimport { SPACE_SCALE_PX } from '../../utils/spacing';\nimport { Badge } from '../Badge';\nimport { Button } from '../Button';\nimport {\n Popover,\n PopoverAnchor,\n PopoverContent,\n PopoverTrigger,\n} from '../Popover';\nimport { Tooltip } from '../Tooltip';\nimport { ChartLegendItemRenderer } from './ChartLegendItemRenderer';\nimport {\n type ChartLegendItemActiveChangeHandler,\n useChartLegendActiveItem,\n} from './useChartLegendActiveItem';\nimport {\n getChartLegendListColumns,\n getChartLegendListGridTemplate,\n widthsMatch,\n} from './utils';\n\nconst LEGEND_GAP_PX = SPACE_SCALE_PX[1];\nconst VIEW_HIDDEN_TOOLTIP = 'Click to view hidden legends';\n\nexport type ChartLegendItem = {\n id: string;\n label: ReactNode;\n value?: ReactNode;\n secondaryValue?: ReactNode;\n 'aria-label'?: string;\n markerColor?: string;\n marker?: ReactNode;\n selected?: boolean;\n};\n\nexport type ChartLegendProps = Omit<\n HTMLAttributes<HTMLDivElement>,\n 'children'\n> & {\n items: readonly ChartLegendItem[];\n layout?: 'inline' | 'list';\n onItemClick?: (item: ChartLegendItem) => void;\n /** Reports the legend item under the pointer or keyboard focus. */\n onItemActiveChange?: (item: ChartLegendItem | null) => void;\n};\n\ntype ChartLegendBaseProps = Omit<\n ChartLegendProps,\n 'layout' | 'onItemActiveChange'\n> & {\n onItemActiveChange?: ChartLegendItemActiveChangeHandler<ChartLegendItem>;\n};\n\nconst ChartLegendList = ({\n items,\n onItemClick,\n onItemActiveChange,\n className,\n role = 'group',\n 'aria-label': ariaLabel = 'Chart legend',\n style,\n ...props\n}: ChartLegendBaseProps) => {\n const listColumns = getChartLegendListColumns(items, onItemClick != null);\n const gridTemplateColumns = getChartLegendListGridTemplate(listColumns);\n\n return (\n <div\n role={role}\n aria-label={ariaLabel}\n className={cn('grid w-full min-w-0', className)}\n style={{ ...style, gridTemplateColumns }}\n {...props}\n >\n {items.map((item) => (\n <ChartLegendItemRenderer\n key={item.id}\n item={item}\n layout=\"list\"\n listColumns={listColumns}\n onActiveChange={onItemActiveChange}\n onClick={\n onItemClick == null\n ? undefined\n : () => {\n onItemClick(item);\n }\n }\n />\n ))}\n </div>\n );\n};\n\nconst ChartLegendInline = ({\n items,\n onItemClick,\n onItemActiveChange,\n className,\n role = 'group',\n 'aria-label': ariaLabel = 'Chart legend',\n ...props\n}: ChartLegendBaseProps) => {\n const [popoverOpen, setPopoverOpen] = useState(false);\n const [containerWidth, setContainerWidth] = useState<number | null>(null);\n const [itemWidths, setItemWidths] = useState<Record<string, number>>({});\n const [badgeWidths, setBadgeWidths] = useState<Record<string, number>>({});\n const containerRef = useRef<HTMLDivElement>(null);\n const measurementItemRefs = useRef<Record<string, HTMLDivElement | null>>({});\n const measurementBadgeRefs = useRef<Record<string, HTMLDivElement | null>>(\n {}\n );\n const isInteractive = onItemClick != null || onItemActiveChange != null;\n\n const itemIds = useMemo(() => items.map((item) => item.id), [items]);\n\n const setMeasurementItemRef = useCallback(\n (id: string, node: HTMLDivElement | null) => {\n measurementItemRefs.current[id] = node;\n },\n []\n );\n\n const setMeasurementBadgeRef = useCallback(\n (count: number, node: HTMLDivElement | null) => {\n measurementBadgeRefs.current[String(count)] = node;\n },\n []\n );\n\n useLayoutEffect(() => {\n const nextItemWidths: Record<string, number> = {};\n const nextBadgeWidths: Record<string, number> = {};\n\n items.forEach((item, index) => {\n const itemWidth = measurementItemRefs.current[item.id]?.offsetWidth;\n if (itemWidth != null) {\n nextItemWidths[item.id] = Math.ceil(itemWidth);\n }\n\n const hiddenCount = index + 1;\n const badgeWidth =\n measurementBadgeRefs.current[String(hiddenCount)]?.offsetWidth;\n if (badgeWidth != null) {\n nextBadgeWidths[String(hiddenCount)] = Math.ceil(badgeWidth);\n }\n });\n\n setItemWidths((current) =>\n widthsMatch(current, nextItemWidths) ? current : nextItemWidths\n );\n setBadgeWidths((current) =>\n widthsMatch(current, nextBadgeWidths) ? current : nextBadgeWidths\n );\n }, [isInteractive, items]);\n\n useLayoutEffect(() => {\n const container = containerRef.current;\n\n if (container == null) {\n return;\n }\n\n const updateWidth = (width: number) => {\n const nextWidth = Math.ceil(width);\n setContainerWidth((current) =>\n current === nextWidth ? current : nextWidth\n );\n };\n\n updateWidth(container.clientWidth);\n\n const observer = new ResizeObserver(([entry]) => {\n updateWidth(entry?.contentRect.width ?? container.clientWidth);\n });\n\n observer.observe(container);\n return () => observer.disconnect();\n }, []);\n\n const visibleCount = useMemo(() => {\n const hasMeasurements =\n containerWidth != null &&\n itemIds.every((id) => itemWidths[id] != null) &&\n items.every((_, index) => badgeWidths[String(index + 1)] != null);\n\n if (!hasMeasurements || containerWidth == null) {\n return items.length;\n }\n\n const allItemsWidth = itemIds.reduce(\n (total, id) => total + (itemWidths[id] ?? 0),\n Math.max(items.length - 1, 0) * LEGEND_GAP_PX\n );\n\n if (allItemsWidth <= containerWidth) {\n return items.length;\n }\n\n for (let count = items.length - 1; count >= 0; count -= 1) {\n const hiddenCount = items.length - count;\n const visibleItemsWidth = itemIds\n .slice(0, count)\n .reduce((total, id) => total + (itemWidths[id] ?? 0), 0);\n const gapsWidth = count * LEGEND_GAP_PX;\n const totalWidth =\n visibleItemsWidth + gapsWidth + (badgeWidths[String(hiddenCount)] ?? 0);\n\n if (totalWidth <= containerWidth) {\n return count;\n }\n }\n\n return 0;\n }, [badgeWidths, containerWidth, itemIds, itemWidths, items]);\n\n const hiddenCount = Math.max(items.length - visibleCount, 0);\n const hasOverflow = hiddenCount > 0;\n const visibleItems = items.slice(0, visibleCount);\n const hiddenItems = items.slice(visibleCount);\n\n useEffect(() => {\n if (!hasOverflow) {\n setPopoverOpen(false);\n }\n }, [hasOverflow]);\n\n const renderItem = (item: ChartLegendItem) => (\n <ChartLegendItemRenderer\n key={item.id}\n item={item}\n onActiveChange={onItemActiveChange}\n onClick={\n onItemClick == null\n ? undefined\n : () => {\n onItemClick(item);\n }\n }\n />\n );\n\n return (\n <Popover open={popoverOpen} onOpenChange={setPopoverOpen}>\n <PopoverAnchor asChild>\n <div\n ref={containerRef}\n role={role}\n aria-label={ariaLabel}\n className={cn(\n 'relative flex w-full min-w-0 items-center gap-space-1 overflow-clip rounded-xs',\n className\n )}\n {...props}\n >\n {visibleItems.map(renderItem)}\n\n {hasOverflow && (\n <Tooltip title={VIEW_HIDDEN_TOOLTIP}>\n <PopoverTrigger asChild>\n <Button\n type=\"button\"\n size=\"xs\"\n color=\"secondary\"\n variant=\"plain\"\n className=\"focus-visible:ring-focus relative rounded-xs border-transparent bg-transparent p-0 shadow-none focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-offset-1\"\n aria-label={`View ${hiddenCount} hidden chart ${\n hiddenCount === 1 ? 'legend' : 'legends'\n }`}\n >\n <Badge size=\"xxs\" rounded=\"xs\">\n {`+${hiddenCount}`}\n </Badge>\n </Button>\n </PopoverTrigger>\n </Tooltip>\n )}\n\n <div\n aria-hidden=\"true\"\n className=\"pointer-events-none invisible absolute left-0 top-0 flex w-max items-center gap-space-1\"\n >\n {items.map((item) => (\n <div\n key={item.id}\n ref={(node) => setMeasurementItemRef(item.id, node)}\n className=\"shrink-0\"\n >\n <ChartLegendItemRenderer\n item={item}\n onClick={onItemClick == null ? undefined : () => undefined}\n tabIndex={-1}\n />\n </div>\n ))}\n {items.map((_, index) => {\n const count = index + 1;\n return (\n <div\n key={count}\n ref={(node) => setMeasurementBadgeRef(count, node)}\n className=\"shrink-0\"\n >\n <Badge size=\"xxs\" rounded=\"xs\">\n {`+${count}`}\n </Badge>\n </div>\n );\n })}\n </div>\n </div>\n </PopoverAnchor>\n\n {hasOverflow && (\n <PopoverContent\n align=\"end\"\n className=\"w-max min-w-48 max-w-[min(24rem,calc(100vw-2rem))] overflow-hidden border border-subtle p-0\"\n aria-label=\"Hidden chart legends\"\n onInteractOutside={(event) => {\n if (\n event.target instanceof Node &&\n containerRef.current?.contains(event.target)\n ) {\n event.preventDefault();\n }\n }}\n >\n <div className=\"scroll-mask-t scroll-mask-b flex max-h-[min(300px,70vh)] flex-col gap-space-1 overflow-y-auto overflow-x-hidden p-space-1\">\n {hiddenItems.map(renderItem)}\n </div>\n </PopoverContent>\n )}\n </Popover>\n );\n};\n\nexport const ChartLegend = ({\n layout = 'inline',\n items,\n onItemActiveChange,\n ...props\n}: ChartLegendProps) => {\n const handleItemActiveChange = useChartLegendActiveItem(\n items,\n onItemActiveChange\n );\n const activeChangeHandler =\n onItemActiveChange == null ? undefined : handleItemActiveChange;\n const legendProps = {\n ...props,\n items,\n onItemActiveChange: activeChangeHandler,\n };\n\n return layout === 'list' ? (\n <ChartLegendList {...legendProps} />\n ) : (\n <ChartLegendInline {...legendProps} />\n );\n};\n"],"mappings":";;;;;;;;;;;;AAiCA,IAAM,gBAAgB,eAAe;AACrC,IAAM,sBAAsB;AA+B5B,IAAM,mBAAmB,EACvB,OACA,aACA,oBACA,WACA,OAAO,SACP,cAAc,YAAY,gBAC1B,OACA,GAAG,YACuB;CAC1B,MAAM,cAAc,0BAA0B,OAAO,eAAe,IAAI;CACxE,MAAM,sBAAsB,+BAA+B,WAAW;CAEtE,OACE,oBAAC,OAAD;EACQ;EACN,cAAY;EACZ,WAAW,GAAG,uBAAuB,SAAS;EAC9C,OAAO;GAAE,GAAG;GAAO;EAAoB;EACvC,GAAI;EAEH,UAAA,MAAM,KAAK,SACV,oBAAC,yBAAD;GAEQ;GACN,QAAO;GACM;GACb,gBAAgB;GAChB,SACE,eAAe,OACX,KAAA,UACM;IACJ,YAAY,IAAI;GAClB;EAEP,GAZM,KAAK,EAYX,CACF;CACE,CAAA;AAET;AAEA,IAAM,qBAAqB,EACzB,OACA,aACA,oBACA,WACA,OAAO,SACP,cAAc,YAAY,gBAC1B,GAAG,YACuB;CAC1B,MAAM,CAAC,aAAa,kBAAkB,SAAS,KAAK;CACpD,MAAM,CAAC,gBAAgB,qBAAqB,SAAwB,IAAI;CACxE,MAAM,CAAC,YAAY,iBAAiB,SAAiC,CAAC,CAAC;CACvE,MAAM,CAAC,aAAa,kBAAkB,SAAiC,CAAC,CAAC;CACzE,MAAM,eAAe,OAAuB,IAAI;CAChD,MAAM,sBAAsB,OAA8C,C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AAG,YACmB;CACtB,MAAM,yBAAyB,yBAC7B,OACA,kBACF;CACA,MAAM,sBACJ,sBAAsB,OAAO,KAAA,IAAY;CAC3C,MAAM,cAAc;EAClB,GAAG;EACH;EACA,oBAAoB;CACtB;CAEA,OAAO,WAAW,SAChB,oBAAC,iBAAD,EAAiB,GAAI,YAAc,CAAA,IAEnC,oBAAC,mBAAD,EAAmB,GAAI,YAAc,CAAA;AAEzC"}
|
|
1
|
+
{"version":3,"file":"ChartLegend.js","names":[],"sources":["../../../src/components/ChartLegend/ChartLegend.tsx"],"sourcesContent":["import {\n type HTMLAttributes,\n type ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport { cn } from '../../utils/cn';\nimport { SPACE_SCALE_PX } from '../../utils/spacing';\nimport { Badge } from '../Badge';\nimport { Button } from '../Button';\nimport {\n Popover,\n PopoverAnchor,\n PopoverContent,\n PopoverTrigger,\n} from '../Popover';\nimport { Tooltip } from '../Tooltip';\nimport { ChartLegendItemRenderer } from './ChartLegendItemRenderer';\nimport {\n type ChartLegendItemActiveChangeHandler,\n useChartLegendActiveItem,\n} from './useChartLegendActiveItem';\nimport {\n getChartLegendListColumns,\n getChartLegendListGridTemplate,\n widthsMatch,\n} from './utils';\n\nconst LEGEND_GAP_PX = SPACE_SCALE_PX[1];\nconst VIEW_HIDDEN_TOOLTIP = 'Click to view hidden legends';\n\nexport type ChartLegendItem = {\n id: string;\n label: ReactNode;\n value?: ReactNode;\n secondaryValue?: ReactNode;\n 'aria-label'?: string;\n markerColor?: string;\n marker?: ReactNode;\n selected?: boolean;\n /**\n * Left out of the chart: the label is struck through and the color marker\n * becomes an outline. Takes precedence over `selected`.\n */\n excluded?: boolean;\n};\n\n/**\n * What clicking a legend item does. `select` isolates the item, marking it\n * with a funnel; `exclude` leaves the item out, marking it with an x — suited\n * to charts where every series shows by default.\n */\nexport type ChartLegendItemClickAction = 'select' | 'exclude';\n\nexport type ChartLegendProps = Omit<\n HTMLAttributes<HTMLDivElement>,\n 'children'\n> & {\n items: readonly ChartLegendItem[];\n layout?: 'inline' | 'list';\n onItemClick?: (item: ChartLegendItem) => void;\n /**\n * What `onItemClick` toggles, which sets the item's affordance and pressed\n * state. With `exclude`, pair `onItemClick` with a chart's `excludedIds`.\n * Defaults to `select`.\n */\n itemClickAction?: ChartLegendItemClickAction;\n /** Reports the legend item under the pointer or keyboard focus. */\n onItemActiveChange?: (item: ChartLegendItem | null) => void;\n};\n\ntype ChartLegendBaseProps = Omit<\n ChartLegendProps,\n 'layout' | 'onItemActiveChange'\n> & {\n onItemActiveChange?: ChartLegendItemActiveChangeHandler<ChartLegendItem>;\n};\n\nconst ChartLegendList = ({\n items,\n onItemClick,\n itemClickAction,\n onItemActiveChange,\n className,\n role = 'group',\n 'aria-label': ariaLabel = 'Chart legend',\n style,\n ...props\n}: ChartLegendBaseProps) => {\n const listColumns = getChartLegendListColumns(items, onItemClick != null);\n const gridTemplateColumns = getChartLegendListGridTemplate(listColumns);\n\n return (\n <div\n role={role}\n aria-label={ariaLabel}\n className={cn('grid w-full min-w-0', className)}\n style={{ ...style, gridTemplateColumns }}\n {...props}\n >\n {items.map((item) => (\n <ChartLegendItemRenderer\n key={item.id}\n item={item}\n layout=\"list\"\n listColumns={listColumns}\n onActiveChange={onItemActiveChange}\n clickAction={itemClickAction}\n onClick={\n onItemClick == null\n ? undefined\n : () => {\n onItemClick(item);\n }\n }\n />\n ))}\n </div>\n );\n};\n\nconst ChartLegendInline = ({\n items,\n onItemClick,\n itemClickAction,\n onItemActiveChange,\n className,\n role = 'group',\n 'aria-label': ariaLabel = 'Chart legend',\n ...props\n}: ChartLegendBaseProps) => {\n const [popoverOpen, setPopoverOpen] = useState(false);\n const [containerWidth, setContainerWidth] = useState<number | null>(null);\n const [itemWidths, setItemWidths] = useState<Record<string, number>>({});\n const [badgeWidths, setBadgeWidths] = useState<Record<string, number>>({});\n const containerRef = useRef<HTMLDivElement>(null);\n const measurementItemRefs = useRef<Record<string, HTMLDivElement | null>>({});\n const measurementBadgeRefs = useRef<Record<string, HTMLDivElement | null>>(\n {}\n );\n const isInteractive = onItemClick != null || onItemActiveChange != null;\n\n const itemIds = useMemo(() => items.map((item) => item.id), [items]);\n\n const setMeasurementItemRef = useCallback(\n (id: string, node: HTMLDivElement | null) => {\n measurementItemRefs.current[id] = node;\n },\n []\n );\n\n const setMeasurementBadgeRef = useCallback(\n (count: number, node: HTMLDivElement | null) => {\n measurementBadgeRefs.current[String(count)] = node;\n },\n []\n );\n\n useLayoutEffect(() => {\n const nextItemWidths: Record<string, number> = {};\n const nextBadgeWidths: Record<string, number> = {};\n\n items.forEach((item, index) => {\n const itemWidth = measurementItemRefs.current[item.id]?.offsetWidth;\n if (itemWidth != null) {\n nextItemWidths[item.id] = Math.ceil(itemWidth);\n }\n\n const hiddenCount = index + 1;\n const badgeWidth =\n measurementBadgeRefs.current[String(hiddenCount)]?.offsetWidth;\n if (badgeWidth != null) {\n nextBadgeWidths[String(hiddenCount)] = Math.ceil(badgeWidth);\n }\n });\n\n setItemWidths((current) =>\n widthsMatch(current, nextItemWidths) ? current : nextItemWidths\n );\n setBadgeWidths((current) =>\n widthsMatch(current, nextBadgeWidths) ? current : nextBadgeWidths\n );\n }, [isInteractive, items]);\n\n useLayoutEffect(() => {\n const container = containerRef.current;\n\n if (container == null) {\n return;\n }\n\n const updateWidth = (width: number) => {\n const nextWidth = Math.ceil(width);\n setContainerWidth((current) =>\n current === nextWidth ? current : nextWidth\n );\n };\n\n updateWidth(container.clientWidth);\n\n const observer = new ResizeObserver(([entry]) => {\n updateWidth(entry?.contentRect.width ?? container.clientWidth);\n });\n\n observer.observe(container);\n return () => observer.disconnect();\n }, []);\n\n const visibleCount = useMemo(() => {\n const hasMeasurements =\n containerWidth != null &&\n itemIds.every((id) => itemWidths[id] != null) &&\n items.every((_, index) => badgeWidths[String(index + 1)] != null);\n\n if (!hasMeasurements || containerWidth == null) {\n return items.length;\n }\n\n const allItemsWidth = itemIds.reduce(\n (total, id) => total + (itemWidths[id] ?? 0),\n Math.max(items.length - 1, 0) * LEGEND_GAP_PX\n );\n\n if (allItemsWidth <= containerWidth) {\n return items.length;\n }\n\n for (let count = items.length - 1; count >= 0; count -= 1) {\n const hiddenCount = items.length - count;\n const visibleItemsWidth = itemIds\n .slice(0, count)\n .reduce((total, id) => total + (itemWidths[id] ?? 0), 0);\n const gapsWidth = count * LEGEND_GAP_PX;\n const totalWidth =\n visibleItemsWidth + gapsWidth + (badgeWidths[String(hiddenCount)] ?? 0);\n\n if (totalWidth <= containerWidth) {\n return count;\n }\n }\n\n return 0;\n }, [badgeWidths, containerWidth, itemIds, itemWidths, items]);\n\n const hiddenCount = Math.max(items.length - visibleCount, 0);\n const hasOverflow = hiddenCount > 0;\n const visibleItems = items.slice(0, visibleCount);\n const hiddenItems = items.slice(visibleCount);\n\n useEffect(() => {\n if (!hasOverflow) {\n setPopoverOpen(false);\n }\n }, [hasOverflow]);\n\n const renderItem = (item: ChartLegendItem) => (\n <ChartLegendItemRenderer\n key={item.id}\n item={item}\n onActiveChange={onItemActiveChange}\n clickAction={itemClickAction}\n onClick={\n onItemClick == null\n ? undefined\n : () => {\n onItemClick(item);\n }\n }\n />\n );\n\n return (\n <Popover open={popoverOpen} onOpenChange={setPopoverOpen}>\n <PopoverAnchor asChild>\n <div\n ref={containerRef}\n role={role}\n aria-label={ariaLabel}\n className={cn(\n 'relative flex w-full min-w-0 items-center gap-space-1 overflow-clip rounded-xs',\n className\n )}\n {...props}\n >\n {visibleItems.map(renderItem)}\n\n {hasOverflow && (\n <Tooltip title={VIEW_HIDDEN_TOOLTIP}>\n <PopoverTrigger asChild>\n <Button\n type=\"button\"\n size=\"xs\"\n color=\"secondary\"\n variant=\"plain\"\n className=\"focus-visible:ring-focus relative rounded-xs border-transparent bg-transparent p-0 shadow-none focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-offset-1\"\n aria-label={`View ${hiddenCount} hidden chart ${\n hiddenCount === 1 ? 'legend' : 'legends'\n }`}\n >\n <Badge size=\"xxs\" rounded=\"xs\">\n {`+${hiddenCount}`}\n </Badge>\n </Button>\n </PopoverTrigger>\n </Tooltip>\n )}\n\n <div\n aria-hidden=\"true\"\n className=\"pointer-events-none invisible absolute left-0 top-0 flex w-max items-center gap-space-1\"\n >\n {items.map((item) => (\n <div\n key={item.id}\n ref={(node) => setMeasurementItemRef(item.id, node)}\n className=\"shrink-0\"\n >\n <ChartLegendItemRenderer\n item={item}\n clickAction={itemClickAction}\n onClick={onItemClick == null ? undefined : () => undefined}\n tabIndex={-1}\n />\n </div>\n ))}\n {items.map((_, index) => {\n const count = index + 1;\n return (\n <div\n key={count}\n ref={(node) => setMeasurementBadgeRef(count, node)}\n className=\"shrink-0\"\n >\n <Badge size=\"xxs\" rounded=\"xs\">\n {`+${count}`}\n </Badge>\n </div>\n );\n })}\n </div>\n </div>\n </PopoverAnchor>\n\n {hasOverflow && (\n <PopoverContent\n align=\"end\"\n className=\"w-max min-w-48 max-w-[min(24rem,calc(100vw-2rem))] overflow-hidden border border-subtle p-0\"\n aria-label=\"Hidden chart legends\"\n onInteractOutside={(event) => {\n if (\n event.target instanceof Node &&\n containerRef.current?.contains(event.target)\n ) {\n event.preventDefault();\n }\n }}\n >\n <div className=\"scroll-mask-t scroll-mask-b flex max-h-[min(300px,70vh)] flex-col gap-space-1 overflow-y-auto overflow-x-hidden p-space-1\">\n {hiddenItems.map(renderItem)}\n </div>\n </PopoverContent>\n )}\n </Popover>\n );\n};\n\nexport const ChartLegend = ({\n layout = 'inline',\n items,\n onItemActiveChange,\n ...props\n}: ChartLegendProps) => {\n const handleItemActiveChange = useChartLegendActiveItem(\n items,\n onItemActiveChange\n );\n const activeChangeHandler =\n onItemActiveChange == null ? undefined : handleItemActiveChange;\n const legendProps = {\n ...props,\n items,\n onItemActiveChange: activeChangeHandler,\n };\n\n return layout === 'list' ? (\n <ChartLegendList {...legendProps} />\n ) : (\n <ChartLegendInline {...leg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"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import type { ChartLegendItem } from './ChartLegend.js';
|
|
1
|
+
import type { ChartLegendItem, ChartLegendItemClickAction } from './ChartLegend.js';
|
|
2
2
|
import type { ChartLegendItemActiveChangeHandler } from './useChartLegendActiveItem.js';
|
|
3
3
|
import { type ChartLegendListColumns } from './utils.js';
|
|
4
4
|
type ChartLegendItemRendererProps = {
|
|
5
5
|
item: ChartLegendItem;
|
|
6
6
|
onClick?: () => void;
|
|
7
|
+
/** What `onClick` toggles. Defaults to `select`. */
|
|
8
|
+
clickAction?: ChartLegendItemClickAction;
|
|
7
9
|
onActiveChange?: ChartLegendItemActiveChangeHandler<ChartLegendItem>;
|
|
8
10
|
className?: string;
|
|
9
11
|
tabIndex?: number;
|
|
10
12
|
layout?: 'inline' | 'list';
|
|
11
13
|
listColumns?: ChartLegendListColumns;
|
|
12
14
|
};
|
|
13
|
-
export declare const ChartLegendItemRenderer: ({ item, onClick, onActiveChange, className, tabIndex, layout, listColumns, }: ChartLegendItemRendererProps) => import("react").JSX.Element;
|
|
15
|
+
export declare const ChartLegendItemRenderer: ({ item, onClick, clickAction, onActiveChange, className, tabIndex, layout, listColumns, }: ChartLegendItemRendererProps) => import("react").JSX.Element;
|
|
14
16
|
export {};
|
|
@@ -4,10 +4,11 @@ import { Button } from "../Button/Button.js";
|
|
|
4
4
|
import { Icon } from "../Icon/Icon.js";
|
|
5
5
|
import { getChartLegendAriaLabel } from "./utils.js";
|
|
6
6
|
import { useEffect, useEffectEvent, useId } from "react";
|
|
7
|
+
import { XIcon } from "@phosphor-icons/react/dist/ssr/X";
|
|
7
8
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
import { FunnelIcon } from "@phosphor-icons/react/dist/ssr/Funnel";
|
|
9
10
|
//#region packages/components/src/components/ChartLegend/ChartLegendItemRenderer.tsx
|
|
10
|
-
var ChartLegendItemRenderer = ({ item, onClick, onActiveChange, className, tabIndex, layout = "inline", listColumns }) => {
|
|
11
|
+
var ChartLegendItemRenderer = ({ item, onClick, clickAction = "select", onActiveChange, className, tabIndex, layout = "inline", listColumns }) => {
|
|
11
12
|
const labelId = useId();
|
|
12
13
|
const clearActivity = useEffectEvent(() => {
|
|
13
14
|
onActiveChange?.(item, "pointer", false);
|
|
@@ -15,19 +16,22 @@ var ChartLegendItemRenderer = ({ item, onClick, onActiveChange, className, tabIn
|
|
|
15
16
|
});
|
|
16
17
|
useEffect(() => () => clearActivity(), []);
|
|
17
18
|
const isList = layout === "list";
|
|
19
|
+
const excluded = item.excluded ?? false;
|
|
20
|
+
const selected = (item.selected ?? false) && !excluded;
|
|
21
|
+
const excludes = clickAction === "exclude";
|
|
18
22
|
const defaultAriaLabel = getChartLegendAriaLabel(item.label, isList ? item.value : void 0, isList ? item.secondaryValue : void 0);
|
|
19
23
|
const ariaLabel = item["aria-label"] ?? defaultAriaLabel;
|
|
20
24
|
const marker = item.marker ?? (item.markerColor != null ? /* @__PURE__ */ jsx("div", {
|
|
21
25
|
"aria-hidden": true,
|
|
22
|
-
className: "size-2 shrink-0 rounded-full",
|
|
23
|
-
style: { backgroundColor: item.markerColor }
|
|
26
|
+
className: cn("size-2 shrink-0 rounded-full", excluded && "border border-solid"),
|
|
27
|
+
style: excluded ? { borderColor: item.markerColor } : { backgroundColor: item.markerColor }
|
|
24
28
|
}) : null);
|
|
25
|
-
const action = onClick != null ||
|
|
29
|
+
const action = (onClick != null || selected) && !(excludes && excluded) ? /* @__PURE__ */ jsx(Icon, {
|
|
26
30
|
"aria-hidden": "true",
|
|
27
|
-
icon: FunnelIcon,
|
|
28
|
-
weight:
|
|
31
|
+
icon: excludes ? XIcon : FunnelIcon,
|
|
32
|
+
weight: selected ? "fill" : void 0,
|
|
29
33
|
size: "xs",
|
|
30
|
-
className: cn("size-3 shrink-0 text-icon-tertiary transition-opacity duration-fast",
|
|
34
|
+
className: cn("size-3 shrink-0 text-icon-tertiary transition-opacity duration-fast", selected ? "opacity-100" : "opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100")
|
|
31
35
|
}) : null;
|
|
32
36
|
const content = /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
33
37
|
isList && listColumns?.marker ? marker ?? /* @__PURE__ */ jsx("div", { "aria-hidden": true }) : marker,
|
|
@@ -35,7 +39,8 @@ var ChartLegendItemRenderer = ({ item, onClick, onActiveChange, className, tabIn
|
|
|
35
39
|
id: labelId,
|
|
36
40
|
as: "span",
|
|
37
41
|
variant: "xs",
|
|
38
|
-
|
|
42
|
+
color: excluded ? "tertiary" : void 0,
|
|
43
|
+
className: cn("min-w-0 flex-1 text-left", isList ? "whitespace-normal break-words" : "truncate", excluded && "line-through"),
|
|
39
44
|
children: item.label
|
|
40
45
|
}),
|
|
41
46
|
isList && listColumns?.value && (item.value != null ? /* @__PURE__ */ jsx(Text, {
|
|
@@ -53,7 +58,7 @@ var ChartLegendItemRenderer = ({ item, onClick, onActiveChange, className, tabIn
|
|
|
53
58
|
}) : /* @__PURE__ */ jsx("div", { "aria-hidden": true })),
|
|
54
59
|
isList && listColumns?.action ? action ?? /* @__PURE__ */ jsx("div", { "aria-hidden": true }) : action
|
|
55
60
|
] });
|
|
56
|
-
const styles = cn("group relative min-w-0 items-center rounded-xs py-space-1 text-primary transition-colors duration-fast", isList ? "col-span-full grid w-full grid-cols-subgrid gap-space-2 px-space-2" : "flex max-w-full shrink-0 gap-space-1 px-space-1",
|
|
61
|
+
const styles = cn("group relative min-w-0 items-center rounded-xs py-space-1 text-primary transition-colors duration-fast", isList ? "col-span-full grid w-full grid-cols-subgrid gap-space-2 px-space-2" : "flex max-w-full shrink-0 gap-space-1 px-space-1", selected ? "bg-surface-level-3 hover:bg-surface-level-3" : (onClick != null || onActiveChange != null) && "hover:bg-surface-level-1-hover focus-visible:bg-surface-level-1-hover", className);
|
|
57
62
|
if (onClick == null) return /* @__PURE__ */ jsx("div", {
|
|
58
63
|
className: cn(styles, onActiveChange != null && "focus-visible:ring-focus focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset"),
|
|
59
64
|
role: onActiveChange == null ? void 0 : "group",
|
|
@@ -71,10 +76,10 @@ var ChartLegendItemRenderer = ({ item, onClick, onActiveChange, className, tabIn
|
|
|
71
76
|
size: "xs",
|
|
72
77
|
color: "secondary",
|
|
73
78
|
variant: "plain",
|
|
74
|
-
className: cn(styles, "focus-visible:ring-focus border-transparent shadow-none focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset", isList && "h-auto justify-start", !
|
|
79
|
+
className: cn(styles, "focus-visible:ring-focus border-transparent shadow-none focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset", isList && "h-auto justify-start", !selected && "bg-transparent"),
|
|
75
80
|
"aria-label": ariaLabel,
|
|
76
81
|
"aria-labelledby": ariaLabel == null ? labelId : void 0,
|
|
77
|
-
"aria-pressed":
|
|
82
|
+
"aria-pressed": excludes ? !excluded : selected,
|
|
78
83
|
tabIndex,
|
|
79
84
|
onPointerEnter: () => onActiveChange?.(item, "pointer", true),
|
|
80
85
|
onPointerLeave: () => onActiveChange?.(item, "pointer", false),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartLegendItemRenderer.js","names":[],"sources":["../../../src/components/ChartLegend/ChartLegendItemRenderer.tsx"],"sourcesContent":["import { useEffect, useEffectEvent, useId } from 'react';\n\nimport { FunnelIcon } from '@phosphor-icons/react/dist/ssr/Funnel';\n\nimport { cn } from '../../utils/cn';\nimport { Button } from '../Button';\nimport { Icon } from '../Icon';\nimport { Text } from '../Text';\nimport type {
|
|
1
|
+
{"version":3,"file":"ChartLegendItemRenderer.js","names":[],"sources":["../../../src/components/ChartLegend/ChartLegendItemRenderer.tsx"],"sourcesContent":["import { useEffect, useEffectEvent, useId } from 'react';\n\nimport { FunnelIcon } from '@phosphor-icons/react/dist/ssr/Funnel';\nimport { XIcon } from '@phosphor-icons/react/dist/ssr/X';\n\nimport { cn } from '../../utils/cn';\nimport { Button } from '../Button';\nimport { Icon } from '../Icon';\nimport { Text } from '../Text';\nimport type {\n ChartLegendItem,\n ChartLegendItemClickAction,\n} from './ChartLegend';\nimport type { ChartLegendItemActiveChangeHandler } from './useChartLegendActiveItem';\nimport { getChartLegendAriaLabel, type ChartLegendListColumns } from './utils';\n\ntype ChartLegendItemRendererProps = {\n item: ChartLegendItem;\n onClick?: () => void;\n /** What `onClick` toggles. Defaults to `select`. */\n clickAction?: ChartLegendItemClickAction;\n onActiveChange?: ChartLegendItemActiveChangeHandler<ChartLegendItem>;\n className?: string;\n tabIndex?: number;\n layout?: 'inline' | 'list';\n listColumns?: ChartLegendListColumns;\n};\n\nexport const ChartLegendItemRenderer = ({\n item,\n onClick,\n clickAction = 'select',\n onActiveChange,\n className,\n tabIndex,\n layout = 'inline',\n listColumns,\n}: ChartLegendItemRendererProps) => {\n const labelId = useId();\n const clearActivity = useEffectEvent(() => {\n onActiveChange?.(item, 'pointer', false);\n onActiveChange?.(item, 'focus', false);\n });\n // Removing a focused or hovered row does not fire blur or pointerleave.\n useEffect(() => () => clearActivity(), []);\n\n const isList = layout === 'list';\n const excluded = item.excluded ?? false;\n // Exclusion takes precedence, so an item is never shown as both.\n const selected = (item.selected ?? false) && !excluded;\n const excludes = clickAction === 'exclude';\n const defaultAriaLabel = getChartLegendAriaLabel(\n item.label,\n isList ? item.value : undefined,\n isList ? item.secondaryValue : undefined\n );\n const ariaLabel = item['aria-label'] ?? defaultAriaLabel;\n const marker =\n item.marker ??\n (item.markerColor != null ? (\n <div\n aria-hidden\n className={cn(\n 'size-2 shrink-0 rounded-full',\n // An excluded series keeps its color as an outline.\n excluded && 'border border-solid'\n )}\n style={\n excluded\n ? { borderColor: item.markerColor }\n : { backgroundColor: item.markerColor }\n }\n />\n ) : null);\n // The affordance previews what a click does: a funnel to isolate the item,\n // or an x to leave it out. An excluded item needs none — its struck-through\n // label already reads as a toggle.\n const action =\n (onClick != null || selected) && !(excludes && excluded) ? (\n <Icon\n aria-hidden=\"true\"\n icon={excludes ? XIcon : FunnelIcon}\n weight={selected ? 'fill' : undefined}\n size=\"xs\"\n className={cn(\n 'size-3 shrink-0 text-icon-tertiary transition-opacity duration-fast',\n selected\n ? 'opacity-100'\n : 'opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100'\n )}\n />\n ) : null;\n const content = (\n <>\n {isList && listColumns?.marker ? (marker ?? <div aria-hidden />) : marker}\n <Text\n id={labelId}\n as=\"span\"\n variant=\"xs\"\n color={excluded ? 'tertiary' : undefined}\n className={cn(\n 'min-w-0 flex-1 text-left',\n isList ? 'whitespace-normal break-words' : 'truncate',\n excluded && 'line-through'\n )}\n >\n {item.label}\n </Text>\n {isList &&\n listColumns?.value &&\n (item.value != null ? (\n <Text\n as=\"span\"\n variant=\"xs\"\n className=\"shrink-0 text-right tabular-nums\"\n >\n {item.value}\n </Text>\n ) : (\n <div aria-hidden />\n ))}\n {isList &&\n listColumns?.secondaryValue &&\n (item.secondaryValue != null ? (\n <Text\n as=\"span\"\n variant=\"xs\"\n color=\"tertiary\"\n className=\"shrink-0 text-right tabular-nums\"\n >\n {item.secondaryValue}\n </Text>\n ) : (\n <div aria-hidden />\n ))}\n {isList && listColumns?.action ? (action ?? <div aria-hidden />) : action}\n </>\n );\n\n const styles = cn(\n 'group relative min-w-0 items-center rounded-xs py-space-1 text-primary transition-colors duration-fast',\n isList\n ? 'col-span-full grid w-full grid-cols-subgrid gap-space-2 px-space-2'\n : 'flex max-w-full shrink-0 gap-space-1 px-space-1',\n selected\n ? 'bg-surface-level-3 hover:bg-surface-level-3'\n : (onClick != null || onActiveChange != null) &&\n 'hover:bg-surface-level-1-hover focus-visible:bg-surface-level-1-hover',\n className\n );\n\n if (onClick == null) {\n return (\n <div\n className={cn(\n styles,\n onActiveChange != null &&\n 'focus-visible:ring-focus focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset'\n )}\n role={onActiveChange == null ? undefined : 'group'}\n aria-label={onActiveChange == null ? undefined : ariaLabel}\n aria-labelledby={\n onActiveChange != null && ariaLabel == null ? labelId : undefined\n }\n tabIndex={onActiveChange == null ? tabIndex : (tabIndex ?? 0)}\n onPointerEnter={() => onActiveChange?.(item, 'pointer', true)}\n onPointerLeave={() => onActiveChange?.(item, 'pointer', false)}\n onFocus={() => onActiveChange?.(item, 'focus', true)}\n onBlur={() => onActiveChange?.(item, 'focus', false)}\n >\n {content}\n </div>\n );\n }\n\n return (\n <Button\n type=\"button\"\n size=\"xs\"\n color=\"secondary\"\n variant=\"plain\"\n className={cn(\n styles,\n 'focus-visible:ring-focus border-transparent shadow-none focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset',\n isList && 'h-auto justify-start',\n !selected && 'bg-transparent'\n )}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabel == null ? labelId : undefined}\n // Pressed reads as \"shown\" when clicks exclude, and \"isolated\" otherwise.\n aria-pressed={excludes ? !excluded : selected}\n tabIndex={tabIndex}\n onPointerEnter={() => onActiveChange?.(item, 'pointer', true)}\n onPointerLeave={() => onActiveChange?.(item, 'pointer', false)}\n onFocus={() => onActiveChange?.(item, 'focus', true)}\n onBlur={() => onActiveChange?.(item, 'focus', false)}\n onClick={onClick}\n >\n {content}\n </Button>\n );\n};\n"],"mappings":";;;;;;;;;;AA4BA,IAAa,2BAA2B,EACtC,MACA,SACA,cAAc,UACd,gBACA,WACA,UACA,SAAS,UACT,kBACkC;CAClC,MAAM,UAAU,MAAM;CACtB,MAAM,gBAAgB,qBAAqB;EACzC,iBAAiB,MAAM,WAAW,KAAK;EACvC,iBAAiB,MAAM,SAAS,KAAK;CACvC,CAAC;CAED,sBAAsB,cAAc,GAAG,CAAC,CAAC;CAEzC,MAAM,SAAS,WAAW;CAC1B,MAAM,WAAW,KAAK,YAAY;CAElC,MAAM,YAAY,KAAK,YAAY,UAAU,CAAC;CAC9C,MAAM,WAAW,gBAAgB;CACjC,MAAM,mBAAmB,wBACvB,KAAK,OACL,SAAS,KAAK,QAAQ,KAA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C,WAAW,QAAQ,kBAAkB,SACpC,yEACN,SACF;CAEA,IAAI,WAAW,MACb,OACE,oBAAC,OAAD;EACE,WAAW,GACT,QACA,kBAAkB,QAChB,qGACJ;EACA,MAAM,kBAAkB,OAAO,KAAA,IAAY;EAC3C,cAAY,kBAAkB,OAAO,KAAA,IAAY;EACjD,mBACE,kBAAkB,QAAQ,aAAa,OAAO,UAAU,KAAA;EAE1D,UAAU,kBAAkB,OAAO,WAAY,YAAY;EAC3D,sBAAsB,iBAAiB,MAAM,WAAW,IAAI;EAC5D,sBAAsB,iBAAiB,MAAM,WAAW,KAAK;EAC7D,eAAe,iBAAiB,MAAM,SAAS,IAAI;EACnD,cAAc,iBAAiB,MAAM,SAAS,KAAK;EAElD,UAAA;CACE,CAAA;CAIT,OACE,oBAAC,QAAD;EACE,MAAK;EACL,MAAK;EACL,OAAM;EACN,SAAQ;EACR,WAAW,GACT,QACA,sIACA,UAAU,wBACV,CAAC,YAAY,gBACf;EACA,cAAY;EACZ,mBAAiB,aAAa,OAAO,UAAU,KAAA;EAE/C,gBAAc,WAAW,CAAC,WAAW;EAC3B;EACV,sBAAsB,iBAAiB,MAAM,WAAW,IAAI;EAC5D,sBAAsB,iBAAiB,MAAM,WAAW,KAAK;EAC7D,eAAe,iBAAiB,MAAM,SAAS,IAAI;EACnD,cAAc,iBAAiB,MAAM,SAAS,KAAK;EAC1C;EAER,UAAA;CACK,CAAA;AAEZ"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { ChartLegend } from './ChartLegend.js';
|
|
2
|
-
export type { ChartLegendItem, ChartLegendProps } from './ChartLegend.js';
|
|
2
|
+
export type { ChartLegendItem, ChartLegendItemClickAction, ChartLegendProps, } from './ChartLegend.js';
|
|
3
3
|
export { getAccessibleText } from './utils.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode, type Ref } from 'react';
|
|
2
|
+
export interface ChatConversationProps {
|
|
3
|
+
/** Messages, or a host-provided empty or loading state. */
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
/** Fixed content above the scrolling messages; the host supplies its styling. */
|
|
6
|
+
header?: ReactNode;
|
|
7
|
+
/** Fixed content below the messages, such as a composer. Shares the message column. */
|
|
8
|
+
footer?: ReactNode;
|
|
9
|
+
/** Accessible name for the region; the message log is named "{label} messages". */
|
|
10
|
+
label?: string;
|
|
11
|
+
className?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The scrolling element. Older messages inserted above the viewport are not
|
|
14
|
+
* anchored; hosts that load history upward can adjust `scrollTop` here.
|
|
15
|
+
*/
|
|
16
|
+
viewportRef?: Ref<HTMLDivElement>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Bounded-height chat layout that follows new output while the reader is at
|
|
20
|
+
* the bottom. Remount with a conversation `key` when switching threads.
|
|
21
|
+
*
|
|
22
|
+
* The message log doesn't announce changes (`aria-live="off"`), since streamed
|
|
23
|
+
* text would be read out word by word. Announce completed replies from a
|
|
24
|
+
* polite `role="status"` region in the host.
|
|
25
|
+
*/
|
|
26
|
+
export declare function ChatConversation({ children, header, footer, label, className, viewportRef: externalViewportRef, }: ChatConversationProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { cn } from "../../utils/cn.js";
|
|
2
|
+
import { Button } from "../Button/Button.js";
|
|
3
|
+
import { mergeRefs } from "../../utils/merge-refs.js";
|
|
4
|
+
import { useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { CaretDownIcon } from "@phosphor-icons/react/dist/ssr/CaretDown";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
//#region packages/components/src/components/ChatConversation/ChatConversation.tsx
|
|
8
|
+
/** Distance from the bottom, in px, that still counts as reading the latest output. */
|
|
9
|
+
var FOLLOW_THRESHOLD = 48;
|
|
10
|
+
var COLUMN_CLASS_NAME = "mx-auto w-full min-w-0 max-w-3xl px-space-4";
|
|
11
|
+
var VIEWPORT_MASK_STYLE = { "--scroll-mask-fade-from-t": "calc(100% - 2rem)" };
|
|
12
|
+
/**
|
|
13
|
+
* Bounded-height chat layout that follows new output while the reader is at
|
|
14
|
+
* the bottom. Remount with a conversation `key` when switching threads.
|
|
15
|
+
*
|
|
16
|
+
* The message log doesn't announce changes (`aria-live="off"`), since streamed
|
|
17
|
+
* text would be read out word by word. Announce completed replies from a
|
|
18
|
+
* polite `role="status"` region in the host.
|
|
19
|
+
*/
|
|
20
|
+
function ChatConversation({ children, header, footer, label = "Conversation", className, viewportRef: externalViewportRef }) {
|
|
21
|
+
const viewportRef = useRef(null);
|
|
22
|
+
const contentRef = useRef(null);
|
|
23
|
+
const followingRef = useRef(true);
|
|
24
|
+
const [isNearBottom, setIsNearBottom] = useState(true);
|
|
25
|
+
const mergedViewportRef = useMemo(() => mergeRefs([viewportRef, externalViewportRef]), [externalViewportRef]);
|
|
26
|
+
useLayoutEffect(() => {
|
|
27
|
+
const viewport = viewportRef.current;
|
|
28
|
+
const content = contentRef.current;
|
|
29
|
+
if (!viewport || !content) return;
|
|
30
|
+
const followContent = () => {
|
|
31
|
+
if (!followingRef.current) return;
|
|
32
|
+
viewport.scrollTop = viewport.scrollHeight;
|
|
33
|
+
};
|
|
34
|
+
let lastScrollTop = viewport.scrollTop;
|
|
35
|
+
const handleScroll = () => {
|
|
36
|
+
const { scrollTop, scrollHeight, clientHeight } = viewport;
|
|
37
|
+
const nearBottom = scrollHeight - clientHeight - scrollTop <= FOLLOW_THRESHOLD;
|
|
38
|
+
followingRef.current = nearBottom || followingRef.current && scrollTop >= lastScrollTop;
|
|
39
|
+
lastScrollTop = scrollTop;
|
|
40
|
+
setIsNearBottom(followingRef.current);
|
|
41
|
+
};
|
|
42
|
+
followContent();
|
|
43
|
+
const observer = new ResizeObserver(() => {
|
|
44
|
+
followContent();
|
|
45
|
+
handleScroll();
|
|
46
|
+
});
|
|
47
|
+
observer.observe(viewport);
|
|
48
|
+
observer.observe(content);
|
|
49
|
+
viewport.addEventListener("scroll", handleScroll, { passive: true });
|
|
50
|
+
return () => {
|
|
51
|
+
observer.disconnect();
|
|
52
|
+
viewport.removeEventListener("scroll", handleScroll);
|
|
53
|
+
};
|
|
54
|
+
}, []);
|
|
55
|
+
function scrollToLatest() {
|
|
56
|
+
const viewport = viewportRef.current;
|
|
57
|
+
if (!viewport) return;
|
|
58
|
+
followingRef.current = true;
|
|
59
|
+
viewport.scrollTop = viewport.scrollHeight;
|
|
60
|
+
setIsNearBottom(true);
|
|
61
|
+
viewport.focus({ preventScroll: true });
|
|
62
|
+
}
|
|
63
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
64
|
+
"aria-label": label,
|
|
65
|
+
className: cn("flex h-full min-h-0 min-w-0 flex-col overflow-hidden bg-surface-level-1 text-primary", className),
|
|
66
|
+
children: [
|
|
67
|
+
header != null && /* @__PURE__ */ jsx("div", {
|
|
68
|
+
className: "min-w-0 shrink-0",
|
|
69
|
+
children: header
|
|
70
|
+
}),
|
|
71
|
+
/* @__PURE__ */ jsxs("div", {
|
|
72
|
+
className: "relative flex min-h-0 flex-1 flex-col",
|
|
73
|
+
children: [
|
|
74
|
+
/* @__PURE__ */ jsx("div", {
|
|
75
|
+
ref: mergedViewportRef,
|
|
76
|
+
role: "log",
|
|
77
|
+
"aria-label": `${label} messages`,
|
|
78
|
+
"aria-live": "off",
|
|
79
|
+
tabIndex: 0,
|
|
80
|
+
style: VIEWPORT_MASK_STYLE,
|
|
81
|
+
className: "peer scroll-mask-t min-h-0 flex-1 overflow-y-auto overflow-x-hidden overscroll-contain outline-hidden [scrollbar-gutter:stable_both-edges]",
|
|
82
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
83
|
+
ref: contentRef,
|
|
84
|
+
className: cn(COLUMN_CLASS_NAME, "flex min-h-full flex-col gap-space-6 py-space-5 pb-space-9"),
|
|
85
|
+
children
|
|
86
|
+
})
|
|
87
|
+
}),
|
|
88
|
+
/* @__PURE__ */ jsx("div", {
|
|
89
|
+
"aria-hidden": true,
|
|
90
|
+
className: "pointer-events-none absolute inset-0 ring-inset ring-focus peer-focus-visible:ring-2"
|
|
91
|
+
}),
|
|
92
|
+
!isNearBottom && /* @__PURE__ */ jsx("div", {
|
|
93
|
+
className: "pointer-events-none absolute inset-x-0 bottom-0 flex justify-center pb-space-3",
|
|
94
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
95
|
+
color: "secondary",
|
|
96
|
+
size: "md",
|
|
97
|
+
leftDecorator: CaretDownIcon,
|
|
98
|
+
className: "pointer-events-auto shadow-md hover:bg-elevated pointer-coarse:h-11",
|
|
99
|
+
onClick: scrollToLatest,
|
|
100
|
+
children: "Jump to latest"
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
]
|
|
104
|
+
}),
|
|
105
|
+
footer != null && /* @__PURE__ */ jsx("div", {
|
|
106
|
+
className: cn(COLUMN_CLASS_NAME, "shrink-0 py-space-3"),
|
|
107
|
+
children: footer
|
|
108
|
+
})
|
|
109
|
+
]
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
export { ChatConversation };
|
|
114
|
+
|
|
115
|
+
//# sourceMappingURL=ChatConversation.js.map
|