@automattic/charts 1.1.0 → 1.2.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.
@@ -1,6 +1,7 @@
1
1
  import { Group } from '@visx/group';
2
2
  import { LegendItem, LegendLabel, LegendOrdinal, LegendShape } from '@visx/legend';
3
3
  import { scaleOrdinal } from '@visx/scale';
4
+ import { Stack } from '@wordpress/ui';
4
5
  import clsx from 'clsx';
5
6
  import {
6
7
  type RefAttributes,
@@ -16,10 +17,11 @@ import { valueOrIdentity, valueOrIdentityString, labelTransformFactory } from '.
16
17
  import styles from './base-legend.module.scss';
17
18
  import type { BaseLegendProps } from '../types';
18
19
 
19
- const orientationToFlexDirection = {
20
- horizontal: 'row' as const,
21
- vertical: 'column' as const,
22
- };
20
+ const ALIGNMENT_TO_FLEX = {
21
+ start: 'flex-start',
22
+ center: 'center',
23
+ end: 'flex-end',
24
+ } as const;
23
25
 
24
26
  // Component for legend text with truncation detection
25
27
  // Moved outside BaseLegend to prevent recreation on every render
@@ -159,6 +161,8 @@ export const BaseLegend: ForwardRefExoticComponent<
159
161
  [ interactive, handleLegendClick ]
160
162
  );
161
163
 
164
+ const flexAlignment = ALIGNMENT_TO_FLEX[ alignment ] ?? 'center';
165
+
162
166
  return render ? (
163
167
  render( items )
164
168
  ) : (
@@ -168,20 +172,17 @@ export const BaseLegend: ForwardRefExoticComponent<
168
172
  labelTransform={ labelTransform }
169
173
  >
170
174
  { labels => (
171
- <div
175
+ <Stack
172
176
  ref={ ref }
177
+ direction={ orientation === 'vertical' ? 'column' : 'row' }
178
+ gap={ orientation === 'vertical' ? 'sm' : 'lg' }
179
+ align={ orientation === 'vertical' ? flexAlignment : undefined }
180
+ justify={ orientation === 'horizontal' ? flexAlignment : undefined }
181
+ wrap={ orientation === 'horizontal' ? 'wrap' : undefined }
173
182
  role="list"
174
183
  data-testid={ `legend-${ orientation }` }
175
- className={ clsx(
176
- styles.legend,
177
- styles[ `legend--${ orientation }` ],
178
- styles[ `legend--alignment-${ alignment }` ],
179
- className
180
- ) }
181
- style={ {
182
- flexDirection: orientationToFlexDirection[ orientation ],
183
- ...theme.legend?.containerStyles,
184
- } }
184
+ className={ clsx( styles.legend, className ) }
185
+ style={ theme.legend?.containerStyles }
185
186
  >
186
187
  { labels.map( ( label, i ) => {
187
188
  const visible = isSeriesVisible( label.text );
@@ -257,28 +258,29 @@ export const BaseLegend: ForwardRefExoticComponent<
257
258
  labelClassName
258
259
  ) }
259
260
  style={ {
260
- justifyContent: labelJustifyContent,
261
261
  flex: labelFlex,
262
262
  margin: labelMargin,
263
263
  ...theme.legend?.labelStyles,
264
264
  } }
265
265
  >
266
- <LegendText
267
- text={ label.text }
268
- textOverflow={ textOverflow }
269
- maxWidth={ maxWidth }
270
- />
271
- { matchedItem?.value != null && matchedItem.value !== '' && (
272
- <span className={ styles[ 'legend-item-value' ] }>
273
- { '\u00A0' }
274
- { matchedItem.value }
275
- </span>
276
- ) }
266
+ <Stack align="center" gap="sm" justify={ labelJustifyContent }>
267
+ <LegendText
268
+ text={ label.text }
269
+ textOverflow={ textOverflow }
270
+ maxWidth={ maxWidth }
271
+ />
272
+ { matchedItem?.value != null && matchedItem.value !== '' && (
273
+ <span className={ styles[ 'legend-item-value' ] }>
274
+ { '\u00A0' }
275
+ { matchedItem.value }
276
+ </span>
277
+ ) }
278
+ </Stack>
277
279
  </LegendLabel>
278
280
  </LegendItem>
279
281
  );
280
282
  } ) }
281
- </div>
283
+ </Stack>
282
284
  ) }
283
285
  </LegendOrdinal>
284
286
  );
@@ -1,9 +1,9 @@
1
1
  .tooltip {
2
- padding: 0.5rem;
2
+ padding: var(--wpds-dimension-padding-sm, 8px);
3
3
  background-color: rgba(0, 0, 0, 0.85);
4
4
  color: #fff;
5
- border-radius: 4px;
6
- font-size: var(--wpds-font-size-md, 13px);
5
+ border-radius: var(--wpds-border-radius-md, 4px);
6
+ font-size: var(--wpds-typography-font-size-md, 13px);
7
7
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
8
8
  position: absolute;
9
9
  pointer-events: none;
@@ -2,8 +2,8 @@
2
2
  display: inline-flex;
3
3
  align-items: center;
4
4
  gap: 0.125em;
5
- font-size: var(--wpds-font-size-md, 13px);
6
- font-weight: var(--wpds-font-weight-medium, 499);
5
+ font-size: var(--wpds-typography-font-size-md, 13px);
6
+ font-weight: var(--wpds-typography-font-weight-medium, 499);
7
7
  line-height: 1;
8
8
 
9
9
  &--up {