@react-magma/charts 13.3.0-next.1 → 14.0.0-next.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.
@@ -103,5 +103,15 @@ export interface CarbonChartProps extends React.HTMLAttributes<HTMLDivElement> {
103
103
  * toolbar is automatically disabled.
104
104
  */
105
105
  chartToolbar?: ChartToolbarConfig;
106
+ /**
107
+ * Custom content rendered below the toolbar row and above the chart itself,
108
+ * for example a filter. Requires `chartToolbar`; ignored without it.
109
+ *
110
+ * Providing this lays the toolbar out in normal flow instead of overlaying
111
+ * the single row Carbon reserves for its title, so the rendered height
112
+ * becomes toolbar + content + chart rather than the chart box alone. Set
113
+ * `options.height` so the chart still has a definite height of its own.
114
+ */
115
+ additionalContent?: React.ReactNode;
106
116
  }
107
117
  export declare const CarbonChart: React.ForwardRefExoticComponent<CarbonChartProps & React.RefAttributes<HTMLDivElement>>;
@@ -158,3 +158,9 @@ export declare const TitleSlots: {
158
158
  }[];
159
159
  };
160
160
  };
161
+ export declare const AdditionalContent: {
162
+ render: ({ isInverse }: Pick<CarbonChartProps, 'isInverse'>) => React.JSX.Element;
163
+ args: {
164
+ isInverse: boolean;
165
+ };
166
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-magma/charts",
3
- "version": "13.3.0-next.1",
3
+ "version": "14.0.0-next.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -47,7 +47,7 @@
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": "^4.15.1-next.0",
50
+ "react-magma-dom": "^4.17.0-next.0",
51
51
  "react-magma-icons": "^3.2.5",
52
52
  "rollup": "^4.52.4",
53
53
  "rollup-plugin-postcss": "^4.0.2"
@@ -57,7 +57,7 @@
57
57
  "@emotion/styled": "^11.13.0",
58
58
  "react": "^17.0.2",
59
59
  "react-dom": "^17.0.2",
60
- "react-magma-dom": "^4.15.1-next.0",
60
+ "react-magma-dom": "^4.17.0-next.0",
61
61
  "react-magma-icons": "^3.2.5"
62
62
  },
63
63
  "engines": {
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
+ import { SimpleBarChart } from '@carbon/charts-react';
3
4
  import { act, render, screen, fireEvent } from '@testing-library/react';
4
5
  import userEvent from '@testing-library/user-event';
5
6
  import { axe } from 'jest-axe';
@@ -190,6 +191,27 @@ describe('CarbonChart', () => {
190
191
  );
191
192
  });
192
193
 
194
+ it("pins Carbon's export `.filled` background to the inverse surface color", () => {
195
+ const testId = 'filled-bg-inverse';
196
+ const { getByTestId } = render(
197
+ <ThemeContext.Provider value={magma}>
198
+ <CarbonChart
199
+ testId={testId}
200
+ dataSet={dataSet}
201
+ options={chartOptions}
202
+ type={CarbonChartType.bar}
203
+ isInverse
204
+ />
205
+ </ThemeContext.Provider>
206
+ );
207
+
208
+ expect(getByTestId(testId)).toHaveStyleRule(
209
+ 'background-color',
210
+ magma.colors.primary600,
211
+ { target: '.cds--chart-holder.filled' }
212
+ );
213
+ });
214
+
193
215
  it('should apply theme.colors.neutral100 for inverse text color', () => {
194
216
  const testId = 'text-inverse-test';
195
217
  const { getByTestId } = render(
@@ -957,6 +979,108 @@ describe('CarbonChart', () => {
957
979
  });
958
980
  });
959
981
 
982
+ describe('image export', () => {
983
+ const toolbarProps = {
984
+ dataSet,
985
+ options: chartOptions,
986
+ type: CarbonChartType.bar,
987
+ chartToolbar: {},
988
+ };
989
+
990
+ let exportToPNG;
991
+ let exportToJPG;
992
+ let createChartSpy;
993
+
994
+ beforeEach(() => {
995
+ exportToPNG = jest.fn();
996
+ exportToJPG = jest.fn();
997
+ createChartSpy = jest
998
+ .spyOn(SimpleBarChart.prototype, 'createChart')
999
+ .mockImplementation(() => ({
1000
+ services: { domUtils: { exportToPNG, exportToJPG } },
1001
+ }));
1002
+ });
1003
+
1004
+ afterEach(() => {
1005
+ createChartSpy.mockRestore();
1006
+ });
1007
+
1008
+ it("runs Carbon's own PNG export from the More options menu", () => {
1009
+ render(<CarbonChart {...toolbarProps} />);
1010
+
1011
+ fireEvent.click(screen.getByRole('button', { name: 'More options' }));
1012
+ fireEvent.click(screen.getByText('Download as PNG'));
1013
+
1014
+ expect(exportToPNG).toHaveBeenCalledTimes(1);
1015
+ expect(exportToJPG).not.toHaveBeenCalled();
1016
+ });
1017
+
1018
+ it("runs Carbon's own JPG export from the More options menu", () => {
1019
+ render(<CarbonChart {...toolbarProps} />);
1020
+
1021
+ fireEvent.click(screen.getByRole('button', { name: 'More options' }));
1022
+ fireEvent.click(screen.getByText('Download as JPG'));
1023
+
1024
+ expect(exportToJPG).toHaveBeenCalledTimes(1);
1025
+ expect(exportToPNG).not.toHaveBeenCalled();
1026
+ });
1027
+
1028
+ it("keeps Carbon's own title alive and uses it as the export file name", () => {
1029
+ render(<CarbonChart {...toolbarProps} />);
1030
+
1031
+ const options = createChartSpy.mock.calls[0][2];
1032
+ expect(options.title).toBe(chartOptions.title);
1033
+ expect(options.fileDownload.fileName).toBe(chartOptions.title);
1034
+ });
1035
+
1036
+ it("reveals Carbon's hidden title for the capture and restores it afterwards", () => {
1037
+ jest.useFakeTimers();
1038
+ try {
1039
+ const { container } = render(<CarbonChart {...toolbarProps} />);
1040
+ const wrapper = container.querySelector('.carbon-chart-wrapper');
1041
+
1042
+ expect(wrapper).toHaveClass('has-magma-toolbar');
1043
+
1044
+ fireEvent.click(screen.getByRole('button', { name: 'More options' }));
1045
+ fireEvent.click(screen.getByText('Download as PNG'));
1046
+
1047
+ expect(wrapper).not.toHaveClass('has-magma-toolbar');
1048
+
1049
+ jest.runOnlyPendingTimers();
1050
+ expect(wrapper).toHaveClass('has-magma-toolbar');
1051
+ } finally {
1052
+ jest.useRealTimers();
1053
+ }
1054
+ });
1055
+
1056
+ it('reveals the title for the flow layout (additionalContent) export too', () => {
1057
+ jest.useFakeTimers();
1058
+ try {
1059
+ const { container } = render(
1060
+ <CarbonChart
1061
+ {...toolbarProps}
1062
+ additionalContent={<div>Filter</div>}
1063
+ />
1064
+ );
1065
+ const wrapper = container.querySelector('.carbon-chart-wrapper');
1066
+
1067
+ expect(createChartSpy.mock.calls[0][2].title).toBe(chartOptions.title);
1068
+ expect(wrapper).toHaveClass('has-magma-toolbar');
1069
+
1070
+ fireEvent.click(screen.getByRole('button', { name: 'More options' }));
1071
+ fireEvent.click(screen.getByText('Download as JPG'));
1072
+
1073
+ expect(exportToJPG).toHaveBeenCalledTimes(1);
1074
+ expect(wrapper).not.toHaveClass('has-magma-toolbar');
1075
+
1076
+ jest.runOnlyPendingTimers();
1077
+ expect(wrapper).toHaveClass('has-magma-toolbar');
1078
+ } finally {
1079
+ jest.useRealTimers();
1080
+ }
1081
+ });
1082
+ });
1083
+
960
1084
  describe('dot keyboard accessibility', () => {
961
1085
  let rafCallbacks;
962
1086