basalt-ui 2.27.2 → 2.29.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 +466 -307
- package/MIGRATING.md +358 -12
- package/agent/rules/basalt-batteries.md +1 -1
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/rules/basalt-tokens.md +2 -2
- package/agent/skills/basalt-app/SKILL.md +3 -3
- package/agent/skills/basalt-charts/SKILL.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +12 -6
- package/agent/skills/basalt-design/references/catalogue.md +42 -36
- package/agent/skills/basalt-design/references/recipes.md +47 -0
- package/agent/skills/basalt-design/references/states.md +1 -1
- package/configs/oxlint-basalt.json +2 -1
- package/configs/oxlint-plugin.js +112 -3
- package/configs/oxlint-plugin.test.ts +99 -4
- package/configs/oxlint.json +1 -0
- package/dist/agent/chat/thread-message.d.ts +1 -160
- package/dist/agent/chat/thread-message.d.ts.map +1 -1
- package/dist/agent/chat/thread-message.js +7 -162
- package/dist/agent/chat/virtualize.d.ts +5 -5
- package/dist/charts/ChartCard.d.ts +14 -7
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +112 -23
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +11 -4
- package/dist/charts/Sparkline.d.ts +14 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +155 -44
- package/dist/charts/chart-box.module.css +59 -2
- package/dist/charts/chart-box.module.css.d.ts +5 -0
- package/dist/charts/chart-card.module.css +28 -17
- package/dist/charts/chart-card.module.css.d.ts +3 -0
- package/dist/charts/compile.d.ts +1 -1
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +38 -27
- package/dist/charts/labels.d.ts +13 -3
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +131 -20
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +1 -1
- package/dist/charts/ref-label.d.ts +37 -8
- package/dist/charts/ref-label.d.ts.map +1 -1
- package/dist/charts/ref-label.js +55 -10
- package/dist/charts/sparkline.module.css +50 -0
- package/dist/charts/sparkline.module.css.d.ts +3 -0
- package/dist/charts/state.d.ts +4 -4
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +23 -5
- package/dist/cli/doctor-upgrade.d.ts +11 -0
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +54 -0
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +32 -0
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +8 -3
- package/dist/cli/index.d.ts +13 -13
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +36 -2
- package/dist/cli/init.d.ts +6 -0
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +118 -27
- package/dist/cli/router-wiring.d.ts +3 -0
- package/dist/cli/router-wiring.d.ts.map +1 -1
- package/dist/cli/router-wiring.js +2 -0
- package/dist/cli/shot/capture.d.ts +34 -2
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +95 -12
- package/dist/cli/shot/detect.d.ts +4 -1
- package/dist/cli/shot/detect.d.ts.map +1 -1
- package/dist/cli/shot/detect.js +38 -16
- package/dist/cli/shot/index.d.ts.map +1 -1
- package/dist/cli/shot/index.js +9 -2
- package/dist/cli/shot/measure.d.ts.map +1 -1
- package/dist/cli/shot/measure.js +11 -2
- package/dist/cli/shot/types.d.ts +4 -1
- package/dist/cli/shot/types.d.ts.map +1 -1
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +10 -2
- package/dist/common/could-not-load.d.ts +13 -0
- package/dist/common/could-not-load.d.ts.map +1 -0
- package/dist/common/could-not-load.js +14 -0
- package/dist/common/empty-copy.d.ts +16 -0
- package/dist/common/empty-copy.d.ts.map +1 -0
- package/dist/common/empty-copy.js +9 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +3 -0
- package/dist/common/props.d.ts +20 -0
- package/dist/common/props.d.ts.map +1 -1
- package/dist/common/props.js +13 -1
- package/dist/common/retry-button.module.css +7 -3
- package/dist/common/virtual-rows.d.ts +196 -0
- package/dist/common/virtual-rows.d.ts.map +1 -0
- package/dist/common/virtual-rows.js +290 -0
- package/dist/controls/controls.module.css +33 -1
- package/dist/controls/controls.module.css.d.ts +2 -0
- package/dist/controls/enum-filter.d.ts.map +1 -1
- package/dist/controls/enum-filter.js +8 -2
- package/dist/controls/filter-pill.d.ts +27 -3
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +15 -4
- package/dist/controls/form-layout.d.ts +9 -3
- package/dist/controls/form-layout.d.ts.map +1 -1
- package/dist/controls/form-layout.js +74 -12
- package/dist/controls/form-layout.module.css +112 -7
- package/dist/controls/form-layout.module.css.d.ts +1 -0
- package/dist/controls/multi-select-filter.d.ts +2 -2
- package/dist/controls/multi-select-filter.d.ts.map +1 -1
- package/dist/controls/multi-select-filter.js +12 -6
- package/dist/controls/range-filter.d.ts +1 -1
- package/dist/controls/range-filter.d.ts.map +1 -1
- package/dist/controls/range-filter.js +8 -2
- package/dist/dashboard/bar-list.d.ts +5 -5
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +15 -8
- package/dist/dashboard/bar-list.module.css +21 -5
- package/dist/dashboard/board-nav.d.ts +22 -0
- package/dist/dashboard/board-nav.d.ts.map +1 -0
- package/dist/dashboard/board-nav.js +49 -0
- package/dist/dashboard/board.d.ts +52 -0
- package/dist/dashboard/board.d.ts.map +1 -0
- package/dist/dashboard/board.js +247 -0
- package/dist/dashboard/board.module.css +179 -0
- package/dist/dashboard/board.module.css.d.ts +28 -0
- package/dist/dashboard/empty-state.d.ts +6 -6
- package/dist/dashboard/empty-state.d.ts.map +1 -1
- package/dist/dashboard/empty-state.js +17 -8
- package/dist/dashboard/event-list-model.d.ts +54 -0
- package/dist/dashboard/event-list-model.d.ts.map +1 -0
- package/dist/dashboard/event-list-model.js +76 -0
- package/dist/dashboard/event-list-rows.d.ts +23 -0
- package/dist/dashboard/event-list-rows.d.ts.map +1 -0
- package/dist/dashboard/event-list-rows.js +89 -0
- package/dist/dashboard/event-list-scroll.d.ts +55 -0
- package/dist/dashboard/event-list-scroll.d.ts.map +1 -0
- package/dist/dashboard/event-list-scroll.js +216 -0
- package/dist/dashboard/event-list-skeleton.d.ts +10 -0
- package/dist/dashboard/event-list-skeleton.d.ts.map +1 -0
- package/dist/dashboard/event-list-skeleton.js +34 -0
- package/dist/dashboard/event-list.d.ts +65 -0
- package/dist/dashboard/event-list.d.ts.map +1 -0
- package/dist/dashboard/event-list.js +208 -0
- package/dist/dashboard/event-list.module.css +336 -0
- package/dist/dashboard/event-list.module.css.d.ts +34 -0
- package/dist/dashboard/index.d.ts +2 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +4 -0
- package/dist/dashboard/meter-model.d.ts +6 -3
- package/dist/dashboard/meter-model.d.ts.map +1 -1
- package/dist/dashboard/meter-model.js +9 -4
- package/dist/dashboard/meter-parts.d.ts +3 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +36 -6
- package/dist/dashboard/meter.d.ts +3 -3
- package/dist/dashboard/meter.d.ts.map +1 -1
- package/dist/dashboard/meter.js +10 -2
- package/dist/dashboard/meter.module.css +20 -12
- package/dist/dashboard/meter.module.css.d.ts +0 -1
- package/dist/dashboard/page-summary.d.ts +3 -3
- package/dist/dashboard/page-summary.d.ts.map +1 -1
- package/dist/dashboard/page-summary.js +7 -2
- package/dist/dashboard/page-summary.module.css +5 -2
- package/dist/dashboard/query-state.d.ts +9 -8
- package/dist/dashboard/query-state.d.ts.map +1 -1
- package/dist/dashboard/query-state.js +29 -11
- package/dist/dashboard/section.d.ts +11 -3
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +34 -7
- package/dist/dashboard/settings-section.d.ts +8 -5
- package/dist/dashboard/settings-section.d.ts.map +1 -1
- package/dist/dashboard/settings-section.js +12 -8
- package/dist/dashboard/settings-section.module.css +25 -4
- package/dist/dashboard/settings-section.module.css.d.ts +1 -0
- package/dist/dashboard/stat-card-parts.d.ts +5 -1
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +8 -3
- package/dist/dashboard/stat-card.d.ts +3 -3
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +47 -12
- package/dist/dashboard/stat-card.module.css +42 -7
- package/dist/dashboard/stat-card.module.css.d.ts +3 -0
- package/dist/dashboard/stat-group.d.ts +2 -2
- package/dist/dashboard/stat-group.d.ts.map +1 -1
- package/dist/dashboard/stat-group.js +10 -3
- package/dist/dashboard/stat-strip.d.ts +5 -4
- package/dist/dashboard/stat-strip.d.ts.map +1 -1
- package/dist/dashboard/stat-strip.js +41 -31
- package/dist/dashboard/stat-strip.module.css +8 -6
- package/dist/dashboard/visual-slot.d.ts +4 -0
- package/dist/dashboard/visual-slot.d.ts.map +1 -1
- package/dist/dashboard/visual-slot.js +2 -0
- package/dist/dashboard/widget-header.d.ts +6 -6
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +4 -2
- package/dist/dashboard/widget-header.module.css +12 -15
- package/dist/format/shared.d.ts.map +1 -1
- package/dist/format/shared.js +24 -1
- package/dist/guard/index.d.ts +1 -1
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +4 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/shell/app-main.module.css +18 -0
- package/dist/styles.css +69 -0
- package/dist/surfaces.d.ts +2 -2
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +8 -2
- package/dist/table/cell-kinds.d.ts +47 -0
- package/dist/table/cell-kinds.d.ts.map +1 -0
- package/dist/table/cell-kinds.js +180 -0
- package/dist/table/cell-kinds.module.css +55 -0
- package/dist/table/cell-kinds.module.css.d.ts +15 -0
- package/dist/table/data-table-fold.d.ts +155 -0
- package/dist/table/data-table-fold.d.ts.map +1 -0
- package/dist/table/data-table-fold.js +320 -0
- package/dist/table/data-table-state.d.ts +10 -3
- package/dist/table/data-table-state.d.ts.map +1 -1
- package/dist/table/data-table-state.js +11 -6
- package/dist/table/data-table.d.ts +13 -28
- package/dist/table/data-table.d.ts.map +1 -1
- package/dist/table/data-table.js +362 -255
- package/dist/table/data-table.module.css +282 -3
- package/dist/table/data-table.module.css.d.ts +16 -0
- package/dist/table/table-features.d.ts +34 -4
- package/dist/table/table-features.d.ts.map +1 -1
- package/dist/table/table-features.js +10 -0
- package/dist/theme/card-inset.module.css +35 -0
- package/dist/theme/controls.module.css +55 -2
- package/dist/theme/ctl-theme.d.ts.map +1 -1
- package/dist/theme/ctl-theme.js +5 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +14 -10
- package/dist/tokens/core.d.ts +1 -0
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +1 -0
- package/dist/tokens/derive.js +1 -1
- package/dist/tokens/palette.d.ts +2 -1
- package/dist/tokens/palette.d.ts.map +1 -1
- package/llms.txt +295 -5
- package/package.json +1 -1
- package/src/agent/chat/thread-message.tsx +10 -403
- package/src/agent/chat/virtualize.ts +5 -5
- package/src/charts/ChartCard.tsx +175 -31
- package/src/charts/Lines.tsx +13 -4
- package/src/charts/Sparkline.tsx +213 -48
- package/src/charts/chart-box.module.css +59 -2
- package/src/charts/chart-box.module.css.d.ts +5 -0
- package/src/charts/chart-card.module.css +28 -17
- package/src/charts/chart-card.module.css.d.ts +3 -0
- package/src/charts/compile.ts +59 -33
- package/src/charts/labels.ts +175 -24
- package/src/charts/legend.tsx +3 -2
- package/src/charts/ref-label.ts +114 -18
- package/src/charts/sparkline.module.css +50 -0
- package/src/charts/sparkline.module.css.d.ts +3 -0
- package/src/charts/state.tsx +40 -10
- package/src/cli/doctor-upgrade.ts +75 -0
- package/src/cli/doctor.ts +36 -0
- package/src/cli/help.ts +16 -6
- package/src/cli/index.ts +73 -67
- package/src/cli/init.ts +157 -36
- package/src/cli/router-wiring.ts +2 -2
- package/src/cli/shot/capture.ts +138 -16
- package/src/cli/shot/detect.ts +46 -22
- package/src/cli/shot/index.ts +8 -2
- package/src/cli/shot/measure.ts +11 -2
- package/src/cli/shot/types.ts +4 -1
- package/src/cli/sync.ts +12 -2
- package/src/common/could-not-load.ts +22 -0
- package/src/common/empty-copy.ts +17 -0
- package/src/common/index.ts +1 -0
- package/src/common/props.ts +30 -0
- package/src/common/retry-button.module.css +7 -3
- package/src/common/virtual-rows.tsx +682 -0
- package/src/controls/controls.module.css +33 -1
- package/src/controls/controls.module.css.d.ts +2 -0
- package/src/controls/enum-filter.tsx +8 -2
- package/src/controls/filter-pill.tsx +80 -27
- package/src/controls/form-layout.module.css +112 -7
- package/src/controls/form-layout.module.css.d.ts +1 -0
- package/src/controls/form-layout.tsx +115 -22
- package/src/controls/multi-select-filter.tsx +22 -11
- package/src/controls/range-filter.tsx +9 -3
- package/src/dashboard/bar-list.module.css +21 -5
- package/src/dashboard/bar-list.tsx +53 -45
- package/src/dashboard/board-nav.ts +67 -0
- package/src/dashboard/board.module.css +179 -0
- package/src/dashboard/board.module.css.d.ts +28 -0
- package/src/dashboard/board.tsx +415 -0
- package/src/dashboard/empty-state.tsx +21 -11
- package/src/dashboard/event-list-model.ts +125 -0
- package/src/dashboard/event-list-rows.tsx +117 -0
- package/src/dashboard/event-list-scroll.ts +291 -0
- package/src/dashboard/event-list-skeleton.tsx +62 -0
- package/src/dashboard/event-list.module.css +336 -0
- package/src/dashboard/event-list.module.css.d.ts +34 -0
- package/src/dashboard/event-list.tsx +336 -0
- package/src/dashboard/index.ts +2 -0
- package/src/dashboard/meter-model.ts +16 -7
- package/src/dashboard/meter-parts.tsx +53 -14
- package/src/dashboard/meter.module.css +20 -12
- package/src/dashboard/meter.module.css.d.ts +0 -1
- package/src/dashboard/meter.tsx +36 -18
- package/src/dashboard/page-summary.module.css +5 -2
- package/src/dashboard/page-summary.tsx +13 -6
- package/src/dashboard/query-state.tsx +55 -30
- package/src/dashboard/section.tsx +83 -41
- package/src/dashboard/settings-section.module.css +25 -4
- package/src/dashboard/settings-section.module.css.d.ts +1 -0
- package/src/dashboard/settings-section.tsx +18 -8
- package/src/dashboard/stat-card-parts.tsx +20 -3
- package/src/dashboard/stat-card.module.css +42 -7
- package/src/dashboard/stat-card.module.css.d.ts +3 -0
- package/src/dashboard/stat-card.tsx +55 -13
- package/src/dashboard/stat-group.tsx +22 -14
- package/src/dashboard/stat-strip.module.css +8 -6
- package/src/dashboard/stat-strip.tsx +29 -20
- package/src/dashboard/visual-slot.ts +5 -0
- package/src/dashboard/widget-header.module.css +12 -15
- package/src/dashboard/widget-header.tsx +8 -5
- package/src/format/shared.ts +30 -1
- package/src/guard/index.ts +7 -1
- package/src/index.ts +4 -0
- package/src/shell/app-main.module.css +18 -0
- package/src/styles.css +69 -0
- package/src/surfaces.ts +7 -1
- package/src/table/cell-kinds.module.css +55 -0
- package/src/table/cell-kinds.module.css.d.ts +15 -0
- package/src/table/cell-kinds.tsx +263 -0
- package/src/table/data-table-fold.tsx +567 -0
- package/src/table/data-table-state.ts +24 -13
- package/src/table/data-table.module.css +282 -3
- package/src/table/data-table.module.css.d.ts +16 -0
- package/src/table/data-table.tsx +430 -362
- package/src/table/table-features.ts +44 -4
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +2 -66
- package/src/theme/card-inset.module.css +35 -0
- package/src/theme/controls.module.css +55 -2
- package/src/theme/ctl-theme.tsx +8 -0
- package/src/theme/index.ts +12 -8
- package/src/tokens/core.ts +1 -0
- package/src/tokens/derive.ts +1 -1
- package/src/tokens/palette.ts +4 -1
package/src/charts/ChartCard.tsx
CHANGED
|
@@ -8,15 +8,20 @@
|
|
|
8
8
|
* `legend={{ placement: 'header' }}` legend is drawn by the chart, at the top of the body under the
|
|
9
9
|
* header, so it is in the server HTML and the header never grows on hydration.
|
|
10
10
|
*/
|
|
11
|
-
import { useRef, useState } from 'react'
|
|
11
|
+
import { Children, isValidElement, useRef, useState } from 'react'
|
|
12
12
|
import type { CSSProperties, ReactElement, ReactNode } from 'react'
|
|
13
13
|
import { useIsomorphicLayoutEffect } from '../common/isomorphic-layout-effect'
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
14
|
+
import { HostTitleContext } from '../common/could-not-load'
|
|
15
|
+
import { cx, splitDataAttributes } from '../common/props'
|
|
16
|
+
import type { BasaltProps, DataAttributes, SlotStylesProps } from '../common/props'
|
|
17
|
+
import { DeltaBadge } from '../dashboard/delta-badge'
|
|
16
18
|
import type { DeltaPolarity } from '../dashboard/delta-badge'
|
|
17
19
|
import { WidgetHeader } from '../dashboard/widget-header'
|
|
18
20
|
import { VX } from '../tokens'
|
|
19
21
|
import { ChartCardContext } from './card-context'
|
|
22
|
+
import { BandStrip } from './BandStrip'
|
|
23
|
+
import { Lines } from './Lines'
|
|
24
|
+
import { StackedArea } from './StackedArea'
|
|
20
25
|
import classes from './chart-card.module.css'
|
|
21
26
|
import { ChartPlaceholder, resolveChartState } from './state'
|
|
22
27
|
import type { ChartState, ResponsiveChartHeight } from './types'
|
|
@@ -27,6 +32,9 @@ import type { ChartState, ResponsiveChartHeight } from './types'
|
|
|
27
32
|
const cardStyle: CSSProperties = {
|
|
28
33
|
display: 'flex',
|
|
29
34
|
flexDirection: 'column',
|
|
35
|
+
// Fills its grid cell (or a `h="100%"` anchor wrapper): two cards in one row end together, with
|
|
36
|
+
// no wrapper background under the shorter one. In an auto-height parent it resolves to auto.
|
|
37
|
+
height: '100%',
|
|
30
38
|
minHeight: 0,
|
|
31
39
|
containerType: 'inline-size',
|
|
32
40
|
containerName: 'basalt-card',
|
|
@@ -101,6 +109,28 @@ function periodText(period: string | readonly string[], afterUnit: boolean): str
|
|
|
101
109
|
return afterUnit && !text.startsWith(PERIOD_SEPARATOR.trim()) ? PERIOD_SEPARATOR + text : text
|
|
102
110
|
}
|
|
103
111
|
|
|
112
|
+
/** A comparison that renders something: `cond && <DeltaBadge />` leaves `false`, `null` or `''`. */
|
|
113
|
+
const hasComparison = (node: ReactNode): boolean =>
|
|
114
|
+
node !== undefined && node !== null && node !== false && node !== ''
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* A plain-text comparison with a leading sign ("+0.3", "-4%") reads as a delta: the sign becomes
|
|
118
|
+
* DeltaBadge's direction glyph (▲/▼). Any other node (a `DeltaBadge`, which carries its own) is as is.
|
|
119
|
+
*/
|
|
120
|
+
function Comparison({ node }: { node: ReactNode }): ReactNode {
|
|
121
|
+
if (typeof node !== 'string') return node
|
|
122
|
+
const sign = /^\s*([+\-−])\s*(.+)$/.exec(node)
|
|
123
|
+
if (sign === null) return node
|
|
124
|
+
return (
|
|
125
|
+
<>
|
|
126
|
+
<span aria-hidden="true" className={classes.factGlyph}>
|
|
127
|
+
{sign[1] === '+' ? '▲' : '▼'}
|
|
128
|
+
</span>
|
|
129
|
+
{sign[2]}
|
|
130
|
+
</>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
104
134
|
/** One headline figure: the value is the hero, then its unit, a comparison node and the period. */
|
|
105
135
|
export type ChartFact = {
|
|
106
136
|
value: ReactNode
|
|
@@ -110,7 +140,9 @@ export type ChartFact = {
|
|
|
110
140
|
/** Plain text the figure covers, e.g. `last 30 d`. A list is joined by ` · ` (`['last entry 3 d
|
|
111
141
|
* ago', '12 entries']`) and, behind a `unit`, led by one. */
|
|
112
142
|
period?: string | readonly string[] | undefined
|
|
113
|
-
/** Ink for the
|
|
143
|
+
/** Ink for the comparison, with its direction glyph (text only, never a fill): an off-target
|
|
144
|
+
* change reads `warn`. A fact with no comparison inks its value instead. A `DeltaBadge` comparison keeps
|
|
145
|
+
* its own polarity ink (it is inline), so `tone` is for plain-text comparisons. */
|
|
114
146
|
tone?: ChartFactTone | undefined
|
|
115
147
|
}
|
|
116
148
|
|
|
@@ -121,6 +153,7 @@ export type ChartFactTone = 'good' | 'warn' | 'bad' | 'muted'
|
|
|
121
153
|
export type ChartCardSlot = 'root' | 'header' | 'body'
|
|
122
154
|
|
|
123
155
|
type ChartCardBaseProps = BasaltProps &
|
|
156
|
+
DataAttributes &
|
|
124
157
|
SlotStylesProps<ChartCardSlot> & {
|
|
125
158
|
title?: string | undefined
|
|
126
159
|
icon?: ReactNode
|
|
@@ -153,11 +186,16 @@ type ChartCardBaseProps = BasaltProps &
|
|
|
153
186
|
* fallback>` should pass a numeric height instead. */
|
|
154
187
|
placeholderHeight?: number | ResponsiveChartHeight | 'content' | undefined
|
|
155
188
|
/** The pending plot's ghost: `'bars'` (default), `'line'` for a line or area chart, or the bar
|
|
156
|
-
* count when the loaded chart's data length is known
|
|
157
|
-
|
|
189
|
+
* count when the loaded chart's data length is known, `'band'` for a `BandStrip`. Omitted, a
|
|
190
|
+
* `Lines` or `StackedArea` body (bare, or inside plain elements) loads as a line, a `BandStrip`
|
|
191
|
+
* as one band row at its own `height`; a body wrapped in your own component hides
|
|
192
|
+
* its kind from the card, so pass `ghost="line"` there. */
|
|
193
|
+
ghost?: 'bars' | 'line' | 'band' | number | undefined
|
|
158
194
|
/** Placeholder data is showing: the facts row dims with the plot (a strip cell's `stale`). */
|
|
159
195
|
stale?: boolean | undefined
|
|
160
|
-
/** What an errored `state` names: "Could not load {stateNoun}". Default:
|
|
196
|
+
/** What an errored `state` names: "Could not load {stateNoun}". Default: the card's `title`; with
|
|
197
|
+
* neither, the title is a bare "Could not load". A leading capital is lowercased unless the next
|
|
198
|
+
* character is a capital or a non-letter ("Revenue" → "revenue", "KPI" and "2024 sales" stay). */
|
|
161
199
|
stateNoun?: string | undefined
|
|
162
200
|
/** An errored `state` shows the shared Retry button (the one `ErrorState` renders). */
|
|
163
201
|
onRetry?: (() => void) | undefined
|
|
@@ -186,6 +224,29 @@ export type ChartCardProps = ChartCardBaseProps &
|
|
|
186
224
|
| { facts?: undefined }
|
|
187
225
|
)
|
|
188
226
|
|
|
227
|
+
/** The legacy `value`/`delta` hero as the one fact the headline row draws. */
|
|
228
|
+
function legacyFact(header: {
|
|
229
|
+
value?: string | undefined
|
|
230
|
+
delta?: number | undefined
|
|
231
|
+
deltaPeriod?: string | undefined
|
|
232
|
+
deltaPolarity?: DeltaPolarity | undefined
|
|
233
|
+
}): ChartFact | undefined {
|
|
234
|
+
const { value, delta, deltaPeriod, deltaPolarity } = header
|
|
235
|
+
if (value === undefined && delta === undefined) return undefined
|
|
236
|
+
return {
|
|
237
|
+
value: value ?? null,
|
|
238
|
+
...(delta !== undefined && {
|
|
239
|
+
comparison: (
|
|
240
|
+
<DeltaBadge
|
|
241
|
+
value={delta}
|
|
242
|
+
period={deltaPeriod}
|
|
243
|
+
{...(deltaPolarity !== undefined && { polarity: deltaPolarity })}
|
|
244
|
+
/>
|
|
245
|
+
),
|
|
246
|
+
}),
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
189
250
|
/** Drops explicit `undefined`s: `WidgetHeader` is exact-optional, this props type is not. */
|
|
190
251
|
const definedOnly = <T extends object>(o: T): { [K in keyof T]?: Exclude<T[K], undefined> } =>
|
|
191
252
|
Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined)) as {
|
|
@@ -221,11 +282,28 @@ function Facts({
|
|
|
221
282
|
{...(f.tone !== undefined && { 'data-tone': f.tone })}
|
|
222
283
|
className={classes.fact}
|
|
223
284
|
>
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
285
|
+
{f.value !== null && f.value !== undefined && f.value !== '' && (
|
|
286
|
+
<span
|
|
287
|
+
data-basalt-fact-value=""
|
|
288
|
+
{...(!hasComparison(f.comparison) && { 'data-basalt-fact-tone': '' })}
|
|
289
|
+
className={cx(
|
|
290
|
+
classes.factValue,
|
|
291
|
+
!hasComparison(f.comparison) && classes.factTone,
|
|
292
|
+
)}
|
|
293
|
+
>
|
|
294
|
+
{f.value}
|
|
295
|
+
</span>
|
|
296
|
+
)}
|
|
227
297
|
{f.unit !== undefined && <span className={classes.factUnit}>{f.unit}</span>}
|
|
228
|
-
{f.comparison
|
|
298
|
+
{hasComparison(f.comparison) && (
|
|
299
|
+
<span
|
|
300
|
+
data-basalt-fact-delta=""
|
|
301
|
+
data-basalt-fact-tone=""
|
|
302
|
+
className={classes.factTone}
|
|
303
|
+
>
|
|
304
|
+
<Comparison node={f.comparison} />
|
|
305
|
+
</span>
|
|
306
|
+
)}
|
|
229
307
|
{period !== '' && <span className={classes.factPeriod}>{period}</span>}
|
|
230
308
|
</span>
|
|
231
309
|
)
|
|
@@ -252,6 +330,57 @@ function FactsSkeleton({ basis }: { basis: boolean }): ReactElement {
|
|
|
252
330
|
)
|
|
253
331
|
}
|
|
254
332
|
|
|
333
|
+
/** A stated `BandStrip` height the placeholder can take: a px number or the per-class object. */
|
|
334
|
+
function isChartHeight(value: unknown): value is number | ResponsiveChartHeight {
|
|
335
|
+
return (
|
|
336
|
+
typeof value === 'number' ||
|
|
337
|
+
(typeof value === 'object' &&
|
|
338
|
+
value !== null &&
|
|
339
|
+
typeof (value as { base?: unknown }).base === 'number')
|
|
340
|
+
)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
type BodyKind = { ghost: 'line' | 'band'; height?: number | ResponsiveChartHeight; legend?: true }
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* What a pending body draws when `ghost` is not passed: a line for a `Lines` or `StackedArea` body,
|
|
347
|
+
* one band row at the strip's own `height` for a `BandStrip` (found through plain elements such as a
|
|
348
|
+
* `Box`), the default bars otherwise, so a loading chart is drawn as its kind, at its loaded height.
|
|
349
|
+
*/
|
|
350
|
+
function bodyKindOf(node: ReactNode): BodyKind | undefined {
|
|
351
|
+
for (const child of Children.toArray(node)) {
|
|
352
|
+
if (!isValidElement<{ children?: ReactNode; height?: unknown }>(child)) continue
|
|
353
|
+
if (child.type === Lines || child.type === StackedArea) return { ghost: 'line' }
|
|
354
|
+
if (child.type === BandStrip) {
|
|
355
|
+
const { height, states, legend } = child.props as {
|
|
356
|
+
height?: unknown
|
|
357
|
+
states?: readonly unknown[]
|
|
358
|
+
legend?: unknown
|
|
359
|
+
}
|
|
360
|
+
return {
|
|
361
|
+
ghost: 'band',
|
|
362
|
+
...(isChartHeight(height) && { height }),
|
|
363
|
+
// The loaded strip's legend row sits under the box: the ghost keeps its room.
|
|
364
|
+
...(legend !== false && (states?.length ?? 0) > 1 && { legend: true as const }),
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const inner = bodyKindOf(child.props.children)
|
|
368
|
+
if (inner !== undefined) return inner
|
|
369
|
+
}
|
|
370
|
+
return undefined
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** The loaded strip's legend row keeps its room under a pending box; other placeholders get no wrapper. */
|
|
374
|
+
function reserveLegend(reserve: boolean, placeholder: ReactElement): ReactElement {
|
|
375
|
+
return reserve ? (
|
|
376
|
+
<div className={classes.legendReserve} data-basalt-legend-reserve="">
|
|
377
|
+
{placeholder}
|
|
378
|
+
</div>
|
|
379
|
+
) : (
|
|
380
|
+
placeholder
|
|
381
|
+
)
|
|
382
|
+
}
|
|
383
|
+
|
|
255
384
|
export function ChartCard({
|
|
256
385
|
actions,
|
|
257
386
|
state,
|
|
@@ -267,25 +396,39 @@ export function ChartCard({
|
|
|
267
396
|
style,
|
|
268
397
|
children,
|
|
269
398
|
facts,
|
|
270
|
-
...
|
|
399
|
+
...headerAndData
|
|
271
400
|
}: ChartCardProps): ReactElement {
|
|
401
|
+
const { data, rest: header } = splitDataAttributes(headerAndData)
|
|
272
402
|
const { ref, short } = useShortCard()
|
|
273
403
|
const resolved = resolveChartState(state)
|
|
274
|
-
|
|
275
|
-
const
|
|
404
|
+
// The noun an error names: `stateNoun`, else the card's own title ("Revenue" → "revenue").
|
|
405
|
+
const noun = stateNoun ?? header.title
|
|
406
|
+
const kind = resolved === 'pending' ? bodyKindOf(children) : undefined
|
|
407
|
+
const plotGhost = ghost ?? kind?.ghost
|
|
408
|
+
// `ghost` changes the shape only: the wrapped strip's height still sizes the pending box.
|
|
409
|
+
const pendingHeight = placeholderHeight ?? kind?.height
|
|
410
|
+
// One headline anatomy: the legacy `value`/`delta` hero is drawn as a fact (title, then value, delta
|
|
411
|
+
// and period in one baseline group), never pushed to the far edge of the title row.
|
|
412
|
+
const headline = facts ?? legacyFact(header)
|
|
413
|
+
const showFacts = headline !== undefined && resolved === null
|
|
414
|
+
const skeletonFacts = headline !== undefined && resolved === 'pending'
|
|
276
415
|
const hasHeader =
|
|
277
416
|
actions !== undefined ||
|
|
278
417
|
showFacts ||
|
|
279
418
|
skeletonFacts ||
|
|
280
419
|
HEADER_TRIGGERS.some((k) => header[k] !== undefined)
|
|
281
420
|
// With facts the subtitle is the basis line after them, not WidgetHeader's foldable row.
|
|
282
|
-
|
|
283
|
-
const
|
|
421
|
+
// The hero props are drawn by the facts row below, so `WidgetHeader` never sees them.
|
|
422
|
+
const { subtitle, value: _v, delta: _d, deltaPeriod: _p, deltaPolarity: _pol, ...rest } = header
|
|
423
|
+
const headerProps = headline === undefined ? header : rest
|
|
424
|
+
|
|
425
|
+
const hostBody = <HostTitleContext value={header.title}>{children}</HostTitleContext>
|
|
284
426
|
|
|
285
427
|
return (
|
|
286
428
|
<ChartCardContext.Provider value>
|
|
287
429
|
<div
|
|
288
430
|
ref={ref}
|
|
431
|
+
{...data}
|
|
289
432
|
data-basalt-chart-card=""
|
|
290
433
|
className={cx(classNames?.root, className)}
|
|
291
434
|
style={{ ...cardStyle, ...style }}
|
|
@@ -293,7 +436,7 @@ export function ChartCard({
|
|
|
293
436
|
{...(short && { 'data-basalt-card-short': '' })}
|
|
294
437
|
>
|
|
295
438
|
{hasHeader && (
|
|
296
|
-
<div className={cx(classes.header, classNames?.header)}>
|
|
439
|
+
<div data-basalt-chart-header="" className={cx(classes.header, classNames?.header)}>
|
|
297
440
|
<WidgetHeader
|
|
298
441
|
tier="widget"
|
|
299
442
|
{...definedOnly(headerProps)}
|
|
@@ -302,7 +445,7 @@ export function ChartCard({
|
|
|
302
445
|
actions: <span data-basalt-tier="widget">{actions}</span>,
|
|
303
446
|
})}
|
|
304
447
|
/>
|
|
305
|
-
{showFacts && <Facts facts={
|
|
448
|
+
{showFacts && <Facts facts={headline} basis={subtitle} stale={stale} />}
|
|
306
449
|
{skeletonFacts && <FactsSkeleton basis={subtitle !== undefined} />}
|
|
307
450
|
</div>
|
|
308
451
|
)}
|
|
@@ -310,19 +453,20 @@ export function ChartCard({
|
|
|
310
453
|
{...(classNames?.body !== undefined && { className: classNames.body })}
|
|
311
454
|
style={bodyClipStyle}
|
|
312
455
|
>
|
|
313
|
-
{resolved === null || (resolved === 'pending' && placeholderHeight === 'content')
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
456
|
+
{resolved === null || (resolved === 'pending' && placeholderHeight === 'content')
|
|
457
|
+
? hostBody
|
|
458
|
+
: reserveLegend(
|
|
459
|
+
kind?.legend === true,
|
|
460
|
+
<ChartPlaceholder
|
|
461
|
+
state={state}
|
|
462
|
+
{...(pendingHeight !== undefined && { height: pendingHeight })}
|
|
463
|
+
{...(noun !== undefined && { noun })}
|
|
464
|
+
{...(plotGhost !== undefined && { ghost: plotGhost })}
|
|
465
|
+
{...(onRetry !== undefined && { onRetry })}
|
|
466
|
+
{...(retrying !== undefined && { retrying })}
|
|
467
|
+
action={stateAction}
|
|
468
|
+
/>,
|
|
469
|
+
)}
|
|
326
470
|
</div>
|
|
327
471
|
</div>
|
|
328
472
|
</ChartCardContext.Provider>
|
package/src/charts/Lines.tsx
CHANGED
|
@@ -21,7 +21,7 @@ import type { ReactElement } from 'react'
|
|
|
21
21
|
import { CartesianRung } from './CartesianChart'
|
|
22
22
|
import { areaGradientId } from './compile'
|
|
23
23
|
import { chartCurve } from './curves'
|
|
24
|
-
import { endLabelMarks, endLabelPlan } from './labels'
|
|
24
|
+
import { claimLabelBoxes, endLabelMarks, endLabelPlan } from './labels'
|
|
25
25
|
import type { LinesNaming } from './labels'
|
|
26
26
|
import { drawnRows, lineMark, loneDots, markersOf, yScaleOf } from './marks'
|
|
27
27
|
import { rowX } from './types'
|
|
@@ -65,7 +65,7 @@ function lastIsPlaceable<T, X extends ChartX>(
|
|
|
65
65
|
const AUTO_END_LABELS = 3
|
|
66
66
|
|
|
67
67
|
export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): ReactElement {
|
|
68
|
-
const { thresholds, naming = 'auto', ...rest } = props
|
|
68
|
+
const { thresholds, naming = 'auto', refLines, ...rest } = props
|
|
69
69
|
const { series } = props
|
|
70
70
|
// Whether end labels can name every legend entry: only then may the legend give way to them.
|
|
71
71
|
const labelled = series.filter((s) => s.role !== 'reference')
|
|
@@ -135,14 +135,23 @@ export function Lines<T, X extends ChartX = ChartX>(props: LinesProps<T, X>): Re
|
|
|
135
135
|
out.push(...markersOf(s, plot.rows(s.key), yScale))
|
|
136
136
|
}
|
|
137
137
|
const labelled = plotted.filter((s) => s.role !== 'reference')
|
|
138
|
-
|
|
138
|
+
// The reference rules on the left axis are lines a label must not sit on; the captions in turn
|
|
139
|
+
// keep clear of the labels placed here.
|
|
140
|
+
const rules = (refLines ?? []).flatMap((r) => (r.axis === 'right' ? [] : [r.value]))
|
|
141
|
+
const plan = endLabelPlan(plot, labelled, effective, rules)
|
|
142
|
+
claimLabelBoxes(
|
|
143
|
+
plot,
|
|
144
|
+
plan.map((p) => p.box),
|
|
145
|
+
)
|
|
146
|
+
out.push(...endLabelMarks(plan))
|
|
139
147
|
return out
|
|
140
148
|
},
|
|
141
|
-
[series, thresholds, effective],
|
|
149
|
+
[series, thresholds, effective, refLines],
|
|
142
150
|
)
|
|
143
151
|
return (
|
|
144
152
|
<CartesianRung
|
|
145
153
|
{...rest}
|
|
154
|
+
{...(refLines !== undefined && { refLines })}
|
|
146
155
|
marks={marks}
|
|
147
156
|
{...(labelsOnly && { legend: false as const })}
|
|
148
157
|
{...(hideAtWide && { hideLegendAtWide: true })}
|