@carto/ps-react-ui 5.2.0 → 5.4.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.
Files changed (50) hide show
  1. package/dist/{actions-CF8RNKd6.js → actions-Dhlz_adK.js} +187 -181
  2. package/dist/actions-Dhlz_adK.js.map +1 -0
  3. package/dist/category-C6myUFUJ.js +936 -0
  4. package/dist/category-C6myUFUJ.js.map +1 -0
  5. package/dist/legend.js +34 -21
  6. package/dist/legend.js.map +1 -1
  7. package/dist/types/legend/stores/types.d.ts +4 -2
  8. package/dist/types/widgets-v2/actions/searcher/filter.d.ts +3 -2
  9. package/dist/types/widgets-v2/category/category-ui.d.ts +10 -2
  10. package/dist/types/widgets-v2/category/category.d.ts +7 -1
  11. package/dist/types/widgets-v2/category/components/category-bar-stacked.d.ts +8 -1
  12. package/dist/types/widgets-v2/category/components/category-bar.d.ts +24 -2
  13. package/dist/types/widgets-v2/category/components/category-row-multi.d.ts +3 -1
  14. package/dist/types/widgets-v2/category/components/category-row-single.d.ts +3 -1
  15. package/dist/types/widgets-v2/category/components/category-row-stacked.d.ts +10 -1
  16. package/dist/types/widgets-v2/category/style.d.ts +33 -6
  17. package/dist/types/widgets-v2/wrapper/style.d.ts +31 -2
  18. package/dist/types/widgets-v2/wrapper/widget-actions.d.ts +2 -2
  19. package/dist/types/widgets-v2/wrapper/widget-wrapper.d.ts +2 -2
  20. package/dist/widgets-v2/actions.js +1 -1
  21. package/dist/widgets-v2/category.js +1 -1
  22. package/dist/widgets-v2.js +342 -295
  23. package/dist/widgets-v2.js.map +1 -1
  24. package/package.json +1 -1
  25. package/src/legend/components/legend-item/legend-item-ui.test.tsx +22 -1
  26. package/src/legend/components/legend-ramp/legend-ramp-ui.tsx +22 -6
  27. package/src/legend/stores/types.ts +4 -2
  28. package/src/widgets-v2/actions/searcher/filter.test.ts +28 -0
  29. package/src/widgets-v2/actions/searcher/filter.ts +22 -4
  30. package/src/widgets-v2/actions/searcher/searcher-toggle.tsx +9 -4
  31. package/src/widgets-v2/actions/searcher/searcher.test.tsx +22 -0
  32. package/src/widgets-v2/category/category-ui.test.tsx +139 -0
  33. package/src/widgets-v2/category/category-ui.tsx +64 -11
  34. package/src/widgets-v2/category/category.test.tsx +67 -0
  35. package/src/widgets-v2/category/category.tsx +32 -15
  36. package/src/widgets-v2/category/components/category-bar-stacked.test.tsx +18 -0
  37. package/src/widgets-v2/category/components/category-bar-stacked.tsx +42 -29
  38. package/src/widgets-v2/category/components/category-bar.test.tsx +66 -0
  39. package/src/widgets-v2/category/components/category-bar.tsx +65 -9
  40. package/src/widgets-v2/category/components/category-row-multi.tsx +21 -0
  41. package/src/widgets-v2/category/components/category-row-single.tsx +4 -0
  42. package/src/widgets-v2/category/components/category-row-stacked.tsx +24 -1
  43. package/src/widgets-v2/category/style.ts +58 -14
  44. package/src/widgets-v2/wrapper/style.ts +38 -2
  45. package/src/widgets-v2/wrapper/widget-actions.tsx +2 -2
  46. package/src/widgets-v2/wrapper/widget-wrapper.test.tsx +32 -2
  47. package/src/widgets-v2/wrapper/widget-wrapper.tsx +58 -32
  48. package/dist/actions-CF8RNKd6.js.map +0 -1
  49. package/dist/category-D01ruG-l.js +0 -842
  50. package/dist/category-D01ruG-l.js.map +0 -1
@@ -1,6 +1,7 @@
1
1
  import { Box } from '@mui/material'
2
2
  import type { CategorySize } from '../types'
3
3
  import { styles } from '../style'
4
+ import { ZeroTickWrap } from './category-bar'
4
5
 
5
6
  export interface CategoryBarStackedProps {
6
7
  /** One value per series. Zero values render no segment (visually + in the DOM). */
@@ -13,6 +14,13 @@ export interface CategoryBarStackedProps {
13
14
  * so cross-row comparison is preserved.
14
15
  */
15
16
  maxValue: number
17
+ /**
18
+ * Where the zero sits, as a percentage of the track. `0` (default) is the
19
+ * positive-only layout. Positive segments stack rightwards from it and
20
+ * negative ones leftwards, both scaled by `maxValue` against the full
21
+ * track width.
22
+ */
23
+ zeroPct?: number
16
24
  /** Visual density. Forwarded to the track styling; segments inherit height. */
17
25
  size?: CategorySize
18
26
  }
@@ -33,41 +41,46 @@ export function CategoryBarStacked({
33
41
  values,
34
42
  colors,
35
43
  maxValue,
44
+ zeroPct = 0,
36
45
  size = 'small',
37
46
  }: CategoryBarStackedProps) {
38
- // Cumulative offsets pre-computed up front so the render map function
39
- // stays pure (no mutable closure variable — keeps the React Compiler
40
- // immutability check happy).
41
- const offsets: number[] = []
47
+ // Left edges pre-computed up front so the render map function stays pure
48
+ // (no mutable closure variable — keeps the React Compiler immutability
49
+ // check happy). Each sign keeps its own running sum away from the zero.
50
+ const lefts: number[] = []
42
51
  {
43
- let acc = 0
52
+ let pos = 0
53
+ let neg = 0
44
54
  for (const v of values) {
45
- offsets.push(acc)
46
- acc += v
55
+ if (v < 0) neg -= v
56
+ lefts.push(v < 0 ? -neg : pos)
57
+ if (v > 0) pos += v
47
58
  }
48
59
  }
49
60
  return (
50
- <Box sx={styles.bar[size]} data-size={size}>
51
- {values.map((v, i) => {
52
- if (v <= 0) return null
53
- const leftPct = maxValue > 0 ? (offsets[i]! / maxValue) * 100 : 0
54
- const pct = maxValue > 0 ? (v / maxValue) * 100 : 0
55
- return (
56
- <Box
57
- // Segments are keyed by per-series colour (the only stable
58
- // distinguishing field on this side) plus the segment index for
59
- // when callers reuse palette colours across series.
60
- key={`seg-${colors[i] ?? 'none'}-${i}`}
61
- sx={styles.stackedSegment[size]}
62
- style={{
63
- left: `${leftPct}%`,
64
- width: `${pct}%`,
65
- backgroundColor: colors[i] ?? '',
66
- }}
67
- data-bar-fill='true'
68
- />
69
- )
70
- })}
71
- </Box>
61
+ <ZeroTickWrap zeroPct={zeroPct > 0 && zeroPct < 100 ? zeroPct : undefined}>
62
+ <Box sx={styles.bar[size]} data-size={size}>
63
+ {values.map((v, i) => {
64
+ if (v === 0 || maxValue <= 0) return null
65
+ const leftPct = zeroPct + (lefts[i]! / maxValue) * 100
66
+ const pct = (Math.abs(v) / maxValue) * 100
67
+ return (
68
+ <Box
69
+ // Segments are keyed by per-series colour (the only stable
70
+ // distinguishing field on this side) plus the segment index for
71
+ // when callers reuse palette colours across series.
72
+ key={`seg-${colors[i] ?? 'none'}-${i}`}
73
+ sx={styles.stackedSegment[size]}
74
+ style={{
75
+ left: `${leftPct}%`,
76
+ width: `${pct}%`,
77
+ backgroundColor: colors[i] ?? '',
78
+ }}
79
+ data-bar-fill='true'
80
+ />
81
+ )
82
+ })}
83
+ </Box>
84
+ </ZeroTickWrap>
72
85
  )
73
86
  }
@@ -61,4 +61,70 @@ describe('<CategoryBar>', () => {
61
61
  expect(track).toBeTruthy()
62
62
  expect(track!.getAttribute('data-size')).toBe('medium')
63
63
  })
64
+
65
+ describe('signed domain (minValue < 0)', () => {
66
+ it('grows a positive value rightwards from the zero', () => {
67
+ const { container } = render(
68
+ <CategoryBar
69
+ value={0.5}
70
+ minValue={-1}
71
+ maxValue={1}
72
+ color='rgb(0, 0, 0)'
73
+ />,
74
+ )
75
+ const fill = getFill(container)!
76
+ expect(fill.style.left).toBe('50%')
77
+ expect(fill.style.width).toBe('25%')
78
+ })
79
+
80
+ it('grows a negative value leftwards from the zero, in the same color', () => {
81
+ const { container } = render(
82
+ <CategoryBar
83
+ value={-0.5}
84
+ minValue={-1}
85
+ maxValue={1}
86
+ color='rgb(0, 200, 0)'
87
+ />,
88
+ )
89
+ const fill = getFill(container)!
90
+ expect(fill.style.left).toBe('25%')
91
+ expect(fill.style.width).toBe('25%')
92
+ expect(fill.style.backgroundColor).toBe('rgb(0, 200, 0)')
93
+ })
94
+
95
+ it('squares the end that grows out of the zero', () => {
96
+ const { container: pos } = render(
97
+ <CategoryBar value={1} minValue={-1} maxValue={1} color='red' />,
98
+ )
99
+ const { container: neg } = render(
100
+ <CategoryBar value={-1} minValue={-1} maxValue={1} color='red' />,
101
+ )
102
+ expect(getFill(pos)!.style.borderTopLeftRadius).toBe('0px')
103
+ expect(getFill(pos)!.style.borderTopRightRadius).toBe('')
104
+ expect(getFill(neg)!.style.borderTopRightRadius).toBe('0px')
105
+ expect(getFill(neg)!.style.borderTopLeftRadius).toBe('')
106
+ })
107
+
108
+ it('puts the zero tick before the track so the bar paints over it', () => {
109
+ const { container } = render(
110
+ <CategoryBar value={1} minValue={-1} maxValue={1} color='red' />,
111
+ )
112
+ const tick = container.querySelector('[data-zero-tick="true"]')!
113
+ expect(tick.nextElementSibling!.getAttribute('data-size')).toBe('small')
114
+ })
115
+
116
+ it('hangs from the right edge when the domain is negative-only', () => {
117
+ const { container } = render(
118
+ <CategoryBar
119
+ value={-1}
120
+ minValue={-4}
121
+ maxValue={0}
122
+ color='rgb(0, 0, 0)'
123
+ />,
124
+ )
125
+ const fill = getFill(container)!
126
+ expect(fill.style.left).toBe('75%')
127
+ expect(fill.style.width).toBe('25%')
128
+ })
129
+ })
64
130
  })
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from 'react'
1
2
  import { Box } from '@mui/material'
2
3
  import type { CategorySize } from '../types'
3
4
  import { styles } from '../style'
@@ -5,8 +6,15 @@ import { styles } from '../style'
5
6
  export interface CategoryBarProps {
6
7
  /** Numeric value driving the fill width. */
7
8
  value: number
8
- /** Denominator for the percentage fill. `0` → empty bar (no division by zero). */
9
+ /** Upper end of the domain. `maxValue === minValue` → empty bar (no division by zero). */
9
10
  maxValue: number
11
+ /**
12
+ * Lower end of the domain. `0` (default) keeps the positive-only bar
13
+ * anchored at the left edge; a negative value moves the zero to
14
+ * `-minValue / (maxValue - minValue)` and bars grow from there in either
15
+ * direction, keeping the fill `color` whatever the sign.
16
+ */
17
+ minValue?: number
10
18
  /** Fill color. Honors any CSS color or MUI theme token. */
11
19
  color: string
12
20
  /**
@@ -16,6 +24,11 @@ export interface CategoryBarProps {
16
24
  * size-invariant.
17
25
  */
18
26
  size?: CategorySize
27
+ /**
28
+ * Draw the zero tick when the domain is signed. `false` when the parent
29
+ * draws its own zero line (multi-series rows span it across every bar).
30
+ */
31
+ zeroTick?: boolean
19
32
  }
20
33
 
21
34
  /**
@@ -27,23 +40,66 @@ export interface CategoryBarProps {
27
40
  export function CategoryBar({
28
41
  value,
29
42
  maxValue,
43
+ minValue = 0,
30
44
  color,
31
45
  size = 'small',
46
+ zeroTick = true,
32
47
  }: CategoryBarProps) {
33
- const pct = maxValue > 0 ? (value / maxValue) * 100 : 0
48
+ const range = maxValue - minValue
49
+ const leftPct =
50
+ range > 0 ? ((Math.min(0, value) - minValue) / range) * 100 : 0
51
+ const pct = range > 0 ? (Math.abs(value) / range) * 100 : 0
52
+ const hasZeroTick = zeroTick && minValue < 0 && maxValue > 0
34
53
  // Width + color rendered as inline `style` (not `sx`) to avoid
35
54
  // generating a new emotion class for every distinct value/color pair
36
55
  // — also makes the rendered DOM testable without computed-style math.
37
56
  return (
38
- <Box sx={styles.bar[size]} data-size={size}>
57
+ <ZeroTickWrap zeroPct={hasZeroTick ? (-minValue / range) * 100 : undefined}>
58
+ <Box sx={styles.bar[size]} data-size={size}>
59
+ <Box
60
+ sx={styles.barFill[size]}
61
+ style={{
62
+ left: `${leftPct}%`,
63
+ width: `${pct}%`,
64
+ backgroundColor: color,
65
+ // The end that grows out of the zero is square; only the far
66
+ // end keeps the rounded corners.
67
+ ...(value < 0
68
+ ? { borderTopRightRadius: 0, borderBottomRightRadius: 0 }
69
+ : { borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }),
70
+ }}
71
+ // Tag the fill so an ancestor row's `:hover` selector can target
72
+ // it (`&:hover [data-bar-fill]`) — the brightening affordance now
73
+ // fires from anywhere in the row, not only the bar track.
74
+ data-bar-fill='true'
75
+ />
76
+ </Box>
77
+ </ZeroTickWrap>
78
+ )
79
+ }
80
+
81
+ /**
82
+ * Wraps a bar track and, when `zeroPct` is set, marks the zero with a tick
83
+ * that overhangs the track. Positive-only, negative-only and all-zero bars
84
+ * pass `undefined` and get no tick.
85
+ */
86
+ export function ZeroTickWrap({
87
+ zeroPct,
88
+ children,
89
+ }: {
90
+ zeroPct: number | undefined
91
+ children: ReactNode
92
+ }) {
93
+ if (zeroPct === undefined) return children
94
+ return (
95
+ <Box sx={styles.barWrap}>
39
96
  <Box
40
- sx={styles.barFill[size]}
41
- style={{ width: `${pct}%`, backgroundColor: color }}
42
- // Tag the fill so an ancestor row's `:hover` selector can target
43
- // it (`&:hover [data-bar-fill]`) — the brightening affordance now
44
- // fires from anywhere in the row, not only the bar track.
45
- data-bar-fill='true'
97
+ aria-hidden
98
+ data-zero-tick='true'
99
+ sx={styles.zeroTick}
100
+ style={{ left: `${zeroPct}%` }}
46
101
  />
102
+ {children}
47
103
  </Box>
48
104
  )
49
105
  }
@@ -15,6 +15,8 @@ export interface CategoryRowMultiProps {
15
15
  colors: readonly string[]
16
16
  /** Shared max across all series + rows (or `maxOverride`). */
17
17
  maxValue: number
18
+ /** Lower end of the shared domain (`0` for positive-only data). */
19
+ minValue?: number
18
20
  formatter: (n: number) => string
19
21
  selected: boolean
20
22
  onToggle: (name: CategoryKey) => void
@@ -40,11 +42,13 @@ export function CategoryRowMulti({
40
42
  values,
41
43
  colors,
42
44
  maxValue,
45
+ minValue,
43
46
  formatter,
44
47
  selected,
45
48
  onToggle,
46
49
  size,
47
50
  }: CategoryRowMultiProps) {
51
+ const min = minValue ?? 0
48
52
  const handleKey = (e: KeyboardEvent<HTMLDivElement>): void => {
49
53
  if (e.key === 'Enter' || e.key === ' ') {
50
54
  e.preventDefault()
@@ -63,6 +67,21 @@ export function CategoryRowMulti({
63
67
  <Typography variant='body2' sx={styles.multiName}>
64
68
  {displayName ?? name}
65
69
  </Typography>
70
+ {min < 0 && maxValue > 0 && (
71
+ <Box
72
+ aria-hidden
73
+ sx={styles.multiZeroArea}
74
+ // Row 1 is the label; the bars fill the next `values.length` rows.
75
+ // Placed before the bars so their tracks paint over the line.
76
+ style={{ gridRow: `2 / span ${values.length}` }}
77
+ >
78
+ <Box
79
+ data-zero-tick='true'
80
+ sx={styles.zeroTick}
81
+ style={{ left: `${(-min / (maxValue - min)) * 100}%` }}
82
+ />
83
+ </Box>
84
+ )}
66
85
  {values.map((v, i) => (
67
86
  // Multi-bar rows iterate per series — the bar belongs to series `i`,
68
87
  // and the row is keyed on the parent's `name`, so a composite of
@@ -72,8 +91,10 @@ export function CategoryRowMulti({
72
91
  <CategoryBar
73
92
  value={v}
74
93
  maxValue={maxValue}
94
+ minValue={minValue}
75
95
  color={colors[i] ?? ''}
76
96
  size={size}
97
+ zeroTick={false}
77
98
  />
78
99
  </Box>
79
100
  <Typography variant='body2' sx={styles.value}>
@@ -11,6 +11,8 @@ export interface CategoryRowSingleProps {
11
11
  displayName?: string | number
12
12
  value: number
13
13
  maxValue: number
14
+ /** Lower end of the shared domain (`0` for positive-only data). */
15
+ minValue?: number
14
16
  color: string
15
17
  formatter: (n: number) => string
16
18
  selected: boolean
@@ -36,6 +38,7 @@ export function CategoryRowSingle({
36
38
  displayName,
37
39
  value,
38
40
  maxValue,
41
+ minValue,
39
42
  color,
40
43
  formatter,
41
44
  selected,
@@ -68,6 +71,7 @@ export function CategoryRowSingle({
68
71
  <CategoryBar
69
72
  value={value}
70
73
  maxValue={maxValue}
74
+ minValue={minValue}
71
75
  color={color}
72
76
  size={size}
73
77
  />
@@ -25,6 +25,11 @@ export interface CategoryRowStackedProps {
25
25
  onToggle: (name: CategoryKey) => void
26
26
  /** Bar visual density. Forwarded to the inner {@link CategoryBarStacked}. */
27
27
  size?: CategorySize
28
+ /**
29
+ * Where the list's zero sits (% of the track), shared by every row so the
30
+ * zero lines up: `0` positive-only, `50` signed, `100` negative-only.
31
+ */
32
+ zeroPct?: number
28
33
  }
29
34
 
30
35
  /**
@@ -40,6 +45,10 @@ export interface CategoryRowStackedProps {
40
45
  * total relative to other rows. The total numeric value is still shown in
41
46
  * the header so the per-row magnitude isn't lost.
42
47
  *
48
+ * Signed data diverges from `zeroPct`: positives stack rightwards and
49
+ * negatives leftwards, and whichever side is longer reaches its edge of the
50
+ * track. The header total is the signed sum.
51
+ *
43
52
  * Visual selection / dim signal lives entirely in the segment colors
44
53
  * (`colors` prop) — every series in a dimmed row receives
45
54
  * `theme.palette.action.disabled`. The bar visually collapses to a single
@@ -56,6 +65,7 @@ export function CategoryRowStacked({
56
65
  selected,
57
66
  onToggle,
58
67
  size,
68
+ zeroPct = 0,
59
69
  }: CategoryRowStackedProps) {
60
70
  const handleKey = (e: KeyboardEvent<HTMLDivElement>): void => {
61
71
  if (e.key === 'Enter' || e.key === ' ') {
@@ -64,6 +74,18 @@ export function CategoryRowStacked({
64
74
  }
65
75
  }
66
76
  const total = values.reduce((a, b) => a + b, 0)
77
+ let pos = 0
78
+ let neg = 0
79
+ for (const v of values) {
80
+ if (v > 0) pos += v
81
+ else neg -= v
82
+ }
83
+ // Magnitude that would fill the whole track, picked so the longer side
84
+ // just reaches its edge: `pos` spans `100 - zeroPct`, `neg` spans `zeroPct`.
85
+ const scale = Math.max(
86
+ zeroPct < 100 ? (pos * 100) / (100 - zeroPct) : 0,
87
+ zeroPct > 0 ? (neg * 100) / zeroPct : 0,
88
+ )
67
89
  return (
68
90
  <Box
69
91
  role='button'
@@ -84,7 +106,8 @@ export function CategoryRowStacked({
84
106
  <CategoryBarStacked
85
107
  values={values}
86
108
  colors={colors}
87
- maxValue={total}
109
+ maxValue={scale}
110
+ zeroPct={zeroPct}
88
111
  size={size}
89
112
  />
90
113
  <Box sx={styles.stackedBreakdown}>
@@ -28,17 +28,19 @@ const bar: Record<CategorySize, SxProps<Theme>> = {
28
28
  const barFill: Record<CategorySize, SxProps<Theme>> = {
29
29
  small: {
30
30
  position: 'absolute',
31
- inset: '0 auto 0 0',
31
+ top: 0,
32
+ bottom: 0,
32
33
  borderRadius: 1,
33
34
  transition:
34
- 'width 300ms ease-in-out, background-color 150ms ease, filter 150ms ease',
35
+ 'left 300ms ease-in-out, width 300ms ease-in-out, background-color 150ms ease, filter 150ms ease',
35
36
  },
36
37
  medium: {
37
38
  position: 'absolute',
38
- inset: '0 auto 0 0',
39
+ top: 0,
40
+ bottom: 0,
39
41
  borderRadius: 0.25,
40
42
  transition:
41
- 'width 300ms ease-in-out, background-color 150ms ease, filter 150ms ease',
43
+ 'left 300ms ease-in-out, width 300ms ease-in-out, background-color 150ms ease, filter 150ms ease',
42
44
  },
43
45
  }
44
46
 
@@ -71,13 +73,47 @@ export const styles = {
71
73
  position: 'relative',
72
74
  width: '100%',
73
75
  },
74
- // Flat list of category rows. Holds both single + multi rows.
76
+ // Flat list of category rows. A grid rather than a flex column so the
77
+ // multi-series rows can share one value column through `subgrid`: with
78
+ // every bar track the same width, the zero ticks line up across rows.
75
79
  list: {
76
- display: 'flex',
77
- flexDirection: 'column',
80
+ position: 'relative',
81
+ display: 'grid',
82
+ gridTemplateColumns: 'minmax(0, 1fr)',
78
83
  gap: 1,
79
84
  py: 0.5,
80
85
  },
86
+ // Layered on `list` for unstacked multi-series: bars | values.
87
+ listMulti: {
88
+ gridTemplateColumns: 'minmax(0, 1fr) max-content',
89
+ },
90
+ // Zero tick for signed data: one per bar track, drawn outside the track's
91
+ // `overflow: hidden` so it can stand 6px proud of it on both sides.
92
+ // Tracks share a width (see `listMulti`), so the ticks line up by rows.
93
+ barWrap: {
94
+ position: 'relative',
95
+ },
96
+ // Multi-series rows draw one zero line through every series bar instead
97
+ // of a tick per bar: this box is the row's bar column (grid area set
98
+ // inline) and holds a `zeroTick`, so the line stays out of the label.
99
+ multiZeroArea: {
100
+ position: 'absolute',
101
+ inset: 0,
102
+ gridColumn: '1 / 2',
103
+ pointerEvents: 'none',
104
+ },
105
+ zeroTick: {
106
+ position: 'absolute',
107
+ top: -6,
108
+ bottom: -6,
109
+ width: '1px',
110
+ // Centred on the zero so both halves of the bar meet it evenly. No
111
+ // z-index: it comes before the track in the DOM, so the bar paints over
112
+ // it and only the overhang shows.
113
+ transform: 'translateX(-50%)',
114
+ bgcolor: 'text.disabled',
115
+ pointerEvents: 'none',
116
+ },
81
117
  // Layered on `list` only in scroll mode (`maxItems === 0`): right padding
82
118
  // so the bars + right-aligned values clear the scrollbar. Right side only
83
119
  // — the left edge stays at 0 so content stays aligned with the capped
@@ -91,6 +127,7 @@ export const styles = {
91
127
  // bar fills the row width below. Mirrors `rowMulti` for visual
92
128
  // consistency.
93
129
  rowSingle: {
130
+ gridColumn: '1 / -1',
94
131
  display: 'flex',
95
132
  flexDirection: 'column',
96
133
  gap: 0.5,
@@ -124,10 +161,14 @@ export const styles = {
124
161
  // Flex column: label fills the top row; bar+value pairs stack below.
125
162
  // Bars get full track width — better legibility for N>=2 series than a
126
163
  // shared grid would give.
164
+ // Spans the list and adopts its columns, so every row's value column is
165
+ // as wide as the widest value in the list.
127
166
  rowMulti: {
128
- display: 'flex',
129
- flexDirection: 'column',
130
- gap: 0.5,
167
+ position: 'relative',
168
+ gridColumn: '1 / -1',
169
+ display: 'grid',
170
+ gridTemplateColumns: 'subgrid',
171
+ rowGap: 0.5,
131
172
  // py: 0.5,
132
173
  // px: 0.5,
133
174
  cursor: 'pointer',
@@ -155,6 +196,7 @@ export const styles = {
155
196
  fontWeight: 'medium',
156
197
  },
157
198
  multiName: {
199
+ gridColumn: '1 / -1',
158
200
  overflow: 'hidden',
159
201
  whiteSpace: 'nowrap',
160
202
  textOverflow: 'ellipsis',
@@ -171,6 +213,7 @@ export const styles = {
171
213
  // minWidth here is also harmless in that context.
172
214
  minWidth: 48,
173
215
  textAlign: 'right',
216
+ alignSelf: 'center',
174
217
  },
175
218
 
176
219
  // ── Bar (track + fill) ────────────────────────────────────────────
@@ -184,13 +227,12 @@ export const styles = {
184
227
 
185
228
  // ── Multi-series internals ────────────────────────────────────────
186
229
  // One [bar | value] flex row per series, inside `rowMulti`'s column.
230
+ // `contents` hands the bar and the value to `rowMulti`'s subgrid cells.
187
231
  multiBarRow: {
188
- display: 'flex',
189
- alignItems: 'center',
190
- gap: 1,
232
+ display: 'contents',
191
233
  },
192
234
  multiBarContainer: {
193
- flex: 1,
235
+ alignSelf: 'center',
194
236
  },
195
237
 
196
238
  // ── Stacked-mode row ──────────────────────────────────────────────
@@ -198,6 +240,7 @@ export const styles = {
198
240
  // focus ring) but stack three children vertically: header line, bar,
199
241
  // breakdown line.
200
242
  rowStacked: {
243
+ gridColumn: '1 / -1',
201
244
  display: 'flex',
202
245
  flexDirection: 'column',
203
246
  gap: 0.5,
@@ -285,6 +328,7 @@ export const styles = {
285
328
  // (no parentheses). Only the label is the click target when interactive;
286
329
  // the count is always static text beside it.
287
330
  otherRow: {
331
+ gridColumn: '1 / -1',
288
332
  display: 'flex',
289
333
  alignItems: 'center',
290
334
  gap: 1,
@@ -57,14 +57,50 @@ export const styles = {
57
57
  height: ({ spacing }: Theme) => spacing(0.35),
58
58
  zIndex: 1,
59
59
  },
60
+ // Title button, then Actions / Options, then the chevron, as siblings.
61
+ // Same spacing as when they all sat inside the summary: its 16px end
62
+ // padding moves to the row, the content's 6px end padding sits before
63
+ // the chevron.
64
+ header: {
65
+ display: 'flex',
66
+ alignItems: 'center',
67
+ gap: ({ spacing }: Theme) => spacing(0.5),
68
+ minHeight: ({ spacing }: Theme) => spacing(7),
69
+ paddingInlineEnd: ({ spacing }: Theme) => spacing(2),
70
+ },
60
71
  summary: {
72
+ flex: 1,
73
+ minWidth: 0,
61
74
  minHeight: ({ spacing }: Theme) => spacing(7),
75
+ paddingInlineEnd: 0,
62
76
  '& .MuiAccordionSummary-content': {
63
- gap: ({ spacing }: Theme) => spacing(0.5),
64
- paddingInlineEnd: ({ spacing }: Theme) => spacing(0.75),
65
77
  alignItems: 'center',
78
+ minWidth: 0,
79
+ marginInlineEnd: 0,
80
+ paddingInlineEnd: 0,
66
81
  },
67
82
  },
83
+ // No chevron (disabled): keep the actions where they sat when the
84
+ // chevron's slot was empty — 10px further from the edge.
85
+ headerNoIcon: {
86
+ paddingInlineEnd: ({ spacing }: Theme) => spacing(3.25),
87
+ },
88
+ // Looks like the icon the summary used to render in its
89
+ // `expandIconWrapper`: 18px, secondary text colour, rotated when open.
90
+ expandIcon: {
91
+ display: 'flex',
92
+ marginInlineStart: ({ spacing }: Theme) => spacing(0.75),
93
+ color: 'text.secondary',
94
+ cursor: 'pointer',
95
+ '& svg': { width: 18, height: 18, color: 'inherit' },
96
+ transition: ({ transitions }: Theme) =>
97
+ transitions.create('transform', {
98
+ duration: transitions.duration.shortest,
99
+ }),
100
+ },
101
+ expanded: {
102
+ transform: 'rotate(180deg)',
103
+ },
68
104
  // Disabled state — only the collapse toggle is inert (enforced by the
69
105
  // guarded `onChange` handler, not `pointer-events`). Actions and Options in
70
106
  // the summary row, and the details panel, all keep their events. We just
@@ -14,8 +14,8 @@ export interface ActionsProps {
14
14
  * pointer devices), and stay full-opacity when a descendant is marked with
15
15
  * `.active` — typically applied by toggled actions.
16
16
  *
17
- * The container also stops click propagation so interacting with an action
18
- * doesn't toggle the wrapper's collapse.
17
+ * The container also stops click propagation, so a click on an action never
18
+ * reaches handlers further up the widget.
19
19
  */
20
20
  export function Actions({ sx, children }: ActionsProps) {
21
21
  return (
@@ -112,11 +112,41 @@ describe('<Wrapper>', () => {
112
112
  )
113
113
  const actionBtn = screen.getByTestId('action-btn')
114
114
  const bodyContent = screen.getByTestId('body-content')
115
- // The action lives inside the AccordionSummary, the body inside AccordionDetails.
116
- expect(actionBtn.closest('.MuiAccordionSummary-root')).not.toBeNull()
115
+ // The action lives in the header row, beside the summary button rather
116
+ // than inside it (a <button> can't contain another); the body lives in
117
+ // AccordionDetails.
118
+ expect(actionBtn.closest('.widget-wrapper-header')).not.toBeNull()
119
+ expect(actionBtn.closest('.MuiAccordionSummary-root')).toBeNull()
117
120
  expect(bodyContent.closest('.MuiAccordionDetails-root')).not.toBeNull()
118
121
  })
119
122
 
123
+ it('never nests a button inside another', () => {
124
+ const { container } = render(
125
+ withProvider(
126
+ 'wrap-6b',
127
+ <Wrapper title='t'>
128
+ <Actions>
129
+ <button type='button'>A</button>
130
+ </Actions>
131
+ </Wrapper>,
132
+ ),
133
+ )
134
+ expect(container.querySelector('button button')).toBeNull()
135
+ })
136
+
137
+ it('clicking the chevron toggles the wrapper', () => {
138
+ const { container } = render(
139
+ withProvider('wrap-6c', <Wrapper title='t'>body</Wrapper>),
140
+ )
141
+ const summary = screen.getByRole('button', { name: 'Collapse' })
142
+ expect(summary.getAttribute('aria-expanded')).toBe('true')
143
+ const chevron = container.querySelector(
144
+ '.widget-wrapper-header [aria-hidden]',
145
+ )
146
+ fireEvent.click(chevron!)
147
+ expect(summary.getAttribute('aria-expanded')).toBe('false')
148
+ })
149
+
120
150
  it('shows a LinearProgress at the top when the store reports isFetching', () => {
121
151
  render(
122
152
  withProvider(