@react-magma/charts 15.0.0-rc.3 → 15.0.0-rc.5
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/dist/charts.js +106 -10
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +107 -11
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +106 -10
- package/dist/charts.umd.js.map +1 -1
- package/dist/components/CarbonChart/CarbonChart.d.ts +5 -0
- package/package.json +1 -1
- package/src/components/CarbonChart/CarbonChart.test.js +92 -3
- package/src/components/CarbonChart/CarbonChart.tsx +138 -10
- package/src/components/CarbonChart/CarbonChartBar.stories.tsx +9 -2
package/dist/charts.umd.js
CHANGED
|
@@ -30384,6 +30384,7 @@
|
|
|
30384
30384
|
img.src = url;
|
|
30385
30385
|
}
|
|
30386
30386
|
function CarbonChartToolbar(_a) {
|
|
30387
|
+
var _b;
|
|
30387
30388
|
var config = _a.config, dataSet = _a.dataSet, isInverse = _a.isInverse, isTableOpen = _a.isTableOpen, isFullscreen = _a.isFullscreen, onOpenTable = _a.onOpenTable, onToggleFullscreen = _a.onToggleFullscreen, theme = _a.theme, title = _a.title, wrapperRef = _a.wrapperRef;
|
|
30388
30389
|
var t = useChartToolbarI18n();
|
|
30389
30390
|
var showTable = config.showAsTable !== false;
|
|
@@ -30406,7 +30407,7 @@
|
|
|
30406
30407
|
React__default__namespace.createElement(DropdownDivider, null),
|
|
30407
30408
|
config.moreOptions))));
|
|
30408
30409
|
return (React__default__namespace.createElement(ToolbarWrapper, { isFullscreen: isFullscreen, isInverse: isInverse, theme: theme },
|
|
30409
|
-
React__default__namespace.createElement(ChartTitle, { isInverse: isInverse, theme: theme }, resolvedTitle),
|
|
30410
|
+
React__default__namespace.createElement(ChartTitle, { as: "h".concat((_b = config.titleLevel) !== null && _b !== void 0 ? _b : 2), isInverse: isInverse, theme: theme }, resolvedTitle),
|
|
30410
30411
|
React__default__namespace.createElement(ToolbarActions, { theme: theme },
|
|
30411
30412
|
showTable && (React__default__namespace.createElement(ChartTableButton, { ariaLabel: resolvedTitle, icon: React__default__namespace.createElement(TableIcon, { size: 20 }), isInverse: isInverse, isTableOpen: isTableOpen, onClick: onOpenTable })),
|
|
30412
30413
|
showFullscreen && (React__default__namespace.createElement(ChartFullscreenButton, { ariaLabel: "".concat(isFullscreen ? 'Exit' : 'View', " ").concat(resolvedTitle, " full screen"), icon: React__default__namespace.createElement(FullscreenIcon, { size: 20 }), exitIcon: React__default__namespace.createElement(FullscreenExitIcon, { size: 20 }), isInverse: isInverse, isFullscreen: isFullscreen, onClick: onToggleFullscreen })),
|
|
@@ -30421,8 +30422,11 @@
|
|
|
30421
30422
|
var _a = React__default__namespace.useState(false), isTableOpen = _a[0], setIsTableOpen = _a[1];
|
|
30422
30423
|
var _b = React__default__namespace.useState(false), isFullscreen = _b[0], setIsFullscreen = _b[1];
|
|
30423
30424
|
var _c = React__default__namespace.useState(''), legendAnnouncement = _c[0], setLegendAnnouncement = _c[1];
|
|
30425
|
+
var legendGroupAnnounceRef = React__default__namespace.useRef(null);
|
|
30424
30426
|
var lastTableTriggerRef = React__default__namespace.useRef(null);
|
|
30425
30427
|
var legendAnnouncedRef = React__default__namespace.useRef(false);
|
|
30428
|
+
var selectionSignatureRef = React__default__namespace.useRef(undefined);
|
|
30429
|
+
var _d = useDeviceDetect(), isMacOS = _d.isMacOS, isChrome = _d.isChrome;
|
|
30426
30430
|
var mergedRef = React__default__namespace.useCallback(function (node) {
|
|
30427
30431
|
internalRef.current = node;
|
|
30428
30432
|
if (typeof ref === 'function') {
|
|
@@ -30489,20 +30493,49 @@
|
|
|
30489
30493
|
if (!container)
|
|
30490
30494
|
return;
|
|
30491
30495
|
var applyListSemantics = function (legend) {
|
|
30492
|
-
legend.
|
|
30493
|
-
|
|
30494
|
-
|
|
30495
|
-
|
|
30496
|
-
|
|
30496
|
+
var itemsHost = legend.matches('[data-name="legend-items"]')
|
|
30497
|
+
? legend
|
|
30498
|
+
: legend.querySelector('[data-name="legend-items"]') || legend;
|
|
30499
|
+
itemsHost.removeAttribute('aria-label');
|
|
30500
|
+
if (itemsHost.getAttribute('role') !== 'list') {
|
|
30501
|
+
itemsHost.setAttribute('role', 'list');
|
|
30502
|
+
}
|
|
30503
|
+
legend.querySelectorAll('.legend-item').forEach(function (item) {
|
|
30504
|
+
if (item.getAttribute('role') !== 'listitem') {
|
|
30505
|
+
item.setAttribute('role', 'listitem');
|
|
30506
|
+
}
|
|
30507
|
+
});
|
|
30508
|
+
container.querySelectorAll('[role="list"]').forEach(function (el) {
|
|
30509
|
+
if (el !== itemsHost && el.contains(itemsHost)) {
|
|
30510
|
+
el.removeAttribute('role');
|
|
30511
|
+
}
|
|
30512
|
+
});
|
|
30513
|
+
container.querySelectorAll('[aria-label="Data groups"]').forEach(function (el) {
|
|
30514
|
+
if (el !== itemsHost && el.contains(itemsHost)) {
|
|
30515
|
+
el.removeAttribute('aria-label');
|
|
30516
|
+
}
|
|
30517
|
+
});
|
|
30518
|
+
};
|
|
30519
|
+
var unwrapFieldset = function (fieldset) {
|
|
30520
|
+
var _a;
|
|
30521
|
+
(_a = fieldset.querySelector(':scope > legend')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
30522
|
+
fieldset.replaceWith.apply(fieldset, Array.from(fieldset.childNodes));
|
|
30497
30523
|
};
|
|
30498
30524
|
var wrapLegend = function () {
|
|
30499
30525
|
var legend = container.querySelector('.cds--cc--legend');
|
|
30500
30526
|
if (!legend)
|
|
30501
30527
|
return;
|
|
30502
30528
|
applyListSemantics(legend);
|
|
30503
|
-
var
|
|
30504
|
-
|
|
30505
|
-
|
|
30529
|
+
var closestFieldset = legend.closest('fieldset.cds--cc--legend-fieldset');
|
|
30530
|
+
container
|
|
30531
|
+
.querySelectorAll('fieldset.cds--cc--legend-fieldset')
|
|
30532
|
+
.forEach(function (fieldset) {
|
|
30533
|
+
if (fieldset !== closestFieldset) {
|
|
30534
|
+
unwrapFieldset(fieldset);
|
|
30535
|
+
}
|
|
30536
|
+
});
|
|
30537
|
+
if (closestFieldset) {
|
|
30538
|
+
var existingCaption = closestFieldset.querySelector(':scope > legend');
|
|
30506
30539
|
if (existingCaption && existingCaption.textContent !== legendLabel) {
|
|
30507
30540
|
existingCaption.textContent = legendLabel;
|
|
30508
30541
|
}
|
|
@@ -30517,9 +30550,58 @@
|
|
|
30517
30550
|
};
|
|
30518
30551
|
wrapLegend();
|
|
30519
30552
|
var observer = new MutationObserver(wrapLegend);
|
|
30520
|
-
observer.observe(container, {
|
|
30553
|
+
observer.observe(container, {
|
|
30554
|
+
childList: true,
|
|
30555
|
+
subtree: true,
|
|
30556
|
+
attributes: true,
|
|
30557
|
+
attributeFilter: ['role', 'aria-label'],
|
|
30558
|
+
});
|
|
30521
30559
|
return function () { return observer.disconnect(); };
|
|
30522
30560
|
}, [legendLabel]);
|
|
30561
|
+
React__default__namespace.useEffect(function () {
|
|
30562
|
+
var container = internalRef.current;
|
|
30563
|
+
if (!container || !isMacOS || !isChrome)
|
|
30564
|
+
return;
|
|
30565
|
+
var announceTimer;
|
|
30566
|
+
var alternateSuffix = false;
|
|
30567
|
+
var closestLegend = function (node) {
|
|
30568
|
+
return node instanceof Element ? node.closest('.cds--cc--legend') : null;
|
|
30569
|
+
};
|
|
30570
|
+
var handleFocusIn = function (event) {
|
|
30571
|
+
var enteredLegend = closestLegend(event.target);
|
|
30572
|
+
var cameFromLegend = closestLegend(event.relatedTarget);
|
|
30573
|
+
if (enteredLegend && !cameFromLegend) {
|
|
30574
|
+
if (legendGroupAnnounceRef.current) {
|
|
30575
|
+
legendGroupAnnounceRef.current.textContent = '';
|
|
30576
|
+
}
|
|
30577
|
+
clearTimeout(announceTimer);
|
|
30578
|
+
announceTimer = setTimeout(function () {
|
|
30579
|
+
if (legendGroupAnnounceRef.current) {
|
|
30580
|
+
alternateSuffix = !alternateSuffix;
|
|
30581
|
+
legendGroupAnnounceRef.current.textContent =
|
|
30582
|
+
legendLabel + (alternateSuffix ? ' ' : '');
|
|
30583
|
+
}
|
|
30584
|
+
}, 250);
|
|
30585
|
+
}
|
|
30586
|
+
};
|
|
30587
|
+
var handleFocusOut = function (event) {
|
|
30588
|
+
var leftLegend = closestLegend(event.target) && !closestLegend(event.relatedTarget);
|
|
30589
|
+
// Reset once focus leaves the legend so re-entering announces again.
|
|
30590
|
+
if (leftLegend) {
|
|
30591
|
+
clearTimeout(announceTimer);
|
|
30592
|
+
if (legendGroupAnnounceRef.current) {
|
|
30593
|
+
legendGroupAnnounceRef.current.textContent = '';
|
|
30594
|
+
}
|
|
30595
|
+
}
|
|
30596
|
+
};
|
|
30597
|
+
container.addEventListener('focusin', handleFocusIn);
|
|
30598
|
+
container.addEventListener('focusout', handleFocusOut);
|
|
30599
|
+
return function () {
|
|
30600
|
+
clearTimeout(announceTimer);
|
|
30601
|
+
container.removeEventListener('focusin', handleFocusIn);
|
|
30602
|
+
container.removeEventListener('focusout', handleFocusOut);
|
|
30603
|
+
};
|
|
30604
|
+
}, [isMacOS, isChrome, legendLabel]);
|
|
30523
30605
|
var handleModalDownloadCsv = React__default__namespace.useCallback(function () {
|
|
30524
30606
|
downloadCsv(dataSet, chartTitle);
|
|
30525
30607
|
}, [dataSet, chartTitle]);
|
|
@@ -30604,6 +30686,17 @@
|
|
|
30604
30686
|
activeLabels.push(((_a = label.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '');
|
|
30605
30687
|
}
|
|
30606
30688
|
});
|
|
30689
|
+
// Carbon re-applies aria-checked (with the same values) on every
|
|
30690
|
+
// render, which still triggers this observer. Only announce when the
|
|
30691
|
+
// selection actually changed, otherwise unrelated re-renders (e.g.
|
|
30692
|
+
// the legend group announcement) cause phantom announcements.
|
|
30693
|
+
var selectionSignature = "".concat(activeLabels.join('|'), "::").concat(allItems.length);
|
|
30694
|
+
if (selectionSignatureRef.current === selectionSignature)
|
|
30695
|
+
return;
|
|
30696
|
+
var isFirstRun = selectionSignatureRef.current === undefined;
|
|
30697
|
+
selectionSignatureRef.current = selectionSignature;
|
|
30698
|
+
if (isFirstRun)
|
|
30699
|
+
return;
|
|
30607
30700
|
if (activeLabels.length === 1) {
|
|
30608
30701
|
if (!legendAnnouncedRef.current) {
|
|
30609
30702
|
legendAnnouncedRef.current = true;
|
|
@@ -30620,6 +30713,7 @@
|
|
|
30620
30713
|
}
|
|
30621
30714
|
});
|
|
30622
30715
|
observer.observe(wrapper, {
|
|
30716
|
+
childList: true,
|
|
30623
30717
|
subtree: true,
|
|
30624
30718
|
attributes: true,
|
|
30625
30719
|
attributeFilter: ['aria-checked'],
|
|
@@ -30631,6 +30725,8 @@
|
|
|
30631
30725
|
return (React__default__namespace.createElement(FullscreenRoot, { ref: mergedRef, isInverse: isInverse, theme: theme },
|
|
30632
30726
|
React__default__namespace.createElement(VisuallyHidden, null,
|
|
30633
30727
|
React__default__namespace.createElement(Announce, null, legendAnnouncement)),
|
|
30728
|
+
React__default__namespace.createElement(VisuallyHidden, null,
|
|
30729
|
+
React__default__namespace.createElement("div", { "aria-live": "polite", ref: legendGroupAnnounceRef })),
|
|
30634
30730
|
React__default__namespace.createElement(CarbonChartWrapper, __assign({ "data-testid": testId, isInverse: isInverse, theme: theme, className: "carbon-chart-wrapper".concat(chartToolbar ? ' has-magma-toolbar' : ''), groupsLength: groupsLength < 6 ? groupsLength : 14, role: "region", "aria-label": ariaLabel || chartTitle, "aria-roledescription": "chart" }, rest),
|
|
30635
30731
|
React__default__namespace.createElement(ChartContentWrapper, null,
|
|
30636
30732
|
chartToolbar && (React__default__namespace.createElement(CarbonChartToolbar, { config: chartToolbar, dataSet: dataSet, isInverse: isInverse, isTableOpen: isTableOpen, isFullscreen: isFullscreen, onOpenTable: openTableModal, onToggleFullscreen: toggleFullscreen, theme: theme, title: chartTitle, wrapperRef: internalRef })),
|