@react-magma/charts 15.0.1-v6-next.0 → 15.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-magma/charts",
3
- "version": "15.0.1-v6-next.0",
3
+ "version": "15.0.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -47,8 +47,8 @@
47
47
  "identity-obj-proxy": "^3.0.0",
48
48
  "react": "^17.0.2",
49
49
  "react-dom": "^17.0.2",
50
- "react-magma-dom": "^6.0.1-v6-next.0",
51
- "react-magma-icons": "^3.3.0",
50
+ "react-magma-dom": "^6.1.0",
51
+ "react-magma-icons": "^3.3.1",
52
52
  "rollup": "^4.52.4",
53
53
  "rollup-plugin-postcss": "^4.0.2"
54
54
  },
@@ -57,8 +57,8 @@
57
57
  "@emotion/styled": "^11.13.0",
58
58
  "react": "^17.0.2",
59
59
  "react-dom": "^17.0.2",
60
- "react-magma-dom": "^6.0.1-v6-next.0",
61
- "react-magma-icons": "^3.3.0"
60
+ "react-magma-dom": "^6.1.0-v6-next.2",
61
+ "react-magma-icons": "^3.3.1"
62
62
  },
63
63
  "engines": {
64
64
  "node": ">=22.14.0",
@@ -25,7 +25,7 @@ global.ResizeObserver = jest.fn().mockImplementation(() => ({
25
25
  // Multiple observers may be created per component; we collect all of them and
26
26
  // call each one so that no observer is silently skipped.
27
27
  let mutationObserverCallbacks = [];
28
- const mutationObserverCallback = mutations =>
28
+ const mutationObserverCallback = (mutations = []) =>
29
29
  mutationObserverCallbacks.forEach(cb => cb(mutations));
30
30
  global.MutationObserver = jest.fn().mockImplementation(callback => {
31
31
  mutationObserverCallbacks.push(callback);
@@ -1023,6 +1023,77 @@ describe('CarbonChart', () => {
1023
1023
  });
1024
1024
  });
1025
1025
 
1026
+ describe('fullscreen', () => {
1027
+ const toolbarProps = {
1028
+ dataSet,
1029
+ options: chartOptions,
1030
+ type: CarbonChartType.bar,
1031
+ chartToolbar: {},
1032
+ };
1033
+
1034
+ let setOptions;
1035
+ let createChartSpy;
1036
+
1037
+ const setFullscreenElement = element => {
1038
+ Object.defineProperty(document, 'fullscreenElement', {
1039
+ configurable: true,
1040
+ value: element,
1041
+ });
1042
+ act(() => {
1043
+ document.dispatchEvent(new Event('fullscreenchange'));
1044
+ });
1045
+ };
1046
+
1047
+ beforeEach(() => {
1048
+ setOptions = jest.fn();
1049
+ createChartSpy = jest
1050
+ .spyOn(SimpleBarChart.prototype, 'createChart')
1051
+ .mockImplementation(holder => {
1052
+ holder.classList.add('cds--chart-holder');
1053
+ holder.style.height = chartOptions.height;
1054
+
1055
+ return { model: { setOptions, setData: jest.fn() } };
1056
+ });
1057
+ });
1058
+
1059
+ afterEach(() => {
1060
+ createChartSpy.mockRestore();
1061
+ delete document.fullscreenElement;
1062
+ });
1063
+
1064
+ it('does not update chart options when entering and exiting fullscreen', () => {
1065
+ const { container } = render(<CarbonChart {...toolbarProps} />);
1066
+ const holder = container.querySelector('.cds--chart-holder');
1067
+
1068
+ setFullscreenElement(container.firstChild);
1069
+
1070
+ expect(
1071
+ screen.getByRole('button', {
1072
+ name: `Exit ${chartOptions.title} full screen`,
1073
+ })
1074
+ ).toBeInTheDocument();
1075
+ expect(holder.style.height).toBe('100vh');
1076
+
1077
+ setFullscreenElement(null);
1078
+
1079
+ expect(
1080
+ screen.getByRole('button', {
1081
+ name: `View ${chartOptions.title} full screen`,
1082
+ })
1083
+ ).toBeInTheDocument();
1084
+ expect(holder.style.height).toBe(chartOptions.height);
1085
+ expect(setOptions).not.toHaveBeenCalled();
1086
+ });
1087
+
1088
+ it('does not update chart options on re-render with the same props', () => {
1089
+ const { rerender } = render(<CarbonChart {...toolbarProps} />);
1090
+
1091
+ rerender(<CarbonChart {...toolbarProps} chartToolbar={{}} />);
1092
+
1093
+ expect(setOptions).not.toHaveBeenCalled();
1094
+ });
1095
+ });
1096
+
1026
1097
  describe('image export', () => {
1027
1098
  const toolbarProps = {
1028
1099
  dataSet,
@@ -1090,7 +1161,9 @@ describe('CarbonChart', () => {
1090
1161
 
1091
1162
  expect(wrapper).not.toHaveClass('has-magma-toolbar');
1092
1163
 
1093
- jest.runOnlyPendingTimers();
1164
+ act(() => {
1165
+ jest.runOnlyPendingTimers();
1166
+ });
1094
1167
  expect(wrapper).toHaveClass('has-magma-toolbar');
1095
1168
  } finally {
1096
1169
  jest.useRealTimers();
@@ -1117,7 +1190,9 @@ describe('CarbonChart', () => {
1117
1190
  expect(exportToJPG).toHaveBeenCalledTimes(1);
1118
1191
  expect(wrapper).not.toHaveClass('has-magma-toolbar');
1119
1192
 
1120
- jest.runOnlyPendingTimers();
1193
+ act(() => {
1194
+ jest.runOnlyPendingTimers();
1195
+ });
1121
1196
  expect(wrapper).toHaveClass('has-magma-toolbar');
1122
1197
  } finally {
1123
1198
  jest.useRealTimers();
@@ -36,10 +36,10 @@ import {
36
36
  VisuallyHidden,
37
37
  } from 'react-magma-dom';
38
38
  import {
39
- FullscreenExitIcon,
40
- FullscreenIcon,
41
- MoreVertIcon,
42
- TableIcon,
39
+ FullscreenExitOutlinedIcon,
40
+ FullscreenOutlinedIcon,
41
+ MoreVertOutlinedIcon,
42
+ TableOutlinedIcon,
43
43
  } from 'react-magma-icons';
44
44
 
45
45
  import { useCarbonModalFocusManagement } from '../../hooks/useCarbonModalFocusManagement';
@@ -1060,7 +1060,7 @@ function CarbonChartToolbar({
1060
1060
  {showTable && (
1061
1061
  <ChartTableButton
1062
1062
  ariaLabel={resolvedTitle}
1063
- icon={<TableIcon size={20} />}
1063
+ icon={<TableOutlinedIcon size={20} />}
1064
1064
  isInverse={isInverse}
1065
1065
  isTableOpen={isTableOpen}
1066
1066
  onClick={onOpenTable}
@@ -1069,15 +1069,15 @@ function CarbonChartToolbar({
1069
1069
  {showFullscreen && (
1070
1070
  <ChartFullscreenButton
1071
1071
  ariaLabel={`${isFullscreen ? 'Exit' : 'View'} ${resolvedTitle} full screen`}
1072
- icon={<FullscreenIcon size={20} />}
1073
- exitIcon={<FullscreenExitIcon size={20} />}
1072
+ icon={<FullscreenOutlinedIcon size={20} />}
1073
+ exitIcon={<FullscreenExitOutlinedIcon size={20} />}
1074
1074
  isInverse={isInverse}
1075
1075
  isFullscreen={isFullscreen}
1076
1076
  onClick={onToggleFullscreen}
1077
1077
  />
1078
1078
  )}
1079
1079
  <ChartMoreOptionsButton
1080
- icon={<MoreVertIcon size={20} />}
1080
+ icon={<MoreVertOutlinedIcon size={20} />}
1081
1081
  isInverse={isInverse}
1082
1082
  >
1083
1083
  {moreOptionsContent}
@@ -1378,28 +1378,32 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1378
1378
  isInverse,
1379
1379
  ]);
1380
1380
 
1381
- const newOptions = {
1382
- ...options,
1383
- theme: isInverse ? ChartTheme.G100 : ChartTheme.WHITE,
1384
- color: {
1385
- scale: colorScale,
1386
- },
1387
- tooltip: {
1388
- ...(options?.tooltip || {}),
1389
- truncation: {
1390
- type: 'none',
1381
+ const hasChartToolbar = Boolean(chartToolbar);
1382
+ const newOptions = React.useMemo(
1383
+ () => ({
1384
+ ...options,
1385
+ theme: isInverse ? ChartTheme.G100 : ChartTheme.WHITE,
1386
+ color: {
1387
+ scale: colorScale,
1391
1388
  },
1392
- },
1393
- ...(chartToolbar
1394
- ? {
1395
- toolbar: { enabled: false },
1396
- title: chartTitle,
1397
- ...(options.fileDownload
1398
- ? {}
1399
- : { fileDownload: { fileName: chartTitle } }),
1400
- }
1401
- : {}),
1402
- };
1389
+ tooltip: {
1390
+ ...(options?.tooltip || {}),
1391
+ truncation: {
1392
+ type: 'none',
1393
+ },
1394
+ },
1395
+ ...(hasChartToolbar
1396
+ ? {
1397
+ toolbar: { enabled: false },
1398
+ title: chartTitle,
1399
+ ...(options.fileDownload
1400
+ ? {}
1401
+ : { fileDownload: { fileName: chartTitle } }),
1402
+ }
1403
+ : {}),
1404
+ }),
1405
+ [options, isInverse, colorScale, hasChartToolbar, chartTitle]
1406
+ );
1403
1407
 
1404
1408
  const ChartType = ALL_CHARTS[type];
1405
1409
 
@@ -6,6 +6,7 @@ import {
6
6
  Dropdown,
7
7
  DropdownButton,
8
8
  DropdownContent,
9
+ Tooltip,
9
10
  } from 'react-magma-dom';
10
11
 
11
12
  import { useChartToolbarI18n } from './chartToolbarI18n';
@@ -37,13 +38,15 @@ export function ChartMoreOptionsButton({
37
38
  const resolvedAriaLabel = ariaLabel ?? t.moreOptionsAriaLabel;
38
39
  return (
39
40
  <Dropdown isInverse={isInverse}>
40
- <DropdownButton
41
- aria-label={resolvedAriaLabel}
42
- color={ButtonColor.subtle}
43
- icon={icon}
44
- variant={ButtonVariant.link}
45
- testId="chart-more-options-button"
46
- />
41
+ <Tooltip content={resolvedAriaLabel} isInverse={isInverse}>
42
+ <DropdownButton
43
+ aria-label={resolvedAriaLabel}
44
+ color={ButtonColor.subtle}
45
+ icon={icon}
46
+ variant={ButtonVariant.link}
47
+ testId="chart-more-options-button"
48
+ />
49
+ </Tooltip>
47
50
  <DropdownContent>{children}</DropdownContent>
48
51
  </Dropdown>
49
52
  );
@@ -364,7 +364,7 @@ describe('ChartFullscreenButton', () => {
364
364
  // ChartMoreOptionsButton
365
365
  // ---------------------------------------------------------------------------
366
366
  describe('ChartMoreOptionsButton', () => {
367
- it('renders with default "More options" label', () => {
367
+ it('renders with default "More options" label and tooltip', async () => {
368
368
  render(
369
369
  <ChartMoreOptionsButton icon={<MoreVertIcon />}>
370
370
  <DropdownMenuItem>Download</DropdownMenuItem>
@@ -374,6 +374,11 @@ describe('ChartMoreOptionsButton', () => {
374
374
  expect(
375
375
  screen.getByRole('button', { name: 'More options' })
376
376
  ).toHaveAttribute('color', 'subtle');
377
+
378
+ fireEvent.mouseEnter(screen.getByRole('button', { name: 'More options' }));
379
+ await waitFor(() => {
380
+ expect(screen.getByText('More options')).toBeInTheDocument();
381
+ });
377
382
  });
378
383
 
379
384
  it('renders with custom aria-label', () => {