@react-magma/charts 16.0.0-next.0 → 16.0.0-v6-next.2

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.
Files changed (89) hide show
  1. package/dist/charts.js +1632 -221
  2. package/dist/charts.js.map +1 -1
  3. package/dist/charts.modern.module.js +1634 -224
  4. package/dist/charts.modern.module.js.map +1 -1
  5. package/dist/charts.umd.js +49747 -28263
  6. package/dist/charts.umd.js.map +1 -1
  7. package/dist/components/CarbonChart/CarbonChart.d.ts +1 -1
  8. package/dist/components/CarbonChart/CarbonChartArea.stories.d.ts +310 -0
  9. package/dist/components/CarbonChart/CarbonChartAreaStacked.stories.d.ts +136 -0
  10. package/dist/components/CarbonChart/CarbonChartBar.stories.d.ts +232 -0
  11. package/dist/components/CarbonChart/CarbonChartBarFloating.stories.d.ts +82 -0
  12. package/dist/components/CarbonChart/CarbonChartBarGrouped.stories.d.ts +234 -0
  13. package/dist/components/CarbonChart/CarbonChartBarStacked.stories.d.ts +266 -0
  14. package/dist/components/CarbonChart/CarbonChartBoxplot.stories.d.ts +53 -0
  15. package/dist/components/CarbonChart/CarbonChartBubble.stories.d.ts +196 -0
  16. package/dist/components/CarbonChart/CarbonChartBullet.stories.d.ts +35 -0
  17. package/dist/components/CarbonChart/CarbonChartCombo.stories.d.ts +580 -0
  18. package/dist/components/CarbonChart/CarbonChartDonut.stories.d.ts +120 -0
  19. package/dist/components/CarbonChart/CarbonChartGauge.stories.d.ts +43 -0
  20. package/dist/components/CarbonChart/CarbonChartHistogram.stories.d.ts +89 -0
  21. package/dist/components/CarbonChart/CarbonChartLine.stories.d.ts +577 -0
  22. package/dist/components/CarbonChart/CarbonChartLollipop.stories.d.ts +55 -0
  23. package/dist/components/CarbonChart/CarbonChartMeter.stories.d.ts +127 -0
  24. package/dist/components/CarbonChart/CarbonChartPie.stories.d.ts +101 -0
  25. package/dist/components/CarbonChart/CarbonChartRadar.stories.d.ts +98 -0
  26. package/dist/components/CarbonChart/CarbonChartScatter.stories.d.ts +173 -0
  27. package/dist/components/CarbonChart/CarbonChartSparkline.stories.d.ts +51 -0
  28. package/dist/components/CarbonChart/CarbonChartStep.stories.d.ts +38 -0
  29. package/dist/components/ChartTable/ChartTable.stories.d.ts +166 -0
  30. package/dist/components/LineChart/Chart.d.ts +27 -0
  31. package/dist/components/LineChart/ChartDataTable.d.ts +17 -0
  32. package/dist/components/LineChart/CustomAxisComponent.d.ts +3 -0
  33. package/dist/components/LineChart/CustomPointComponent.d.ts +17 -0
  34. package/dist/components/LineChart/DataTable.d.ts +5 -0
  35. package/dist/components/LineChart/GraphTooltip.d.ts +3 -0
  36. package/dist/components/LineChart/LegendButton.d.ts +6 -0
  37. package/dist/components/LineChart/LineChart.d.ts +67 -0
  38. package/dist/components/LineChart/LineChart.stories.d.ts +113 -0
  39. package/dist/components/LineChart/index.d.ts +1 -0
  40. package/dist/components/LineChart/magma-charts.d.ts +1 -0
  41. package/dist/index.d.ts +1 -0
  42. package/package.json +21 -24
  43. package/src/components/CarbonChart/CarbonChart.test.js +316 -188
  44. package/src/components/CarbonChart/CarbonChart.tsx +94 -84
  45. package/src/components/CarbonChart/CarbonChartArea.stories.tsx +5 -3
  46. package/src/components/CarbonChart/CarbonChartAreaStacked.stories.tsx +5 -3
  47. package/src/components/CarbonChart/CarbonChartBar.stories.tsx +5 -3
  48. package/src/components/CarbonChart/CarbonChartBarFloating.stories.tsx +5 -3
  49. package/src/components/CarbonChart/CarbonChartBarGrouped.stories.tsx +5 -3
  50. package/src/components/CarbonChart/CarbonChartBarStacked.stories.tsx +5 -3
  51. package/src/components/CarbonChart/CarbonChartBoxplot.stories.tsx +5 -3
  52. package/src/components/CarbonChart/CarbonChartBubble.stories.tsx +5 -3
  53. package/src/components/CarbonChart/CarbonChartBullet.stories.tsx +5 -3
  54. package/src/components/CarbonChart/CarbonChartCombo.stories.tsx +5 -3
  55. package/src/components/CarbonChart/CarbonChartDonut.stories.tsx +5 -3
  56. package/src/components/CarbonChart/CarbonChartGauge.stories.tsx +5 -3
  57. package/src/components/CarbonChart/CarbonChartHistogram.stories.tsx +5 -3
  58. package/src/components/CarbonChart/CarbonChartLine.stories.tsx +5 -3
  59. package/src/components/CarbonChart/CarbonChartLollipop.stories.tsx +5 -3
  60. package/src/components/CarbonChart/CarbonChartMeter.stories.tsx +5 -3
  61. package/src/components/CarbonChart/CarbonChartPie.stories.tsx +5 -3
  62. package/src/components/CarbonChart/CarbonChartRadar.stories.tsx +5 -3
  63. package/src/components/CarbonChart/CarbonChartScatter.stories.tsx +5 -3
  64. package/src/components/CarbonChart/CarbonChartSparkline.stories.tsx +5 -3
  65. package/src/components/CarbonChart/CarbonChartStep.stories.tsx +5 -3
  66. package/src/components/ChartTable/ChartDataTable.tsx +0 -3
  67. package/src/components/ChartTable/ChartFullscreenButton.tsx +7 -1
  68. package/src/components/ChartTable/ChartMoreOptionsButton.tsx +2 -1
  69. package/src/components/ChartTable/ChartTable.test.js +3 -9
  70. package/src/components/ChartTable/ChartTableButton.tsx +7 -2
  71. package/src/components/ChartTable/ChartTableModal.tsx +1 -1
  72. package/src/components/ChartTable/ChartToolbar.tsx +0 -1
  73. package/src/components/ChartTable/chartToolbarI18n.ts +1 -1
  74. package/src/components/LineChart/Chart.tsx +241 -0
  75. package/src/components/LineChart/ChartDataTable.test.js +165 -0
  76. package/src/components/LineChart/ChartDataTable.tsx +135 -0
  77. package/src/components/LineChart/CustomAxisComponent.tsx +30 -0
  78. package/src/components/LineChart/CustomPointComponent.tsx +93 -0
  79. package/src/components/LineChart/DataTable.tsx +57 -0
  80. package/src/components/LineChart/GraphTooltip.tsx +100 -0
  81. package/src/components/LineChart/LegendButton.tsx +77 -0
  82. package/src/components/LineChart/LineChart.stories.tsx +399 -0
  83. package/src/components/LineChart/LineChart.test.js +501 -0
  84. package/src/components/LineChart/LineChart.tsx +669 -0
  85. package/src/components/LineChart/index.ts +1 -0
  86. package/src/components/LineChart/magma-charts.ts +279 -0
  87. package/src/components/LineChart/test/exampleChartData.js +289 -0
  88. package/src/hooks/useCarbonModalFocusManagement.ts +0 -12
  89. package/src/index.ts +1 -0
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { StoryFn, Meta } from '@storybook/react-webpack5';
3
+ import { StoryFn, Meta } from '@storybook/react/types-6-0';
4
4
  import { Card } from 'react-magma-dom';
5
5
 
6
6
  import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
@@ -15,8 +15,10 @@ export default {
15
15
  },
16
16
  },
17
17
  type: {
18
- control: { type: 'select' },
19
- options: Object.values(CarbonChartType),
18
+ control: {
19
+ type: 'select',
20
+ options: CarbonChartType,
21
+ },
20
22
  },
21
23
  },
22
24
  } as Meta;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { StoryFn, Meta } from '@storybook/react-webpack5';
3
+ import { StoryFn, Meta } from '@storybook/react/types-6-0';
4
4
  import { Card } from 'react-magma-dom';
5
5
 
6
6
  import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
@@ -15,8 +15,10 @@ export default {
15
15
  },
16
16
  },
17
17
  type: {
18
- control: { type: 'select' },
19
- options: Object.values(CarbonChartType),
18
+ control: {
19
+ type: 'select',
20
+ options: CarbonChartType,
21
+ },
20
22
  },
21
23
  },
22
24
  } as Meta;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { StoryFn, Meta } from '@storybook/react-webpack5';
3
+ import { StoryFn, Meta } from '@storybook/react/types-6-0';
4
4
  import { Card } from 'react-magma-dom';
5
5
 
6
6
  import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
@@ -15,8 +15,10 @@ export default {
15
15
  },
16
16
  },
17
17
  type: {
18
- control: { type: 'select' },
19
- options: Object.values(CarbonChartType),
18
+ control: {
19
+ type: 'select',
20
+ options: CarbonChartType,
21
+ },
20
22
  },
21
23
  },
22
24
  } as Meta;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { StoryFn, Meta } from '@storybook/react-webpack5';
3
+ import { StoryFn, Meta } from '@storybook/react/types-6-0';
4
4
  import { Card } from 'react-magma-dom';
5
5
 
6
6
  import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
@@ -15,8 +15,10 @@ export default {
15
15
  },
16
16
  },
17
17
  type: {
18
- control: { type: 'select' },
19
- options: Object.values(CarbonChartType),
18
+ control: {
19
+ type: 'select',
20
+ options: CarbonChartType,
21
+ },
20
22
  },
21
23
  },
22
24
  } as Meta;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { StoryFn, Meta } from '@storybook/react-webpack5';
3
+ import { StoryFn, Meta } from '@storybook/react/types-6-0';
4
4
  import { Card } from 'react-magma-dom';
5
5
 
6
6
  import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
@@ -15,8 +15,10 @@ export default {
15
15
  },
16
16
  },
17
17
  type: {
18
- control: { type: 'select' },
19
- options: Object.values(CarbonChartType),
18
+ control: {
19
+ type: 'select',
20
+ options: CarbonChartType,
21
+ },
20
22
  },
21
23
  },
22
24
  } as Meta;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { StoryFn, Meta } from '@storybook/react-webpack5';
3
+ import { StoryFn, Meta } from '@storybook/react/types-6-0';
4
4
  import { Card } from 'react-magma-dom';
5
5
 
6
6
  import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
@@ -15,8 +15,10 @@ export default {
15
15
  },
16
16
  },
17
17
  type: {
18
- control: { type: 'select' },
19
- options: Object.values(CarbonChartType),
18
+ control: {
19
+ type: 'select',
20
+ options: CarbonChartType,
21
+ },
20
22
  },
21
23
  },
22
24
  } as Meta;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { StoryFn, Meta } from '@storybook/react-webpack5';
3
+ import { StoryFn, Meta } from '@storybook/react/types-6-0';
4
4
  import { Card } from 'react-magma-dom';
5
5
 
6
6
  import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
@@ -15,8 +15,10 @@ export default {
15
15
  },
16
16
  },
17
17
  type: {
18
- control: { type: 'select' },
19
- options: Object.values(CarbonChartType),
18
+ control: {
19
+ type: 'select',
20
+ options: CarbonChartType,
21
+ },
20
22
  },
21
23
  },
22
24
  } as Meta;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { StoryFn, Meta } from '@storybook/react-webpack5';
3
+ import { StoryFn, Meta } from '@storybook/react/types-6-0';
4
4
  import { Card } from 'react-magma-dom';
5
5
 
6
6
  import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
@@ -15,8 +15,10 @@ export default {
15
15
  },
16
16
  },
17
17
  type: {
18
- control: { type: 'select' },
19
- options: Object.values(CarbonChartType),
18
+ control: {
19
+ type: 'select',
20
+ options: CarbonChartType,
21
+ },
20
22
  },
21
23
  },
22
24
  } as Meta;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { StoryFn, Meta } from '@storybook/react-webpack5';
3
+ import { StoryFn, Meta } from '@storybook/react/types-6-0';
4
4
  import { Card } from 'react-magma-dom';
5
5
 
6
6
  import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
@@ -15,8 +15,10 @@ export default {
15
15
  },
16
16
  },
17
17
  type: {
18
- control: { type: 'select' },
19
- options: Object.values(CarbonChartType),
18
+ control: {
19
+ type: 'select',
20
+ options: CarbonChartType,
21
+ },
20
22
  },
21
23
  },
22
24
  } as Meta;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { StoryFn, Meta } from '@storybook/react-webpack5';
3
+ import { StoryFn, Meta } from '@storybook/react/types-6-0';
4
4
  import { Card } from 'react-magma-dom';
5
5
 
6
6
  import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
@@ -15,8 +15,10 @@ export default {
15
15
  },
16
16
  },
17
17
  type: {
18
- control: { type: 'select' },
19
- options: Object.values(CarbonChartType),
18
+ control: {
19
+ type: 'select',
20
+ options: CarbonChartType,
21
+ },
20
22
  },
21
23
  },
22
24
  } as Meta;
@@ -32,7 +32,6 @@ function deriveColumns(
32
32
  dataSet: Array<Record<string, React.ReactNode>>
33
33
  ): ChartDataTableColumn[] {
34
34
  if (!dataSet.length) return [];
35
-
36
35
  return Object.keys(dataSet[0]).map(key => ({
37
36
  header: key.charAt(0).toUpperCase() + key.slice(1),
38
37
  key,
@@ -45,7 +44,6 @@ export function ChartDataTable({
45
44
  isInverse,
46
45
  }: ChartDataTableProps) {
47
46
  const resolvedColumns = columns || deriveColumns(dataSet);
48
-
49
47
  return (
50
48
  <Table isInverse={isInverse}>
51
49
  <TableHead>
@@ -60,7 +58,6 @@ export function ChartDataTable({
60
58
  const rowKey = resolvedColumns
61
59
  .map(col => String(row[col.key] ?? ''))
62
60
  .join('-');
63
-
64
61
  return (
65
62
  <TableRow key={`${rowKey}-${index}`}>
66
63
  {resolvedColumns.map(col => (
@@ -1,6 +1,11 @@
1
1
  import * as React from 'react';
2
2
 
3
- import { ButtonVariant, IconButton, Tooltip } from 'react-magma-dom';
3
+ import {
4
+ ButtonColor,
5
+ ButtonVariant,
6
+ IconButton,
7
+ Tooltip,
8
+ } from 'react-magma-dom';
4
9
 
5
10
  import { useChartToolbarI18n } from './chartToolbarI18n';
6
11
 
@@ -48,6 +53,7 @@ export function ChartFullscreenButton({
48
53
  <Tooltip content={resolvedTooltip} isInverse={isInverse}>
49
54
  <IconButton
50
55
  aria-label={ariaLabel}
56
+ color={ButtonColor.subtle}
51
57
  icon={resolvedIcon}
52
58
  isInverse={isInverse}
53
59
  onClick={onClick}
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
 
3
3
  import {
4
+ ButtonColor,
4
5
  ButtonVariant,
5
6
  Dropdown,
6
7
  DropdownButton,
@@ -34,11 +35,11 @@ export function ChartMoreOptionsButton({
34
35
  }: ChartMoreOptionsButtonProps) {
35
36
  const t = useChartToolbarI18n();
36
37
  const resolvedAriaLabel = ariaLabel ?? t.moreOptionsAriaLabel;
37
-
38
38
  return (
39
39
  <Dropdown isInverse={isInverse}>
40
40
  <DropdownButton
41
41
  aria-label={resolvedAriaLabel}
42
+ color={ButtonColor.subtle}
42
43
  icon={icon}
43
44
  variant={ButtonVariant.link}
44
45
  testId="chart-more-options-button"
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
2
 
3
- import '@testing-library/jest-dom';
4
3
  import {
5
4
  act,
6
5
  render,
@@ -63,7 +62,6 @@ describe('ChartDataTable', () => {
63
62
  { header: 'Category', key: 'group' },
64
63
  { header: 'Count', key: 'value' },
65
64
  ];
66
-
67
65
  render(<ChartDataTable columns={columns} dataSet={dataSet} />);
68
66
 
69
67
  expect(
@@ -168,7 +166,6 @@ describe('ChartTableModal', () => {
168
166
  it('calls onClose when close button is activated', async () => {
169
167
  jest.useFakeTimers();
170
168
  const onClose = jest.fn();
171
-
172
169
  render(
173
170
  <ChartTableModal
174
171
  dataSet={dataSet}
@@ -220,8 +217,8 @@ describe('ChartTableButton', () => {
220
217
  );
221
218
 
222
219
  const button = screen.getByRole('button', { name: 'Overall Performance' });
223
-
224
220
  expect(button).toHaveAttribute('aria-haspopup', 'dialog');
221
+ expect(button).toHaveAttribute('color', 'subtle');
225
222
  });
226
223
 
227
224
  it('sets aria-expanded to false when modal is closed', () => {
@@ -256,7 +253,6 @@ describe('ChartTableButton', () => {
256
253
 
257
254
  it('calls onClick when activated', () => {
258
255
  const onClick = jest.fn();
259
-
260
256
  render(
261
257
  <ChartTableButton
262
258
  ariaLabel="Overall Performance"
@@ -284,7 +280,6 @@ describe('ChartTableButton', () => {
284
280
  );
285
281
 
286
282
  const button = screen.getByRole('button', { name: 'Overall Performance' });
287
-
288
283
  fireEvent.mouseEnter(button);
289
284
 
290
285
  await waitFor(() => {
@@ -310,13 +305,12 @@ describe('ChartFullscreenButton', () => {
310
305
  const button = screen.getByRole('button', {
311
306
  name: 'View chart in full screen',
312
307
  });
313
-
314
308
  expect(button).not.toHaveAttribute('aria-haspopup');
309
+ expect(button).toHaveAttribute('color', 'subtle');
315
310
  });
316
311
 
317
312
  it('calls onClick when activated', () => {
318
313
  const onClick = jest.fn();
319
-
320
314
  render(
321
315
  <ChartFullscreenButton
322
316
  ariaLabel="View chart in full screen"
@@ -379,7 +373,7 @@ describe('ChartMoreOptionsButton', () => {
379
373
 
380
374
  expect(
381
375
  screen.getByRole('button', { name: 'More options' })
382
- ).toBeInTheDocument();
376
+ ).toHaveAttribute('color', 'subtle');
383
377
  });
384
378
 
385
379
  it('renders with custom aria-label', () => {
@@ -1,6 +1,11 @@
1
1
  import * as React from 'react';
2
2
 
3
- import { ButtonVariant, IconButton, Tooltip } from 'react-magma-dom';
3
+ import {
4
+ ButtonColor,
5
+ ButtonVariant,
6
+ IconButton,
7
+ Tooltip,
8
+ } from 'react-magma-dom';
4
9
 
5
10
  import { useChartToolbarI18n } from './chartToolbarI18n';
6
11
 
@@ -38,13 +43,13 @@ export function ChartTableButton({
38
43
  }: ChartTableButtonProps) {
39
44
  const t = useChartToolbarI18n();
40
45
  const resolvedTooltip = tooltipContent ?? t.showAsTableTooltip;
41
-
42
46
  return (
43
47
  <Tooltip content={resolvedTooltip} isInverse={isInverse}>
44
48
  <IconButton
45
49
  aria-expanded={isTableOpen}
46
50
  aria-haspopup="dialog"
47
51
  aria-label={ariaLabel}
52
+ color={ButtonColor.subtle}
48
53
  icon={icon}
49
54
  isInverse={isInverse}
50
55
  onClick={onClick}
@@ -60,7 +60,7 @@ const HeaderLabel = styled.span<{ isInverse?: boolean; theme: any }>`
60
60
  color: ${props =>
61
61
  props.isInverse
62
62
  ? props.theme.colors.neutral100
63
- : props.theme.colors.neutral500};
63
+ : props.theme.colors.brand.navy};
64
64
  line-height: ${props => props.theme.typeScale.size02.lineHeight};
65
65
  `;
66
66
 
@@ -39,7 +39,6 @@ export function ChartToolbar({
39
39
  title,
40
40
  }: ChartToolbarProps) {
41
41
  const theme = React.useContext(ThemeContext);
42
-
43
42
  return (
44
43
  <ToolbarWrapper>
45
44
  <Heading level={headingLevel} noMargins visualStyle={headingVisualStyle}>
@@ -32,7 +32,7 @@ const defaults: ChartToolbarI18n = {
32
32
  * Reads chart toolbar i18n strings from the I18nContext if available,
33
33
  * falling back to English defaults.
34
34
  */
35
-
35
+ // eslint-disable-next-line complexity
36
36
  export function useChartToolbarI18n(): ChartToolbarI18n {
37
37
  const i18n = React.useContext(I18nContext);
38
38
  const toolbar = (i18n.charts as { toolbar?: Partial<ChartToolbarI18n> })
@@ -0,0 +1,241 @@
1
+ import * as React from 'react';
2
+
3
+ import { css } from '@emotion/react';
4
+ import {
5
+ Announce,
6
+ ButtonVariant,
7
+ Card,
8
+ I18nContext,
9
+ IconButton,
10
+ Paragraph,
11
+ Tab,
12
+ TabPanel,
13
+ TabPanelsContainer,
14
+ Tabs,
15
+ TabsContainer,
16
+ ThemeContext,
17
+ Tooltip,
18
+ TypographyVisualStyle,
19
+ useDescendants,
20
+ styled,
21
+ } from 'react-magma-dom';
22
+ import { KeyboardIcon } from 'react-magma-icons';
23
+
24
+ import { ChartDataTable } from './ChartDataTable';
25
+ import { LineChart, LineChartProps } from './LineChart';
26
+
27
+ interface BaseChartProps {
28
+ /**
29
+ * Description of what the line chart data represents placed above the chart
30
+ */
31
+ description?: string;
32
+ /**
33
+ * @internal
34
+ */
35
+ testId?: string;
36
+ /**
37
+ * Title of the line chart
38
+ */
39
+ title: string;
40
+ /**
41
+ * Type of chart - for now just 'line' is accepted
42
+ */
43
+ type: string;
44
+ }
45
+ export interface ChartProps<T extends any>
46
+ extends BaseChartProps,
47
+ Omit<React.HTMLAttributes<HTMLDivElement>, 'title'>,
48
+ LineChartProps<T> {}
49
+
50
+ const StyledTitle = styled.span`
51
+ color: ${props => props.theme.colors.neutral};
52
+ font-size: ${props => props.theme.typeScale.size04.fontSize};
53
+ font-weight: 600;
54
+ font-family: ${props => props.theme.bodyFont};
55
+ line-height: ${props => props.theme.typeScale.size04.lineHeight};
56
+ margin: 0 0 12px 0;
57
+ `;
58
+
59
+ const StyledParagraph = styled(Paragraph)`
60
+ font-size: ${props => props.theme.typeScale.size02.fontSize};
61
+ margin: 0 0 18px 0;
62
+ `;
63
+
64
+ const StyledTabsContainer = styled(TabsContainer)`
65
+ width: 800px;
66
+ ul {
67
+ box-shadow: inset 0 -1px 0 ${props => props.theme.colors.neutral300};
68
+ }
69
+ `;
70
+
71
+ const StyledTabPanel = styled(TabPanel)`
72
+ padding: 22px 0;
73
+ `;
74
+
75
+ const KeyboardInstructionsCard = styled(Card)<{
76
+ isOpen?: boolean;
77
+ maxHeight?: string;
78
+ width?: string;
79
+ }>`
80
+ box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
81
+ display: ${props => (props.isOpen ? 'block' : 'none')};
82
+ right: ${props => props.theme.spaceScale.spacing02};
83
+ max-height: ${props =>
84
+ props.maxHeight ? props.maxHeight : props.theme.dropdown.content.maxHeight};
85
+ opacity: ${props => (props.isOpen ? '1' : '0')};
86
+ outline: 0;
87
+ overflow-y: auto;
88
+ padding: ${props => props.theme.spaceScale.spacing05}
89
+ ${props => props.theme.spaceScale.spacing05};
90
+ position: absolute;
91
+ transition: opacity 0.3s;
92
+ white-space: nowrap;
93
+ z-index: 2;
94
+
95
+ ${props =>
96
+ props.width &&
97
+ css`
98
+ white-space: normal;
99
+ width: ${props.width};
100
+ `}
101
+ `;
102
+
103
+ function BaseChart<T>(props: ChartProps<T>, ref: React.Ref<HTMLDivElement>) {
104
+ const { description, title, testId, type, ...other } = props;
105
+ const keyboardInstructionsRef = React.useRef<HTMLButtonElement>(null);
106
+ const lastFocusedScatterPoint = React.useRef<SVGPathElement>(null);
107
+ const theme = React.useContext(ThemeContext);
108
+ const i18n = React.useContext(I18nContext);
109
+
110
+ const [pointRefArray, registerPoint, unregisterPoint] = useDescendants();
111
+
112
+ const [isKeyboardInstructionsOpen, setIsKeyboardInstructionsOpen] =
113
+ React.useState<boolean>(false);
114
+
115
+ function handleKeyboardInstructionsButtonBlur() {
116
+ setIsKeyboardInstructionsOpen(false);
117
+ }
118
+
119
+ function handleKeyboardInstructionsButtonClick() {
120
+ setIsKeyboardInstructionsOpen(prevOpen => !prevOpen);
121
+ }
122
+
123
+ function handleKeyboardInstructionsButtonKeydown(event: {
124
+ preventDefault?: any;
125
+ key?: any;
126
+ shiftKey?: any;
127
+ }) {
128
+ const { key, shiftKey } = event;
129
+
130
+ switch (key) {
131
+ case 'Escape': {
132
+ setIsKeyboardInstructionsOpen(false);
133
+ break;
134
+ }
135
+ case 'Tab': {
136
+ if (
137
+ !shiftKey &&
138
+ lastFocusedScatterPoint &&
139
+ lastFocusedScatterPoint.current &&
140
+ pointRefArray.current.find(
141
+ point => point.current === lastFocusedScatterPoint.current
142
+ )
143
+ ) {
144
+ event.preventDefault();
145
+ lastFocusedScatterPoint.current.focus();
146
+ }
147
+ break;
148
+ }
149
+ }
150
+ }
151
+
152
+ return (
153
+ <div ref={ref}>
154
+ <StyledTitle theme={theme}>{title}</StyledTitle>
155
+ {description && (
156
+ <StyledParagraph
157
+ theme={theme}
158
+ visualStyle={TypographyVisualStyle.bodySmall}
159
+ >
160
+ {description}
161
+ </StyledParagraph>
162
+ )}
163
+ <StyledTabsContainer theme={theme}>
164
+ <Tabs>
165
+ <Tab>{i18n.charts.line.chartTabLabel}</Tab>
166
+ <Tab>{i18n.charts.line.dataTabLabel}</Tab>
167
+ <div
168
+ onBlur={handleKeyboardInstructionsButtonBlur}
169
+ style={{
170
+ display: 'inline-block',
171
+ marginLeft: 'auto',
172
+ }}
173
+ >
174
+ <Tooltip
175
+ content={i18n.charts.line.keyboardInstructionsTooltip}
176
+ ref={keyboardInstructionsRef}
177
+ >
178
+ <IconButton
179
+ aria-controls="keyboardInstructions"
180
+ aria-label={i18n.charts.line.keyboardInstructionsTooltip}
181
+ aria-expanded={Boolean(isKeyboardInstructionsOpen)}
182
+ icon={<KeyboardIcon />}
183
+ onClick={handleKeyboardInstructionsButtonClick}
184
+ onKeyDown={handleKeyboardInstructionsButtonKeydown}
185
+ variant={ButtonVariant.link}
186
+ />
187
+ </Tooltip>
188
+ <Announce>
189
+ <KeyboardInstructionsCard
190
+ id="keyboardInstructions"
191
+ isOpen={isKeyboardInstructionsOpen}
192
+ theme={theme}
193
+ width="350px"
194
+ >
195
+ <Paragraph
196
+ visualStyle={TypographyVisualStyle.headingXSmall}
197
+ style={{ margin: '0 0 16px' }}
198
+ >
199
+ {i18n.charts.line.keyboardInstructionsHeader}
200
+ </Paragraph>
201
+ {i18n.charts.line.keyboardInstructions}
202
+ </KeyboardInstructionsCard>
203
+ </Announce>
204
+ </div>
205
+ </Tabs>
206
+ <TabPanelsContainer>
207
+ <StyledTabPanel theme={theme}>
208
+ {type === 'line' && (
209
+ <LineChart<T>
210
+ {...other}
211
+ lastFocusedScatterPoint={lastFocusedScatterPoint}
212
+ pointRefArray={pointRefArray}
213
+ registerPoint={registerPoint}
214
+ tabRef={keyboardInstructionsRef}
215
+ unregisterPoint={unregisterPoint}
216
+ />
217
+ )}
218
+ </StyledTabPanel>
219
+ <StyledTabPanel theme={theme}>
220
+ <ChartDataTable
221
+ data={other.data}
222
+ xData={{
223
+ keyValue: other.x,
224
+ label: other.componentProps?.xAxis?.label,
225
+ tickFormat: other.componentProps?.xAxis?.tickFormat,
226
+ }}
227
+ yData={{
228
+ keyValue: other.y,
229
+ tickFormat: other.componentProps?.yAxis?.tickFormat,
230
+ }}
231
+ />
232
+ </StyledTabPanel>
233
+ </TabPanelsContainer>
234
+ </StyledTabsContainer>
235
+ </div>
236
+ );
237
+ }
238
+
239
+ export const Chart = React.forwardRef(BaseChart) as <T>(
240
+ props: ChartProps<T> & { ref?: React.MutableRefObject<HTMLDivElement> }
241
+ ) => ReturnType<typeof BaseChart>;