@economic/taco 2.46.5 → 2.46.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. package/dist/charts/components/Area/AreaChart.d.ts +19 -0
  2. package/dist/charts/components/Bar/BarChart.d.ts +20 -0
  3. package/dist/charts/components/Donut/ActiveShape.d.ts +8 -0
  4. package/dist/charts/components/Donut/CenteredLabel.d.ts +11 -0
  5. package/dist/charts/components/Donut/DonutChart.d.ts +21 -0
  6. package/dist/charts/components/Donut/Legend.d.ts +13 -0
  7. package/dist/charts/components/Donut/util.d.ts +2 -0
  8. package/dist/charts/components/Legend.d.ts +16 -0
  9. package/dist/charts/components/Line/LineChart.d.ts +18 -0
  10. package/dist/charts/components/ResponsiveContainer.d.ts +5 -0
  11. package/dist/charts/components/Tooltip.d.ts +10 -0
  12. package/dist/charts/components/types.d.ts +5 -0
  13. package/dist/charts/utils/color.d.ts +3 -0
  14. package/dist/charts/utils/common.d.ts +37 -0
  15. package/dist/components/RadioGroup/RadioGroup.d.ts +2 -2
  16. package/dist/components/Table3/features/useEditingState.d.ts +1 -1
  17. package/dist/components/Table3/features/useTableEditing.d.ts +4 -3
  18. package/dist/esm/index.css +18 -0
  19. package/dist/esm/packages/taco/src/charts/components/Area/AreaChart.js +67 -0
  20. package/dist/esm/packages/taco/src/charts/components/Area/AreaChart.js.map +1 -0
  21. package/dist/esm/packages/taco/src/charts/components/Bar/BarChart.js +120 -0
  22. package/dist/esm/packages/taco/src/charts/components/Bar/BarChart.js.map +1 -0
  23. package/dist/esm/packages/taco/src/charts/components/Donut/ActiveShape.js +47 -0
  24. package/dist/esm/packages/taco/src/charts/components/Donut/ActiveShape.js.map +1 -0
  25. package/dist/esm/packages/taco/src/charts/components/Donut/CenteredLabel.js +27 -0
  26. package/dist/esm/packages/taco/src/charts/components/Donut/CenteredLabel.js.map +1 -0
  27. package/dist/esm/packages/taco/src/charts/components/Donut/DonutChart.js +170 -0
  28. package/dist/esm/packages/taco/src/charts/components/Donut/DonutChart.js.map +1 -0
  29. package/dist/esm/packages/taco/src/charts/components/Donut/Legend.js +164 -0
  30. package/dist/esm/packages/taco/src/charts/components/Donut/Legend.js.map +1 -0
  31. package/dist/esm/packages/taco/src/charts/components/Donut/util.js +5 -0
  32. package/dist/esm/packages/taco/src/charts/components/Donut/util.js.map +1 -0
  33. package/dist/esm/packages/taco/src/charts/components/Legend.js +145 -0
  34. package/dist/esm/packages/taco/src/charts/components/Legend.js.map +1 -0
  35. package/dist/esm/packages/taco/src/charts/components/Line/LineChart.js +65 -0
  36. package/dist/esm/packages/taco/src/charts/components/Line/LineChart.js.map +1 -0
  37. package/dist/esm/packages/taco/src/charts/components/ResponsiveContainer.js +10 -0
  38. package/dist/esm/packages/taco/src/charts/components/ResponsiveContainer.js.map +1 -0
  39. package/dist/esm/packages/taco/src/charts/components/Tooltip.js +44 -0
  40. package/dist/esm/packages/taco/src/charts/components/Tooltip.js.map +1 -0
  41. package/dist/esm/packages/taco/src/charts/utils/color.js +24 -0
  42. package/dist/esm/packages/taco/src/charts/utils/color.js.map +1 -0
  43. package/dist/esm/packages/taco/src/charts/utils/common.js +34 -0
  44. package/dist/esm/packages/taco/src/charts/utils/common.js.map +1 -0
  45. package/dist/esm/packages/taco/src/components/Input/util.js +1 -1
  46. package/dist/esm/packages/taco/src/components/Input/util.js.map +1 -1
  47. package/dist/esm/packages/taco/src/components/RadioGroup/RadioGroup.js.map +1 -1
  48. package/dist/esm/packages/taco/src/components/Table3/Table3.js +0 -1
  49. package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
  50. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js +4 -33
  51. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js.map +1 -1
  52. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js +1 -1
  53. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js.map +1 -1
  54. package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js +4 -4
  55. package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js.map +1 -1
  56. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js +32 -1
  57. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js.map +1 -1
  58. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js +2 -2
  59. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js.map +1 -1
  60. package/dist/esm/packages/taco/src/components/Table3/useTable3.js +4 -1
  61. package/dist/esm/packages/taco/src/components/Table3/useTable3.js.map +1 -1
  62. package/dist/esm/packages/taco/src/index.js +4 -0
  63. package/dist/esm/packages/taco/src/index.js.map +1 -1
  64. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js +5 -4
  65. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js.map +1 -1
  66. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Body/EmptyStateBody.js +6 -0
  67. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Body/EmptyStateBody.js.map +1 -1
  68. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Actions.js +2 -2
  69. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Actions.js.map +1 -1
  70. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Drag.js +7 -0
  71. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Drag.js.map +1 -1
  72. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Expansion.js +7 -0
  73. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Expansion.js.map +1 -1
  74. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js +2 -1
  75. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js.map +1 -1
  76. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/Row.js +3 -1
  77. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/Row.js.map +1 -1
  78. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/RowContext.js +3 -2
  79. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/RowContext.js.map +1 -1
  80. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +5 -1
  81. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
  82. package/dist/esm/packages/taco/src/utils/colors.js +122 -0
  83. package/dist/esm/packages/taco/src/utils/colors.js.map +1 -0
  84. package/dist/index.css +18 -0
  85. package/dist/index.d.ts +5 -0
  86. package/dist/primitives/Table/Core/components/Body/EmptyStateBody.d.ts +1 -0
  87. package/dist/primitives/Table/Core/components/Row/RowContext.d.ts +2 -1
  88. package/dist/primitives/Table/Core/types.d.ts +1 -0
  89. package/dist/taco.cjs.development.js +881 -55
  90. package/dist/taco.cjs.development.js.map +1 -1
  91. package/dist/taco.cjs.production.min.js +1 -1
  92. package/dist/taco.cjs.production.min.js.map +1 -1
  93. package/package.json +3 -3
  94. package/tailwind.config.js +3 -2
@@ -0,0 +1,170 @@
1
+ import React__default from 'react';
2
+ import cn from 'clsx';
3
+ import { PieChart, Tooltip, Pie, Cell } from 'recharts';
4
+ import { getThemeColor } from '../../utils/color.js';
5
+ import { getTooltipProps } from '../../utils/common.js';
6
+ import { Legend } from './Legend.js';
7
+ import { HOVER_DONUT_WIDTH, DONUT_WIDTH } from './util.js';
8
+ import { CenteredLabel } from './CenteredLabel.js';
9
+ import { ActiveShape } from './ActiveShape.js';
10
+
11
+ const Segment = _ => null;
12
+ const DonutChart = function DonutChart({
13
+ children,
14
+ formatter,
15
+ onClick,
16
+ showLegend = false,
17
+ legendPosition = 'bottom',
18
+ label
19
+ }) {
20
+ const ref = React__default.useRef(null);
21
+ const [radius, setRadius] = React__default.useState(0);
22
+ const [hoveredItem, setHoveredItem] = React__default.useState([]);
23
+ // used for right legends
24
+ const [selectedItem, setSelectedItem] = React__default.useState([]);
25
+ // used for bottom legends
26
+ const [visibleItems, setVisibleItems] = React__default.useState(() => {
27
+ const keys = {};
28
+ React__default.Children.forEach(children, child => {
29
+ keys[child.props.id] = true;
30
+ });
31
+ return keys;
32
+ });
33
+ React__default.useEffect(() => {
34
+ if (ref.current) {
35
+ var _ref$current$parentEl;
36
+ const rect = (_ref$current$parentEl = ref.current.parentElement) === null || _ref$current$parentEl === void 0 ? void 0 : _ref$current$parentEl.getBoundingClientRect();
37
+ if (rect) {
38
+ const width = showLegend ? rect.width / 2 : rect.width;
39
+ const max = rect.height < width ? rect.height : width;
40
+ setRadius(max / 2);
41
+ }
42
+ }
43
+ }, [showLegend]);
44
+ const diameter = radius * 2; // get dimensions of the parent container to find the max radius, so we can fill the container AND always have a 16px wide donut
45
+ const data = React__default.Children.map(children, child => ({
46
+ id: child.props.id,
47
+ color: child.props.color,
48
+ label: child.props.label,
49
+ value: child.props.value
50
+ }));
51
+ const displayedData = data.filter(child => visibleItems[child.id]);
52
+ const total = displayedData.reduce((accum, entry) => accum + entry.value, 0);
53
+ const showTooltip = (!showLegend || legendPosition === 'bottom') && displayedData.length > 0;
54
+ const handleLegendClick = entry => {
55
+ if (legendPosition === 'bottom' && !Array.isArray(entry)) {
56
+ setVisibleItems({
57
+ ...visibleItems,
58
+ [entry.id]: !visibleItems[entry.id]
59
+ });
60
+ } else {
61
+ const nextSelectedItem = Array.isArray(entry) ? entry.map(entryItem => entryItem.id) : [entry.id];
62
+ // Using slice to avoid mutation of the react state 'selectedItem'
63
+ const isCurrentSegmentActive = selectedItem.slice().sort().join(',') === nextSelectedItem.sort().join(',');
64
+ if (onClick && !isCurrentSegmentActive) {
65
+ onClick(entry);
66
+ }
67
+ setSelectedItem(isCurrentSegmentActive ? [] : nextSelectedItem);
68
+ }
69
+ };
70
+ const handlePieClick = React__default.useCallback(pieId => {
71
+ if (onClick && pieId !== undefined) {
72
+ const pieProps = displayedData.find(item => item.id === pieId);
73
+ onClick(pieProps);
74
+ }
75
+ }, [onClick, displayedData]);
76
+ const singlePieDonutChart = displayedData.length === 1;
77
+ const activeShapeColor = React__default.useMemo(() => {
78
+ const getSegmentColor = item => item.reduce((colors, itemId) => {
79
+ const visibleHoveredItem = displayedData.find(dataItem => dataItem.id === itemId);
80
+ if (visibleHoveredItem) {
81
+ colors[visibleHoveredItem.id] = visibleHoveredItem.color;
82
+ }
83
+ return colors;
84
+ }, {});
85
+ const hoveredSegmentColor = getSegmentColor(hoveredItem);
86
+ const selectedSegmentColor = getSegmentColor(selectedItem);
87
+ return legendPosition === 'bottom' || hoveredItem.length !== 0 ? hoveredSegmentColor : selectedSegmentColor;
88
+ }, [hoveredItem, selectedItem, legendPosition]);
89
+ if (ref.current && !radius) {
90
+ return null;
91
+ }
92
+ const getActiveIndex = () => {
93
+ if (hoveredItem.length > 0) {
94
+ return hoveredItem.map(itemId => displayedData.findIndex(element => element.id === itemId));
95
+ }
96
+ return selectedItem.map(selectedItemId => displayedData.findIndex(element => element.id === selectedItemId));
97
+ };
98
+ const content = () => {
99
+ const elements = React__default.Children.toArray(children).filter(child => /*#__PURE__*/React__default.isValidElement(child) && visibleItems[child.props.id]);
100
+ return elements.length > 0 ? elements.map((child, index) => {
101
+ var _getThemeColor;
102
+ return /*#__PURE__*/React__default.createElement(Cell, {
103
+ key: `cell-${index}`,
104
+ name: child.props.label,
105
+ fill: (_getThemeColor = getThemeColor(child.props.color)) !== null && _getThemeColor !== void 0 ? _getThemeColor : getThemeColor('blue-300')
106
+ });
107
+ }) : (/*#__PURE__*/React__default.createElement(Cell, {
108
+ key: "empty-chart",
109
+ name: '',
110
+ fill: getThemeColor('grey-200')
111
+ }));
112
+ };
113
+ return /*#__PURE__*/React__default.createElement("div", {
114
+ className: cn('relative h-full w-full', {
115
+ [`flex `]: showLegend,
116
+ 'flex-col items-center': legendPosition === 'bottom'
117
+ }),
118
+ ref: ref
119
+ }, /*#__PURE__*/React__default.createElement(CenteredLabel, {
120
+ radius: radius,
121
+ legendPosition: legendPosition,
122
+ label: label,
123
+ total: total,
124
+ formatter: formatter,
125
+ showLegend: showLegend
126
+ }), /*#__PURE__*/React__default.createElement(PieChart, {
127
+ data: data,
128
+ height: diameter,
129
+ width: diameter,
130
+ style: {
131
+ transform: 'rotate(90deg) scale(-1,1)'
132
+ }
133
+ }, showTooltip ? (/*#__PURE__*/React__default.createElement(Tooltip, Object.assign({}, getTooltipProps({
134
+ style: {
135
+ transform: 'rotate(90deg) scale(-1,1)'
136
+ },
137
+ singlePieDonutChart
138
+ })))) : null, /*#__PURE__*/React__default.createElement(Pie, {
139
+ isAnimationActive: false,
140
+ activeIndex: getActiveIndex(),
141
+ activeShape: /*#__PURE__*/React__default.createElement(ActiveShape, {
142
+ pieColors: activeShapeColor,
143
+ onClick: handlePieClick
144
+ }),
145
+ data: displayedData.length > 0 ? displayedData : [],
146
+ dataKey: "value",
147
+ innerRadius: radius - HOVER_DONUT_WIDTH - DONUT_WIDTH,
148
+ onMouseEnter: segment => displayedData.length > 0 && setHoveredItem([segment.id]),
149
+ onMouseLeave: () => setHoveredItem([]),
150
+ outerRadius: radius - HOVER_DONUT_WIDTH,
151
+ paddingAngle: 2,
152
+ // Prevents the pie group element from being focusable
153
+ rootTabIndex: -1
154
+ }, content())), showLegend && (/*#__PURE__*/React__default.createElement(Legend, {
155
+ data: data,
156
+ visibleItems: visibleItems,
157
+ onClick: handleLegendClick,
158
+ total: total,
159
+ setHoveredItem: setHoveredItem,
160
+ label: label,
161
+ legendPosition: legendPosition,
162
+ hoveredItem: hoveredItem,
163
+ selectedItem: selectedItem,
164
+ formatter: formatter
165
+ })));
166
+ };
167
+ DonutChart.Segment = Segment;
168
+
169
+ export { DonutChart };
170
+ //# sourceMappingURL=DonutChart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DonutChart.js","sources":["../../../../../../../../src/charts/components/Donut/DonutChart.tsx"],"sourcesContent":["import React from 'react';\nimport * as Recharts from 'recharts';\nimport cn from 'clsx';\n\nimport { Color, getThemeColor } from '../../utils/color';\nimport { getTooltipProps } from '../../utils/common';\nimport { Legend } from './Legend';\nimport { CenteredLabel } from './CenteredLabel';\nimport { ActiveShape } from './ActiveShape';\nimport { DONUT_WIDTH, HOVER_DONUT_WIDTH } from './util';\n\nconst Segment = (_: DonutChartSegmentProps) => null;\n\nexport type DonutChartSegmentProps = {\n color: Color;\n id: string;\n label: string;\n value: number;\n};\n\nexport type SegmentIds = string[];\n\nexport type DonutChartProps = {\n children: React.ReactElement<DonutChartSegmentProps> | React.ReactElement<DonutChartSegmentProps>[];\n formatter?: (value: number) => string;\n onClick?: (segment: DonutChartSegmentProps | DonutChartSegmentProps[]) => void;\n showLegend?: boolean;\n legendPosition?: string;\n label: string;\n};\n\nexport const DonutChart = function DonutChart({\n children,\n formatter,\n onClick,\n showLegend = false,\n legendPosition = 'bottom',\n label,\n}: DonutChartProps) {\n const ref = React.useRef<HTMLDivElement>(null);\n const [radius, setRadius] = React.useState<number>(0);\n\n const [hoveredItem, setHoveredItem] = React.useState<SegmentIds>([]);\n // used for right legends\n const [selectedItem, setSelectedItem] = React.useState<SegmentIds>([]);\n // used for bottom legends\n const [visibleItems, setVisibleItems] = React.useState<Record<string, boolean>>(() => {\n const keys = {};\n\n React.Children.forEach(children, child => {\n keys[child.props.id] = true;\n });\n\n return keys;\n });\n\n React.useEffect(() => {\n if (ref.current) {\n const rect = ref.current.parentElement?.getBoundingClientRect();\n\n if (rect) {\n const width = showLegend ? rect.width / 2 : rect.width;\n const max: number = rect.height < width ? rect.height : width;\n setRadius(max / 2);\n }\n }\n }, [showLegend]);\n\n const diameter = radius * 2; // get dimensions of the parent container to find the max radius, so we can fill the container AND always have a 16px wide donut\n const data: DonutChartSegmentProps[] = React.Children.map(children, child => ({\n id: child.props.id,\n color: child.props.color,\n label: child.props.label,\n value: child.props.value,\n }));\n const displayedData = data.filter(child => visibleItems[child.id]);\n\n const total = displayedData.reduce((accum, entry) => accum + entry.value, 0);\n const showTooltip = (!showLegend || legendPosition === 'bottom') && displayedData.length > 0;\n\n const handleLegendClick = (entry: DonutChartSegmentProps | DonutChartSegmentProps[]): void => {\n if (legendPosition === 'bottom' && !Array.isArray(entry)) {\n setVisibleItems({ ...visibleItems, [entry.id]: !visibleItems[entry.id] });\n } else {\n const nextSelectedItem = Array.isArray(entry) ? entry.map(entryItem => entryItem.id) : [entry.id];\n\n // Using slice to avoid mutation of the react state 'selectedItem'\n const isCurrentSegmentActive = selectedItem.slice().sort().join(',') === nextSelectedItem.sort().join(',');\n\n if (onClick && !isCurrentSegmentActive) {\n onClick(entry);\n }\n\n setSelectedItem(isCurrentSegmentActive ? [] : nextSelectedItem);\n }\n };\n const handlePieClick = React.useCallback(\n (pieId: string | undefined) => {\n if (onClick && pieId !== undefined) {\n const pieProps = displayedData.find(item => item.id === pieId);\n\n onClick(pieProps as DonutChartSegmentProps);\n }\n },\n [onClick, displayedData]\n );\n\n const singlePieDonutChart = displayedData.length === 1;\n const activeShapeColor = React.useMemo(() => {\n const getSegmentColor = (item: SegmentIds) =>\n item.reduce((colors, itemId) => {\n const visibleHoveredItem = displayedData.find(dataItem => dataItem.id === itemId);\n\n if (visibleHoveredItem) {\n colors[visibleHoveredItem.id] = visibleHoveredItem.color;\n }\n\n return colors;\n }, {});\n\n const hoveredSegmentColor = getSegmentColor(hoveredItem);\n const selectedSegmentColor = getSegmentColor(selectedItem);\n\n return legendPosition === 'bottom' || hoveredItem.length !== 0 ? hoveredSegmentColor : selectedSegmentColor;\n }, [hoveredItem, selectedItem, legendPosition]);\n\n if (ref.current && !radius) {\n return null;\n }\n\n const getActiveIndex = () => {\n if (hoveredItem.length > 0) {\n return hoveredItem.map(itemId => displayedData.findIndex(element => element.id === itemId));\n }\n\n return selectedItem.map(selectedItemId => displayedData.findIndex(element => element.id === selectedItemId));\n };\n\n const content = () => {\n const elements = React.Children.toArray(children).filter(\n (child): child is React.ReactElement<DonutChartSegmentProps> =>\n React.isValidElement<DonutChartSegmentProps>(child) && visibleItems[child.props.id]\n );\n\n return elements.length > 0 ? (\n elements.map((child, index) => {\n return (\n <Recharts.Cell\n key={`cell-${index}`}\n name={child.props.label}\n fill={getThemeColor(child.props.color) ?? getThemeColor('blue-300')}\n />\n );\n })\n ) : (\n <Recharts.Cell key=\"empty-chart\" name={''} fill={getThemeColor('grey-200')} />\n );\n };\n\n return (\n <div\n className={cn('relative h-full w-full', {\n [`flex `]: showLegend,\n 'flex-col items-center': legendPosition === 'bottom',\n })}\n ref={ref}>\n <CenteredLabel\n radius={radius}\n legendPosition={legendPosition}\n label={label}\n total={total}\n formatter={formatter}\n showLegend={showLegend}\n />\n\n <Recharts.PieChart data={data} height={diameter} width={diameter} style={{ transform: 'rotate(90deg) scale(-1,1)' }}>\n {showTooltip ? (\n <Recharts.Tooltip\n {...getTooltipProps({\n style: { transform: 'rotate(90deg) scale(-1,1)' },\n singlePieDonutChart,\n })}\n />\n ) : null}\n <Recharts.Pie\n isAnimationActive={false}\n activeIndex={getActiveIndex()}\n activeShape={<ActiveShape pieColors={activeShapeColor} onClick={handlePieClick} />}\n data={displayedData.length > 0 ? displayedData : []}\n dataKey=\"value\"\n innerRadius={radius - HOVER_DONUT_WIDTH - DONUT_WIDTH} // offset the 12px wider hover state, and then make the donut 16px wide\n onMouseEnter={segment => displayedData.length > 0 && setHoveredItem([segment.id])}\n onMouseLeave={() => setHoveredItem([])}\n outerRadius={radius - HOVER_DONUT_WIDTH} // offset the 12px wide hover state\n paddingAngle={2}\n // Prevents the pie group element from being focusable\n rootTabIndex={-1}>\n {content()}\n </Recharts.Pie>\n </Recharts.PieChart>\n {showLegend && (\n <Legend\n data={data}\n visibleItems={visibleItems}\n onClick={handleLegendClick}\n total={total}\n setHoveredItem={setHoveredItem}\n label={label}\n legendPosition={legendPosition}\n hoveredItem={hoveredItem}\n selectedItem={selectedItem}\n formatter={formatter}\n />\n )}\n </div>\n );\n};\n\nDonutChart.Segment = Segment;\n"],"names":["Segment","_","DonutChart","children","formatter","onClick","showLegend","legendPosition","label","ref","React","useRef","radius","setRadius","useState","hoveredItem","setHoveredItem","selectedItem","setSelectedItem","visibleItems","setVisibleItems","keys","Children","forEach","child","props","id","useEffect","current","_ref$current$parentEl","rect","parentElement","getBoundingClientRect","width","max","height","diameter","data","map","color","value","displayedData","filter","total","reduce","accum","entry","showTooltip","length","handleLegendClick","Array","isArray","nextSelectedItem","entryItem","isCurrentSegmentActive","slice","sort","join","handlePieClick","useCallback","pieId","undefined","pieProps","find","item","singlePieDonutChart","activeShapeColor","useMemo","getSegmentColor","colors","itemId","visibleHoveredItem","dataItem","hoveredSegmentColor","selectedSegmentColor","getActiveIndex","findIndex","element","selectedItemId","content","elements","toArray","isValidElement","index","Recharts","key","name","fill","_getThemeColor","getThemeColor","className","cn","CenteredLabel","style","transform","getTooltipProps","isAnimationActive","activeIndex","activeShape","ActiveShape","pieColors","dataKey","innerRadius","HOVER_DONUT_WIDTH","DONUT_WIDTH","onMouseEnter","segment","onMouseLeave","outerRadius","paddingAngle","rootTabIndex","Legend"],"mappings":";;;;;;;;;;AAWA,MAAMA,OAAO,GAAIC,CAAyB,IAAK,IAAI;MAoBtCC,UAAU,GAAG,SAASA,UAAUA,CAAC;EAC1CC,QAAQ;EACRC,SAAS;EACTC,OAAO;EACPC,UAAU,GAAG,KAAK;EAClBC,cAAc,GAAG,QAAQ;EACzBC;CACc;EACd,MAAMC,GAAG,GAAGC,cAAK,CAACC,MAAM,CAAiB,IAAI,CAAC;EAC9C,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,GAAGH,cAAK,CAACI,QAAQ,CAAS,CAAC,CAAC;EAErD,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGN,cAAK,CAACI,QAAQ,CAAa,EAAE,CAAC;;EAEpE,MAAM,CAACG,YAAY,EAAEC,eAAe,CAAC,GAAGR,cAAK,CAACI,QAAQ,CAAa,EAAE,CAAC;;EAEtE,MAAM,CAACK,YAAY,EAAEC,eAAe,CAAC,GAAGV,cAAK,CAACI,QAAQ,CAA0B;IAC5E,M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,0 +1,164 @@
1
+ import React__default from 'react';
2
+ import cn from 'clsx';
3
+ import '../../../components/Icon/components/index.js';
4
+ import { Icon } from '../../../components/Icon/Icon.js';
5
+ import '../../../components/BadgeIcon/BadgeIcon.js';
6
+ import '../../../components/Alert/Alert.js';
7
+ import '../../../utils/mergeRefs.js';
8
+ import '../../../components/Backdrop/Backdrop.js';
9
+ import '../../../components/AlertDialog/AlertDialog.js';
10
+ import '../../../components/Accordion/Accordion.js';
11
+ import '../../../components/VisuallyHidden/VisuallyHidden.js';
12
+ import '../../../components/Badge/Badge.js';
13
+ import '../../../hooks/useMergedRef.js';
14
+ import '../../../utils/keyboard.js';
15
+ import '../../../components/Tooltip/Tooltip.js';
16
+ import '../../../components/IconButton/IconButton.js';
17
+ import '../../../components/Provider/Localization.js';
18
+ import '../../../components/Banner/Banner.js';
19
+ import { Button } from '../../../components/Button/Button.js';
20
+ import '../../../components/Calendar/Calendar.js';
21
+ import '../../../components/Card/Card.js';
22
+ import '../../../components/Spinner/Spinner.js';
23
+ import '../../../components/Checkbox/Checkbox.js';
24
+ import '../../../hooks/useBoundingClientRectListener.js';
25
+ import '../../../components/Input/Input.js';
26
+ import '../../../utils/hooks/useListKeyboardNavigation.js';
27
+ import '../../../utils/hooks/useListScrollTo.js';
28
+ import '../../../components/Combobox/Combobox.js';
29
+ import '../../../utils/date.js';
30
+ import '../../../components/Popover/Popover.js';
31
+ import '../../../components/Datepicker/Datepicker.js';
32
+ import '../../../components/Dialog/Dialog.js';
33
+ import '../../../components/Group/Group.js';
34
+ import '../../../components/Drawer/Drawer.js';
35
+ import '../../../components/Field/Field.js';
36
+ import '../../../components/Form/Form.js';
37
+ import '../../../components/Hanger/Hanger.js';
38
+ import '../../../components/HoverCard/HoverCard.js';
39
+ import '../../../components/Switch/Switch.js';
40
+ import '../../../components/List/List.js';
41
+ import '../../../components/Listbox/Listbox.js';
42
+ import '../../../components/Shortcut/Shortcut.js';
43
+ import '../../../components/RadioGroup/RadioGroup.js';
44
+ import '../../../components/Menu/Menu.js';
45
+ import '../../../components/ModeSwitch/ModeSwitch.js';
46
+ import '../../../components/Treeview/Treeview.js';
47
+ import '../../../utils/hooks/useDropTarget.js';
48
+ import '../../../components/Navigation/Navigation.js';
49
+ import '../../../hooks/useIntersectionObserver.js';
50
+ import { OverflowGroup } from '../../../components/OverflowGroup/OverflowGroup.js';
51
+ import '../../../components/Select/Select.js';
52
+ import '../../../components/Pagination/usePagination.js';
53
+ import '../../../components/Pagination/Pagination.js';
54
+ import '../../../components/Progress/Progress.js';
55
+ import '../../../components/Toast/Toaster.js';
56
+ import '../../../components/Provider/Provider.js';
57
+ import '../../../types.js';
58
+ import '../../../primitives/Table/types.js';
59
+ import '../../../primitives/Table/useTableDataLoader.js';
60
+ import '../../../hooks/useLazyEffect.js';
61
+ import '../../../components/SearchInput/SearchInput.js';
62
+ import '../../../components/SearchInput2/SearchInput2.js';
63
+ import '../../../primitives/Collection/Collection.js';
64
+ import '../../../components/Tag/Tag.js';
65
+ import '../../../components/Select2/Select2.js';
66
+ import '../../../hooks/useMatchMedia.js';
67
+ import '../../../hooks/useIsLargeScreen.js';
68
+ import '../../../components/Report/Report.js';
69
+ import '../../../components/Table/components/Table.js';
70
+ import '../../../components/Table/components/PaginatedTable.js';
71
+ import '../../../components/Table/components/WindowedTable.js';
72
+ import '../../../components/Table/util/rowIndexPath.js';
73
+ import '../../../components/Table/hooks/useRowCreation.js';
74
+ import '../../../components/Textarea/Textarea.js';
75
+ import '../../../components/Table3/Table3.js';
76
+ import '../../../components/Tabs/Tabs.js';
77
+ import '../../../components/Tour/Tour.js';
78
+ import { getThemeColor } from '../../utils/color.js';
79
+ import '../Area/AreaChart.js';
80
+ import '../Bar/BarChart.js';
81
+ import './DonutChart.js';
82
+ import '../Line/LineChart.js';
83
+ import '../../../components/Header/Header.js';
84
+ import '../../../components/Layout/Layout.js';
85
+ import '../../../components/Navigation2/components/Link.js';
86
+ import '../../../components/Navigation2/Navigation2.js';
87
+ import '../../../hooks/useBoundaryOverflowDetection.js';
88
+ import '../../../utils/hooks/useOnClickOutside.js';
89
+
90
+ const Legend = ({
91
+ legendPosition,
92
+ hoveredItem,
93
+ selectedItem,
94
+ data,
95
+ onClick,
96
+ setHoveredItem,
97
+ formatter,
98
+ total,
99
+ visibleItems,
100
+ label
101
+ }) => {
102
+ const isTotalLegendSelected = selectedItem.length === data.length;
103
+ const isTotalLegendHovered = hoveredItem.length === data.length;
104
+ const handleMouseLeave = () => setHoveredItem([]);
105
+ const renderLegendItem = (entry, index) => {
106
+ const isTotal = entry === null;
107
+ // We can't use `isTotal` here because TypeScript is unable to infer the type when `entry` is not null.
108
+ const itemData = entry === null ? {
109
+ id: 'total',
110
+ label,
111
+ value: total,
112
+ color: 'grey-300'
113
+ } : entry;
114
+ const isSelected = isTotal ? isTotalLegendSelected : selectedItem.includes(itemData.id);
115
+ const isHovered = isTotal ? isTotalLegendHovered : hoveredItem.includes(itemData.id);
116
+ return /*#__PURE__*/React__default.createElement("li", {
117
+ key: isTotal ? 'total' : `${itemData.label}-${index}`,
118
+ className: cn('mr-2 flex cursor-pointer gap-2 rounded pl-0 pr-1', {
119
+ 'bg-grey-100': isHovered && (!isTotal || legendPosition === 'right'),
120
+ 'bg-grey-200': isSelected && (!isTotal || legendPosition === 'right')
121
+ }),
122
+ onClick: () => onClick(isTotal ? data : itemData),
123
+ onMouseEnter: () => setHoveredItem(isTotal ? data.map(item => item.id) : [itemData.id]),
124
+ onMouseLeave: handleMouseLeave
125
+ }, legendPosition === 'bottom' ? (/*#__PURE__*/React__default.createElement("div", {
126
+ className: "flex items-center gap-1"
127
+ }, /*#__PURE__*/React__default.createElement("span", {
128
+ className: cn('ml-1 h-3 w-3 rounded-sm', {
129
+ 'border-grey-300 border !bg-white': !visibleItems[itemData.id]
130
+ }),
131
+ style: {
132
+ backgroundColor: getThemeColor(itemData.color)
133
+ }
134
+ }, visibleItems[itemData.id] && isHovered && (/*#__PURE__*/React__default.createElement(Icon, {
135
+ name: "tick-bold",
136
+ className: "mb-2.5 !h-full !w-full text-white"
137
+ }))), /*#__PURE__*/React__default.createElement("div", null, itemData.label))) : (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("span", {
138
+ className: "ml-1 mt-1 h-9 w-2 rounded-[1px]",
139
+ style: {
140
+ backgroundColor: getThemeColor(itemData.color)
141
+ }
142
+ }), /*#__PURE__*/React__default.createElement("div", null, itemData.label, /*#__PURE__*/React__default.createElement("span", {
143
+ className: "-mt-1 flex w-full text-lg font-bold"
144
+ }, formatter ? formatter(itemData.value) : itemData.value)))));
145
+ };
146
+ const moreButton = moreButtonText => (/*#__PURE__*/React__default.createElement(Button, {
147
+ appearance: "transparent",
148
+ className: "text-grey-700"
149
+ }, moreButtonText));
150
+ const className = cn('flex-grow pl-4', {
151
+ 'w-full': legendPosition === 'bottom'
152
+ });
153
+ return /*#__PURE__*/React__default.createElement("div", {
154
+ className: className
155
+ }, /*#__PURE__*/React__default.createElement("ul", {
156
+ className: cn('mb-0 ml-0 mt-4 flex justify-center space-y-1', legendPosition === 'right' ? 'flex-col gap-1' : 'flex-row')
157
+ }, legendPosition === 'right' ? (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, renderLegendItem(null), data.map(renderLegendItem))) : (/*#__PURE__*/React__default.createElement(OverflowGroup, {
158
+ className: "w-full items-center py-1",
159
+ moreButton: moreButton
160
+ }, data.map(renderLegendItem)))));
161
+ };
162
+
163
+ export { Legend };
164
+ //# sourceMappingURL=Legend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Legend.js","sources":["../../../../../../../../src/charts/components/Donut/Legend.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'clsx';\nimport { Button, Icon, OverflowGroup } from '../../../index';\n\nimport { getThemeColor } from '../../utils/color';\nimport { DonutChartProps, DonutChartSegmentProps, SegmentIds } from './DonutChart';\n\ntype LegendProps = Pick<DonutChartProps, 'formatter' | 'label' | 'legendPosition'> & {\n data: DonutChartSegmentProps[];\n hoveredItem: SegmentIds;\n onClick: (entry: DonutChartSegmentProps | DonutChartSegmentProps[]) => void;\n selectedItem: SegmentIds;\n setHoveredItem: React.Dispatch<React.SetStateAction<SegmentIds>>;\n total: number;\n visibleItems: Record<string, boolean>;\n};\n\nexport const Legend = ({\n legendPosition,\n hoveredItem,\n selectedItem,\n data,\n onClick,\n setHoveredItem,\n formatter,\n total,\n visibleItems,\n label,\n}: LegendProps) => {\n const isTotalLegendSelected = selectedItem.length === data.length;\n const isTotalLegendHovered = hoveredItem.length === data.length;\n\n const handleMouseLeave = () => setHoveredItem([]);\n\n const renderLegendItem = (entry: DonutChartSegmentProps | null, index?: number) => {\n const isTotal = entry === null;\n // We can't use `isTotal` here because TypeScript is unable to infer the type when `entry` is not null.\n const itemData = entry === null ? { id: 'total', label, value: total, color: 'grey-300' } : entry;\n const isSelected = isTotal ? isTotalLegendSelected : selectedItem.includes(itemData.id);\n const isHovered = isTotal ? isTotalLegendHovered : hoveredItem.includes(itemData.id);\n\n return (\n <li\n key={isTotal ? 'total' : `${itemData.label}-${index}`}\n className={cn('mr-2 flex cursor-pointer gap-2 rounded pl-0 pr-1', {\n 'bg-grey-100': isHovered && (!isTotal || legendPosition === 'right'),\n 'bg-grey-200': isSelected && (!isTotal || legendPosition === 'right'),\n })}\n onClick={() => onClick(isTotal ? data : itemData)}\n onMouseEnter={() => setHoveredItem(isTotal ? data.map(item => item.id) : [itemData.id])}\n onMouseLeave={handleMouseLeave}>\n {legendPosition === 'bottom' ? (\n <div className=\"flex items-center gap-1\">\n <span\n className={cn('ml-1 h-3 w-3 rounded-sm', {\n 'border-grey-300 border !bg-white': !visibleItems[itemData.id],\n })}\n style={{ backgroundColor: getThemeColor(itemData.color) }}>\n {visibleItems[itemData.id] && isHovered && (\n <Icon name=\"tick-bold\" className=\"mb-2.5 !h-full !w-full text-white\" />\n )}\n </span>\n <div>{itemData.label}</div>\n </div>\n ) : (\n <>\n <span\n className=\"ml-1 mt-1 h-9 w-2 rounded-[1px]\"\n style={{ backgroundColor: getThemeColor(itemData.color) }}\n />\n <div>\n {itemData.label}\n <span className=\"-mt-1 flex w-full text-lg font-bold\">\n {formatter ? formatter(itemData.value) : itemData.value}\n </span>\n </div>\n </>\n )}\n </li>\n );\n };\n\n const moreButton = moreButtonText => (\n <Button appearance=\"transparent\" className=\"text-grey-700\">\n {moreButtonText}\n </Button>\n );\n\n const className = cn('flex-grow pl-4', {\n 'w-full': legendPosition === 'bottom',\n });\n return (\n <div className={className}>\n <ul\n className={cn(\n 'mb-0 ml-0 mt-4 flex justify-center space-y-1',\n legendPosition === 'right' ? 'flex-col gap-1' : 'flex-row'\n )}>\n {legendPosition === 'right' ? (\n <>\n {renderLegendItem(null)}\n {data.map(renderLegendItem)}\n </>\n ) : (\n <OverflowGroup className=\"w-full items-center py-1\" moreButton={moreButton}>\n {data.map(renderLegendItem)}\n </OverflowGroup>\n )}\n </ul>\n </div>\n );\n};\n"],"names":["Legend","legendPosition","hoveredItem","selectedItem","data","onClick","setHoveredItem","formatter","total","visibleItems","label","isTotalLegendSelected","length","isTotalLegendHovered","handleMouseLeave","renderLegendItem","entry","index","isTotal","itemData","id","value","color","isSelected","includes","isHovered","React","key","className","cn","onMouseEnter","map","item","onMouseLeave","style","backgroundColor","getThemeColor","Icon","name","moreButton","moreButtonText","Button","appearance","OverflowGroup"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAiBaA,MAAM,GAAGA,CAAC;EACnBC,cAAc;EACdC,WAAW;EACXC,YAAY;EACZC,IAAI;EACJC,OAAO;EACPC,cAAc;EACdC,SAAS;EACTC,KAAK;EACLC,YAAY;EACZC;CACU;EACV,MAAMC,qBAAqB,GAAGR,YAAY,CAACS,MAAM,KAAKR,IAAI,CAACQ,MAAM;EACjE,MAAMC,oBAAoB,GAAGX,WAAW,CAACU,MAAM,KAAKR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,CACnB,CACA,CACH;AAEd;;;;"}
@@ -0,0 +1,5 @@
1
+ const DONUT_WIDTH = 16;
2
+ const HOVER_DONUT_WIDTH = 10;
3
+
4
+ export { DONUT_WIDTH, HOVER_DONUT_WIDTH };
5
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sources":["../../../../../../../../src/charts/components/Donut/util.ts"],"sourcesContent":["export const DONUT_WIDTH = 16;\nexport const HOVER_DONUT_WIDTH = 10;\n"],"names":["DONUT_WIDTH","HOVER_DONUT_WIDTH"],"mappings":"MAAaA,WAAW,GAAG;MACdC,iBAAiB,GAAG;;;;"}
@@ -0,0 +1,145 @@
1
+ import React__default, { useState } from 'react';
2
+ import cn from 'clsx';
3
+ import '../../components/Icon/components/index.js';
4
+ import { Icon } from '../../components/Icon/Icon.js';
5
+ import '../../components/BadgeIcon/BadgeIcon.js';
6
+ import '../../components/Alert/Alert.js';
7
+ import '../../utils/mergeRefs.js';
8
+ import '../../components/Backdrop/Backdrop.js';
9
+ import '../../components/AlertDialog/AlertDialog.js';
10
+ import '../../components/Accordion/Accordion.js';
11
+ import '../../components/VisuallyHidden/VisuallyHidden.js';
12
+ import '../../components/Badge/Badge.js';
13
+ import '../../hooks/useMergedRef.js';
14
+ import '../../utils/keyboard.js';
15
+ import '../../components/Tooltip/Tooltip.js';
16
+ import '../../components/IconButton/IconButton.js';
17
+ import '../../components/Provider/Localization.js';
18
+ import '../../components/Banner/Banner.js';
19
+ import { Button } from '../../components/Button/Button.js';
20
+ import '../../components/Calendar/Calendar.js';
21
+ import '../../components/Card/Card.js';
22
+ import '../../components/Spinner/Spinner.js';
23
+ import '../../components/Checkbox/Checkbox.js';
24
+ import '../../hooks/useBoundingClientRectListener.js';
25
+ import '../../components/Input/Input.js';
26
+ import '../../utils/hooks/useListKeyboardNavigation.js';
27
+ import '../../utils/hooks/useListScrollTo.js';
28
+ import '../../components/Combobox/Combobox.js';
29
+ import '../../utils/date.js';
30
+ import '../../components/Popover/Popover.js';
31
+ import '../../components/Datepicker/Datepicker.js';
32
+ import '../../components/Dialog/Dialog.js';
33
+ import '../../components/Group/Group.js';
34
+ import '../../components/Drawer/Drawer.js';
35
+ import '../../components/Field/Field.js';
36
+ import '../../components/Form/Form.js';
37
+ import '../../components/Hanger/Hanger.js';
38
+ import '../../components/HoverCard/HoverCard.js';
39
+ import '../../components/Switch/Switch.js';
40
+ import '../../components/List/List.js';
41
+ import '../../components/Listbox/Listbox.js';
42
+ import '../../components/Shortcut/Shortcut.js';
43
+ import '../../components/RadioGroup/RadioGroup.js';
44
+ import '../../components/Menu/Menu.js';
45
+ import '../../components/ModeSwitch/ModeSwitch.js';
46
+ import '../../components/Treeview/Treeview.js';
47
+ import '../../utils/hooks/useDropTarget.js';
48
+ import '../../components/Navigation/Navigation.js';
49
+ import '../../hooks/useIntersectionObserver.js';
50
+ import { OverflowGroup } from '../../components/OverflowGroup/OverflowGroup.js';
51
+ import '../../components/Select/Select.js';
52
+ import '../../components/Pagination/usePagination.js';
53
+ import '../../components/Pagination/Pagination.js';
54
+ import '../../components/Progress/Progress.js';
55
+ import '../../components/Toast/Toaster.js';
56
+ import '../../components/Provider/Provider.js';
57
+ import '../../types.js';
58
+ import '../../primitives/Table/types.js';
59
+ import '../../primitives/Table/useTableDataLoader.js';
60
+ import '../../hooks/useLazyEffect.js';
61
+ import '../../components/SearchInput/SearchInput.js';
62
+ import '../../components/SearchInput2/SearchInput2.js';
63
+ import '../../primitives/Collection/Collection.js';
64
+ import '../../components/Tag/Tag.js';
65
+ import '../../components/Select2/Select2.js';
66
+ import '../../hooks/useMatchMedia.js';
67
+ import '../../hooks/useIsLargeScreen.js';
68
+ import '../../components/Report/Report.js';
69
+ import '../../components/Table/components/Table.js';
70
+ import '../../components/Table/components/PaginatedTable.js';
71
+ import '../../components/Table/components/WindowedTable.js';
72
+ import '../../components/Table/util/rowIndexPath.js';
73
+ import '../../components/Table/hooks/useRowCreation.js';
74
+ import '../../components/Textarea/Textarea.js';
75
+ import '../../components/Table3/Table3.js';
76
+ import '../../components/Tabs/Tabs.js';
77
+ import '../../components/Tour/Tour.js';
78
+ import './Area/AreaChart.js';
79
+ import './Bar/BarChart.js';
80
+ import './Donut/DonutChart.js';
81
+ import './Line/LineChart.js';
82
+ import '../../components/Header/Header.js';
83
+ import '../../components/Layout/Layout.js';
84
+ import '../../components/Navigation2/components/Link.js';
85
+ import '../../components/Navigation2/Navigation2.js';
86
+ import '../../hooks/useBoundaryOverflowDetection.js';
87
+ import '../../utils/hooks/useOnClickOutside.js';
88
+
89
+ function Legend(props) {
90
+ const {
91
+ activeIndex,
92
+ onMouseEnter,
93
+ onMouseLeave,
94
+ onClick,
95
+ payload,
96
+ layout,
97
+ activeItems
98
+ } = props;
99
+ const [hoverIndex, setHoverIndex] = useState(null);
100
+ const handleMouseEnter = (entry, index) => {
101
+ setHoverIndex(index);
102
+ if (activeItems[entry.dataKey]) onMouseEnter(entry, index);
103
+ };
104
+ const handleMouseLeave = () => {
105
+ onMouseLeave();
106
+ setHoverIndex(null);
107
+ };
108
+ const moreButton = moreButtonText => (/*#__PURE__*/React__default.createElement(Button, {
109
+ appearance: "transparent",
110
+ className: "text-grey-700"
111
+ }, moreButtonText));
112
+ return /*#__PURE__*/React__default.createElement("div", {
113
+ className: "mx-auto w-auto max-w-full overflow-hidden"
114
+ }, /*#__PURE__*/React__default.createElement("div", {
115
+ className: cn('mb-0 ml-0 flex justify-center', {
116
+ 'flex-col': layout === 'vertical'
117
+ })
118
+ }, /*#__PURE__*/React__default.createElement(OverflowGroup, {
119
+ className: "w-full items-center py-1",
120
+ moreButton: moreButton
121
+ }, payload.map((entry, index) => (/*#__PURE__*/React__default.createElement("span", {
122
+ key: `${entry.dataKey}-${index}`,
123
+ className: cn(' hover:bg-grey-100 cursor-pointer px-[8px] py-[2px] hover:rounded-[4px]', {
124
+ 'bg-grey-100 rounded': activeIndex === index
125
+ }),
126
+ onMouseEnter: () => handleMouseEnter(entry, index),
127
+ onMouseLeave: handleMouseLeave,
128
+ onClick: onClick ? () => onClick(entry) : undefined
129
+ }, /*#__PURE__*/React__default.createElement("span", {
130
+ className: "text-grey-700 flex items-center gap-[4px]"
131
+ }, /*#__PURE__*/React__default.createElement("span", {
132
+ className: cn('-mt-px ml-1 flex h-3 w-3 rounded-sm', {
133
+ 'border-grey-300 border !bg-white': !activeItems[entry.dataKey]
134
+ }),
135
+ style: {
136
+ backgroundColor: entry.color
137
+ }
138
+ }, hoverIndex === index && activeItems[entry.dataKey] && (/*#__PURE__*/React__default.createElement(Icon, {
139
+ name: "tick-bold",
140
+ className: "!h-full !w-full text-white"
141
+ }))), entry.value)))))));
142
+ }
143
+
144
+ export { Legend };
145
+ //# sourceMappingURL=Legend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Legend.js","sources":["../../../../../../../src/charts/components/Legend.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport cn from 'clsx';\nimport { Icon, OverflowGroup, Button } from '../../index';\n\nimport { ActiveChartItems, PayloadType } from './types';\n\ntype InternalProps<TType> = {\n payload: PayloadType<TType>[];\n layout: string;\n activeIndex: number | undefined;\n};\n\nexport type LegendProps<TType> = {\n activeItems: ActiveChartItems<TType>;\n onMouseEnter: (entry: PayloadType<TType>, index: number) => void;\n onMouseLeave: () => void;\n onClick: (entry: PayloadType<TType>) => void;\n};\n\nexport type Props<TType> = LegendProps<TType> & InternalProps<TType>;\n\nexport function Legend<TType>(props: LegendProps<TType>) {\n const { activeIndex, onMouseEnter, onMouseLeave, onClick, payload, layout, activeItems } = props as Props<TType>;\n const [hoverIndex, setHoverIndex] = useState<number | null>(null);\n\n const handleMouseEnter = (entry: PayloadType<TType>, index: number) => {\n setHoverIndex(index);\n if (activeItems[entry.dataKey]) onMouseEnter(entry, index);\n };\n\n const handleMouseLeave = () => {\n onMouseLeave();\n setHoverIndex(null);\n };\n\n const moreButton = moreButtonText => (\n <Button appearance=\"transparent\" className=\"text-grey-700\">\n {moreButtonText}\n </Button>\n );\n\n return (\n <div className=\"mx-auto w-auto max-w-full overflow-hidden\">\n <div className={cn('mb-0 ml-0 flex justify-center', { 'flex-col': layout === 'vertical' })}>\n {/** py-1 is need to make sure the more button focus outline doesn't get cropped */}\n <OverflowGroup className=\"w-full items-center py-1\" moreButton={moreButton}>\n {payload.map((entry, index) => (\n <span\n key={`${entry.dataKey}-${index}`}\n className={cn(' hover:bg-grey-100 cursor-pointer px-[8px] py-[2px] hover:rounded-[4px]', {\n 'bg-grey-100 rounded': activeIndex === index,\n })}\n onMouseEnter={() => handleMouseEnter(entry, index)}\n onMouseLeave={handleMouseLeave}\n onClick={onClick ? () => onClick(entry) : undefined}>\n <span className=\"text-grey-700 flex items-center gap-[4px]\">\n <span\n className={cn('-mt-px ml-1 flex h-3 w-3 rounded-sm', {\n 'border-grey-300 border !bg-white': !activeItems[entry.dataKey],\n })}\n style={{ backgroundColor: entry.color }}>\n {hoverIndex === index && activeItems[entry.dataKey] && (\n <Icon name=\"tick-bold\" className=\"!h-full !w-full text-white\" />\n )}\n </span>\n {entry.value}\n </span>\n </span>\n ))}\n </OverflowGroup>\n </div>\n </div>\n );\n}\n"],"names":["Legend","props","activeIndex","onMouseEnter","onMouseLeave","onClick","payload","layout","activeItems","hoverIndex","setHoverIndex","useState","handleMouseEnter","entry","index","dataKey","handleMouseLeave","moreButton","moreButtonText","React","Button","appearance","className","cn","OverflowGroup","map","key","undefined","style","backgroundColor","color","Icon","name","value"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAqBgBA,MAAMA,CAAQC,KAAyB;EACnD,MAAM;IAAEC,WAAW;IAAEC,YAAY;IAAEC,YAAY;IAAEC,OAAO;IAAEC,OAAO;IAAEC,MAAM;IAAEC;GAAa,GAAGP,KAAqB;EAChH,MAAM,CAACQ,UAAU,EAAEC,aAAa,CAAC,GAAGC,QAAQ,CAAg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AAIN,WAAW,CAACK,KAAK,CAACE,OAAO,CAAC,kBAC/CI,6BAACY,IAAI;IAACC,IAAI,EAAC,WAAW;IAACV,SAAS,EAAC;IAA+B,CACnE,CACE,EACNT,KAAK,CAACoB,KAAK,CACT,CACJ,CACV,CAAC,CACU,CACd,CACJ;AAEd;;;;"}
@@ -0,0 +1,65 @@
1
+ import React__default, { useState } from 'react';
2
+ import { LineChart as LineChart$1, CartesianGrid, XAxis, YAxis, Legend, Tooltip, Line as Line$1 } from 'recharts';
3
+ import { getThemeColor } from '../../utils/color.js';
4
+ import { getCartesianGridProps, getXAxisProps, getYAxisProps, getLegendProps, getTooltipProps } from '../../utils/common.js';
5
+ import { ResponsiveContainer } from '../ResponsiveContainer.js';
6
+
7
+ const Line = _ => null;
8
+ const LineChart = function LineChart(externalProps) {
9
+ const {
10
+ children,
11
+ data,
12
+ formatter,
13
+ ...props
14
+ } = externalProps;
15
+ const [hoveredLine, setHoveredLine] = useState(null);
16
+ const [activeLines, setActiveLines] = useState(() => {
17
+ const keys = {};
18
+ React__default.Children.forEach(children, child => {
19
+ keys[child.props.accessor] = true;
20
+ });
21
+ return keys;
22
+ });
23
+ const handleLegendClick = entry => {
24
+ setHoveredLine(null);
25
+ setActiveLines({
26
+ ...activeLines,
27
+ [entry.dataKey]: !activeLines[entry.dataKey]
28
+ });
29
+ };
30
+ return /*#__PURE__*/React__default.createElement(ResponsiveContainer, null, /*#__PURE__*/React__default.createElement(LineChart$1, {
31
+ data: data,
32
+ margin: {
33
+ top: 10,
34
+ right: 0,
35
+ left: -25,
36
+ bottom: 0
37
+ }
38
+ }, /*#__PURE__*/React__default.createElement(CartesianGrid, Object.assign({}, getCartesianGridProps())), /*#__PURE__*/React__default.createElement(XAxis, Object.assign({}, getXAxisProps(props))), /*#__PURE__*/React__default.createElement(YAxis, Object.assign({}, getYAxisProps(props))), /*#__PURE__*/React__default.createElement(Legend, Object.assign({}, getLegendProps({
39
+ onClick: handleLegendClick,
40
+ onMouseEnter: entry => setHoveredLine(entry.dataKey),
41
+ onMouseLeave: () => setHoveredLine(null),
42
+ activeItems: activeLines
43
+ }))), /*#__PURE__*/React__default.createElement(Tooltip, Object.assign({}, getTooltipProps(), {
44
+ formatter: formatter
45
+ })), React__default.Children.map(children, child => {
46
+ var _child$props$color, _child$props$color2;
47
+ return /*#__PURE__*/React__default.createElement(Line$1, {
48
+ activeDot: {
49
+ fill: getThemeColor((_child$props$color = child.props.color) !== null && _child$props$color !== void 0 ? _child$props$color : 'blue-300')
50
+ },
51
+ dataKey: child.props.accessor,
52
+ isAnimationActive: false,
53
+ dot: false,
54
+ name: child.props.label,
55
+ stroke: getThemeColor((_child$props$color2 = child.props.color) !== null && _child$props$color2 !== void 0 ? _child$props$color2 : 'blue-300'),
56
+ strokeWidth: 2,
57
+ hide: !activeLines[child.props.accessor],
58
+ opacity: hoveredLine && child.props.accessor !== hoveredLine ? 0.3 : 1
59
+ });
60
+ })));
61
+ };
62
+ LineChart.Line = Line;
63
+
64
+ export { LineChart };
65
+ //# sourceMappingURL=LineChart.js.map