@wallarm-org/design-system 0.32.0 → 0.32.1
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/dist/components/SimpleCharts/PieChart/PieChartCenter.d.ts +42 -1
- package/dist/components/SimpleCharts/PieChart/PieChartCenter.js +29 -4
- package/dist/components/SimpleCharts/PieChart/PieChartContext.d.ts +1 -0
- package/dist/components/SimpleCharts/PieChart/PieChartContext.js +3 -1
- package/dist/components/SimpleCharts/PieChart/PieChartDonut.js +3 -2
- package/dist/components/SimpleCharts/PieChart/PieChartLegendItem.js +3 -1
- package/dist/components/SimpleCharts/PieChart/PieChartSkeleton.js +2 -1
- package/dist/components/SimpleCharts/PieChart/constants.d.ts +2 -2
- package/dist/components/SimpleCharts/PieChart/constants.js +2 -2
- package/dist/components/SimpleCharts/PieChart/index.d.ts +1 -1
- package/dist/components/SimpleCharts/index.d.ts +1 -1
- package/dist/metadata/components.json +26 -2
- package/package.json +1 -1
|
@@ -1,13 +1,54 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type FC, type HTMLAttributes, type ReactNode, type Ref } from 'react';
|
|
2
|
+
import { type PieChartDatum } from './PieChartContext';
|
|
2
3
|
export interface PieChartCenterProps extends HTMLAttributes<HTMLDivElement> {
|
|
3
4
|
ref?: Ref<HTMLDivElement>;
|
|
4
5
|
}
|
|
5
6
|
export declare const PieChartCenter: FC<PieChartCenterProps>;
|
|
6
7
|
export interface PieChartCenterValueProps extends HTMLAttributes<HTMLSpanElement> {
|
|
7
8
|
ref?: Ref<HTMLSpanElement>;
|
|
9
|
+
/**
|
|
10
|
+
* When `true` (default), hovering a slice or legend row replaces `children` with the
|
|
11
|
+
* hovered datum's value (formatted via `formatHoveredValue`). Set to `false` to keep
|
|
12
|
+
* `children` visible regardless of hover state — useful when the centre value should
|
|
13
|
+
* always reflect the unfiltered total.
|
|
14
|
+
*/
|
|
15
|
+
hoverSync?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Formatter applied to the hovered datum when `hoverSync` is enabled. Defaults to
|
|
18
|
+
* `datum.value.toLocaleString()`. Pass a custom formatter to keep the hover format
|
|
19
|
+
* aligned with whatever formatter produced `children` (e.g. compact notation, units).
|
|
20
|
+
*/
|
|
21
|
+
formatHoveredValue?: (datum: PieChartDatum) => ReactNode;
|
|
8
22
|
}
|
|
9
23
|
export declare const PieChartCenterValue: FC<PieChartCenterValueProps>;
|
|
24
|
+
/**
|
|
25
|
+
* CLDR plural categories supported by `Intl.PluralRules`. `other` is required as the
|
|
26
|
+
* fallback for any category the rules object does not define.
|
|
27
|
+
*/
|
|
28
|
+
export interface PieChartCenterLabelPluralRules {
|
|
29
|
+
zero?: ReactNode;
|
|
30
|
+
one?: ReactNode;
|
|
31
|
+
two?: ReactNode;
|
|
32
|
+
few?: ReactNode;
|
|
33
|
+
many?: ReactNode;
|
|
34
|
+
other: ReactNode;
|
|
35
|
+
/** BCP-47 locale tag forwarded to `Intl.PluralRules`. Defaults to `'en'`. */
|
|
36
|
+
locale?: string;
|
|
37
|
+
}
|
|
10
38
|
export interface PieChartCenterLabelProps extends HTMLAttributes<HTMLSpanElement> {
|
|
11
39
|
ref?: Ref<HTMLSpanElement>;
|
|
40
|
+
/**
|
|
41
|
+
* When `true` (default), the label tracks the hovered slice/legend row — so a
|
|
42
|
+
* `pluralize` rules object picks the form for the hovered datum's value rather than
|
|
43
|
+
* the chart total. Has no effect when `pluralize` is omitted.
|
|
44
|
+
*/
|
|
45
|
+
hoverSync?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Optional pluralization rules. When provided, the label content is selected from
|
|
48
|
+
* the rules using `Intl.PluralRules` for the currently visible count (the hovered
|
|
49
|
+
* datum's value when `hoverSync` is on, otherwise the chart total). When omitted,
|
|
50
|
+
* `children` renders unchanged.
|
|
51
|
+
*/
|
|
52
|
+
pluralize?: PieChartCenterLabelPluralRules;
|
|
12
53
|
}
|
|
13
54
|
export declare const PieChartCenterLabel: FC<PieChartCenterLabelProps>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useMemo } from "react";
|
|
2
3
|
import { cn } from "../../../utils/cn.js";
|
|
3
4
|
import { useTestId } from "../../../utils/testId.js";
|
|
4
5
|
import { pieChartCenterClasses, pieChartCenterLabelClasses, pieChartCenterValueClasses } from "./classes.js";
|
|
6
|
+
import { PieChartActiveContext, PieChartDataContext } from "./PieChartContext.js";
|
|
5
7
|
const PieChartCenter = ({ className, ref, ...props })=>{
|
|
6
8
|
const testId = useTestId('center');
|
|
7
9
|
return /*#__PURE__*/ jsx("div", {
|
|
@@ -14,25 +16,48 @@ const PieChartCenter = ({ className, ref, ...props })=>{
|
|
|
14
16
|
});
|
|
15
17
|
};
|
|
16
18
|
PieChartCenter.displayName = 'PieChartCenter';
|
|
17
|
-
const
|
|
19
|
+
const defaultFormatHoveredValue = (datum)=>datum.value.toLocaleString();
|
|
20
|
+
const PieChartCenterValue = ({ hoverSync = true, formatHoveredValue = defaultFormatHoveredValue, className, children, ref, ...props })=>{
|
|
18
21
|
const testId = useTestId('center-value');
|
|
22
|
+
const dataCtx = useContext(PieChartDataContext);
|
|
23
|
+
const { activeName } = useContext(PieChartActiveContext);
|
|
24
|
+
const hoveredDatum = hoverSync && null !== activeName ? dataCtx?.byName.get(activeName) ?? null : null;
|
|
25
|
+
const content = hoveredDatum ? formatHoveredValue(hoveredDatum) : children;
|
|
19
26
|
return /*#__PURE__*/ jsx("span", {
|
|
20
27
|
...props,
|
|
21
28
|
ref: ref,
|
|
22
29
|
"data-slot": "pie-chart-center-value",
|
|
23
30
|
"data-testid": testId,
|
|
24
|
-
|
|
31
|
+
"data-hovered": hoveredDatum ? 'true' : void 0,
|
|
32
|
+
className: cn(pieChartCenterValueClasses, className),
|
|
33
|
+
children: content
|
|
25
34
|
});
|
|
26
35
|
};
|
|
27
36
|
PieChartCenterValue.displayName = 'PieChartCenterValue';
|
|
28
|
-
const PieChartCenterLabel = ({ className, ref, ...props })=>{
|
|
37
|
+
const PieChartCenterLabel = ({ hoverSync = true, pluralize, className, children, ref, ...props })=>{
|
|
29
38
|
const testId = useTestId('center-label');
|
|
39
|
+
const dataCtx = useContext(PieChartDataContext);
|
|
40
|
+
const { activeName } = useContext(PieChartActiveContext);
|
|
41
|
+
const hasPluralize = !!pluralize;
|
|
42
|
+
const pluralLocale = pluralize?.locale ?? 'en';
|
|
43
|
+
const pluralRules = useMemo(()=>hasPluralize ? new Intl.PluralRules(pluralLocale) : null, [
|
|
44
|
+
hasPluralize,
|
|
45
|
+
pluralLocale
|
|
46
|
+
]);
|
|
47
|
+
let content = children;
|
|
48
|
+
if (pluralize && pluralRules) {
|
|
49
|
+
const hoveredValue = hoverSync && null !== activeName ? dataCtx?.byName.get(activeName)?.value ?? null : null;
|
|
50
|
+
const count = hoveredValue ?? dataCtx?.total ?? 0;
|
|
51
|
+
const matched = pluralize[pluralRules.select(count)];
|
|
52
|
+
content = void 0 !== matched ? matched : pluralize.other;
|
|
53
|
+
}
|
|
30
54
|
return /*#__PURE__*/ jsx("span", {
|
|
31
55
|
...props,
|
|
32
56
|
ref: ref,
|
|
33
57
|
"data-slot": "pie-chart-center-label",
|
|
34
58
|
"data-testid": testId,
|
|
35
|
-
className: cn(pieChartCenterLabelClasses, className)
|
|
59
|
+
className: cn(pieChartCenterLabelClasses, className),
|
|
60
|
+
children: content
|
|
36
61
|
});
|
|
37
62
|
};
|
|
38
63
|
PieChartCenterLabel.displayName = 'PieChartCenterLabel';
|
|
@@ -54,6 +54,7 @@ export interface PieChartItemContextValue {
|
|
|
54
54
|
active: boolean;
|
|
55
55
|
}
|
|
56
56
|
export declare const EMPTY_SELECTION: Set<string>;
|
|
57
|
+
export declare const isHoverSyncTarget: (target: EventTarget | null | undefined) => boolean;
|
|
57
58
|
export declare const PieChartDataContext: import("react").Context<PieChartDataContextValue | null>;
|
|
58
59
|
export declare const PieChartActiveContext: import("react").Context<PieChartActiveContextValue>;
|
|
59
60
|
export declare const PieChartSelectionContext: import("react").Context<PieChartSelectionContextValue>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createContext } from "react";
|
|
2
2
|
const EMPTY_SELECTION = new Set();
|
|
3
|
+
const HOVER_SYNC_SELECTOR = '[data-slot="pie-chart-legend-item"], [data-slot="pie-chart-slice"]';
|
|
4
|
+
const isHoverSyncTarget = (target)=>target instanceof Element && null !== target.closest(HOVER_SYNC_SELECTOR);
|
|
3
5
|
const PieChartDataContext = createContext(null);
|
|
4
6
|
const PieChartActiveContext = createContext({
|
|
5
7
|
activeName: null
|
|
@@ -8,4 +10,4 @@ const PieChartSelectionContext = createContext({
|
|
|
8
10
|
selectedSet: EMPTY_SELECTION
|
|
9
11
|
});
|
|
10
12
|
const PieChartItemContext = createContext(null);
|
|
11
|
-
export { EMPTY_SELECTION, PieChartActiveContext, PieChartDataContext, PieChartItemContext, PieChartSelectionContext };
|
|
13
|
+
export { EMPTY_SELECTION, PieChartActiveContext, PieChartDataContext, PieChartItemContext, PieChartSelectionContext, isHoverSyncTarget };
|
|
@@ -5,7 +5,7 @@ import { cn } from "../../../utils/cn.js";
|
|
|
5
5
|
import { useTestId } from "../../../utils/testId.js";
|
|
6
6
|
import { pieChartDonutClasses } from "./classes.js";
|
|
7
7
|
import { PIE_DONUT_ANIMATION_BEGIN, PIE_DONUT_ANIMATION_DURATION, PIE_DONUT_CORNER_RADIUS, PIE_DONUT_INNER_RADIUS, PIE_DONUT_OUTER_RADIUS, PIE_DONUT_PADDING_ANGLE, PIE_DONUT_SIZE, PIE_SLICE_FILL } from "./constants.js";
|
|
8
|
-
import { PieChartActiveContext, PieChartDataContext, PieChartSelectionContext } from "./PieChartContext.js";
|
|
8
|
+
import { PieChartActiveContext, PieChartDataContext, PieChartSelectionContext, isHoverSyncTarget } from "./PieChartContext.js";
|
|
9
9
|
const PLACEHOLDER_DATA = [
|
|
10
10
|
{
|
|
11
11
|
name: '',
|
|
@@ -24,7 +24,8 @@ const PieChartDonut = ({ inactiveOpacity = 0.3, disableAnimation = false, classN
|
|
|
24
24
|
}, [
|
|
25
25
|
dataCtx
|
|
26
26
|
]);
|
|
27
|
-
const handleLeave = useCallback(()=>{
|
|
27
|
+
const handleLeave = useCallback((_data, _index, event)=>{
|
|
28
|
+
if (event && isHoverSyncTarget(event.relatedTarget)) return;
|
|
28
29
|
dataCtx?.setActive(null);
|
|
29
30
|
}, [
|
|
30
31
|
dataCtx
|
|
@@ -4,7 +4,7 @@ import { cn } from "../../../utils/cn.js";
|
|
|
4
4
|
import { useTestId } from "../../../utils/testId.js";
|
|
5
5
|
import { clamp01 } from "../lib/clamp01.js";
|
|
6
6
|
import { pieChartLegendItemVariants } from "./classes.js";
|
|
7
|
-
import { PieChartActiveContext, PieChartDataContext, PieChartItemContext, PieChartSelectionContext } from "./PieChartContext.js";
|
|
7
|
+
import { PieChartActiveContext, PieChartDataContext, PieChartItemContext, PieChartSelectionContext, isHoverSyncTarget } from "./PieChartContext.js";
|
|
8
8
|
const PieChartLegendItem = ({ name, value, selected: selectedProp, className, children, ref, onClick, onKeyDown, onMouseEnter, onMouseLeave, onFocus, onBlur, ...props })=>{
|
|
9
9
|
const testId = useTestId('legend-item');
|
|
10
10
|
const dataCtx = useContext(PieChartDataContext);
|
|
@@ -50,6 +50,7 @@ const PieChartLegendItem = ({ name, value, selected: selectedProp, className, ch
|
|
|
50
50
|
const handleMouseLeave = useCallback((event)=>{
|
|
51
51
|
onMouseLeave?.(event);
|
|
52
52
|
if (event.defaultPrevented) return;
|
|
53
|
+
if (isHoverSyncTarget(event.relatedTarget)) return;
|
|
53
54
|
setActive?.(null);
|
|
54
55
|
}, [
|
|
55
56
|
onMouseLeave,
|
|
@@ -67,6 +68,7 @@ const PieChartLegendItem = ({ name, value, selected: selectedProp, className, ch
|
|
|
67
68
|
const handleBlur = useCallback((event)=>{
|
|
68
69
|
onBlur?.(event);
|
|
69
70
|
if (event.defaultPrevented) return;
|
|
71
|
+
if (isHoverSyncTarget(event.relatedTarget)) return;
|
|
70
72
|
setActive?.(null);
|
|
71
73
|
}, [
|
|
72
74
|
onBlur,
|
|
@@ -33,7 +33,8 @@ const PieChartSkeleton = ({ rows = 5, className, ref, 'data-testid': testId, ...
|
|
|
33
33
|
children: /*#__PURE__*/ jsx(Skeleton, {
|
|
34
34
|
width: "120px",
|
|
35
35
|
height: "120px",
|
|
36
|
-
rounded: "full"
|
|
36
|
+
rounded: "full",
|
|
37
|
+
className: "mask-[radial-gradient(circle,transparent_48px,#000_49px)]"
|
|
37
38
|
})
|
|
38
39
|
}),
|
|
39
40
|
/*#__PURE__*/ jsx("div", {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ChartColor } from '../types';
|
|
2
2
|
export declare const PIE_DONUT_SIZE = 120;
|
|
3
3
|
export declare const PIE_DONUT_OUTER_RADIUS = 60;
|
|
4
|
-
export declare const PIE_DONUT_INNER_RADIUS =
|
|
5
|
-
export declare const PIE_DONUT_CORNER_RADIUS =
|
|
4
|
+
export declare const PIE_DONUT_INNER_RADIUS = 48;
|
|
5
|
+
export declare const PIE_DONUT_CORNER_RADIUS = 2;
|
|
6
6
|
export declare const PIE_DONUT_PADDING_ANGLE = 2;
|
|
7
7
|
export declare const PIE_DONUT_ANIMATION_DURATION = 400;
|
|
8
8
|
export declare const PIE_DONUT_ANIMATION_BEGIN = 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const PIE_DONUT_SIZE = 120;
|
|
2
2
|
const PIE_DONUT_OUTER_RADIUS = 60;
|
|
3
|
-
const PIE_DONUT_INNER_RADIUS =
|
|
4
|
-
const PIE_DONUT_CORNER_RADIUS =
|
|
3
|
+
const PIE_DONUT_INNER_RADIUS = 48;
|
|
4
|
+
const PIE_DONUT_CORNER_RADIUS = 2;
|
|
5
5
|
const PIE_DONUT_PADDING_ANGLE = 2;
|
|
6
6
|
const PIE_DONUT_ANIMATION_DURATION = 400;
|
|
7
7
|
const PIE_DONUT_ANIMATION_BEGIN = 0;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { LegendDot, type LegendDotProps } from './LegendDot';
|
|
2
2
|
export { PieChart, type PieChartProps } from './PieChart';
|
|
3
|
-
export { PieChartCenter, PieChartCenterLabel, type PieChartCenterLabelProps, type PieChartCenterProps, PieChartCenterValue, type PieChartCenterValueProps, } from './PieChartCenter';
|
|
3
|
+
export { PieChartCenter, PieChartCenterLabel, type PieChartCenterLabelPluralRules, type PieChartCenterLabelProps, type PieChartCenterProps, PieChartCenterValue, type PieChartCenterValueProps, } from './PieChartCenter';
|
|
4
4
|
export type { PieChartDatum } from './PieChartContext';
|
|
5
5
|
export { PieChartDonut, type PieChartDonutProps } from './PieChartDonut';
|
|
6
6
|
export { PieChartLegend, type PieChartLegendProps } from './PieChartLegend';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { BarList, BarListBar, type BarListBarProps, BarListItem, type BarListItemProps, BarListLabel, type BarListLabelProps, BarListPercent, type BarListPercentProps, type BarListProps, BarListSkeleton, type BarListSkeletonProps, BarListValue, type BarListValueProps, } from './BarList';
|
|
2
2
|
export { Chart, ChartActions, type ChartActionsProps, ChartEmpty, type ChartEmptyProps, ChartHeader, type ChartHeaderProps, type ChartProps, ChartTitle, type ChartTitleProps, } from './Chart';
|
|
3
|
-
export { LegendDot, type LegendDotProps, PieChart, PieChartCenter, PieChartCenterLabel, type PieChartCenterLabelProps, type PieChartCenterProps, PieChartCenterValue, type PieChartCenterValueProps, type PieChartDatum, PieChartDonut, type PieChartDonutProps, PieChartLegend, PieChartLegendItem, type PieChartLegendItemProps, PieChartLegendPercent, type PieChartLegendPercentProps, type PieChartLegendPercentVariant, type PieChartLegendProps, PieChartLegendValue, type PieChartLegendValueProps, type PieChartProps, PieChartSkeleton, type PieChartSkeletonProps, } from './PieChart';
|
|
3
|
+
export { LegendDot, type LegendDotProps, PieChart, PieChartCenter, PieChartCenterLabel, type PieChartCenterLabelPluralRules, type PieChartCenterLabelProps, type PieChartCenterProps, PieChartCenterValue, type PieChartCenterValueProps, type PieChartDatum, PieChartDonut, type PieChartDonutProps, PieChartLegend, PieChartLegendItem, type PieChartLegendItemProps, PieChartLegendPercent, type PieChartLegendPercentProps, type PieChartLegendPercentVariant, type PieChartLegendProps, PieChartLegendValue, type PieChartLegendValueProps, type PieChartProps, PieChartSkeleton, type PieChartSkeletonProps, } from './PieChart';
|
|
4
4
|
export type { ChartColor } from './types';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
3
|
-
"generatedAt": "2026-
|
|
2
|
+
"version": "0.32.0",
|
|
3
|
+
"generatedAt": "2026-05-04T09:33:04.349Z",
|
|
4
4
|
"components": [
|
|
5
5
|
{
|
|
6
6
|
"name": "Alert",
|
|
@@ -28353,6 +28353,18 @@
|
|
|
28353
28353
|
{
|
|
28354
28354
|
"name": "PieChartCenterLabel",
|
|
28355
28355
|
"props": [
|
|
28356
|
+
{
|
|
28357
|
+
"name": "hoverSync",
|
|
28358
|
+
"type": "boolean | undefined",
|
|
28359
|
+
"required": false,
|
|
28360
|
+
"description": "When `true` (default), the label tracks the hovered slice/legend row — so a\n`pluralize` rules object picks the form for the hovered datum's value rather than\nthe chart total. Has no effect when `pluralize` is omitted."
|
|
28361
|
+
},
|
|
28362
|
+
{
|
|
28363
|
+
"name": "pluralize",
|
|
28364
|
+
"type": "PieChartCenterLabelPluralRules | undefined",
|
|
28365
|
+
"required": false,
|
|
28366
|
+
"description": "Optional pluralization rules. When provided, the label content is selected from\nthe rules using `Intl.PluralRules` for the currently visible count (the hovered\ndatum's value when `hoverSync` is on, otherwise the chart total). When omitted,\n`children` renders unchanged."
|
|
28367
|
+
},
|
|
28356
28368
|
{
|
|
28357
28369
|
"name": "defaultChecked",
|
|
28358
28370
|
"type": "boolean | undefined",
|
|
@@ -28903,6 +28915,18 @@
|
|
|
28903
28915
|
{
|
|
28904
28916
|
"name": "PieChartCenterValue",
|
|
28905
28917
|
"props": [
|
|
28918
|
+
{
|
|
28919
|
+
"name": "hoverSync",
|
|
28920
|
+
"type": "boolean | undefined",
|
|
28921
|
+
"required": false,
|
|
28922
|
+
"description": "When `true` (default), hovering a slice or legend row replaces `children` with the\nhovered datum's value (formatted via `formatHoveredValue`). Set to `false` to keep\n`children` visible regardless of hover state — useful when the centre value should\nalways reflect the unfiltered total."
|
|
28923
|
+
},
|
|
28924
|
+
{
|
|
28925
|
+
"name": "formatHoveredValue",
|
|
28926
|
+
"type": "((datum: PieChartDatum) => ReactNode) | undefined",
|
|
28927
|
+
"required": false,
|
|
28928
|
+
"description": "Formatter applied to the hovered datum when `hoverSync` is enabled. Defaults to\n`datum.value.toLocaleString()`. Pass a custom formatter to keep the hover format\naligned with whatever formatter produced `children` (e.g. compact notation, units)."
|
|
28929
|
+
},
|
|
28906
28930
|
{
|
|
28907
28931
|
"name": "defaultChecked",
|
|
28908
28932
|
"type": "boolean | undefined",
|