@scalewing/react 1.38.0 → 1.40.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/CHANGELOG.md +18 -0
- package/README.md +155 -1
- package/dist/calendar-month.d.ts +6 -0
- package/dist/calendar-month.js +15 -0
- package/dist/chart-axis.d.ts +61 -0
- package/dist/chart-axis.js +83 -0
- package/dist/chart-dates.d.ts +6 -0
- package/dist/chart-dates.js +15 -0
- package/dist/chart-metrics.d.ts +40 -0
- package/dist/chart-metrics.js +48 -0
- package/dist/chart-scale.d.ts +48 -0
- package/dist/chart-scale.js +116 -0
- package/dist/chart-table-rows.d.ts +8 -0
- package/dist/chart-table-rows.js +1 -0
- package/dist/column-chart-bars.d.ts +38 -0
- package/dist/column-chart-bars.js +82 -0
- package/dist/column-chart-callouts.d.ts +48 -0
- package/dist/column-chart-callouts.js +54 -0
- package/dist/column-chart-input.d.ts +40 -0
- package/dist/column-chart-input.js +60 -0
- package/dist/column-chart-layout.d.ts +63 -0
- package/dist/column-chart-layout.js +97 -0
- package/dist/components/BarChart.d.ts +1 -1
- package/dist/components/BarChart.js +1 -1
- package/dist/components/ChartLegend.d.ts +38 -0
- package/dist/components/ChartLegend.js +32 -0
- package/dist/components/ColumnChart.d.ts +72 -0
- package/dist/components/ColumnChart.js +71 -0
- package/dist/components/DataBar.d.ts +6 -6
- package/dist/components/DateRangeButton.d.ts +65 -0
- package/dist/components/DateRangeButton.js +54 -0
- package/dist/components/LineChart.d.ts +83 -0
- package/dist/components/LineChart.js +77 -0
- package/dist/components/ListGroup.d.ts +33 -0
- package/dist/components/ListGroup.js +19 -0
- package/dist/components/ListRow.d.ts +51 -0
- package/dist/components/ListRow.js +59 -0
- package/dist/components/NavCount.d.ts +21 -0
- package/dist/components/NavCount.js +23 -0
- package/dist/components/SectionNav.js +1 -8
- package/dist/components/StatTile.d.ts +11 -4
- package/dist/components/StatTile.js +11 -4
- package/dist/components/{date-field → calendar}/CalendarGrid.d.ts +17 -2
- package/dist/components/{date-field → calendar}/CalendarGrid.js +11 -3
- package/dist/components/calendar/CalendarPopover.d.ts +25 -0
- package/dist/components/calendar/CalendarPopover.js +22 -0
- package/dist/components/calendar/MonthStep.d.ts +16 -0
- package/dist/components/calendar/MonthStep.js +17 -0
- package/dist/components/calendar/use-grid-focus.d.ts +18 -0
- package/dist/components/calendar/use-grid-focus.js +35 -0
- package/dist/components/calendar/wrap-tab.d.ts +7 -0
- package/dist/components/calendar/wrap-tab.js +29 -0
- package/dist/components/chart/ChartTable.d.ts +16 -0
- package/dist/components/chart/ChartTable.js +12 -0
- package/dist/components/chart/ChartValueAxis.d.ts +14 -0
- package/dist/components/chart/ChartValueAxis.js +11 -0
- package/dist/components/chart/use-chart-width.d.ts +8 -0
- package/dist/components/chart/use-chart-width.js +34 -0
- package/dist/components/column-chart/ChartCalloutList.d.ts +16 -0
- package/dist/components/column-chart/ChartCalloutList.js +13 -0
- package/dist/components/column-chart/ColumnChartDrawing.d.ts +17 -0
- package/dist/components/column-chart/ColumnChartDrawing.js +18 -0
- package/dist/components/date-field/CalendarDialog.js +9 -67
- package/dist/components/date-field/CalendarHeader.js +2 -11
- package/dist/components/date-range/DateRangePopover.d.ts +7 -0
- package/dist/components/date-range/DateRangePopover.js +17 -0
- package/dist/components/date-range/DateRangeSheet.d.ts +7 -0
- package/dist/components/date-range/DateRangeSheet.js +15 -0
- package/dist/components/date-range/RangeMonths.d.ts +28 -0
- package/dist/components/date-range/RangeMonths.js +50 -0
- package/dist/components/date-range/RangePresets.d.ts +16 -0
- package/dist/components/date-range/RangePresets.js +10 -0
- package/dist/components/date-range/RangeSummary.d.ts +15 -0
- package/dist/components/date-range/RangeSummary.js +11 -0
- package/dist/components/date-range/range-panel-props.d.ts +31 -0
- package/dist/components/date-range/range-panel-props.js +1 -0
- package/dist/components/date-range/use-range-popup.d.ts +21 -0
- package/dist/components/date-range/use-range-popup.js +53 -0
- package/dist/components/line-chart/LineChartDrawing.d.ts +17 -0
- package/dist/components/line-chart/LineChartDrawing.js +16 -0
- package/dist/components/link-press.d.ts +7 -0
- package/dist/components/link-press.js +13 -0
- package/dist/components/list/ListRowAccessoryMark.d.ts +5 -0
- package/dist/components/list/ListRowAccessoryMark.js +7 -0
- package/dist/components/list/ListRowContent.d.ts +20 -0
- package/dist/components/list/ListRowContent.js +10 -0
- package/dist/components/list/list-row-container.d.ts +5 -0
- package/dist/components/list/list-row-container.js +6 -0
- package/dist/components/use-media-query.d.ts +5 -0
- package/dist/components/use-media-query.js +18 -0
- package/dist/css/chart-marks.d.ts +10 -0
- package/dist/css/chart-marks.js +15 -0
- package/dist/css/chart-tones.d.ts +68 -0
- package/dist/css/chart-tones.js +130 -0
- package/dist/css/chevron.d.ts +6 -0
- package/dist/css/chevron.js +14 -0
- package/dist/css/{css-chart.d.ts → css-bar-chart.d.ts} +2 -2
- package/dist/css/{css-chart.js → css-bar-chart.js} +2 -2
- package/dist/css/css-button-group-attached.js +8 -4
- package/dist/css/css-button-group-track.js +1 -1
- package/dist/css/css-chart-legend.d.ts +5 -0
- package/dist/css/css-chart-legend.js +102 -0
- package/dist/css/css-chart-plot.d.ts +2 -0
- package/dist/css/css-chart-plot.js +170 -0
- package/dist/css/css-checkbox.js +2 -2
- package/dist/css/css-components.js +23 -2
- package/dist/css/css-count-pill.d.ts +2 -0
- package/dist/css/css-count-pill.js +54 -0
- package/dist/css/css-data-bar.d.ts +4 -9
- package/dist/css/css-data-bar.js +15 -31
- package/dist/css/css-date-field.js +3 -2
- package/dist/css/css-date-range-presets.d.ts +2 -0
- package/dist/css/css-date-range-presets.js +109 -0
- package/dist/css/css-date-range.d.ts +2 -0
- package/dist/css/css-date-range.js +197 -0
- package/dist/css/css-line-chart.d.ts +2 -0
- package/dist/css/css-line-chart.js +31 -0
- package/dist/css/css-list-row.d.ts +2 -0
- package/dist/css/css-list-row.js +193 -0
- package/dist/css/css-list.d.ts +3 -0
- package/dist/css/css-list.js +85 -0
- package/dist/css/css-scroll-region.d.ts +18 -0
- package/dist/css/css-scroll-region.js +41 -0
- package/dist/css/css-section-nav-filled.js +2 -25
- package/dist/css/css-stat-tile.d.ts +7 -0
- package/dist/css/css-stat-tile.js +16 -0
- package/dist/css/css-steps.js +2 -2
- package/dist/css/css-table-bounded-edges.js +4 -27
- package/dist/css/range-band.d.ts +2 -0
- package/dist/css/range-band.js +7 -0
- package/dist/css/stacking.js +2 -2
- package/dist/css/stylesheet.js +16 -2
- package/dist/date-range-draft.d.ts +26 -0
- package/dist/date-range-draft.js +36 -0
- package/dist/date-range-input.d.ts +26 -0
- package/dist/date-range-input.js +58 -0
- package/dist/date-range-labels.d.ts +22 -0
- package/dist/date-range-labels.js +26 -0
- package/dist/date-range-view.d.ts +12 -0
- package/dist/date-range-view.js +29 -0
- package/dist/date-range-words.d.ts +11 -0
- package/dist/date-range-words.js +40 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +9 -1
- package/dist/is-one-of.d.ts +5 -0
- package/dist/is-one-of.js +7 -0
- package/dist/line-chart-input.d.ts +39 -0
- package/dist/line-chart-input.js +70 -0
- package/dist/line-chart-layout.d.ts +68 -0
- package/dist/line-chart-layout.js +99 -0
- package/dist/line-chart-markers.d.ts +29 -0
- package/dist/line-chart-markers.js +57 -0
- package/dist/line-chart-path.d.ts +18 -0
- package/dist/line-chart-path.js +33 -0
- package/dist/line-chart-points.d.ts +6 -0
- package/dist/line-chart-points.js +8 -0
- package/dist/line-chart-table.d.ts +15 -0
- package/dist/line-chart-table.js +29 -0
- package/dist/list-options.d.ts +70 -0
- package/dist/list-options.js +77 -0
- package/dist/styles.css +726 -26
- package/package.json +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { chartInset, chartMarkerSize, chartTextWidth, chartType, } from './chart-metrics.js';
|
|
2
|
+
function meets(a, b) {
|
|
3
|
+
return (a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* A centre for words `width` wide that keeps them over the plot, clear of
|
|
7
|
+
* the value axis's words and the last value beside it; centred on the plot
|
|
8
|
+
* when they are wider than it.
|
|
9
|
+
*/
|
|
10
|
+
function overPlot(x, width, plot) {
|
|
11
|
+
const low = plot.left + width / 2;
|
|
12
|
+
const high = plot.right - width / 2;
|
|
13
|
+
if (low > high)
|
|
14
|
+
return (plot.left + plot.right) / 2;
|
|
15
|
+
return Math.min(Math.max(x, low), high);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Places each marker at the line's height on its date: the triangle a
|
|
19
|
+
* small inset under the line, its words under it (moved in to stay over
|
|
20
|
+
* the plot), or both above the line when the words would pass the plot's
|
|
21
|
+
* bottom.
|
|
22
|
+
*/
|
|
23
|
+
export function placeMarkers(markers, plot) {
|
|
24
|
+
const half = chartMarkerSize / 2;
|
|
25
|
+
const shown = [];
|
|
26
|
+
return markers.map((marker, order) => {
|
|
27
|
+
const below = marker.y + chartInset + chartMarkerSize + chartType.lineHeight <=
|
|
28
|
+
plot.bottom;
|
|
29
|
+
const top = below
|
|
30
|
+
? marker.y + chartInset
|
|
31
|
+
: marker.y - chartInset - chartMarkerSize;
|
|
32
|
+
const bottom = top + chartMarkerSize;
|
|
33
|
+
const labelY = below
|
|
34
|
+
? bottom + chartType.fontSize
|
|
35
|
+
: top - (chartType.lineHeight - chartType.fontSize);
|
|
36
|
+
const width = chartTextWidth(marker.label);
|
|
37
|
+
const labelX = overPlot(marker.x, width, plot);
|
|
38
|
+
const box = {
|
|
39
|
+
left: labelX - width / 2,
|
|
40
|
+
right: labelX + width / 2,
|
|
41
|
+
top: labelY - chartType.fontSize,
|
|
42
|
+
bottom: labelY + (chartType.lineHeight - chartType.fontSize),
|
|
43
|
+
};
|
|
44
|
+
const labelShown = !shown.some((taken) => meets(taken, box));
|
|
45
|
+
if (labelShown)
|
|
46
|
+
shown.push(box);
|
|
47
|
+
return {
|
|
48
|
+
order,
|
|
49
|
+
x: marker.x,
|
|
50
|
+
labelX,
|
|
51
|
+
triangle: `${marker.x - half},${top} ${marker.x + half},${top} ${marker.x},${bottom}`,
|
|
52
|
+
labelY,
|
|
53
|
+
label: marker.label,
|
|
54
|
+
labelShown,
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** How a line runs between its points. */
|
|
2
|
+
export declare const lineChartCurves: readonly ["linear", "step"];
|
|
3
|
+
export type LineChartCurve = (typeof lineChartCurves)[number];
|
|
4
|
+
/** A point in the chart's pixels. */
|
|
5
|
+
export type ChartPoint = {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The vertices a line is drawn through. `linear` joins each point to the
|
|
11
|
+
* next; `step` holds each value until the next point's date, then moves
|
|
12
|
+
* straight up or down to it, as a balance that changes on a day does.
|
|
13
|
+
*/
|
|
14
|
+
export declare function linePath(points: readonly ChartPoint[], curve: LineChartCurve): ChartPoint[];
|
|
15
|
+
/** The area under a line's path, closed along the zero line. */
|
|
16
|
+
export declare function areaPath(path: readonly ChartPoint[], zeroY: number): ChartPoint[];
|
|
17
|
+
/** Vertices as an SVG `points` list. */
|
|
18
|
+
export declare function svgPoints(path: readonly ChartPoint[]): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** How a line runs between its points. */
|
|
2
|
+
export const lineChartCurves = ['linear', 'step'];
|
|
3
|
+
/**
|
|
4
|
+
* The vertices a line is drawn through. `linear` joins each point to the
|
|
5
|
+
* next; `step` holds each value until the next point's date, then moves
|
|
6
|
+
* straight up or down to it, as a balance that changes on a day does.
|
|
7
|
+
*/
|
|
8
|
+
export function linePath(points, curve) {
|
|
9
|
+
if (curve === 'linear')
|
|
10
|
+
return [...points];
|
|
11
|
+
const path = [];
|
|
12
|
+
points.forEach((point, index) => {
|
|
13
|
+
const previous = points[index - 1];
|
|
14
|
+
if (previous)
|
|
15
|
+
path.push({ x: point.x, y: previous.y });
|
|
16
|
+
path.push(point);
|
|
17
|
+
});
|
|
18
|
+
return path;
|
|
19
|
+
}
|
|
20
|
+
/** The area under a line's path, closed along the zero line. */
|
|
21
|
+
export function areaPath(path, zeroY) {
|
|
22
|
+
if (path.length === 0)
|
|
23
|
+
return [];
|
|
24
|
+
return [
|
|
25
|
+
{ x: path[0].x, y: zeroY },
|
|
26
|
+
...path,
|
|
27
|
+
{ x: path.at(-1).x, y: zeroY },
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
/** Vertices as an SVG `points` list. */
|
|
31
|
+
export function svgPoints(path) {
|
|
32
|
+
return path.map((point) => `${point.x},${point.y}`).join(' ');
|
|
33
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Each date's closing point: the index of the last point on it. A balance
|
|
3
|
+
* can change twice on one day; the day's markers and figures belong to its
|
|
4
|
+
* closing value.
|
|
5
|
+
*/
|
|
6
|
+
export function closingIndexes(days) {
|
|
7
|
+
return new Map(days.map((day, index) => [day, index]));
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ChartTableRow } from './chart-table-rows.js';
|
|
2
|
+
import { type LineChartMarker, type LineChartPeriod, type LineChartPoint } from './line-chart-input.js';
|
|
3
|
+
/**
|
|
4
|
+
* A line chart's hidden table rows: one per point, headed by its date in
|
|
5
|
+
* the consumer's words, holding its value and (when the chart has markers)
|
|
6
|
+
* the words of the markers on its date, in the date's closing row only;
|
|
7
|
+
* the rows inside the boxed period are current.
|
|
8
|
+
*/
|
|
9
|
+
export declare function lineChartRows({ formatDate, formatValue, highlight, markers, points, }: {
|
|
10
|
+
points: readonly LineChartPoint[];
|
|
11
|
+
markers: readonly LineChartMarker[];
|
|
12
|
+
highlight: LineChartPeriod | undefined;
|
|
13
|
+
formatDate: (date: string) => string;
|
|
14
|
+
formatValue: (value: number) => string;
|
|
15
|
+
}): ChartTableRow[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { closingIndexes } from './line-chart-points.js';
|
|
2
|
+
/**
|
|
3
|
+
* A line chart's hidden table rows: one per point, headed by its date in
|
|
4
|
+
* the consumer's words, holding its value and (when the chart has markers)
|
|
5
|
+
* the words of the markers on its date, in the date's closing row only;
|
|
6
|
+
* the rows inside the boxed period are current.
|
|
7
|
+
*/
|
|
8
|
+
export function lineChartRows({ formatDate, formatValue, highlight, markers, points, }) {
|
|
9
|
+
const closing = closingIndexes(points.map((point) => point.x));
|
|
10
|
+
return points.map((point, index) => {
|
|
11
|
+
const cells = [formatValue(point.y)];
|
|
12
|
+
if (markers.length > 0)
|
|
13
|
+
cells.push(closing.get(point.x) === index
|
|
14
|
+
? markers
|
|
15
|
+
.filter((marker) => marker.x === point.x)
|
|
16
|
+
.map((marker) => marker.label)
|
|
17
|
+
.join(', ')
|
|
18
|
+
: '');
|
|
19
|
+
return {
|
|
20
|
+
key: `${point.x}-${index}`,
|
|
21
|
+
header: formatDate(point.x),
|
|
22
|
+
cells,
|
|
23
|
+
// YYYY-MM-DD dates compare in date order as text.
|
|
24
|
+
current: highlight !== undefined &&
|
|
25
|
+
point.x >= highlight.from &&
|
|
26
|
+
point.x <= highlight.to,
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
import { type TableCellTone } from './css/css-table-ledger.js';
|
|
3
|
+
/**
|
|
4
|
+
* `panel` (the default) is one bordered panel on the surface; `plain`
|
|
5
|
+
* draws no panel and a hairline above the first row too, for rows inside
|
|
6
|
+
* a surface that already has one, such as a Card.
|
|
7
|
+
*/
|
|
8
|
+
export declare const listGroupVariants: readonly ["panel", "plain"];
|
|
9
|
+
export type ListGroupVariant = (typeof listGroupVariants)[number];
|
|
10
|
+
/**
|
|
11
|
+
* A list's bounded height, counted in rows: as tall as `rows` rows of a
|
|
12
|
+
* title and one detail line, the rest scrolling inside it. Taller rows
|
|
13
|
+
* show fewer at a time, shorter ones more.
|
|
14
|
+
*/
|
|
15
|
+
export type ListGroupMaxHeight = {
|
|
16
|
+
rows: number;
|
|
17
|
+
};
|
|
18
|
+
/** `danger` draws the title in the danger colour, for a row that ends something. */
|
|
19
|
+
export declare const listRowTones: readonly ["default", "danger"];
|
|
20
|
+
export type ListRowTone = (typeof listRowTones)[number];
|
|
21
|
+
/** `strong` (the default) sets the title at the label weight; `plain` at the body's. */
|
|
22
|
+
export declare const listRowTitleAppearances: readonly ["strong", "plain"];
|
|
23
|
+
export type ListRowTitleAppearance = (typeof listRowTitleAppearances)[number];
|
|
24
|
+
/** The colours a row's value can take, as a table cell's. */
|
|
25
|
+
export declare const listRowValueTones: readonly ["success", "danger", "muted", "accent"];
|
|
26
|
+
export type ListRowValueTone = TableCellTone;
|
|
27
|
+
/** What ends a row: a chevron (it opens something), a check (chosen), or none. */
|
|
28
|
+
export type ListRowAccessory = 'chevron' | 'check' | 'none';
|
|
29
|
+
export type ListGroupInput = {
|
|
30
|
+
label: string | undefined;
|
|
31
|
+
labelledBy: string | undefined;
|
|
32
|
+
variant: unknown;
|
|
33
|
+
maxHeight: ListGroupMaxHeight | undefined;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Fails closed on a ListGroup it cannot draw: an unknown variant, a
|
|
37
|
+
* `maxHeight` that is not a whole row count from 1, or a bounded list with
|
|
38
|
+
* no name (its scroll region is a keyboard stop and must say what it holds).
|
|
39
|
+
*/
|
|
40
|
+
export declare function assertListGroup({ label, labelledBy, variant, maxHeight, }: ListGroupInput): void;
|
|
41
|
+
/** The row count the generated `sw-list-group-scroll` height reads. */
|
|
42
|
+
export declare function listMaxHeightStyle(maxHeight: ListGroupMaxHeight): CSSProperties;
|
|
43
|
+
export type ListRowInput = {
|
|
44
|
+
title: string;
|
|
45
|
+
tone: unknown;
|
|
46
|
+
titleAppearance: unknown;
|
|
47
|
+
valueTone: unknown;
|
|
48
|
+
accessory: unknown;
|
|
49
|
+
value: string | undefined;
|
|
50
|
+
valueDetail: string | undefined;
|
|
51
|
+
selected: boolean | undefined;
|
|
52
|
+
pressable: boolean;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Fails closed on a ListRow it cannot draw: an empty title or value, an
|
|
56
|
+
* unknown tone, title appearance, value tone or accessory, a `valueDetail`
|
|
57
|
+
* or `valueTone` with no value, or `selected` on a row that is not a
|
|
58
|
+
* button or link (its check would be a state nothing can read).
|
|
59
|
+
*/
|
|
60
|
+
export declare function assertListRow(input: ListRowInput): void;
|
|
61
|
+
/**
|
|
62
|
+
* The row's end: a check while `selected`, nothing for an unchosen choice,
|
|
63
|
+
* a chevron on a row that opens something (unless `accessory` is `none`),
|
|
64
|
+
* and nothing on a read-only row.
|
|
65
|
+
*/
|
|
66
|
+
export declare function listRowAccessory(options: {
|
|
67
|
+
pressable: boolean;
|
|
68
|
+
selected: boolean | undefined;
|
|
69
|
+
accessory: 'chevron' | 'none';
|
|
70
|
+
}): ListRowAccessory;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { tableCellTones } from './css/css-table-ledger.js';
|
|
2
|
+
import { isOneOf } from './is-one-of.js';
|
|
3
|
+
/**
|
|
4
|
+
* `panel` (the default) is one bordered panel on the surface; `plain`
|
|
5
|
+
* draws no panel and a hairline above the first row too, for rows inside
|
|
6
|
+
* a surface that already has one, such as a Card.
|
|
7
|
+
*/
|
|
8
|
+
export const listGroupVariants = ['panel', 'plain'];
|
|
9
|
+
/** `danger` draws the title in the danger colour, for a row that ends something. */
|
|
10
|
+
export const listRowTones = ['default', 'danger'];
|
|
11
|
+
/** `strong` (the default) sets the title at the label weight; `plain` at the body's. */
|
|
12
|
+
export const listRowTitleAppearances = ['strong', 'plain'];
|
|
13
|
+
/** The colours a row's value can take, as a table cell's. */
|
|
14
|
+
export const listRowValueTones = tableCellTones;
|
|
15
|
+
function isBlank(text) {
|
|
16
|
+
return typeof text !== 'string' || text.trim() === '';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Fails closed on a ListGroup it cannot draw: an unknown variant, a
|
|
20
|
+
* `maxHeight` that is not a whole row count from 1, or a bounded list with
|
|
21
|
+
* no name (its scroll region is a keyboard stop and must say what it holds).
|
|
22
|
+
*/
|
|
23
|
+
export function assertListGroup({ label, labelledBy, variant, maxHeight, }) {
|
|
24
|
+
if (!isOneOf(listGroupVariants, variant))
|
|
25
|
+
throw new RangeError(`Unknown ListGroup variant: ${String(variant)}`);
|
|
26
|
+
if (maxHeight === undefined)
|
|
27
|
+
return;
|
|
28
|
+
const rows = typeof maxHeight === 'object' && maxHeight !== null
|
|
29
|
+
? maxHeight.rows
|
|
30
|
+
: undefined;
|
|
31
|
+
if (typeof rows !== 'number' || !Number.isInteger(rows) || rows < 1)
|
|
32
|
+
throw new RangeError('ListGroup maxHeight must be { rows } with a whole number from 1');
|
|
33
|
+
if (isBlank(label) && isBlank(labelledBy))
|
|
34
|
+
throw new RangeError('A ListGroup with maxHeight needs aria-label or aria-labelledby');
|
|
35
|
+
}
|
|
36
|
+
/** The row count the generated `sw-list-group-scroll` height reads. */
|
|
37
|
+
export function listMaxHeightStyle(maxHeight) {
|
|
38
|
+
return { '--sw-list-max-rows': maxHeight.rows };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Fails closed on a ListRow it cannot draw: an empty title or value, an
|
|
42
|
+
* unknown tone, title appearance, value tone or accessory, a `valueDetail`
|
|
43
|
+
* or `valueTone` with no value, or `selected` on a row that is not a
|
|
44
|
+
* button or link (its check would be a state nothing can read).
|
|
45
|
+
*/
|
|
46
|
+
export function assertListRow(input) {
|
|
47
|
+
if (isBlank(input.title))
|
|
48
|
+
throw new RangeError('ListRow title must be non-empty text');
|
|
49
|
+
if (!isOneOf(listRowTones, input.tone))
|
|
50
|
+
throw new RangeError(`Unknown ListRow tone: ${String(input.tone)}`);
|
|
51
|
+
if (!isOneOf(listRowTitleAppearances, input.titleAppearance))
|
|
52
|
+
throw new RangeError(`Unknown ListRow titleAppearance: ${String(input.titleAppearance)}`);
|
|
53
|
+
if (input.valueTone !== undefined &&
|
|
54
|
+
!isOneOf(listRowValueTones, input.valueTone))
|
|
55
|
+
throw new RangeError(`Unknown ListRow valueTone: ${String(input.valueTone)}`);
|
|
56
|
+
if (!isOneOf(['chevron', 'none'], input.accessory))
|
|
57
|
+
throw new RangeError(`Unknown ListRow accessory: ${String(input.accessory)}`);
|
|
58
|
+
if (input.value !== undefined && isBlank(input.value))
|
|
59
|
+
throw new RangeError('ListRow value must be non-empty text');
|
|
60
|
+
if (input.selected !== undefined && !input.pressable)
|
|
61
|
+
throw new RangeError('A ListRow choice (selected) needs onPress or href to say its state');
|
|
62
|
+
if (input.value === undefined &&
|
|
63
|
+
(input.valueDetail !== undefined || input.valueTone !== undefined))
|
|
64
|
+
throw new RangeError('ListRow valueDetail and valueTone need a value');
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The row's end: a check while `selected`, nothing for an unchosen choice,
|
|
68
|
+
* a chevron on a row that opens something (unless `accessory` is `none`),
|
|
69
|
+
* and nothing on a read-only row.
|
|
70
|
+
*/
|
|
71
|
+
export function listRowAccessory(options) {
|
|
72
|
+
if (options.selected !== undefined)
|
|
73
|
+
return options.selected ? 'check' : 'none';
|
|
74
|
+
if (!options.pressable)
|
|
75
|
+
return 'none';
|
|
76
|
+
return options.accessory;
|
|
77
|
+
}
|