@react-magma/charts 14.0.0-rc.4 → 14.0.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.
Files changed (32) hide show
  1. package/dist/charts.js +421 -7
  2. package/dist/charts.js.map +1 -1
  3. package/dist/charts.modern.module.js +416 -9
  4. package/dist/charts.modern.module.js.map +1 -1
  5. package/dist/charts.umd.js +6429 -307
  6. package/dist/charts.umd.js.map +1 -1
  7. package/dist/components/CarbonChart/CarbonChart.d.ts +41 -0
  8. package/dist/components/ChartTable/ChartDataTable.d.ts +19 -0
  9. package/dist/components/ChartTable/ChartFullscreenButton.d.ts +26 -0
  10. package/dist/components/ChartTable/ChartMoreOptionsButton.d.ts +18 -0
  11. package/dist/components/ChartTable/ChartTable.test.d.ts +1 -0
  12. package/dist/components/ChartTable/ChartTableButton.d.ts +24 -0
  13. package/dist/components/ChartTable/ChartTableModal.d.ts +44 -0
  14. package/dist/components/ChartTable/ChartToolbar.d.ts +19 -0
  15. package/dist/components/ChartTable/chartToolbarI18n.d.ts +16 -0
  16. package/dist/components/ChartTable/index.d.ts +14 -0
  17. package/dist/index.d.ts +1 -0
  18. package/package.json +5 -5
  19. package/src/components/CarbonChart/CarbonChart.test.js +143 -2
  20. package/src/components/CarbonChart/CarbonChart.tsx +624 -15
  21. package/src/components/ChartTable/ChartDataTable.tsx +75 -0
  22. package/src/components/ChartTable/ChartFullscreenButton.tsx +59 -0
  23. package/src/components/ChartTable/ChartMoreOptionsButton.tsx +48 -0
  24. package/src/components/ChartTable/ChartTable.stories.tsx +152 -0
  25. package/src/components/ChartTable/ChartTable.test.tsx +452 -0
  26. package/src/components/ChartTable/ChartTableButton.tsx +56 -0
  27. package/src/components/ChartTable/ChartTableModal.tsx +135 -0
  28. package/src/components/ChartTable/ChartToolbar.tsx +51 -0
  29. package/src/components/ChartTable/chartToolbarI18n.ts +55 -0
  30. package/src/components/ChartTable/index.ts +23 -0
  31. package/src/hooks/useCarbonModalFocusManagement.ts +12 -0
  32. package/src/index.ts +1 -0
@@ -0,0 +1,55 @@
1
+ import * as React from 'react';
2
+
3
+ import { I18nContext } from 'react-magma-dom';
4
+
5
+ export interface ChartToolbarI18n {
6
+ defaultTitle: string;
7
+ downloadAsCsv: string;
8
+ downloadAsJpg: string;
9
+ downloadAsPng: string;
10
+ exitFullScreen: string;
11
+ makeFullScreen: string;
12
+ moreOptionsAriaLabel: string;
13
+ showAsTableTooltip: string;
14
+ tabularRepresentationLabel: string;
15
+ }
16
+
17
+ const defaults: ChartToolbarI18n = {
18
+ defaultTitle: 'Chart',
19
+ downloadAsCsv: 'Download as CSV',
20
+ downloadAsJpg: 'Download as JPG',
21
+ downloadAsPng: 'Download as PNG',
22
+ exitFullScreen: 'Exit full screen',
23
+ makeFullScreen: 'Make full screen',
24
+ moreOptionsAriaLabel: 'More options',
25
+ showAsTableTooltip: 'Show as table',
26
+ tabularRepresentationLabel: 'Tabular representation',
27
+ };
28
+
29
+ /**
30
+ * Reads chart toolbar i18n strings from the I18nContext if available,
31
+ * falling back to English defaults.
32
+ */
33
+
34
+ export function useChartToolbarI18n(): ChartToolbarI18n {
35
+ const i18n = React.useContext(I18nContext);
36
+ const toolbar = (i18n.charts as { toolbar?: Partial<ChartToolbarI18n> })
37
+ ?.toolbar;
38
+
39
+ if (!toolbar) return defaults;
40
+
41
+ return {
42
+ defaultTitle: toolbar.defaultTitle ?? defaults.defaultTitle,
43
+ downloadAsCsv: toolbar.downloadAsCsv ?? defaults.downloadAsCsv,
44
+ downloadAsJpg: toolbar.downloadAsJpg ?? defaults.downloadAsJpg,
45
+ downloadAsPng: toolbar.downloadAsPng ?? defaults.downloadAsPng,
46
+ exitFullScreen: toolbar.exitFullScreen ?? defaults.exitFullScreen,
47
+ makeFullScreen: toolbar.makeFullScreen ?? defaults.makeFullScreen,
48
+ moreOptionsAriaLabel:
49
+ toolbar.moreOptionsAriaLabel ?? defaults.moreOptionsAriaLabel,
50
+ showAsTableTooltip:
51
+ toolbar.showAsTableTooltip ?? defaults.showAsTableTooltip,
52
+ tabularRepresentationLabel:
53
+ toolbar.tabularRepresentationLabel ?? defaults.tabularRepresentationLabel,
54
+ };
55
+ }
@@ -0,0 +1,23 @@
1
+ export { ChartDataTable } from './ChartDataTable';
2
+ export type {
3
+ ChartDataTableProps,
4
+ ChartDataTableColumn,
5
+ } from './ChartDataTable';
6
+
7
+ export { ChartFullscreenButton } from './ChartFullscreenButton';
8
+ export type { ChartFullscreenButtonProps } from './ChartFullscreenButton';
9
+
10
+ export { ChartMoreOptionsButton } from './ChartMoreOptionsButton';
11
+ export type { ChartMoreOptionsButtonProps } from './ChartMoreOptionsButton';
12
+
13
+ export { ChartTableButton } from './ChartTableButton';
14
+ export type { ChartTableButtonProps } from './ChartTableButton';
15
+
16
+ export { ChartTableModal } from './ChartTableModal';
17
+ export type { ChartTableModalProps } from './ChartTableModal';
18
+
19
+ export { ChartToolbar } from './ChartToolbar';
20
+ export type { ChartToolbarProps } from './ChartToolbar';
21
+
22
+ export { useChartToolbarI18n } from './chartToolbarI18n';
23
+ export type { ChartToolbarI18n } from './chartToolbarI18n';
@@ -7,6 +7,7 @@ function getFocusableElements(container: HTMLElement): HTMLElement[] {
7
7
  return Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter(
8
8
  (el): el is HTMLElement => {
9
9
  const style = window.getComputedStyle(el);
10
+
10
11
  return (
11
12
  style.display !== 'none' &&
12
13
  style.visibility !== 'hidden' &&
@@ -18,6 +19,7 @@ function getFocusableElements(container: HTMLElement): HTMLElement[] {
18
19
 
19
20
  function findVisibleModal(wrapper: HTMLElement): HTMLElement | null {
20
21
  const modal = wrapper.querySelector<HTMLElement>('.cds--modal');
22
+
21
23
  if (!modal) return null;
22
24
 
23
25
  const isVisible =
@@ -40,14 +42,17 @@ export function useCarbonModalFocusManagement(
40
42
 
41
43
  React.useEffect(() => {
42
44
  const wrapper = wrapperRef.current;
45
+
43
46
  if (!wrapper) return;
44
47
 
45
48
  function focusModalCloseButton(modal: HTMLElement) {
46
49
  const closeButton = modal.querySelector<HTMLElement>('.cds--modal-close');
50
+
47
51
  if (closeButton) {
48
52
  closeButton.focus();
49
53
  } else {
50
54
  const focusable = getFocusableElements(modal);
55
+
51
56
  if (focusable.length > 0) {
52
57
  focusable[0].focus();
53
58
  }
@@ -62,6 +67,7 @@ export function useCarbonModalFocusManagement(
62
67
  // (e.g. Carbon's overflow menu returning focus to its trigger).
63
68
  focusinHandler.current = (event: FocusEvent) => {
64
69
  const target = event.target as HTMLElement;
70
+
65
71
  if (!modal.contains(target)) {
66
72
  setTimeout(() => {
67
73
  if (currentModal.current === modal) {
@@ -78,11 +84,13 @@ export function useCarbonModalFocusManagement(
78
84
  if (modal.contains(document.activeElement)) return;
79
85
 
80
86
  const closeBtn = modal.querySelector<HTMLElement>('.cds--modal-close');
87
+
81
88
  if (
82
89
  closeBtn &&
83
90
  window.getComputedStyle(closeBtn).visibility !== 'hidden'
84
91
  ) {
85
92
  closeBtn.focus();
93
+
86
94
  return;
87
95
  }
88
96
 
@@ -90,14 +98,17 @@ export function useCarbonModalFocusManagement(
90
98
  requestAnimationFrame(pollAndFocus);
91
99
  }
92
100
  };
101
+
93
102
  requestAnimationFrame(pollAndFocus);
94
103
 
95
104
  keydownHandler.current = (event: KeyboardEvent) => {
96
105
  if (event.key !== 'Tab') return;
97
106
 
98
107
  const focusable = getFocusableElements(modal);
108
+
99
109
  if (focusable.length === 0) {
100
110
  event.preventDefault();
111
+
101
112
  return;
102
113
  }
103
114
 
@@ -106,6 +117,7 @@ export function useCarbonModalFocusManagement(
106
117
  if (focusable[0] !== document.activeElement) {
107
118
  focusable[0].focus();
108
119
  }
120
+
109
121
  return;
110
122
  }
111
123
 
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './components/CarbonChart';
2
+ export * from './components/ChartTable';