@sybilion/uilib 1.8.1 → 1.8.3
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/esm/src/components/ui/Chart/components/ChartAxes.js +4 -4
- package/dist/esm/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.js +2 -2
- package/dist/esm/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.styl.js +2 -2
- package/dist/esm/src/components/ui/TimeRangeControls/TimeRangeControls.js +18 -4
- package/dist/esm/src/components/ui/Toggle/Toggle.styl.js +2 -2
- package/dist/esm/src/components/ui/ToggleGroup/ToggleGroup.js +1 -1
- package/dist/esm/src/components/ui/ToggleGroup/ToggleGroup.styl.js +1 -1
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.d.ts +1 -1
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.types.d.ts +7 -0
- package/dist/esm/types/src/components/ui/TimeRangeControls/TimeRangeControls.d.ts +16 -4
- package/dist/esm/types/src/components/ui/TimeRangeControls/TimeRangeControls.test.d.ts +1 -0
- package/dist/esm/types/src/components/ui/Toggle/Toggle.types.d.ts +1 -1
- package/dist/esm/types/src/components/ui/ToggleGroup/ToggleGroup.helpers.d.ts +2 -2
- package/dist/esm/types/src/components/ui/ToggleGroup/ToggleGroup.types.d.ts +3 -3
- package/package.json +1 -1
- package/src/components/ui/Chart/components/ChartAxes.test.tsx +11 -0
- package/src/components/ui/Chart/components/ChartAxes.tsx +6 -25
- package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.styl +5 -0
- package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.styl.d.ts +1 -0
- package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.tsx +7 -1
- package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.types.ts +7 -0
- package/src/components/ui/TimeRangeControls/AGENT.md +1 -1
- package/src/components/ui/TimeRangeControls/TimeRangeControls.test.tsx +61 -0
- package/src/components/ui/TimeRangeControls/TimeRangeControls.tsx +57 -35
- package/src/components/ui/Toggle/Toggle.styl +24 -0
- package/src/components/ui/Toggle/Toggle.styl.d.ts +1 -0
- package/src/components/ui/Toggle/Toggle.types.ts +1 -1
- package/src/components/ui/ToggleGroup/AGENT.md +1 -0
- package/src/components/ui/ToggleGroup/ToggleGroup.helpers.ts +2 -2
- package/src/components/ui/ToggleGroup/ToggleGroup.styl +8 -0
- package/src/components/ui/ToggleGroup/ToggleGroup.tsx +1 -0
- package/src/components/ui/ToggleGroup/ToggleGroup.types.ts +3 -3
- package/src/docs/pages/ChartAreaInteractivePage.tsx +34 -0
- package/src/docs/pages/TimeRangeControlsPage.tsx +9 -0
|
@@ -38,10 +38,10 @@ formatNumber: formatNumber$1 = formatNumber, xMin, xMax, yMin, yMax, autoScaleYA
|
|
|
38
38
|
// Determine Y-axis domain
|
|
39
39
|
let yDomain;
|
|
40
40
|
if (autoScaleYAxis) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
];
|
|
41
|
+
// recharts' own fit: nice round ticks just around the data, so a series
|
|
42
|
+
// moving 1000–1010 fills the chart (scaling the values by 0.95/1.05 left
|
|
43
|
+
// it flat) and a negative one is padded too.
|
|
44
|
+
yDomain = ['auto', 'auto'];
|
|
45
45
|
}
|
|
46
46
|
else if (yMin !== undefined && yMax !== undefined) {
|
|
47
47
|
yDomain = [yMin, yMax];
|
|
@@ -23,7 +23,7 @@ function historyKeyLookup(serialised) {
|
|
|
23
23
|
const chartConfig = {
|
|
24
24
|
// Chart now supports light/dark themes with dynamic colors
|
|
25
25
|
};
|
|
26
|
-
function ChartAreaInteractive({ className, chartContainerClassName, legendClassName, xAxisClassName, yAxisClassName, timeRange, onTimeRangeChange, pinMonth, onPinMonthChange, onPreviewMonthChange, chartData, forecastData, historyData, error, loading = false, isDarkTheme = false, footerActions, mode, selectedForecast, upperQuantiles, lowerQuantiles, selectedLowerQuantile, selectedUpperQuantile, onLowerQuantileChange, onUpperQuantileChange, lowerThreshold, upperThreshold, onLowerThresholdChange, onUpperThresholdChange, discreteThresholdValues, headerActions, excludeLegendIds, loadingAnalyses, onLegendClick, onAnalysisSelect, disableTimeRangeSelector, enableTimeRangeBrush = false, forecastLineStyle = 'dashed', selectedAnalysisId, chartRenderId, toggleLegendSeries, ensureAnalysisSeriesVisible, overlayForecastData = {}, hiddenSeries, disableForecastHistoricalBridge, overlayElements: overlayElementsProp, ...restProps }) {
|
|
26
|
+
function ChartAreaInteractive({ className, chartContainerClassName, legendClassName, xAxisClassName, yAxisClassName, timeRange, onTimeRangeChange, pinMonth, onPinMonthChange, onPreviewMonthChange, chartData, forecastData, historyData, error, loading = false, isDarkTheme = false, footerActions, mode, selectedForecast, upperQuantiles, lowerQuantiles, selectedLowerQuantile, selectedUpperQuantile, onLowerQuantileChange, onUpperQuantileChange, lowerThreshold, upperThreshold, onLowerThresholdChange, onUpperThresholdChange, discreteThresholdValues, headerActions, headerTitle, timeRangeVariant, excludeLegendIds, loadingAnalyses, onLegendClick, onAnalysisSelect, disableTimeRangeSelector, enableTimeRangeBrush = false, forecastLineStyle = 'dashed', selectedAnalysisId, chartRenderId, toggleLegendSeries, ensureAnalysisSeriesVisible, overlayForecastData = {}, hiddenSeries, disableForecastHistoricalBridge, overlayElements: overlayElementsProp, ...restProps }) {
|
|
27
27
|
const seriesHidden = hiddenSeries ?? new Set();
|
|
28
28
|
const hiddenSeriesRef = useRef(seriesHidden);
|
|
29
29
|
const prevSelectedAnalysisIdRef = useRef(selectedAnalysisId);
|
|
@@ -147,7 +147,7 @@ function ChartAreaInteractive({ className, chartContainerClassName, legendClassN
|
|
|
147
147
|
return (jsx(BaseChartWrapper, { ...baseChartProps, chartClassName: cn(S.chartContainer, chartContainerClassName) }));
|
|
148
148
|
}
|
|
149
149
|
};
|
|
150
|
-
return (jsxs(InteractionOverlay, { className: cn(className, loading && S.loading), disabled: loading, children: [(!disableTimeRangeSelector || headerActions) && (jsxs("div", { className: S.chartHeaderContainer, children: [!disableTimeRangeSelector && (jsx(TimeRangeControls, { timeRange: timeRange, onTimeRangeChange: onTimeRangeChange, loading: loading })), headerActions] })), jsx(TimeRangeBrushHost, { chartData: bridgedChartData, onTimeRangeChange: onTimeRangeChange, enabled: brushEnabled, layoutKey: chartRenderId ?? null, children: renderChart() })] }));
|
|
150
|
+
return (jsxs(InteractionOverlay, { className: cn(className, loading && S.loading), disabled: loading, children: [(!disableTimeRangeSelector || headerActions || headerTitle) && (jsxs("div", { className: S.chartHeaderContainer, children: [headerTitle != null && (jsx("div", { className: S.chartHeaderTitle, children: headerTitle })), !disableTimeRangeSelector && (jsx(TimeRangeControls, { timeRange: timeRange, onTimeRangeChange: onTimeRangeChange, loading: loading, variant: timeRangeVariant })), headerActions] })), jsx(TimeRangeBrushHost, { chartData: bridgedChartData, onTimeRangeChange: onTimeRangeChange, enabled: brushEnabled, layoutKey: chartRenderId ?? null, children: renderChart() })] }));
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
export { ChartAreaInteractive, chartConfig };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import styleInject from 'style-inject';
|
|
2
2
|
|
|
3
|
-
var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}:root{--chart-height:586px}@media (max-width:768px){:root{--chart-height:300px}}.ChartAreaInteractive_loadingSpinner__A7jox{animation:ChartAreaInteractive_spin__zU5LX 1s linear infinite;border-top-color:var(--muted-foreground);border:2px solid var(--muted-foreground);border-radius:9999px;height:1.5rem;width:1.5rem}.ChartAreaInteractive_chartHeaderContainer__XkPiP{align-items:center;display:flex;flex-wrap:wrap;gap:var(--p-2);justify-content:space-between;margin-bottom:1rem}.ChartAreaInteractive_chartContainerWrapper__sa2zO{position:relative}.ChartAreaInteractive_chartContainer__PLbGm{aspect-ratio:auto;height:var(--chart-height);transition:opacity .3s ease-out;width:100%}.ChartAreaInteractive_loading__M0in3 .ChartAreaInteractive_chartContainer__PLbGm{opacity:.3;pointer-events:none}.ChartAreaInteractive_chartContainer__PLbGm .recharts-legend-item{cursor:pointer;margin-right:var(--p-6)!important}.ChartAreaInteractive_overlay__V8w04{inset:0;margin:var(--p-5) var(--p-8) var(--p-24) var(--p-12);position:absolute}@media (max-width:768px){.ChartAreaInteractive_overlay__V8w04{height:230px!important}}@keyframes ChartAreaInteractive_spin__zU5LX{to{transform:rotate(1turn)}}@keyframes ChartAreaInteractive_fadeIn__qDomf{0%{opacity:0}to{opacity:1}}";
|
|
4
|
-
var S = {"loadingSpinner":"ChartAreaInteractive_loadingSpinner__A7jox","spin":"ChartAreaInteractive_spin__zU5LX","chartHeaderContainer":"ChartAreaInteractive_chartHeaderContainer__XkPiP","chartContainerWrapper":"ChartAreaInteractive_chartContainerWrapper__sa2zO","chartContainer":"ChartAreaInteractive_chartContainer__PLbGm","loading":"ChartAreaInteractive_loading__M0in3","overlay":"ChartAreaInteractive_overlay__V8w04","fadeIn":"ChartAreaInteractive_fadeIn__qDomf"};
|
|
3
|
+
var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}:root{--chart-height:586px}@media (max-width:768px){:root{--chart-height:300px}}.ChartAreaInteractive_loadingSpinner__A7jox{animation:ChartAreaInteractive_spin__zU5LX 1s linear infinite;border-top-color:var(--muted-foreground);border:2px solid var(--muted-foreground);border-radius:9999px;height:1.5rem;width:1.5rem}.ChartAreaInteractive_chartHeaderContainer__XkPiP{align-items:center;display:flex;flex-wrap:wrap;gap:var(--p-2);justify-content:space-between;margin-bottom:1rem}.ChartAreaInteractive_chartHeaderTitle__pTi-h{flex:1 1 auto;min-width:0}.ChartAreaInteractive_chartContainerWrapper__sa2zO{position:relative}.ChartAreaInteractive_chartContainer__PLbGm{aspect-ratio:auto;height:var(--chart-height);transition:opacity .3s ease-out;width:100%}.ChartAreaInteractive_loading__M0in3 .ChartAreaInteractive_chartContainer__PLbGm{opacity:.3;pointer-events:none}.ChartAreaInteractive_chartContainer__PLbGm .recharts-legend-item{cursor:pointer;margin-right:var(--p-6)!important}.ChartAreaInteractive_overlay__V8w04{inset:0;margin:var(--p-5) var(--p-8) var(--p-24) var(--p-12);position:absolute}@media (max-width:768px){.ChartAreaInteractive_overlay__V8w04{height:230px!important}}@keyframes ChartAreaInteractive_spin__zU5LX{to{transform:rotate(1turn)}}@keyframes ChartAreaInteractive_fadeIn__qDomf{0%{opacity:0}to{opacity:1}}";
|
|
4
|
+
var S = {"loadingSpinner":"ChartAreaInteractive_loadingSpinner__A7jox","spin":"ChartAreaInteractive_spin__zU5LX","chartHeaderContainer":"ChartAreaInteractive_chartHeaderContainer__XkPiP","chartHeaderTitle":"ChartAreaInteractive_chartHeaderTitle__pTi-h","chartContainerWrapper":"ChartAreaInteractive_chartContainerWrapper__sa2zO","chartContainer":"ChartAreaInteractive_chartContainer__PLbGm","loading":"ChartAreaInteractive_loading__M0in3","overlay":"ChartAreaInteractive_overlay__V8w04","fadeIn":"ChartAreaInteractive_fadeIn__qDomf"};
|
|
5
5
|
styleInject(css_248z);
|
|
6
6
|
|
|
7
7
|
export { S as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { memo } from 'react';
|
|
3
3
|
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '../Select/Select.js';
|
|
4
4
|
import { ToggleGroup, ToggleGroupItem } from '../ToggleGroup/ToggleGroup.js';
|
|
@@ -10,9 +10,23 @@ function toggleValueForTimeRange(timeRange) {
|
|
|
10
10
|
? timeRange
|
|
11
11
|
: '';
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The preset ranges as a select. A range that is not a preset (one dragged on
|
|
15
|
+
* the chart) shows "Custom" rather than a preset it is not.
|
|
16
|
+
*/
|
|
17
|
+
const TimeRangeSelect = memo(({ timeRange, onTimeRangeChange, loading }) => (jsxs(Select
|
|
18
|
+
// An empty value shows the placeholder; undefined would leave the
|
|
19
|
+
// select uncontrolled and keep the last preset picked.
|
|
20
|
+
, {
|
|
21
|
+
// An empty value shows the placeholder; undefined would leave the
|
|
22
|
+
// select uncontrolled and keep the last preset picked.
|
|
23
|
+
value: toggleValueForTimeRange(timeRange), onValueChange: onTimeRangeChange, disabled: loading, children: [jsx(SelectTrigger, { className: S.timeRangeSelectTrigger, size: "sm", "aria-label": "Time range", children: jsx(SelectValue, { placeholder: "Custom" }) }), jsx(SelectContent, { className: S.timeRangeSelectContent, children: TIME_RANGES.map(range => (jsx(SelectItem, { value: range, className: S.timeRangeSelectItem, children: range }, range))) })] })));
|
|
16
24
|
TimeRangeSelect.displayName = 'TimeRangeSelect';
|
|
25
|
+
/**
|
|
26
|
+
* The preset ranges as a toggle row from 768px up, and as a select below it
|
|
27
|
+
* (CSS shows one of the two), so the control stays on a phone.
|
|
28
|
+
*/
|
|
29
|
+
const TimeRangeControls = memo(({ timeRange, onTimeRangeChange, loading, variant = 'default', }) => (jsxs("div", { className: S.timeRangeContainer, children: [jsx(ToggleGroup, { type: "single", value: toggleValueForTimeRange(timeRange), onValueChange: onTimeRangeChange, variant: variant === 'segmented' ? 'segmented' : 'outline', disabled: loading, className: S.timeRangeToggleGroup, children: TIME_RANGES.map(range => (jsx(ToggleGroupItem, { value: range, className: S.timeRangeToggleItem, children: range }, range))) }), jsx(TimeRangeSelect, { timeRange: timeRange, onTimeRangeChange: onTimeRangeChange, loading: loading })] })));
|
|
30
|
+
TimeRangeControls.displayName = 'TimeRangeControls';
|
|
17
31
|
|
|
18
32
|
export { TimeRangeControls, TimeRangeSelect };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import styleInject from 'style-inject';
|
|
2
2
|
|
|
3
|
-
var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}.Toggle_toggle__zrQdU{align-items:center;background-color:transparent;color:var(--muted-foreground);cursor:pointer;display:inline-flex;font-size:var(--text-sm);font-weight:600;gap:.5rem;justify-content:center;transition:all .15s ease-in-out;white-space:nowrap}.Toggle_toggle__zrQdU:hover{background-color:var(--muted-80);color:var(--muted-foreground)}.Toggle_toggle__zrQdU:disabled{opacity:.5;pointer-events:none}.Toggle_toggle__zrQdU[data-state=on]{background-color:var(--background);box-shadow:0 1px 2px 0 rgba(0,0,0,.05);color:var(--foreground)}.Toggle_toggle__zrQdU svg{flex-shrink:0;pointer-events:none}.Toggle_toggle__zrQdU svg:not([class*=size-]){height:1rem;width:1rem}.Toggle_toggle__zrQdU:focus-visible:not(:disabled):not([data-disabled]){outline:2px solid var(--focus-outline-color,var(--ring));outline:var(--focus-outline-width,2px) solid var(--focus-outline-color,var(--ring));outline-offset:2px;outline-offset:var(--focus-outline-offset,2px)}.Toggle_toggle__zrQdU[aria-invalid=true]{border-color:var(--destructive);box-shadow:0 0 0 3px var(--destructive-20)}.dark .Toggle_toggle__zrQdU[aria-invalid=true]{box-shadow:0 0 0 3px var(--destructive-40)}.Toggle_variant-default__n4-yB{border-radius:.375rem}.Toggle_variant-outline__J4zWJ{background-color:transparent;border:none}.Toggle_variant-outline__J4zWJ:hover{color:var(--foreground)}.Toggle_variant-outline__J4zWJ[data-state=on]{background-color:var(--background);color:var(--foreground)}.Toggle_size-md__llTAJ,.Toggle_size-sm__hODTn{border-radius:.375rem;height:1.75rem;padding-left:.75rem;padding-right:.75rem}.Toggle_size-lg__Y6-g6{border-radius:.5rem;height:2rem;padding-left:.875rem;padding-right:.875rem}";
|
|
4
|
-
var S = {"toggle":"Toggle_toggle__zrQdU","variant-default":"Toggle_variant-default__n4-yB","variant-outline":"Toggle_variant-outline__J4zWJ","size-sm":"Toggle_size-sm__hODTn","size-md":"Toggle_size-md__llTAJ","size-lg":"Toggle_size-lg__Y6-g6"};
|
|
3
|
+
var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}.Toggle_toggle__zrQdU{align-items:center;background-color:transparent;color:var(--muted-foreground);cursor:pointer;display:inline-flex;font-size:var(--text-sm);font-weight:600;gap:.5rem;justify-content:center;transition:all .15s ease-in-out;white-space:nowrap}.Toggle_toggle__zrQdU:hover{background-color:var(--muted-80);color:var(--muted-foreground)}.Toggle_toggle__zrQdU:disabled{opacity:.5;pointer-events:none}.Toggle_toggle__zrQdU[data-state=on]{background-color:var(--background);box-shadow:0 1px 2px 0 rgba(0,0,0,.05);color:var(--foreground)}.Toggle_toggle__zrQdU svg{flex-shrink:0;pointer-events:none}.Toggle_toggle__zrQdU svg:not([class*=size-]){height:1rem;width:1rem}.Toggle_toggle__zrQdU:focus-visible:not(:disabled):not([data-disabled]){outline:2px solid var(--focus-outline-color,var(--ring));outline:var(--focus-outline-width,2px) solid var(--focus-outline-color,var(--ring));outline-offset:2px;outline-offset:var(--focus-outline-offset,2px)}.Toggle_toggle__zrQdU[aria-invalid=true]{border-color:var(--destructive);box-shadow:0 0 0 3px var(--destructive-20)}.dark .Toggle_toggle__zrQdU[aria-invalid=true]{box-shadow:0 0 0 3px var(--destructive-40)}.Toggle_variant-default__n4-yB{border-radius:.375rem}.Toggle_variant-outline__J4zWJ{background-color:transparent;border:none}.Toggle_variant-outline__J4zWJ:hover{color:var(--foreground)}.Toggle_variant-outline__J4zWJ[data-state=on]{background-color:var(--background);color:var(--foreground)}.Toggle_toggle__zrQdU.Toggle_variant-segmented__V36EN{background-color:transparent;border:none;border-radius:6px;color:var(--muted-foreground);font-size:var(--text-xs);font-weight:400;height:auto;line-height:1.4;padding:4px 10px}.Toggle_toggle__zrQdU.Toggle_variant-segmented__V36EN:hover{background-color:transparent;color:var(--foreground)}.Toggle_toggle__zrQdU.Toggle_variant-segmented__V36EN[data-state=on]{background-color:var(--background);border-radius:6px;box-shadow:0 1px 2px 0 rgba(0,0,0,.08);color:var(--foreground)}.Toggle_size-md__llTAJ,.Toggle_size-sm__hODTn{border-radius:.375rem;height:1.75rem;padding-left:.75rem;padding-right:.75rem}.Toggle_size-lg__Y6-g6{border-radius:.5rem;height:2rem;padding-left:.875rem;padding-right:.875rem}";
|
|
4
|
+
var S = {"toggle":"Toggle_toggle__zrQdU","variant-default":"Toggle_variant-default__n4-yB","variant-outline":"Toggle_variant-outline__J4zWJ","variant-segmented":"Toggle_variant-segmented__V36EN","size-sm":"Toggle_size-sm__hODTn","size-md":"Toggle_size-md__llTAJ","size-lg":"Toggle_size-lg__Y6-g6"};
|
|
5
5
|
styleInject(css_248z);
|
|
6
6
|
|
|
7
7
|
export { S as default };
|
|
@@ -8,7 +8,7 @@ import S from './ToggleGroup.styl.js';
|
|
|
8
8
|
|
|
9
9
|
const ToggleGroupContext = createContext(getDefaultContextValues());
|
|
10
10
|
function ToggleGroup({ className, variant, size, children, disabled, ...props }) {
|
|
11
|
-
return (jsx(ToggleGroupPrimitive.Root, { "data-slot": "toggle-group", "data-disabled": disabled ? '' : undefined, className: cn(S.container, className), ...props, children: jsx(ToggleGroupContext.Provider, { value: { variant, size }, children: children }) }));
|
|
11
|
+
return (jsx(ToggleGroupPrimitive.Root, { "data-slot": "toggle-group", "data-variant": variant, "data-disabled": disabled ? '' : undefined, className: cn(S.container, className), ...props, children: jsx(ToggleGroupContext.Provider, { value: { variant, size }, children: children }) }));
|
|
12
12
|
}
|
|
13
13
|
function ToggleGroupItem({ className, children, variant, size, ...props }) {
|
|
14
14
|
const context = useContext(ToggleGroupContext);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import styleInject from 'style-inject';
|
|
2
2
|
|
|
3
|
-
var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}.ToggleGroup_container__HKgJE{align-items:center;border-radius:var(--p-6);display:flex;font-weight:600;gap:var(--p-1);transition:opacity .1s ease-out;width:-moz-fit-content;width:fit-content}.ToggleGroup_container__HKgJE[data-disabled]{opacity:.5;pointer-events:none}.ToggleGroup_item__Jz9yW{border:none;border-radius:var(--p-4);box-shadow:none;color:var(--muted-foreground);flex-shrink:0;transition:all .15s ease-in-out}.ToggleGroup_item__Jz9yW:focus{z-index:10}.ToggleGroup_item__Jz9yW:focus-visible:not(:disabled):not([data-disabled]){outline:2px solid var(--focus-outline-color,var(--ring));outline:var(--focus-outline-width,2px) solid var(--focus-outline-color,var(--ring));outline-offset:2px;outline-offset:var(--focus-outline-offset,2px)}.ToggleGroup_item__Jz9yW:focus-visible{z-index:10}.ToggleGroup_item__Jz9yW[data-state=on]{border-radius:var(--p-6);color:var(--foreground)}.ToggleGroup_item__Jz9yW[data-disabled]{opacity:.5;pointer-events:none}";
|
|
3
|
+
var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}.ToggleGroup_container__HKgJE{align-items:center;border-radius:var(--p-6);display:flex;font-weight:600;gap:var(--p-1);transition:opacity .1s ease-out;width:-moz-fit-content;width:fit-content}.ToggleGroup_container__HKgJE[data-disabled]{opacity:.5;pointer-events:none}.ToggleGroup_container__HKgJE[data-variant=segmented]{background-color:var(--sb-slate-100);border-radius:8px;font-weight:400;gap:2px;padding:2px}.ToggleGroup_item__Jz9yW{border:none;border-radius:var(--p-4);box-shadow:none;color:var(--muted-foreground);flex-shrink:0;transition:all .15s ease-in-out}.ToggleGroup_item__Jz9yW:focus{z-index:10}.ToggleGroup_item__Jz9yW:focus-visible:not(:disabled):not([data-disabled]){outline:2px solid var(--focus-outline-color,var(--ring));outline:var(--focus-outline-width,2px) solid var(--focus-outline-color,var(--ring));outline-offset:2px;outline-offset:var(--focus-outline-offset,2px)}.ToggleGroup_item__Jz9yW:focus-visible{z-index:10}.ToggleGroup_item__Jz9yW[data-state=on]{border-radius:var(--p-6);color:var(--foreground)}.ToggleGroup_item__Jz9yW[data-disabled]{opacity:.5;pointer-events:none}";
|
|
4
4
|
var S = {"container":"ToggleGroup_container__HKgJE","item":"ToggleGroup_item__Jz9yW"};
|
|
5
5
|
styleInject(css_248z);
|
|
6
6
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ChartAreaInteractiveProps } from './ChartAreaInteractive.types';
|
|
2
2
|
export declare const chartConfig: {};
|
|
3
|
-
export declare function ChartAreaInteractive({ className, chartContainerClassName, legendClassName, xAxisClassName, yAxisClassName, timeRange, onTimeRangeChange, pinMonth, onPinMonthChange, onPreviewMonthChange, chartData, forecastData, historyData, error, loading, isDarkTheme, footerActions, mode, selectedForecast, upperQuantiles, lowerQuantiles, selectedLowerQuantile, selectedUpperQuantile, onLowerQuantileChange, onUpperQuantileChange, lowerThreshold, upperThreshold, onLowerThresholdChange, onUpperThresholdChange, discreteThresholdValues, headerActions, excludeLegendIds, loadingAnalyses, onLegendClick, onAnalysisSelect, disableTimeRangeSelector, enableTimeRangeBrush, forecastLineStyle, selectedAnalysisId, chartRenderId, toggleLegendSeries, ensureAnalysisSeriesVisible, overlayForecastData, hiddenSeries, disableForecastHistoricalBridge, overlayElements: overlayElementsProp, ...restProps }: ChartAreaInteractiveProps): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare function ChartAreaInteractive({ className, chartContainerClassName, legendClassName, xAxisClassName, yAxisClassName, timeRange, onTimeRangeChange, pinMonth, onPinMonthChange, onPreviewMonthChange, chartData, forecastData, historyData, error, loading, isDarkTheme, footerActions, mode, selectedForecast, upperQuantiles, lowerQuantiles, selectedLowerQuantile, selectedUpperQuantile, onLowerQuantileChange, onUpperQuantileChange, lowerThreshold, upperThreshold, onLowerThresholdChange, onUpperThresholdChange, discreteThresholdValues, headerActions, headerTitle, timeRangeVariant, excludeLegendIds, loadingAnalyses, onLegendClick, onAnalysisSelect, disableTimeRangeSelector, enableTimeRangeBrush, forecastLineStyle, selectedAnalysisId, chartRenderId, toggleLegendSeries, ensureAnalysisSeriesVisible, overlayForecastData, hiddenSeries, disableForecastHistoricalBridge, overlayElements: overlayElementsProp, ...restProps }: ChartAreaInteractiveProps): import("react/jsx-runtime").JSX.Element;
|
package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.types.d.ts
CHANGED
|
@@ -44,6 +44,13 @@ export interface ChartAreaInteractiveProps extends BaseChartWrapperProps {
|
|
|
44
44
|
upper: number[];
|
|
45
45
|
};
|
|
46
46
|
headerActions?: React.ReactNode;
|
|
47
|
+
/**
|
|
48
|
+
* Shown at the start of the header row, before the time range control,
|
|
49
|
+
* which then sits at the row's end (e.g. a one-line summary of the chart).
|
|
50
|
+
*/
|
|
51
|
+
headerTitle?: React.ReactNode;
|
|
52
|
+
/** The time range control's look (`TimeRangeControls` `variant`). */
|
|
53
|
+
timeRangeVariant?: 'default' | 'segmented';
|
|
47
54
|
loadingAnalyses?: Set<string>;
|
|
48
55
|
onLegendClick?: (data: LegendPayload) => undefined | boolean;
|
|
49
56
|
disableTimeRangeSelector?: boolean;
|
|
@@ -2,8 +2,20 @@ export type TimeRangeControlsProps = {
|
|
|
2
2
|
timeRange: string;
|
|
3
3
|
onTimeRangeChange: (range: string) => void;
|
|
4
4
|
loading?: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* The toggle row's look: `default` (plain buttons) or `segmented` (small
|
|
7
|
+
* buttons on a grey track, the picked one raised). The select shown below
|
|
8
|
+
* 768px is the same either way.
|
|
9
|
+
*/
|
|
10
|
+
variant?: 'default' | 'segmented';
|
|
5
11
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The preset ranges as a select. A range that is not a preset (one dragged on
|
|
14
|
+
* the chart) shows "Custom" rather than a preset it is not.
|
|
15
|
+
*/
|
|
16
|
+
export declare const TimeRangeSelect: import("react").MemoExoticComponent<({ timeRange, onTimeRangeChange, loading }: TimeRangeControlsProps) => import("react/jsx-runtime").JSX.Element>;
|
|
17
|
+
/**
|
|
18
|
+
* The preset ranges as a toggle row from 768px up, and as a select below it
|
|
19
|
+
* (CSS shows one of the two), so the control stays on a phone.
|
|
20
|
+
*/
|
|
21
|
+
export declare const TimeRangeControls: import("react").MemoExoticComponent<({ timeRange, onTimeRangeChange, loading, variant, }: TimeRangeControlsProps) => import("react/jsx-runtime").JSX.Element>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,6 +2,6 @@ import type { ComponentProps } from 'react';
|
|
|
2
2
|
import * as TogglePrimitive from '@radix-ui/react-toggle';
|
|
3
3
|
export interface ToggleProps extends ComponentProps<typeof TogglePrimitive.Root> {
|
|
4
4
|
className?: string;
|
|
5
|
-
variant?: 'default' | 'outline';
|
|
5
|
+
variant?: 'default' | 'outline' | 'segmented';
|
|
6
6
|
size?: 'sm' | 'md' | 'lg';
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ToggleGroupContextValue } from './ToggleGroup.types';
|
|
2
|
-
export declare const getContextValues: (context: ToggleGroupContextValue, itemVariant?: "default" | "outline", itemSize?: "sm" | "md" | "lg") => {
|
|
3
|
-
variant: "default" | "outline";
|
|
2
|
+
export declare const getContextValues: (context: ToggleGroupContextValue, itemVariant?: "default" | "outline" | "segmented", itemSize?: "sm" | "md" | "lg") => {
|
|
3
|
+
variant: "default" | "outline" | "segmented";
|
|
4
4
|
size: "sm" | "md" | "lg";
|
|
5
5
|
};
|
|
6
6
|
export declare const getDefaultContextValues: () => ToggleGroupContextValue;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export interface ToggleGroupContextValue {
|
|
2
2
|
size?: 'sm' | 'md' | 'lg';
|
|
3
|
-
variant?: 'default' | 'outline';
|
|
3
|
+
variant?: 'default' | 'outline' | 'segmented';
|
|
4
4
|
}
|
|
5
5
|
interface ToggleGroupBaseProps extends React.ComponentPropsWithoutRef<'div'> {
|
|
6
6
|
size?: 'sm' | 'md' | 'lg';
|
|
7
|
-
variant?: 'default' | 'outline';
|
|
7
|
+
variant?: 'default' | 'outline' | 'segmented';
|
|
8
8
|
orientation?: 'horizontal' | 'vertical';
|
|
9
9
|
dir?: 'ltr' | 'rtl';
|
|
10
10
|
rovingFocus?: boolean;
|
|
@@ -27,6 +27,6 @@ export type ToggleGroupProps = ToggleGroupSingleProps | ToggleGroupMultipleProps
|
|
|
27
27
|
export interface ToggleGroupItemProps extends React.ComponentPropsWithoutRef<'button'> {
|
|
28
28
|
value: string;
|
|
29
29
|
size?: 'sm' | 'md' | 'lg';
|
|
30
|
-
variant?: 'default' | 'outline';
|
|
30
|
+
variant?: 'default' | 'outline' | 'segmented';
|
|
31
31
|
}
|
|
32
32
|
export {};
|
package/package.json
CHANGED
|
@@ -47,3 +47,14 @@ describe('ChartAxes y-axis numbers', () => {
|
|
|
47
47
|
expect(own).toHaveBeenCalled();
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
|
+
|
|
51
|
+
describe('ChartAxes auto-scaled y range', () => {
|
|
52
|
+
it("uses recharts' own fit around the data, not the values scaled", () => {
|
|
53
|
+
yAxisProps.length = 0;
|
|
54
|
+
render(<ChartAxes formatDate={formatDate} autoScaleYAxis />);
|
|
55
|
+
expect((yAxisProps.at(-1) as { domain?: unknown })?.domain).toEqual([
|
|
56
|
+
'auto',
|
|
57
|
+
'auto',
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo, useRef } from 'react';
|
|
1
|
+
import { type ComponentProps, useMemo, useRef } from 'react';
|
|
2
2
|
|
|
3
3
|
import { Label, XAxis, YAxis } from 'recharts';
|
|
4
4
|
|
|
@@ -81,32 +81,13 @@ export function ChartAxes({
|
|
|
81
81
|
}, [hide, yMin, yMax, autoScaleYAxis, formatNumber]);
|
|
82
82
|
|
|
83
83
|
// Determine Y-axis domain
|
|
84
|
-
let yDomain:
|
|
85
|
-
| [
|
|
86
|
-
(
|
|
87
|
-
| number
|
|
88
|
-
| string
|
|
89
|
-
| 'auto'
|
|
90
|
-
| 'dataMin'
|
|
91
|
-
| 'dataMax'
|
|
92
|
-
| ((dataMin: number) => number)
|
|
93
|
-
),
|
|
94
|
-
(
|
|
95
|
-
| number
|
|
96
|
-
| string
|
|
97
|
-
| 'auto'
|
|
98
|
-
| 'dataMin'
|
|
99
|
-
| 'dataMax'
|
|
100
|
-
| ((dataMax: number) => number)
|
|
101
|
-
),
|
|
102
|
-
]
|
|
103
|
-
| undefined;
|
|
84
|
+
let yDomain: ComponentProps<typeof YAxis>['domain'];
|
|
104
85
|
|
|
105
86
|
if (autoScaleYAxis) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
];
|
|
87
|
+
// recharts' own fit: nice round ticks just around the data, so a series
|
|
88
|
+
// moving 1000–1010 fills the chart (scaling the values by 0.95/1.05 left
|
|
89
|
+
// it flat) and a negative one is padded too.
|
|
90
|
+
yDomain = ['auto', 'auto'];
|
|
110
91
|
} else if (yMin !== undefined && yMax !== undefined) {
|
|
111
92
|
yDomain = [yMin, yMax];
|
|
112
93
|
}
|
|
@@ -74,6 +74,8 @@ export function ChartAreaInteractive({
|
|
|
74
74
|
onUpperThresholdChange,
|
|
75
75
|
discreteThresholdValues,
|
|
76
76
|
headerActions,
|
|
77
|
+
headerTitle,
|
|
78
|
+
timeRangeVariant,
|
|
77
79
|
excludeLegendIds,
|
|
78
80
|
loadingAnalyses,
|
|
79
81
|
onLegendClick,
|
|
@@ -296,13 +298,17 @@ export function ChartAreaInteractive({
|
|
|
296
298
|
className={cn(className, loading && S.loading)}
|
|
297
299
|
disabled={loading}
|
|
298
300
|
>
|
|
299
|
-
{(!disableTimeRangeSelector || headerActions) && (
|
|
301
|
+
{(!disableTimeRangeSelector || headerActions || headerTitle) && (
|
|
300
302
|
<div className={S.chartHeaderContainer}>
|
|
303
|
+
{headerTitle != null && (
|
|
304
|
+
<div className={S.chartHeaderTitle}>{headerTitle}</div>
|
|
305
|
+
)}
|
|
301
306
|
{!disableTimeRangeSelector && (
|
|
302
307
|
<TimeRangeControls
|
|
303
308
|
timeRange={timeRange}
|
|
304
309
|
onTimeRangeChange={onTimeRangeChange}
|
|
305
310
|
loading={loading}
|
|
311
|
+
variant={timeRangeVariant}
|
|
306
312
|
/>
|
|
307
313
|
)}
|
|
308
314
|
|
|
@@ -48,6 +48,13 @@ export interface ChartAreaInteractiveProps extends BaseChartWrapperProps {
|
|
|
48
48
|
onUpperThresholdChange?: (value: number) => void;
|
|
49
49
|
discreteThresholdValues?: { lower: number[]; upper: number[] };
|
|
50
50
|
headerActions?: React.ReactNode;
|
|
51
|
+
/**
|
|
52
|
+
* Shown at the start of the header row, before the time range control,
|
|
53
|
+
* which then sits at the row's end (e.g. a one-line summary of the chart).
|
|
54
|
+
*/
|
|
55
|
+
headerTitle?: React.ReactNode;
|
|
56
|
+
/** The time range control's look (`TimeRangeControls` `variant`). */
|
|
57
|
+
timeRangeVariant?: 'default' | 'segmented';
|
|
51
58
|
loadingAnalyses?: Set<string>;
|
|
52
59
|
onLegendClick?: (data: LegendPayload) => undefined | boolean;
|
|
53
60
|
disableTimeRangeSelector?: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
TimeRangeControls renders a row of preset time range toggles, such as one month or one year, for switching the window of a chart. Control it with timeRange and onTimeRangeChange, and pass loading to disable the controls while data refreshes.
|
|
1
|
+
TimeRangeControls renders a row of preset time range toggles, such as one month or one year, for switching the window of a chart. Control it with timeRange and onTimeRangeChange, and pass loading to disable the controls while data refreshes. Below 768px the same presets show as a select instead of the toggle row, so the control stays on a phone; a range that is not a preset (one dragged on the chart) selects no toggle and shows "Custom" in the select. Pass variant="segmented" for the compact look (small buttons on a grey track, the picked one raised); ChartAreaInteractive passes it through as timeRangeVariant, and its headerTitle puts a one-line summary at the start of the same row, with the control at the end.
|
|
2
2
|
|
|
3
3
|
## When to use
|
|
4
4
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
|
|
3
|
+
import { TimeRangeControls } from './TimeRangeControls';
|
|
4
|
+
|
|
5
|
+
const noop = () => {};
|
|
6
|
+
|
|
7
|
+
describe('TimeRangeControls', () => {
|
|
8
|
+
it('renders the toggle row and the select, so a phone still has the control', () => {
|
|
9
|
+
render(<TimeRangeControls timeRange="1y" onTimeRangeChange={noop} />);
|
|
10
|
+
expect(screen.getByRole('group')).toBeTruthy();
|
|
11
|
+
const select = screen.getByRole('combobox', { name: 'Time range' });
|
|
12
|
+
expect(select.textContent).toContain('1y');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('says "Custom" for a range that is not a preset', () => {
|
|
16
|
+
const { rerender } = render(
|
|
17
|
+
<TimeRangeControls timeRange="1y" onTimeRangeChange={noop} />,
|
|
18
|
+
);
|
|
19
|
+
rerender(
|
|
20
|
+
<TimeRangeControls
|
|
21
|
+
timeRange="2024-01-01_2024-06-01"
|
|
22
|
+
onTimeRangeChange={noop}
|
|
23
|
+
/>,
|
|
24
|
+
);
|
|
25
|
+
const select = screen.getByRole('combobox', { name: 'Time range' });
|
|
26
|
+
expect(select.textContent).toContain('Custom');
|
|
27
|
+
expect(select.textContent).not.toContain('1y');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('disables both while loading', () => {
|
|
31
|
+
render(
|
|
32
|
+
<TimeRangeControls timeRange="1y" onTimeRangeChange={noop} loading />,
|
|
33
|
+
);
|
|
34
|
+
expect(
|
|
35
|
+
screen.getByRole('combobox', { name: 'Time range' }).hasAttribute(
|
|
36
|
+
'disabled',
|
|
37
|
+
),
|
|
38
|
+
).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('draws the segmented look on the toggle row when asked', () => {
|
|
42
|
+
const { rerender } = render(
|
|
43
|
+
<TimeRangeControls timeRange="1y" onTimeRangeChange={noop} />,
|
|
44
|
+
);
|
|
45
|
+
expect(screen.getByRole('group').getAttribute('data-variant')).toBe(
|
|
46
|
+
'outline',
|
|
47
|
+
);
|
|
48
|
+
rerender(
|
|
49
|
+
<TimeRangeControls
|
|
50
|
+
timeRange="1y"
|
|
51
|
+
onTimeRangeChange={noop}
|
|
52
|
+
variant="segmented"
|
|
53
|
+
/>,
|
|
54
|
+
);
|
|
55
|
+
const group = screen.getByRole('group');
|
|
56
|
+
expect(group.getAttribute('data-variant')).toBe('segmented');
|
|
57
|
+
for (const item of group.querySelectorAll('[data-slot="toggle-group-item"]')) {
|
|
58
|
+
expect(item.getAttribute('data-variant')).toBe('segmented');
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -25,52 +25,33 @@ export type TimeRangeControlsProps = {
|
|
|
25
25
|
timeRange: string;
|
|
26
26
|
onTimeRangeChange: (range: string) => void;
|
|
27
27
|
loading?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The toggle row's look: `default` (plain buttons) or `segmented` (small
|
|
30
|
+
* buttons on a grey track, the picked one raised). The select shown below
|
|
31
|
+
* 768px is the same either way.
|
|
32
|
+
*/
|
|
33
|
+
variant?: 'default' | 'segmented';
|
|
28
34
|
};
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
type="single"
|
|
35
|
-
value={toggleValueForTimeRange(timeRange)}
|
|
36
|
-
onValueChange={onTimeRangeChange}
|
|
37
|
-
variant="outline"
|
|
38
|
-
disabled={loading}
|
|
39
|
-
className={S.timeRangeToggleGroup}
|
|
40
|
-
>
|
|
41
|
-
{TIME_RANGES.map(range => (
|
|
42
|
-
<ToggleGroupItem
|
|
43
|
-
key={range}
|
|
44
|
-
value={range}
|
|
45
|
-
className={S.timeRangeToggleItem}
|
|
46
|
-
>
|
|
47
|
-
{range}
|
|
48
|
-
</ToggleGroupItem>
|
|
49
|
-
))}
|
|
50
|
-
</ToggleGroup>
|
|
51
|
-
</div>
|
|
52
|
-
),
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
TimeRangeControls.displayName = 'TimeRangeControls';
|
|
56
|
-
|
|
36
|
+
/**
|
|
37
|
+
* The preset ranges as a select. A range that is not a preset (one dragged on
|
|
38
|
+
* the chart) shows "Custom" rather than a preset it is not.
|
|
39
|
+
*/
|
|
57
40
|
export const TimeRangeSelect = memo(
|
|
58
|
-
({
|
|
59
|
-
timeRange,
|
|
60
|
-
onTimeRangeChange,
|
|
61
|
-
loading,
|
|
62
|
-
}: TimeRangeControlsProps & { loading: boolean }) => (
|
|
41
|
+
({ timeRange, onTimeRangeChange, loading }: TimeRangeControlsProps) => (
|
|
63
42
|
<Select
|
|
64
|
-
value
|
|
43
|
+
// An empty value shows the placeholder; undefined would leave the
|
|
44
|
+
// select uncontrolled and keep the last preset picked.
|
|
45
|
+
value={toggleValueForTimeRange(timeRange)}
|
|
65
46
|
onValueChange={onTimeRangeChange}
|
|
66
47
|
disabled={loading}
|
|
67
48
|
>
|
|
68
49
|
<SelectTrigger
|
|
69
50
|
className={S.timeRangeSelectTrigger}
|
|
70
51
|
size="sm"
|
|
71
|
-
aria-label="
|
|
52
|
+
aria-label="Time range"
|
|
72
53
|
>
|
|
73
|
-
<SelectValue placeholder="
|
|
54
|
+
<SelectValue placeholder="Custom" />
|
|
74
55
|
</SelectTrigger>
|
|
75
56
|
|
|
76
57
|
<SelectContent className={S.timeRangeSelectContent}>
|
|
@@ -89,3 +70,44 @@ export const TimeRangeSelect = memo(
|
|
|
89
70
|
);
|
|
90
71
|
|
|
91
72
|
TimeRangeSelect.displayName = 'TimeRangeSelect';
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The preset ranges as a toggle row from 768px up, and as a select below it
|
|
76
|
+
* (CSS shows one of the two), so the control stays on a phone.
|
|
77
|
+
*/
|
|
78
|
+
export const TimeRangeControls = memo(
|
|
79
|
+
({
|
|
80
|
+
timeRange,
|
|
81
|
+
onTimeRangeChange,
|
|
82
|
+
loading,
|
|
83
|
+
variant = 'default',
|
|
84
|
+
}: TimeRangeControlsProps) => (
|
|
85
|
+
<div className={S.timeRangeContainer}>
|
|
86
|
+
<ToggleGroup
|
|
87
|
+
type="single"
|
|
88
|
+
value={toggleValueForTimeRange(timeRange)}
|
|
89
|
+
onValueChange={onTimeRangeChange}
|
|
90
|
+
variant={variant === 'segmented' ? 'segmented' : 'outline'}
|
|
91
|
+
disabled={loading}
|
|
92
|
+
className={S.timeRangeToggleGroup}
|
|
93
|
+
>
|
|
94
|
+
{TIME_RANGES.map(range => (
|
|
95
|
+
<ToggleGroupItem
|
|
96
|
+
key={range}
|
|
97
|
+
value={range}
|
|
98
|
+
className={S.timeRangeToggleItem}
|
|
99
|
+
>
|
|
100
|
+
{range}
|
|
101
|
+
</ToggleGroupItem>
|
|
102
|
+
))}
|
|
103
|
+
</ToggleGroup>
|
|
104
|
+
<TimeRangeSelect
|
|
105
|
+
timeRange={timeRange}
|
|
106
|
+
onTimeRangeChange={onTimeRangeChange}
|
|
107
|
+
loading={loading}
|
|
108
|
+
/>
|
|
109
|
+
</div>
|
|
110
|
+
),
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
TimeRangeControls.displayName = 'TimeRangeControls';
|
|
@@ -60,6 +60,30 @@
|
|
|
60
60
|
background-color var(--background)
|
|
61
61
|
color var(--foreground)
|
|
62
62
|
|
|
63
|
+
// One button of a segmented control (ToggleGroup variant="segmented"): small
|
|
64
|
+
// and quiet, the picked one a raised white chip on the group's grey track.
|
|
65
|
+
// Two classes, so it wins over the size classes and ToggleGroup's .item.
|
|
66
|
+
.toggle.variant-segmented
|
|
67
|
+
height auto
|
|
68
|
+
padding 4px 10px
|
|
69
|
+
border none
|
|
70
|
+
border-radius 6px
|
|
71
|
+
font-size var(--text-xs)
|
|
72
|
+
font-weight 400
|
|
73
|
+
line-height 1.4
|
|
74
|
+
color var(--muted-foreground)
|
|
75
|
+
background-color transparent
|
|
76
|
+
|
|
77
|
+
&:hover
|
|
78
|
+
background-color transparent
|
|
79
|
+
color var(--foreground)
|
|
80
|
+
|
|
81
|
+
&[data-state='on']
|
|
82
|
+
border-radius 6px
|
|
83
|
+
background-color var(--background)
|
|
84
|
+
color var(--foreground)
|
|
85
|
+
box-shadow 0 1px 2px 0 rgba(0, 0, 0, 0.08)
|
|
86
|
+
|
|
63
87
|
.size-sm
|
|
64
88
|
height 1.75rem
|
|
65
89
|
padding-left 0.75rem
|
|
@@ -13,3 +13,4 @@ ToggleGroup presents a set of related toggle buttons where, in single mode, exac
|
|
|
13
13
|
## Do
|
|
14
14
|
|
|
15
15
|
- In single mode, ignore empty values from onValueChange so one option always stays selected.
|
|
16
|
+
- Use `variant="segmented"` for a compact picker on a grey track, where the chosen option is raised on a white chip (the chart time range uses it through `TimeRangeControls`).
|
|
@@ -3,10 +3,10 @@ import { ToggleGroupContextValue } from './ToggleGroup.types';
|
|
|
3
3
|
// Helper function to get context values with defaults
|
|
4
4
|
export const getContextValues = (
|
|
5
5
|
context: ToggleGroupContextValue,
|
|
6
|
-
itemVariant?: 'default' | 'outline',
|
|
6
|
+
itemVariant?: 'default' | 'outline' | 'segmented',
|
|
7
7
|
itemSize?: 'sm' | 'md' | 'lg',
|
|
8
8
|
): {
|
|
9
|
-
variant: 'default' | 'outline';
|
|
9
|
+
variant: 'default' | 'outline' | 'segmented';
|
|
10
10
|
size: 'sm' | 'md' | 'lg';
|
|
11
11
|
} => ({
|
|
12
12
|
variant: context.variant || itemVariant || 'default',
|
|
@@ -15,6 +15,14 @@
|
|
|
15
15
|
pointer-events none
|
|
16
16
|
opacity 0.5
|
|
17
17
|
|
|
18
|
+
// A segmented control: the buttons sit on one grey track.
|
|
19
|
+
.container[data-variant='segmented']
|
|
20
|
+
gap 2px
|
|
21
|
+
padding 2px
|
|
22
|
+
border-radius 8px
|
|
23
|
+
background-color var(--sb-slate-100)
|
|
24
|
+
font-weight 400
|
|
25
|
+
|
|
18
26
|
// Item styles for ToggleGroupItem
|
|
19
27
|
.item
|
|
20
28
|
flex-shrink 0
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export interface ToggleGroupContextValue {
|
|
2
2
|
size?: 'sm' | 'md' | 'lg';
|
|
3
|
-
variant?: 'default' | 'outline';
|
|
3
|
+
variant?: 'default' | 'outline' | 'segmented';
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
interface ToggleGroupBaseProps extends React.ComponentPropsWithoutRef<'div'> {
|
|
7
7
|
size?: 'sm' | 'md' | 'lg';
|
|
8
|
-
variant?: 'default' | 'outline';
|
|
8
|
+
variant?: 'default' | 'outline' | 'segmented';
|
|
9
9
|
orientation?: 'horizontal' | 'vertical';
|
|
10
10
|
dir?: 'ltr' | 'rtl';
|
|
11
11
|
rovingFocus?: boolean;
|
|
@@ -34,5 +34,5 @@ export type ToggleGroupProps =
|
|
|
34
34
|
export interface ToggleGroupItemProps extends React.ComponentPropsWithoutRef<'button'> {
|
|
35
35
|
value: string;
|
|
36
36
|
size?: 'sm' | 'md' | 'lg';
|
|
37
|
-
variant?: 'default' | 'outline';
|
|
37
|
+
variant?: 'default' | 'outline' | 'segmented';
|
|
38
38
|
}
|
|
@@ -152,6 +152,30 @@ function MultiHistoryDemo({ isDarkTheme }: { isDarkTheme: boolean }) {
|
|
|
152
152
|
);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
function SegmentedHeaderDemo({ isDarkTheme }: { isDarkTheme: boolean }) {
|
|
156
|
+
const [timeRange, setTimeRange] = useState<string>('1y');
|
|
157
|
+
const [pinMonth, setPinMonth] = useState<string | undefined>(undefined);
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<ChartAreaInteractive
|
|
161
|
+
chartRenderId="segmented-header-demo"
|
|
162
|
+
headerTitle="Fair value 12.4 · horizon 3m · model A"
|
|
163
|
+
timeRangeVariant="segmented"
|
|
164
|
+
timeRange={timeRange}
|
|
165
|
+
onTimeRangeChange={setTimeRange}
|
|
166
|
+
pinMonth={pinMonth}
|
|
167
|
+
onPinMonthChange={setPinMonth}
|
|
168
|
+
chartData={INITIAL_CHART}
|
|
169
|
+
forecastData={DEMO_FORECAST_ITEMS}
|
|
170
|
+
loading={false}
|
|
171
|
+
isDarkTheme={isDarkTheme}
|
|
172
|
+
toggleLegendSeries={() => {}}
|
|
173
|
+
ensureAnalysisSeriesVisible={() => {}}
|
|
174
|
+
hiddenSeries={new Set()}
|
|
175
|
+
/>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
155
179
|
export default function ChartAreaInteractivePage() {
|
|
156
180
|
const { isDarkMode } = useTheme();
|
|
157
181
|
const [timeRange, setTimeRange] = useState<string>('1y');
|
|
@@ -272,6 +296,16 @@ export default function ChartAreaInteractivePage() {
|
|
|
272
296
|
</p>
|
|
273
297
|
<MultiHistoryDemo isDarkTheme={isDarkMode} />
|
|
274
298
|
</PageContentSection>
|
|
299
|
+
<PageContentSection>
|
|
300
|
+
<h3 style={{ marginBottom: '1rem' }}>Title and segmented range</h3>
|
|
301
|
+
<p>
|
|
302
|
+
<code>headerTitle</code> puts a caption at the start of the header
|
|
303
|
+
row, with the range control at its end;{' '}
|
|
304
|
+
<code>timeRangeVariant="segmented"</code> draws the compact picker on
|
|
305
|
+
a grey track.
|
|
306
|
+
</p>
|
|
307
|
+
<SegmentedHeaderDemo isDarkTheme={isDarkMode} />
|
|
308
|
+
</PageContentSection>
|
|
275
309
|
</>
|
|
276
310
|
);
|
|
277
311
|
}
|
|
@@ -27,6 +27,15 @@ export default function TimeRangeControlsPage() {
|
|
|
27
27
|
loading={false}
|
|
28
28
|
/>
|
|
29
29
|
</PageContentSection>
|
|
30
|
+
<PageContentSection>
|
|
31
|
+
<h3 style={{ marginBottom: '1rem' }}>Segmented</h3>
|
|
32
|
+
<TimeRangeControls
|
|
33
|
+
timeRange={range}
|
|
34
|
+
onTimeRangeChange={setRange}
|
|
35
|
+
loading={false}
|
|
36
|
+
variant="segmented"
|
|
37
|
+
/>
|
|
38
|
+
</PageContentSection>
|
|
30
39
|
</>
|
|
31
40
|
);
|
|
32
41
|
}
|