@timefoldai/viz-react 0.0.0-stage → 0.1.0
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/LICENSE +202 -0
- package/README.md +240 -2
- package/dist/THIRD-PARTY-NOTICES.txt +99 -0
- package/dist/a11y/AccessibleTable.d.mts +42 -0
- package/dist/a11y/AccessibleTable.mjs +82 -0
- package/dist/a11y/activation.d.mts +4 -0
- package/dist/a11y/activation.mjs +0 -0
- package/dist/analytics/AnalyticsProvider.d.mts +16 -0
- package/dist/analytics/AnalyticsProvider.mjs +32 -0
- package/dist/assets/Inter-latin-ext.woff2 +0 -0
- package/dist/badge/Badge.css +122 -0
- package/dist/badge/Badge.d.mts +50 -0
- package/dist/badge/Badge.mjs +145 -0
- package/dist/badge/Badge.module.css.mjs +15 -0
- package/dist/badge/BadgeFacetGroup.d.mts +23 -0
- package/dist/badge/BadgeFacetGroup.mjs +220 -0
- package/dist/badge/BadgeGroup.d.mts +13 -0
- package/dist/badge/BadgeGroup.mjs +53 -0
- package/dist/badge/BadgeList.d.mts +14 -0
- package/dist/badge/BadgeList.mjs +15 -0
- package/dist/badge/badge-facet-fit.d.mts +18 -0
- package/dist/badge/badge-facet-fit.mjs +50 -0
- package/dist/badge/badge-item.d.mts +19 -0
- package/dist/badge/badge-item.mjs +23 -0
- package/dist/button/CopyButton.d.mts +12 -0
- package/dist/button/CopyButton.mjs +52 -0
- package/dist/button/ShowAllButton.d.mts +14 -0
- package/dist/button/ShowAllButton.mjs +61 -0
- package/dist/button/ShowMoreButton.d.mts +13 -0
- package/dist/button/ShowMoreButton.mjs +51 -0
- package/dist/button/SolveButton.d.mts +16 -0
- package/dist/button/SolveButton.mjs +56 -0
- package/dist/charts/BarChart.css +59 -0
- package/dist/charts/BarChart.d.mts +26 -0
- package/dist/charts/BarChart.mjs +167 -0
- package/dist/charts/BarChart.module.css.mjs +10 -0
- package/dist/charts/ChartGrid.d.mts +8 -0
- package/dist/charts/ChartGrid.mjs +47 -0
- package/dist/charts/DistributionChart.d.mts +60 -0
- package/dist/charts/DistributionChart.mjs +151 -0
- package/dist/code/CodeBlock.d.mts +13 -0
- package/dist/code/CodeBlock.mjs +71 -0
- package/dist/composition-bar/CompositionBar.d.mts +24 -0
- package/dist/composition-bar/CompositionBar.mjs +124 -0
- package/dist/composition-bar/composition-shares.d.mts +8 -0
- package/dist/composition-bar/composition-shares.mjs +30 -0
- package/dist/data-gate/DataGate.d.mts +34 -0
- package/dist/data-gate/DataGate.mjs +80 -0
- package/dist/date-scope/DateScope.d.mts +30 -0
- package/dist/date-scope/DateScope.mjs +285 -0
- package/dist/design-system/part-props.d.mts +39 -0
- package/dist/design-system/part-props.mjs +0 -0
- package/dist/detail-panel/DetailPanel.d.mts +22 -0
- package/dist/detail-panel/DetailPanel.mjs +80 -0
- package/dist/detail-panel/DetailPanelSection.d.mts +20 -0
- package/dist/detail-panel/DetailPanelSection.mjs +27 -0
- package/dist/detail-panel/micro-label.d.mts +7 -0
- package/dist/detail-panel/micro-label.mjs +9 -0
- package/dist/env.d.mts +2 -0
- package/dist/env.mjs +4 -0
- package/dist/export/ExportCsvButton.d.mts +19 -0
- package/dist/export/ExportCsvButton.mjs +73 -0
- package/dist/export/download-csv.d.mts +5 -0
- package/dist/export/download-csv.mjs +11 -0
- package/dist/export/download-file.d.mts +11 -0
- package/dist/export/download-file.mjs +32 -0
- package/dist/export/download-json.d.mts +2 -0
- package/dist/export/download-json.mjs +8 -0
- package/dist/filter/FilterGroup.d.mts +24 -0
- package/dist/filter/FilterGroup.mjs +71 -0
- package/dist/filter/FilterGroupTitle.d.mts +3 -0
- package/dist/filter/FilterGroupTitle.mjs +18 -0
- package/dist/filter/FilterItem.d.mts +17 -0
- package/dist/filter/FilterItem.mjs +94 -0
- package/dist/filter/FilterPanel.d.mts +22 -0
- package/dist/filter/FilterPanel.mjs +158 -0
- package/dist/filter/FilterToggleButton.d.mts +15 -0
- package/dist/filter/FilterToggleButton.mjs +30 -0
- package/dist/filter/date-range.d.mts +8 -0
- package/dist/filter/date-range.mjs +13 -0
- package/dist/filter/filter-facet.d.mts +7 -0
- package/dist/filter/filter-facet.mjs +0 -0
- package/dist/heatmap/Heatmap.css +138 -0
- package/dist/heatmap/Heatmap.d.mts +10 -0
- package/dist/heatmap/Heatmap.mjs +370 -0
- package/dist/heatmap/Heatmap.module.css.mjs +17 -0
- package/dist/heatmap/HeatmapCell.d.mts +25 -0
- package/dist/heatmap/HeatmapCell.mjs +124 -0
- package/dist/heatmap/heatmap-scale.d.mts +19 -0
- package/dist/heatmap/heatmap-scale.mjs +43 -0
- package/dist/heatmap/heatmap-types.d.mts +49 -0
- package/dist/heatmap/heatmap-types.mjs +0 -0
- package/dist/hooks/use-controllable-state.d.mts +9 -0
- package/dist/hooks/use-controllable-state.mjs +44 -0
- package/dist/hooks/use-debounced-value.d.mts +1 -0
- package/dist/hooks/use-debounced-value.mjs +27 -0
- package/dist/hooks/use-detail-panel-layout.d.mts +18 -0
- package/dist/hooks/use-detail-panel-layout.mjs +94 -0
- package/dist/hooks/use-hover-card.d.mts +47 -0
- package/dist/hooks/use-hover-card.mjs +190 -0
- package/dist/hooks/use-hover-focus-card.d.mts +38 -0
- package/dist/hooks/use-hover-focus-card.mjs +321 -0
- package/dist/hooks/use-hover-intent.d.mts +6 -0
- package/dist/hooks/use-hover-intent.mjs +55 -0
- package/dist/hooks/use-merged-ref.d.mts +2 -0
- package/dist/hooks/use-merged-ref.mjs +36 -0
- package/dist/hooks/use-tracked-anchor.d.mts +14 -0
- package/dist/hooks/use-tracked-anchor.mjs +42 -0
- package/dist/index.d.mts +97 -0
- package/dist/index.mjs +88 -0
- package/dist/input/MenuButton.d.mts +47 -0
- package/dist/input/MenuButton.mjs +152 -0
- package/dist/interval-strip/IntervalStrip.css +7 -0
- package/dist/interval-strip/IntervalStrip.d.mts +39 -0
- package/dist/interval-strip/IntervalStrip.mjs +233 -0
- package/dist/interval-strip/IntervalStrip.module.css.mjs +4 -0
- package/dist/interval-strip/IntervalStripAxis.d.mts +18 -0
- package/dist/interval-strip/IntervalStripAxis.mjs +73 -0
- package/dist/interval-strip/interval-fill.d.mts +2 -0
- package/dist/interval-strip/interval-fill.mjs +13 -0
- package/dist/interval-strip/interval-layout.d.mts +33 -0
- package/dist/interval-strip/interval-layout.mjs +79 -0
- package/dist/layout/AppShell.css +103 -0
- package/dist/layout/AppShell.d.mts +73 -0
- package/dist/layout/AppShell.mjs +397 -0
- package/dist/layout/AppShell.module.css.mjs +16 -0
- package/dist/layout/ColorSchemeMenu.d.mts +14 -0
- package/dist/layout/ColorSchemeMenu.mjs +92 -0
- package/dist/layout/DemoDataPicker.d.mts +17 -0
- package/dist/layout/DemoDataPicker.mjs +150 -0
- package/dist/layout/OverflowMenu.d.mts +11 -0
- package/dist/layout/OverflowMenu.mjs +94 -0
- package/dist/layout/SidebarLayout.css +70 -0
- package/dist/layout/SidebarLayout.d.mts +33 -0
- package/dist/layout/SidebarLayout.mjs +129 -0
- package/dist/layout/SidebarLayout.module.css.mjs +8 -0
- package/dist/layout/use-date-scope-day.d.mts +23 -0
- package/dist/layout/use-date-scope-day.mjs +63 -0
- package/dist/layout/use-fill-height.d.mts +7 -0
- package/dist/layout/use-fill-height.mjs +50 -0
- package/dist/layout/use-followed-state.d.mts +5 -0
- package/dist/layout/use-followed-state.mjs +75 -0
- package/dist/layout/use-page-route.d.mts +10 -0
- package/dist/layout/use-page-route.mjs +65 -0
- package/dist/legend/Legend.d.mts +54 -0
- package/dist/legend/Legend.mjs +132 -0
- package/dist/map/MapLayersControl.d.mts +11 -0
- package/dist/map/MapLayersControl.mjs +157 -0
- package/dist/map/MapLocator.css +9 -0
- package/dist/map/MapLocator.d.mts +18 -0
- package/dist/map/MapLocator.mjs +97 -0
- package/dist/map/MapLocator.module.css.mjs +4 -0
- package/dist/map/MapMarker.d.mts +29 -0
- package/dist/map/MapMarker.mjs +265 -0
- package/dist/map/MapStops.d.mts +19 -0
- package/dist/map/MapStops.mjs +355 -0
- package/dist/map/MapView.css +24 -0
- package/dist/map/MapView.d.mts +11 -0
- package/dist/map/MapView.mjs +141 -0
- package/dist/map/MapWebgl.d.mts +9 -0
- package/dist/map/MapWebgl.mjs +727 -0
- package/dist/map/area-layers.d.mts +33 -0
- package/dist/map/area-layers.mjs +96 -0
- package/dist/map/control-group.d.mts +6 -0
- package/dist/map/control-group.mjs +12 -0
- package/dist/map/for-each-chunk.d.mts +4 -0
- package/dist/map/for-each-chunk.mjs +14 -0
- package/dist/map/highlight.d.mts +30 -0
- package/dist/map/highlight.mjs +99 -0
- package/dist/map/locator-tile.d.mts +24 -0
- package/dist/map/locator-tile.mjs +41 -0
- package/dist/map/map-sites.d.mts +12 -0
- package/dist/map/map-sites.mjs +39 -0
- package/dist/map/map-style.d.mts +24 -0
- package/dist/map/map-style.mjs +79 -0
- package/dist/map/marker-geometry.d.mts +5 -0
- package/dist/map/marker-geometry.mjs +13 -0
- package/dist/map/marker-icon.d.mts +26 -0
- package/dist/map/marker-icon.mjs +223 -0
- package/dist/map/observe-color-scheme.d.mts +5 -0
- package/dist/map/observe-color-scheme.mjs +19 -0
- package/dist/map/popup-placement.d.mts +20 -0
- package/dist/map/popup-placement.mjs +20 -0
- package/dist/map/route-layers.d.mts +28 -0
- package/dist/map/route-layers.mjs +73 -0
- package/dist/map/types.d.mts +97 -0
- package/dist/map/types.mjs +0 -0
- package/dist/map/use-painted-color-scheme.d.mts +6 -0
- package/dist/map/use-painted-color-scheme.mjs +43 -0
- package/dist/map/use-resolved-colors.d.mts +5 -0
- package/dist/map/use-resolved-colors.mjs +63 -0
- package/dist/pagination/paginationLabels.d.mts +6 -0
- package/dist/pagination/paginationLabels.mjs +8 -0
- package/dist/popover/Popover.css +176 -0
- package/dist/popover/Popover.d.mts +239 -0
- package/dist/popover/Popover.mjs +672 -0
- package/dist/popover/Popover.module.css.mjs +18 -0
- package/dist/popover/PopoverFacts.d.mts +24 -0
- package/dist/popover/PopoverFacts.mjs +63 -0
- package/dist/readout/Readout.d.mts +15 -0
- package/dist/readout/Readout.mjs +53 -0
- package/dist/readout/TimeZoneReadout.d.mts +11 -0
- package/dist/readout/TimeZoneReadout.mjs +46 -0
- package/dist/score-box/ScoreBox.css +62 -0
- package/dist/score-box/ScoreBox.d.mts +12 -0
- package/dist/score-box/ScoreBox.mjs +143 -0
- package/dist/score-box/ScoreBox.module.css.mjs +15 -0
- package/dist/segment-bar/Segment.d.mts +23 -0
- package/dist/segment-bar/Segment.mjs +27 -0
- package/dist/segment-bar/SegmentBar.css +44 -0
- package/dist/segment-bar/SegmentBar.d.mts +35 -0
- package/dist/segment-bar/SegmentBar.mjs +57 -0
- package/dist/segment-bar/SegmentBar.module.css.mjs +9 -0
- package/dist/segment-bar/segment-box.d.mts +10 -0
- package/dist/segment-bar/segment-box.mjs +30 -0
- package/dist/stat/Stat.d.mts +25 -0
- package/dist/stat/Stat.mjs +36 -0
- package/dist/stat/StatTile.d.mts +18 -0
- package/dist/stat/StatTile.mjs +37 -0
- package/dist/styles.css +1 -0
- package/dist/swatch/Swatch.d.mts +8 -0
- package/dist/swatch/Swatch.mjs +30 -0
- package/dist/swatch/legend-swatch.d.mts +3 -0
- package/dist/swatch/legend-swatch.mjs +0 -0
- package/dist/tab-bar/FilteredTabBar.d.mts +32 -0
- package/dist/tab-bar/FilteredTabBar.mjs +181 -0
- package/dist/tab-bar/TabBar.d.mts +22 -0
- package/dist/tab-bar/TabBar.mjs +151 -0
- package/dist/tab-bar/TabPanel.d.mts +9 -0
- package/dist/tab-bar/TabPanel.mjs +55 -0
- package/dist/tab-bar/assert-named-value.d.mts +4 -0
- package/dist/tab-bar/assert-named-value.mjs +6 -0
- package/dist/table/DataTable.d.mts +31 -0
- package/dist/table/DataTable.mjs +43 -0
- package/dist/theme/use-color-scheme.d.mts +14 -0
- package/dist/theme/use-color-scheme.mjs +92 -0
- package/dist/theme.css +58 -0
- package/dist/timeline/Timeline.d.mts +54 -0
- package/dist/timeline/Timeline.mjs +220 -0
- package/dist/timeline/TimelineBand.d.mts +18 -0
- package/dist/timeline/TimelineBand.mjs +30 -0
- package/dist/timeline/TimelineGroup.d.mts +7 -0
- package/dist/timeline/TimelineGroup.mjs +50 -0
- package/dist/timeline/TimelineItem.d.mts +19 -0
- package/dist/timeline/TimelineItem.mjs +64 -0
- package/dist/timeline/TimelineItemChip.css +153 -0
- package/dist/timeline/TimelineItemChip.d.mts +23 -0
- package/dist/timeline/TimelineItemChip.mjs +74 -0
- package/dist/timeline/TimelineItemChip.module.css.mjs +15 -0
- package/dist/timeline/TimelineItemMark.css +38 -0
- package/dist/timeline/TimelineItemMark.d.mts +15 -0
- package/dist/timeline/TimelineItemMark.mjs +129 -0
- package/dist/timeline/TimelineItemMark.module.css.mjs +4 -0
- package/dist/timeline/TimelineRoot.d.mts +19 -0
- package/dist/timeline/TimelineRoot.mjs +742 -0
- package/dist/timeline/TimelineRowHeader.d.mts +23 -0
- package/dist/timeline/TimelineRowHeader.mjs +244 -0
- package/dist/timeline/TimelineZoomHint.d.mts +9 -0
- package/dist/timeline/TimelineZoomHint.mjs +32 -0
- package/dist/timeline/axis-label.d.mts +5 -0
- package/dist/timeline/axis-label.mjs +53 -0
- package/dist/timeline/batched-dataset-writer.d.mts +29 -0
- package/dist/timeline/batched-dataset-writer.mjs +58 -0
- package/dist/timeline/row-card-side.d.mts +7 -0
- package/dist/timeline/row-card-side.mjs +6 -0
- package/dist/timeline/timeline-a11y.d.mts +33 -0
- package/dist/timeline/timeline-a11y.mjs +96 -0
- package/dist/timeline/timeline-context.d.mts +33 -0
- package/dist/timeline/timeline-context.mjs +40 -0
- package/dist/timeline/timeline-types.d.mts +126 -0
- package/dist/timeline/timeline-types.mjs +0 -0
- package/dist/timeline/timeline-utils.d.mts +52 -0
- package/dist/timeline/timeline-utils.mjs +130 -0
- package/dist/timeline/zoom-modifier.d.mts +21 -0
- package/dist/timeline/zoom-modifier.mjs +25 -0
- package/dist/toast/ToastProvider.d.mts +33 -0
- package/dist/toast/ToastProvider.mjs +257 -0
- package/dist/toast/toast-context.d.mts +2 -0
- package/dist/toast/toast-context.mjs +5 -0
- package/dist/tokens.css +1 -0
- package/dist/tooltip/Tooltip.d.mts +17 -0
- package/dist/tooltip/Tooltip.mjs +41 -0
- package/dist/tooltip/hover-open-delay.d.mts +2 -0
- package/dist/tooltip/hover-open-delay.mjs +4 -0
- package/dist/tooltip/is-text-cut.d.mts +1 -0
- package/dist/tooltip/is-text-cut.mjs +5 -0
- package/dist/vendor/components.d.mts +664 -0
- package/dist/vendor/components.mjs +2060 -0
- package/package.json +61 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DayBounds, DayRangeValue } from "@timefoldai/viz-core";
|
|
2
|
+
/** The `DateScope` props shared by the day and the range form. */
|
|
3
|
+
export interface DateScopeBaseProps extends Pick<React.ComponentProps<"div">, "className" | "style" | "ref"> {
|
|
4
|
+
/** @remarks Inclusive `yyyy-MM-dd` bounds; `undefined` while the dataset loads, `null` for a dataset with no dates. */
|
|
5
|
+
bounds: DayBounds | null | undefined;
|
|
6
|
+
}
|
|
7
|
+
/** `DateScope` props for one day. */
|
|
8
|
+
export interface DateScopeDayProps extends DateScopeBaseProps {
|
|
9
|
+
mode: "day";
|
|
10
|
+
value: string | null;
|
|
11
|
+
onValueChange: (day: string) => void;
|
|
12
|
+
}
|
|
13
|
+
/** `DateScope` props for a range of at most `MAX_SCOPE_DAYS` days. */
|
|
14
|
+
export interface DateScopeRangeProps extends DateScopeBaseProps {
|
|
15
|
+
mode: "range";
|
|
16
|
+
value: DayRangeValue | null;
|
|
17
|
+
onValueChange: (range: DayRangeValue) => void;
|
|
18
|
+
/** @remarks Days that hold data, read when the calendar first needs them; the calendar disables the others. */
|
|
19
|
+
dataDays?: () => ReadonlySet<string>;
|
|
20
|
+
}
|
|
21
|
+
/** The props of `DateScope`: either a single day or a range of days. */
|
|
22
|
+
export type DateScopeProps = DateScopeDayProps | DateScopeRangeProps;
|
|
23
|
+
/**
|
|
24
|
+
* Steps the days a page shows with previous and next buttons around a date field with a calendar.
|
|
25
|
+
* Range mode caps a pick at seven days; day mode moves one day at a time.
|
|
26
|
+
*
|
|
27
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/examples/datepicker-dialog/
|
|
28
|
+
* @category Controls
|
|
29
|
+
*/
|
|
30
|
+
export default function DateScope(props: DateScopeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { c } from "react/compiler-runtime";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import { Button, DateField, DateRangeField } from "../vendor/components.mjs";
|
|
6
|
+
import clsx$1 from "clsx";
|
|
7
|
+
import { MAX_SCOPE_DAYS, OVERLAY_ATTRIBUTE, canStepRange, rangeLength, stepDay, stepRange } from "@timefoldai/viz-core";
|
|
8
|
+
import { TbChevronLeft, TbChevronRight } from "react-icons/tb";
|
|
9
|
+
// src/date-scope/DateScope.tsx
|
|
10
|
+
const LOCALE = "en-GB";
|
|
11
|
+
const NO_DATES = "No dates";
|
|
12
|
+
const CALENDAR_PROPS = { [OVERLAY_ATTRIBUTE]: "" };
|
|
13
|
+
function Stepper(t0) {
|
|
14
|
+
const $ = c(25);
|
|
15
|
+
let canStep;
|
|
16
|
+
let children;
|
|
17
|
+
let className;
|
|
18
|
+
let label;
|
|
19
|
+
let onStep;
|
|
20
|
+
let root;
|
|
21
|
+
let stepUnit;
|
|
22
|
+
if ($[0] !== t0) {
|
|
23
|
+
({label, stepUnit, canStep, onStep, children, className, ...root} = t0);
|
|
24
|
+
$[0] = t0;
|
|
25
|
+
$[1] = canStep;
|
|
26
|
+
$[2] = children;
|
|
27
|
+
$[3] = className;
|
|
28
|
+
$[4] = label;
|
|
29
|
+
$[5] = onStep;
|
|
30
|
+
$[6] = root;
|
|
31
|
+
$[7] = stepUnit;
|
|
32
|
+
} else {
|
|
33
|
+
canStep = $[1];
|
|
34
|
+
children = $[2];
|
|
35
|
+
className = $[3];
|
|
36
|
+
label = $[4];
|
|
37
|
+
onStep = $[5];
|
|
38
|
+
root = $[6];
|
|
39
|
+
stepUnit = $[7];
|
|
40
|
+
}
|
|
41
|
+
let t1;
|
|
42
|
+
if ($[8] !== canStep || $[9] !== onStep || $[10] !== stepUnit) {
|
|
43
|
+
t1 = (direction) => /* @__PURE__ */ jsx(Button, {
|
|
44
|
+
type: "button",
|
|
45
|
+
"aria-label": `${direction === 1 ? "Next" : "Previous"} ${stepUnit}`,
|
|
46
|
+
disabled: !canStep(direction),
|
|
47
|
+
onClick: () => onStep(direction),
|
|
48
|
+
variant: "soft",
|
|
49
|
+
soloIcon: direction === 1 ? TbChevronRight : TbChevronLeft
|
|
50
|
+
});
|
|
51
|
+
$[8] = canStep;
|
|
52
|
+
$[9] = onStep;
|
|
53
|
+
$[10] = stepUnit;
|
|
54
|
+
$[11] = t1;
|
|
55
|
+
} else t1 = $[11];
|
|
56
|
+
const stepButton = t1;
|
|
57
|
+
const t2 = `${label} shown`;
|
|
58
|
+
let t3;
|
|
59
|
+
if ($[12] !== className) {
|
|
60
|
+
t3 = clsx$1("inline-flex items-center gap-2", className);
|
|
61
|
+
$[12] = className;
|
|
62
|
+
$[13] = t3;
|
|
63
|
+
} else t3 = $[13];
|
|
64
|
+
let t4;
|
|
65
|
+
if ($[14] !== stepButton) {
|
|
66
|
+
t4 = stepButton(-1);
|
|
67
|
+
$[14] = stepButton;
|
|
68
|
+
$[15] = t4;
|
|
69
|
+
} else t4 = $[15];
|
|
70
|
+
let t5;
|
|
71
|
+
if ($[16] !== stepButton) {
|
|
72
|
+
t5 = stepButton(1);
|
|
73
|
+
$[16] = stepButton;
|
|
74
|
+
$[17] = t5;
|
|
75
|
+
} else t5 = $[17];
|
|
76
|
+
let t6;
|
|
77
|
+
if ($[18] !== children || $[19] !== root || $[20] !== t2 || $[21] !== t3 || $[22] !== t4 || $[23] !== t5) {
|
|
78
|
+
t6 = /* @__PURE__ */ jsxs("div", {
|
|
79
|
+
...root,
|
|
80
|
+
role: "group",
|
|
81
|
+
"aria-label": t2,
|
|
82
|
+
"data-slot": "date-scope",
|
|
83
|
+
className: t3,
|
|
84
|
+
children: [
|
|
85
|
+
t4,
|
|
86
|
+
children,
|
|
87
|
+
t5
|
|
88
|
+
]
|
|
89
|
+
});
|
|
90
|
+
$[18] = children;
|
|
91
|
+
$[19] = root;
|
|
92
|
+
$[20] = t2;
|
|
93
|
+
$[21] = t3;
|
|
94
|
+
$[22] = t4;
|
|
95
|
+
$[23] = t5;
|
|
96
|
+
$[24] = t6;
|
|
97
|
+
} else t6 = $[24];
|
|
98
|
+
return t6;
|
|
99
|
+
}
|
|
100
|
+
function useWithoutData(dataDays) {
|
|
101
|
+
return useMemo(() => {
|
|
102
|
+
if (!dataDays) return void 0;
|
|
103
|
+
let days;
|
|
104
|
+
return (day) => !(days ??= dataDays()).has(day);
|
|
105
|
+
}, [dataDays]);
|
|
106
|
+
}
|
|
107
|
+
function rangeStepUnit(value) {
|
|
108
|
+
if (!value) return "days";
|
|
109
|
+
const length = rangeLength(value);
|
|
110
|
+
return length === 1 ? "day" : `${length} days`;
|
|
111
|
+
}
|
|
112
|
+
function RangeScope(t0) {
|
|
113
|
+
const $ = c(22);
|
|
114
|
+
const { bounds, dataDays, value, onValueChange, className, style, ref } = t0;
|
|
115
|
+
const withoutData = useWithoutData(dataDays);
|
|
116
|
+
let t1;
|
|
117
|
+
if ($[0] !== value) {
|
|
118
|
+
t1 = rangeStepUnit(value);
|
|
119
|
+
$[0] = value;
|
|
120
|
+
$[1] = t1;
|
|
121
|
+
} else t1 = $[1];
|
|
122
|
+
let t2;
|
|
123
|
+
if ($[2] !== bounds || $[3] !== value) {
|
|
124
|
+
t2 = (direction) => !!bounds && !!value && canStepRange(value, direction, bounds);
|
|
125
|
+
$[2] = bounds;
|
|
126
|
+
$[3] = value;
|
|
127
|
+
$[4] = t2;
|
|
128
|
+
} else t2 = $[4];
|
|
129
|
+
let t3;
|
|
130
|
+
if ($[5] !== bounds || $[6] !== onValueChange || $[7] !== value) {
|
|
131
|
+
t3 = (direction_0) => {
|
|
132
|
+
if (bounds && value) onValueChange(stepRange(value, direction_0, bounds));
|
|
133
|
+
};
|
|
134
|
+
$[5] = bounds;
|
|
135
|
+
$[6] = onValueChange;
|
|
136
|
+
$[7] = value;
|
|
137
|
+
$[8] = t3;
|
|
138
|
+
} else t3 = $[8];
|
|
139
|
+
let t4;
|
|
140
|
+
if ($[9] !== bounds || $[10] !== onValueChange || $[11] !== value || $[12] !== withoutData) {
|
|
141
|
+
t4 = bounds === null ? /* @__PURE__ */ jsx(DateField, {
|
|
142
|
+
"aria-label": "Days",
|
|
143
|
+
"data-slot": "date-scope-field",
|
|
144
|
+
width: "content",
|
|
145
|
+
value: null,
|
|
146
|
+
placeholder: NO_DATES,
|
|
147
|
+
disabled: true
|
|
148
|
+
}) : /* @__PURE__ */ jsx(DateRangeField, {
|
|
149
|
+
"aria-label": "Days",
|
|
150
|
+
"data-slot": "date-scope-field",
|
|
151
|
+
width: "fixed",
|
|
152
|
+
locale: LOCALE,
|
|
153
|
+
calendarProps: CALENDAR_PROPS,
|
|
154
|
+
value,
|
|
155
|
+
onValueChange: (range) => range && onValueChange(range),
|
|
156
|
+
min: bounds?.min,
|
|
157
|
+
max: bounds?.max,
|
|
158
|
+
maxDays: MAX_SCOPE_DAYS,
|
|
159
|
+
isDateDisabled: withoutData,
|
|
160
|
+
disabled: !bounds
|
|
161
|
+
});
|
|
162
|
+
$[9] = bounds;
|
|
163
|
+
$[10] = onValueChange;
|
|
164
|
+
$[11] = value;
|
|
165
|
+
$[12] = withoutData;
|
|
166
|
+
$[13] = t4;
|
|
167
|
+
} else t4 = $[13];
|
|
168
|
+
let t5;
|
|
169
|
+
if ($[14] !== className || $[15] !== ref || $[16] !== style || $[17] !== t1 || $[18] !== t2 || $[19] !== t3 || $[20] !== t4) {
|
|
170
|
+
t5 = /* @__PURE__ */ jsx(Stepper, {
|
|
171
|
+
className,
|
|
172
|
+
style,
|
|
173
|
+
ref,
|
|
174
|
+
label: "Days",
|
|
175
|
+
stepUnit: t1,
|
|
176
|
+
canStep: t2,
|
|
177
|
+
onStep: t3,
|
|
178
|
+
children: t4
|
|
179
|
+
});
|
|
180
|
+
$[14] = className;
|
|
181
|
+
$[15] = ref;
|
|
182
|
+
$[16] = style;
|
|
183
|
+
$[17] = t1;
|
|
184
|
+
$[18] = t2;
|
|
185
|
+
$[19] = t3;
|
|
186
|
+
$[20] = t4;
|
|
187
|
+
$[21] = t5;
|
|
188
|
+
} else t5 = $[21];
|
|
189
|
+
return t5;
|
|
190
|
+
}
|
|
191
|
+
function DayScope(t0) {
|
|
192
|
+
const $ = c(23);
|
|
193
|
+
const { bounds, value, onValueChange, className, style, ref } = t0;
|
|
194
|
+
let t1;
|
|
195
|
+
if ($[0] !== bounds || $[1] !== value) {
|
|
196
|
+
t1 = (direction) => !!bounds && !!value && stepDay(value, direction, bounds) !== value;
|
|
197
|
+
$[0] = bounds;
|
|
198
|
+
$[1] = value;
|
|
199
|
+
$[2] = t1;
|
|
200
|
+
} else t1 = $[2];
|
|
201
|
+
let t2;
|
|
202
|
+
if ($[3] !== bounds || $[4] !== onValueChange || $[5] !== value) {
|
|
203
|
+
t2 = (direction_0) => {
|
|
204
|
+
if (bounds && value) onValueChange(stepDay(value, direction_0, bounds));
|
|
205
|
+
};
|
|
206
|
+
$[3] = bounds;
|
|
207
|
+
$[4] = onValueChange;
|
|
208
|
+
$[5] = value;
|
|
209
|
+
$[6] = t2;
|
|
210
|
+
} else t2 = $[6];
|
|
211
|
+
const t3 = bounds === null ? null : value;
|
|
212
|
+
const t4 = bounds === null ? NO_DATES : void 0;
|
|
213
|
+
let t5;
|
|
214
|
+
if ($[7] !== onValueChange) {
|
|
215
|
+
t5 = (day) => day && onValueChange(day);
|
|
216
|
+
$[7] = onValueChange;
|
|
217
|
+
$[8] = t5;
|
|
218
|
+
} else t5 = $[8];
|
|
219
|
+
const t6 = bounds?.min;
|
|
220
|
+
const t7 = bounds?.max;
|
|
221
|
+
const t8 = !bounds;
|
|
222
|
+
let t9;
|
|
223
|
+
if ($[9] !== t3 || $[10] !== t4 || $[11] !== t5 || $[12] !== t6 || $[13] !== t7 || $[14] !== t8) {
|
|
224
|
+
t9 = /* @__PURE__ */ jsx(DateField, {
|
|
225
|
+
"aria-label": "Day",
|
|
226
|
+
"data-slot": "date-scope-field",
|
|
227
|
+
width: "fixed",
|
|
228
|
+
weekday: "short",
|
|
229
|
+
locale: LOCALE,
|
|
230
|
+
calendarProps: CALENDAR_PROPS,
|
|
231
|
+
value: t3,
|
|
232
|
+
placeholder: t4,
|
|
233
|
+
onValueChange: t5,
|
|
234
|
+
min: t6,
|
|
235
|
+
max: t7,
|
|
236
|
+
disabled: t8
|
|
237
|
+
});
|
|
238
|
+
$[9] = t3;
|
|
239
|
+
$[10] = t4;
|
|
240
|
+
$[11] = t5;
|
|
241
|
+
$[12] = t6;
|
|
242
|
+
$[13] = t7;
|
|
243
|
+
$[14] = t8;
|
|
244
|
+
$[15] = t9;
|
|
245
|
+
} else t9 = $[15];
|
|
246
|
+
let t10;
|
|
247
|
+
if ($[16] !== className || $[17] !== ref || $[18] !== style || $[19] !== t1 || $[20] !== t2 || $[21] !== t9) {
|
|
248
|
+
t10 = /* @__PURE__ */ jsx(Stepper, {
|
|
249
|
+
className,
|
|
250
|
+
style,
|
|
251
|
+
ref,
|
|
252
|
+
label: "Day",
|
|
253
|
+
stepUnit: "day",
|
|
254
|
+
canStep: t1,
|
|
255
|
+
onStep: t2,
|
|
256
|
+
children: t9
|
|
257
|
+
});
|
|
258
|
+
$[16] = className;
|
|
259
|
+
$[17] = ref;
|
|
260
|
+
$[18] = style;
|
|
261
|
+
$[19] = t1;
|
|
262
|
+
$[20] = t2;
|
|
263
|
+
$[21] = t9;
|
|
264
|
+
$[22] = t10;
|
|
265
|
+
} else t10 = $[22];
|
|
266
|
+
return t10;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Steps the days a page shows with previous and next buttons around a date field with a calendar.
|
|
270
|
+
* Range mode caps a pick at seven days; day mode moves one day at a time.
|
|
271
|
+
*
|
|
272
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/examples/datepicker-dialog/
|
|
273
|
+
* @category Controls
|
|
274
|
+
*/
|
|
275
|
+
function DateScope(props) {
|
|
276
|
+
const $ = c(2);
|
|
277
|
+
let t0;
|
|
278
|
+
if ($[0] !== props) {
|
|
279
|
+
t0 = props.mode === "range" ? /* @__PURE__ */ jsx(RangeScope, { ...props }) : /* @__PURE__ */ jsx(DayScope, { ...props });
|
|
280
|
+
$[0] = props;
|
|
281
|
+
$[1] = t0;
|
|
282
|
+
} else t0 = $[1];
|
|
283
|
+
return t0;
|
|
284
|
+
}
|
|
285
|
+
export { DateScope as default };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SlotIcon } from "../vendor/components.mjs";
|
|
2
|
+
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
3
|
+
/** A dropdown menu item's look: `destructive` for an irreversible action such as delete. */
|
|
4
|
+
export type DropdownMenuItemVariant = "default" | "destructive";
|
|
5
|
+
/** The props of `DropdownMenuItem`: the Radix item props, its icons, its look and its current choice. */
|
|
6
|
+
export interface DropdownMenuItemProps extends React.ComponentPropsWithRef<typeof DropdownMenuPrimitive.Item> {
|
|
7
|
+
leadingIcon?: SlotIcon;
|
|
8
|
+
trailingIcon?: SlotIcon;
|
|
9
|
+
/** @defaultValue "default" */
|
|
10
|
+
variant?: DropdownMenuItemVariant;
|
|
11
|
+
selected?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** The props of `Pagination`: the current page of `pageCount`, its labels and the page change. */
|
|
14
|
+
export interface PaginationProps extends Omit<React.ComponentPropsWithRef<"nav">, "onChange"> {
|
|
15
|
+
current: number;
|
|
16
|
+
pageCount: number;
|
|
17
|
+
onPageChange: (page: number) => void;
|
|
18
|
+
previousLabel: string;
|
|
19
|
+
nextLabel: string;
|
|
20
|
+
pageLabel: (page: number) => string;
|
|
21
|
+
}
|
|
22
|
+
/** The width of a search field: `full` fills the container, `content` fits its value. */
|
|
23
|
+
export type SearchInputWidth = "full" | "content";
|
|
24
|
+
/** The props of `SearchInput`: the input props, its width and the props of its wrapping `div`. */
|
|
25
|
+
export interface SearchInputProps extends Omit<React.ComponentPropsWithRef<"input">, "width"> {
|
|
26
|
+
/** @defaultValue "full" */
|
|
27
|
+
width?: SearchInputWidth;
|
|
28
|
+
containerProps?: React.ComponentPropsWithoutRef<"div">;
|
|
29
|
+
}
|
|
30
|
+
/** A table's look: `plain` keeps only the frame and semantics, so the table lays out its own cells. */
|
|
31
|
+
export type TableVariant = "default" | "plain";
|
|
32
|
+
/** The props of `Table`: the table props, the props of its scroll container, its border and its look. */
|
|
33
|
+
export interface TableProps extends React.ComponentPropsWithRef<"table"> {
|
|
34
|
+
containerProps?: React.ComponentPropsWithRef<"div">;
|
|
35
|
+
/** @defaultValue true */
|
|
36
|
+
bordered?: boolean;
|
|
37
|
+
/** @defaultValue "default" */
|
|
38
|
+
variant?: TableVariant;
|
|
39
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DetailPanelPlacement } from "../hooks/use-detail-panel-layout.mjs";
|
|
2
|
+
/** The props of `DetailPanel`: whether it is open and the content it shows. */
|
|
3
|
+
export interface DetailPanelProps extends Pick<React.ComponentProps<"div">, "className" | "style" | "ref"> {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onOpenChange: (open: boolean) => void;
|
|
6
|
+
title: React.ReactNode;
|
|
7
|
+
placement: DetailPanelPlacement;
|
|
8
|
+
/** @defaultValue "right" */
|
|
9
|
+
side?: "left" | "right";
|
|
10
|
+
/** @defaultValue false */
|
|
11
|
+
initialFocus?: boolean;
|
|
12
|
+
finalFocus?: React.RefObject<HTMLElement | null>;
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A detail surface for a selected item, beside or over the chart it belongs to.
|
|
17
|
+
* Model-agnostic — placement/side are typed props, exposed as `data-placement`/`data-side`.
|
|
18
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/
|
|
19
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/landmarks/examples/region.html
|
|
20
|
+
* @category Overlays
|
|
21
|
+
*/
|
|
22
|
+
export default function DetailPanel({ open, onOpenChange, title, placement, side, initialFocus, finalFocus, children, className, style, ref }: DetailPanelProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMergedRef } from "../hooks/use-merged-ref.mjs";
|
|
3
|
+
import Tooltip$1 from "../tooltip/Tooltip.mjs";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useEffect, useId, useRef } from "react";
|
|
6
|
+
import { Button } from "../vendor/components.mjs";
|
|
7
|
+
import clsx$1 from "clsx";
|
|
8
|
+
import { TbX } from "react-icons/tb";
|
|
9
|
+
// src/detail-panel/DetailPanel.tsx
|
|
10
|
+
/**
|
|
11
|
+
* A detail surface for a selected item, beside or over the chart it belongs to.
|
|
12
|
+
* Model-agnostic — placement/side are typed props, exposed as `data-placement`/`data-side`.
|
|
13
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/
|
|
14
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/landmarks/examples/region.html
|
|
15
|
+
* @category Overlays
|
|
16
|
+
*/
|
|
17
|
+
function DetailPanel({ open, onOpenChange, title, placement, side = "right", initialFocus = false, finalFocus, children, className, style, ref }) {
|
|
18
|
+
const titleId = useId();
|
|
19
|
+
const panelRef = useRef(null);
|
|
20
|
+
const rootRef = useMergedRef(panelRef, ref);
|
|
21
|
+
const wasOpen = useRef(false);
|
|
22
|
+
const latest = useRef({
|
|
23
|
+
onOpenChange,
|
|
24
|
+
initialFocus,
|
|
25
|
+
finalFocus
|
|
26
|
+
});
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
latest.current = {
|
|
29
|
+
onOpenChange,
|
|
30
|
+
initialFocus,
|
|
31
|
+
finalFocus
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!open) {
|
|
36
|
+
if (wasOpen.current) {
|
|
37
|
+
wasOpen.current = false;
|
|
38
|
+
latest.current.finalFocus?.current?.focus();
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
wasOpen.current = true;
|
|
43
|
+
if (latest.current.initialFocus) panelRef.current?.focus();
|
|
44
|
+
function onKeyDown(event) {
|
|
45
|
+
if (event.key === "Escape") latest.current.onOpenChange(false);
|
|
46
|
+
}
|
|
47
|
+
document.addEventListener("keydown", onKeyDown);
|
|
48
|
+
return () => document.removeEventListener("keydown", onKeyDown);
|
|
49
|
+
}, [open]);
|
|
50
|
+
if (!open) return null;
|
|
51
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
52
|
+
ref: rootRef,
|
|
53
|
+
style,
|
|
54
|
+
tabIndex: -1,
|
|
55
|
+
role: placement === "inline" ? "region" : "dialog",
|
|
56
|
+
"aria-labelledby": titleId,
|
|
57
|
+
"data-slot": "detail-panel",
|
|
58
|
+
"data-placement": placement,
|
|
59
|
+
"data-side": side,
|
|
60
|
+
className: clsx$1("border-border bg-background flex flex-none flex-col gap-3.5 overflow-y-auto rounded-[0.375rem] border p-4", placement === "inline" && "w-[var(--viz-detail-panel-width)]", placement !== "inline" && "shadow-3 absolute top-0 z-[5] max-h-full", placement === "overlay" && "w-[var(--viz-detail-panel-width-overlay)]", placement === "overlay" && (side === "right" ? "right-0" : "left-0"), placement === "sheet" && "inset-x-0", className),
|
|
61
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
62
|
+
className: "flex items-center justify-between gap-2",
|
|
63
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
64
|
+
id: titleId,
|
|
65
|
+
className: clsx$1("m-0 font-semibold", placement === "inline" ? "text-base" : "text-sm"),
|
|
66
|
+
children: title
|
|
67
|
+
}), /* @__PURE__ */ jsx(Tooltip$1, {
|
|
68
|
+
label: "Close",
|
|
69
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
70
|
+
"data-slot": "detail-panel-close",
|
|
71
|
+
variant: "ghost",
|
|
72
|
+
"aria-label": "Close",
|
|
73
|
+
soloIcon: TbX,
|
|
74
|
+
onClick: () => onOpenChange(false)
|
|
75
|
+
})
|
|
76
|
+
})]
|
|
77
|
+
}), children]
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export { DetailPanel as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DetailPanelSize } from "./micro-label.mjs";
|
|
2
|
+
/** The props of `DetailPanelSection`: its label and its size. */
|
|
3
|
+
export interface DetailPanelSectionProps extends React.ComponentProps<"div"> {
|
|
4
|
+
label: React.ReactNode;
|
|
5
|
+
/** @defaultValue false */
|
|
6
|
+
ruled?: boolean;
|
|
7
|
+
/** @defaultValue "md" */
|
|
8
|
+
size?: DetailPanelSize;
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* One labelled block of a detail panel: an uppercase micro label over its
|
|
13
|
+
* children, optionally opened by a hairline.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Identity for tests and consumers is `data-slot="detail-panel-section"` and `data-slot="detail-panel-section-label"`.
|
|
17
|
+
*
|
|
18
|
+
* @category Data display
|
|
19
|
+
*/
|
|
20
|
+
export default function DetailPanelSection({ label, ruled, size, children, className, ...props }: DetailPanelSectionProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { microLabel } from "./micro-label.mjs";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import clsx$1 from "clsx";
|
|
4
|
+
// src/detail-panel/DetailPanelSection.tsx
|
|
5
|
+
/**
|
|
6
|
+
* One labelled block of a detail panel: an uppercase micro label over its
|
|
7
|
+
* children, optionally opened by a hairline.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Identity for tests and consumers is `data-slot="detail-panel-section"` and `data-slot="detail-panel-section-label"`.
|
|
11
|
+
*
|
|
12
|
+
* @category Data display
|
|
13
|
+
*/
|
|
14
|
+
function DetailPanelSection({ label, ruled = false, size = "md", children, className, ...props }) {
|
|
15
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
16
|
+
"data-slot": "detail-panel-section",
|
|
17
|
+
"data-size": size,
|
|
18
|
+
className: clsx$1("border-border flex flex-col", ruled && "border-t pt-3", className),
|
|
19
|
+
...props,
|
|
20
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
21
|
+
"data-slot": "detail-panel-section-label",
|
|
22
|
+
className: clsx$1("flex justify-between pb-1 font-semibold uppercase", microLabel(size)),
|
|
23
|
+
children: label
|
|
24
|
+
}), children]
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export { DetailPanelSection as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The density of a detail panel's labels and figures: `sm` for a floating panel, `md` for the inline column. */
|
|
2
|
+
export type DetailPanelSize = "sm" | "md";
|
|
3
|
+
/**
|
|
4
|
+
* The uppercase micro label a detail panel wears over a section or a
|
|
5
|
+
* figure, shared by `DetailPanelSection` and `Stat` so the two cannot drift.
|
|
6
|
+
*/
|
|
7
|
+
export declare function microLabel(size: DetailPanelSize): "text-[0.625rem] tracking-[0.05em]" | "text-[0.6875rem] tracking-[0.09em]";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// src/detail-panel/micro-label.ts
|
|
2
|
+
/**
|
|
3
|
+
* The uppercase micro label a detail panel wears over a section or a
|
|
4
|
+
* figure, shared by `DetailPanelSection` and `Stat` so the two cannot drift.
|
|
5
|
+
*/
|
|
6
|
+
function microLabel(size) {
|
|
7
|
+
return size === "sm" ? "text-[0.625rem] tracking-[0.05em]" : "text-[0.6875rem] tracking-[0.09em]";
|
|
8
|
+
}
|
|
9
|
+
export { microLabel };
|
package/dist/env.d.mts
ADDED
package/dist/env.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DataTableColumn } from "../table/DataTable.mjs";
|
|
2
|
+
/** The props of `ExportCsvButton`: the rows and columns it exports and the base name of the file. */
|
|
3
|
+
export interface ExportCsvButtonProps<T> {
|
|
4
|
+
rows: T[];
|
|
5
|
+
columns: DataTableColumn<T>[];
|
|
6
|
+
baseName: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Exports a table's rows as a CSV download, reusing the very column
|
|
10
|
+
* config the table renders so the export cannot drift from the view.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Disabled when there is nothing to export (no rows, or no column
|
|
14
|
+
* declares a `value`), so it never hands the user an empty file.
|
|
15
|
+
*
|
|
16
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/button/
|
|
17
|
+
* @category Controls
|
|
18
|
+
*/
|
|
19
|
+
export default function ExportCsvButton<T>({ rows, columns, baseName }: ExportCsvButtonProps<T>): import("react").JSX.Element;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { downloadCsv } from "./download-csv.mjs";
|
|
3
|
+
import { c } from "react/compiler-runtime";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { Button } from "../vendor/components.mjs";
|
|
6
|
+
import { toCsv } from "@timefoldai/viz-core";
|
|
7
|
+
import { TbDownload } from "react-icons/tb";
|
|
8
|
+
import { title } from "radash";
|
|
9
|
+
// src/export/ExportCsvButton.tsx
|
|
10
|
+
/**
|
|
11
|
+
* Exports a table's rows as a CSV download, reusing the very column
|
|
12
|
+
* config the table renders so the export cannot drift from the view.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Disabled when there is nothing to export (no rows, or no column
|
|
16
|
+
* declares a `value`), so it never hands the user an empty file.
|
|
17
|
+
*
|
|
18
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/button/
|
|
19
|
+
* @category Controls
|
|
20
|
+
*/
|
|
21
|
+
function ExportCsvButton(t0) {
|
|
22
|
+
const $ = c(10);
|
|
23
|
+
const { rows, columns, baseName } = t0;
|
|
24
|
+
let t1;
|
|
25
|
+
if ($[0] !== columns) {
|
|
26
|
+
t1 = columns.flatMap(_temp);
|
|
27
|
+
$[0] = columns;
|
|
28
|
+
$[1] = t1;
|
|
29
|
+
} else t1 = $[1];
|
|
30
|
+
const exportable = t1;
|
|
31
|
+
let t2;
|
|
32
|
+
if ($[2] !== baseName || $[3] !== exportable || $[4] !== rows) {
|
|
33
|
+
t2 = function handleClick() {
|
|
34
|
+
downloadCsv(toCsv(rows, exportable), baseName);
|
|
35
|
+
};
|
|
36
|
+
$[2] = baseName;
|
|
37
|
+
$[3] = exportable;
|
|
38
|
+
$[4] = rows;
|
|
39
|
+
$[5] = t2;
|
|
40
|
+
} else t2 = $[5];
|
|
41
|
+
const handleClick = t2;
|
|
42
|
+
const t3 = rows.length === 0 || exportable.length === 0;
|
|
43
|
+
let t4;
|
|
44
|
+
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
|
|
45
|
+
t4 = /* @__PURE__ */ jsx("span", {
|
|
46
|
+
"data-slot": "export-csv-button-label",
|
|
47
|
+
children: "Download CSV"
|
|
48
|
+
});
|
|
49
|
+
$[6] = t4;
|
|
50
|
+
} else t4 = $[6];
|
|
51
|
+
let t5;
|
|
52
|
+
if ($[7] !== handleClick || $[8] !== t3) {
|
|
53
|
+
t5 = /* @__PURE__ */ jsx(Button, {
|
|
54
|
+
type: "button",
|
|
55
|
+
variant: "soft",
|
|
56
|
+
leadingIcon: TbDownload,
|
|
57
|
+
onClick: handleClick,
|
|
58
|
+
disabled: t3,
|
|
59
|
+
children: t4
|
|
60
|
+
});
|
|
61
|
+
$[7] = handleClick;
|
|
62
|
+
$[8] = t3;
|
|
63
|
+
$[9] = t5;
|
|
64
|
+
} else t5 = $[9];
|
|
65
|
+
return t5;
|
|
66
|
+
}
|
|
67
|
+
function _temp(column) {
|
|
68
|
+
return column.value ? [{
|
|
69
|
+
header: column.exportHeader ?? title(column.key),
|
|
70
|
+
value: column.value
|
|
71
|
+
}] : [];
|
|
72
|
+
}
|
|
73
|
+
export { ExportCsvButton as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { buildExportFilename, downloadBlob } from "./download-file.mjs";
|
|
3
|
+
// src/export/download-csv.ts
|
|
4
|
+
/**
|
|
5
|
+
* Downloads `csv` as `<base>-YYYYMMDD-HHMMSS.csv`. No BOM — the platform's own
|
|
6
|
+
* exporter emits none; an Excel user who needs one can import instead.
|
|
7
|
+
*/
|
|
8
|
+
function downloadCsv(csv, base) {
|
|
9
|
+
downloadBlob(new Blob([csv], { type: "text/csv;charset=utf-8" }), buildExportFilename(base, "csv", /* @__PURE__ */ new Date()));
|
|
10
|
+
}
|
|
11
|
+
export { downloadCsv };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<base>-YYYYMMDD-HHMMSS.<extension>`, an export's file name.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* `base` is sanitised to `[A-Za-z0-9._-]` so a model or view name can
|
|
6
|
+
* never inject a path separator. `now` is an explicit argument so the
|
|
7
|
+
* stamp is testable.
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildExportFilename(base: string, extension: string, now: Date): string;
|
|
10
|
+
/** Triggers a browser download of `blob` as `filename`. */
|
|
11
|
+
export declare function downloadBlob(blob: Blob, filename: string): void;
|