@react-magma/charts 14.1.1-rc.0 → 14.2.0-rc.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/dist/charts.js +23 -5
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +24 -6
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +147 -97
- package/dist/charts.umd.js.map +1 -1
- package/dist/components/CarbonChart/CarbonChart.d.ts +15 -0
- package/package.json +1 -1
- package/src/components/CarbonChart/CarbonChart.test.js +143 -0
- package/src/components/CarbonChart/CarbonChart.tsx +73 -19
- package/src/components/CarbonChart/carbon-charts.css +81 -81
- package/src/components/ChartTable/ChartTable.stories.tsx +86 -1
|
@@ -61,6 +61,21 @@ export interface ChartToolbarConfig {
|
|
|
61
61
|
* @default 2
|
|
62
62
|
*/
|
|
63
63
|
titleLevel?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
64
|
+
/**
|
|
65
|
+
* Custom content rendered before the chart title.
|
|
66
|
+
*
|
|
67
|
+
* The content is placed inline in the title row and follows the same
|
|
68
|
+
* accessibility rules as `titleSuffix`.
|
|
69
|
+
*/
|
|
70
|
+
titlePrefix?: React.ReactNode;
|
|
71
|
+
/**
|
|
72
|
+
* Custom content rendered after the chart title and before toolbar actions.
|
|
73
|
+
*
|
|
74
|
+
* The content is placed inline in the title row and renders outside the
|
|
75
|
+
* heading element to preserve `options.title` as the heading's accessible name.
|
|
76
|
+
* Useful for patterns like Tooltip + IconButton.
|
|
77
|
+
*/
|
|
78
|
+
titleSuffix?: React.ReactNode;
|
|
64
79
|
}
|
|
65
80
|
export interface CarbonChartProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
66
81
|
dataSet: Array<object>;
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import { act, render, screen, fireEvent } from '@testing-library/react';
|
|
4
|
+
import { axe } from 'jest-axe';
|
|
4
5
|
import {
|
|
5
6
|
ThemeContext,
|
|
6
7
|
magma,
|
|
7
8
|
DropdownMenuItem,
|
|
8
9
|
I18nContext,
|
|
9
10
|
defaultI18n,
|
|
11
|
+
useIsInverse,
|
|
10
12
|
} from 'react-magma-dom';
|
|
11
13
|
|
|
12
14
|
import { CarbonChart, CarbonChartType } from '.';
|
|
@@ -928,6 +930,147 @@ describe('CarbonChart', () => {
|
|
|
928
930
|
});
|
|
929
931
|
});
|
|
930
932
|
|
|
933
|
+
describe('custom content slots', () => {
|
|
934
|
+
const toolbarProps = {
|
|
935
|
+
dataSet,
|
|
936
|
+
options: chartOptions,
|
|
937
|
+
type: CarbonChartType.bar,
|
|
938
|
+
chartToolbar: {},
|
|
939
|
+
};
|
|
940
|
+
|
|
941
|
+
it('should render titlePrefix and titleSuffix around the title', () => {
|
|
942
|
+
render(
|
|
943
|
+
<CarbonChart
|
|
944
|
+
{...toolbarProps}
|
|
945
|
+
chartToolbar={{
|
|
946
|
+
titlePrefix: <span data-testid="before">Badge</span>,
|
|
947
|
+
titleSuffix: <button type="button">About this chart</button>,
|
|
948
|
+
}}
|
|
949
|
+
/>
|
|
950
|
+
);
|
|
951
|
+
|
|
952
|
+
const before = screen.getByTestId('before');
|
|
953
|
+
const heading = screen.getByRole('heading', {
|
|
954
|
+
level: 2,
|
|
955
|
+
name: chartOptions.title,
|
|
956
|
+
});
|
|
957
|
+
const after = screen.getByRole('button', { name: 'About this chart' });
|
|
958
|
+
|
|
959
|
+
expect(
|
|
960
|
+
before.compareDocumentPosition(heading) &
|
|
961
|
+
Node.DOCUMENT_POSITION_FOLLOWING
|
|
962
|
+
).toBeTruthy();
|
|
963
|
+
expect(
|
|
964
|
+
heading.compareDocumentPosition(after) &
|
|
965
|
+
Node.DOCUMENT_POSITION_FOLLOWING
|
|
966
|
+
).toBeTruthy();
|
|
967
|
+
});
|
|
968
|
+
|
|
969
|
+
it('should place title slots before the toolbar actions in focus order', () => {
|
|
970
|
+
render(
|
|
971
|
+
<CarbonChart
|
|
972
|
+
{...toolbarProps}
|
|
973
|
+
chartToolbar={{
|
|
974
|
+
titleSuffix: <button type="button">About this chart</button>,
|
|
975
|
+
}}
|
|
976
|
+
/>
|
|
977
|
+
);
|
|
978
|
+
|
|
979
|
+
const after = screen.getByRole('button', { name: 'About this chart' });
|
|
980
|
+
const tableButton = screen.getByRole('button', {
|
|
981
|
+
name: chartOptions.title,
|
|
982
|
+
});
|
|
983
|
+
|
|
984
|
+
expect(
|
|
985
|
+
after.compareDocumentPosition(tableButton) &
|
|
986
|
+
Node.DOCUMENT_POSITION_FOLLOWING
|
|
987
|
+
).toBeTruthy();
|
|
988
|
+
});
|
|
989
|
+
|
|
990
|
+
it('should keep the title as the accessible name when titleSuffix is used', () => {
|
|
991
|
+
render(
|
|
992
|
+
<CarbonChart
|
|
993
|
+
{...toolbarProps}
|
|
994
|
+
chartToolbar={{
|
|
995
|
+
titleSuffix: <button type="button">About this chart</button>,
|
|
996
|
+
}}
|
|
997
|
+
/>
|
|
998
|
+
);
|
|
999
|
+
|
|
1000
|
+
// The heading, the chart region and the table modal must all stay
|
|
1001
|
+
// anchored to options.title, which is also the exported file name.
|
|
1002
|
+
expect(
|
|
1003
|
+
screen.getByRole('heading', { level: 2, name: chartOptions.title })
|
|
1004
|
+
).toBeInTheDocument();
|
|
1005
|
+
expect(
|
|
1006
|
+
screen.getByRole('region', { name: chartOptions.title })
|
|
1007
|
+
).toBeInTheDocument();
|
|
1008
|
+
|
|
1009
|
+
fireEvent.click(screen.getByRole('button', { name: chartOptions.title }));
|
|
1010
|
+
|
|
1011
|
+
expect(
|
|
1012
|
+
screen.getByRole('heading', {
|
|
1013
|
+
level: 2,
|
|
1014
|
+
name: `Tabular representation ${chartOptions.title}`,
|
|
1015
|
+
})
|
|
1016
|
+
).toBeInTheDocument();
|
|
1017
|
+
});
|
|
1018
|
+
|
|
1019
|
+
it('should render no slot markup by default', () => {
|
|
1020
|
+
render(<CarbonChart {...toolbarProps} />);
|
|
1021
|
+
|
|
1022
|
+
expect(screen.queryByTestId('before')).not.toBeInTheDocument();
|
|
1023
|
+
expect(
|
|
1024
|
+
screen.getByRole('heading', { level: 2, name: chartOptions.title })
|
|
1025
|
+
).toBeInTheDocument();
|
|
1026
|
+
});
|
|
1027
|
+
|
|
1028
|
+
it('should expose the resolved inverse value to slot content', () => {
|
|
1029
|
+
// Slot content is the adopter's, so it reads isInverse from context
|
|
1030
|
+
// rather than from our prop.
|
|
1031
|
+
function InverseProbe() {
|
|
1032
|
+
return <span>{useIsInverse() ? 'inverse' : 'default'}</span>;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
render(
|
|
1036
|
+
<CarbonChart
|
|
1037
|
+
{...toolbarProps}
|
|
1038
|
+
isInverse
|
|
1039
|
+
chartToolbar={{
|
|
1040
|
+
titlePrefix: <InverseProbe />,
|
|
1041
|
+
titleSuffix: <InverseProbe />,
|
|
1042
|
+
}}
|
|
1043
|
+
/>
|
|
1044
|
+
);
|
|
1045
|
+
|
|
1046
|
+
expect(screen.getAllByText('inverse')).toHaveLength(2);
|
|
1047
|
+
});
|
|
1048
|
+
|
|
1049
|
+
it('should not introduce accessibility violations with both slots', async () => {
|
|
1050
|
+
const { container } = render(
|
|
1051
|
+
<CarbonChart
|
|
1052
|
+
{...toolbarProps}
|
|
1053
|
+
chartToolbar={{
|
|
1054
|
+
titlePrefix: <span>Badge</span>,
|
|
1055
|
+
titleSuffix: <button type="button">About this chart</button>,
|
|
1056
|
+
}}
|
|
1057
|
+
/>
|
|
1058
|
+
);
|
|
1059
|
+
|
|
1060
|
+
// aria-prohibited-attr and aria-tooltip-name come from Carbon's own SVG
|
|
1061
|
+
// output and are present on a chart with no slots at all, so they are
|
|
1062
|
+
// excluded here rather than being attributed to the slots.
|
|
1063
|
+
const results = await axe(container, {
|
|
1064
|
+
rules: {
|
|
1065
|
+
'aria-prohibited-attr': { enabled: false },
|
|
1066
|
+
'aria-tooltip-name': { enabled: false },
|
|
1067
|
+
},
|
|
1068
|
+
});
|
|
1069
|
+
|
|
1070
|
+
expect(results).toHaveNoViolations();
|
|
1071
|
+
});
|
|
1072
|
+
});
|
|
1073
|
+
|
|
931
1074
|
describe('Legend accessibility wrap', () => {
|
|
932
1075
|
const testId = 'legend-a11y';
|
|
933
1076
|
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
Announce,
|
|
28
28
|
DropdownDivider,
|
|
29
29
|
DropdownMenuItem,
|
|
30
|
+
InverseContext,
|
|
30
31
|
ThemeInterface,
|
|
31
32
|
ThemeContext,
|
|
32
33
|
useDeviceDetect,
|
|
@@ -111,6 +112,22 @@ export interface ChartToolbarConfig {
|
|
|
111
112
|
* @default 2
|
|
112
113
|
*/
|
|
113
114
|
titleLevel?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
115
|
+
/**
|
|
116
|
+
* Custom content rendered before the chart title.
|
|
117
|
+
*
|
|
118
|
+
* The content is placed inline in the title row and follows the same
|
|
119
|
+
* accessibility rules as `titleSuffix`.
|
|
120
|
+
*/
|
|
121
|
+
titlePrefix?: React.ReactNode;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Custom content rendered after the chart title and before toolbar actions.
|
|
125
|
+
*
|
|
126
|
+
* The content is placed inline in the title row and renders outside the
|
|
127
|
+
* heading element to preserve `options.title` as the heading's accessible name.
|
|
128
|
+
* Useful for patterns like Tooltip + IconButton.
|
|
129
|
+
*/
|
|
130
|
+
titleSuffix?: React.ReactNode;
|
|
114
131
|
}
|
|
115
132
|
|
|
116
133
|
export interface CarbonChartProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
@@ -710,6 +727,23 @@ const ChartTitle = styled.h2<{
|
|
|
710
727
|
: props.theme.colors.neutral700} !important;
|
|
711
728
|
`;
|
|
712
729
|
|
|
730
|
+
const TitleGroup = styled.div<{ theme: ThemeInterface }>`
|
|
731
|
+
align-items: center;
|
|
732
|
+
display: flex;
|
|
733
|
+
gap: ${props => props.theme.spaceScale.spacing02};
|
|
734
|
+
min-width: 0;
|
|
735
|
+
`;
|
|
736
|
+
|
|
737
|
+
/*
|
|
738
|
+
* The `magma-chart-slot` class is what keeps the tag reset in
|
|
739
|
+
* carbon-charts.css out of this subtree, so adopter components keep their own
|
|
740
|
+
* styling. Renaming it means updating the `:not()` selectors in that file.
|
|
741
|
+
*/
|
|
742
|
+
const TitleSlot = styled.div`
|
|
743
|
+
align-items: center;
|
|
744
|
+
display: flex;
|
|
745
|
+
`;
|
|
746
|
+
|
|
713
747
|
const ToolbarActions = styled.div<{ theme: ThemeInterface }>`
|
|
714
748
|
align-items: center;
|
|
715
749
|
display: flex;
|
|
@@ -1030,13 +1064,25 @@ function CarbonChartToolbar({
|
|
|
1030
1064
|
isInverse={isInverse}
|
|
1031
1065
|
theme={theme}
|
|
1032
1066
|
>
|
|
1033
|
-
<
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1067
|
+
<TitleGroup theme={theme}>
|
|
1068
|
+
{config.titlePrefix ? (
|
|
1069
|
+
<TitleSlot className="magma-chart-slot">
|
|
1070
|
+
{config.titlePrefix}
|
|
1071
|
+
</TitleSlot>
|
|
1072
|
+
) : null}
|
|
1073
|
+
<ChartTitle
|
|
1074
|
+
as={`h${config.titleLevel ?? 2}` as keyof JSX.IntrinsicElements}
|
|
1075
|
+
isInverse={isInverse}
|
|
1076
|
+
theme={theme}
|
|
1077
|
+
>
|
|
1078
|
+
{resolvedTitle}
|
|
1079
|
+
</ChartTitle>
|
|
1080
|
+
{config.titleSuffix ? (
|
|
1081
|
+
<TitleSlot className="magma-chart-slot">
|
|
1082
|
+
{config.titleSuffix}
|
|
1083
|
+
</TitleSlot>
|
|
1084
|
+
) : null}
|
|
1085
|
+
</TitleGroup>
|
|
1040
1086
|
<ToolbarActions theme={theme}>
|
|
1041
1087
|
{showTable && (
|
|
1042
1088
|
<ChartTableButton
|
|
@@ -1492,18 +1538,26 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1492
1538
|
>
|
|
1493
1539
|
<ChartContentWrapper>
|
|
1494
1540
|
{chartToolbar && (
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1541
|
+
/*
|
|
1542
|
+
* Slot content comes from the adopter, so it resolves
|
|
1543
|
+
* `isInverse` from context rather than from our prop. Without
|
|
1544
|
+
* this provider a Magma component in a title slot would stay
|
|
1545
|
+
* light on an inverse chart.
|
|
1546
|
+
*/
|
|
1547
|
+
<InverseContext.Provider value={{ isInverse }}>
|
|
1548
|
+
<CarbonChartToolbar
|
|
1549
|
+
config={chartToolbar}
|
|
1550
|
+
dataSet={dataSet as Array<Record<string, unknown>>}
|
|
1551
|
+
isInverse={isInverse}
|
|
1552
|
+
isTableOpen={isTableOpen}
|
|
1553
|
+
isFullscreen={isFullscreen}
|
|
1554
|
+
onOpenTable={openTableModal}
|
|
1555
|
+
onToggleFullscreen={toggleFullscreen}
|
|
1556
|
+
theme={theme}
|
|
1557
|
+
title={chartTitle}
|
|
1558
|
+
wrapperRef={internalRef}
|
|
1559
|
+
/>
|
|
1560
|
+
</InverseContext.Provider>
|
|
1507
1561
|
)}
|
|
1508
1562
|
<ChartType data={dataSet} options={newOptions} />
|
|
1509
1563
|
</ChartContentWrapper>
|
|
@@ -475,87 +475,87 @@ html[data-carbon-theme='g10'] {
|
|
|
475
475
|
--cds-fluid-display-04-line-height: 1.19;
|
|
476
476
|
--cds-fluid-display-04-letter-spacing: 0;
|
|
477
477
|
}
|
|
478
|
-
.carbon-chart-wrapper a,
|
|
479
|
-
.carbon-chart-wrapper abbr,
|
|
480
|
-
.carbon-chart-wrapper acronym,
|
|
481
|
-
.carbon-chart-wrapper address,
|
|
482
|
-
.carbon-chart-wrapper applet,
|
|
483
|
-
.carbon-chart-wrapper article,
|
|
484
|
-
.carbon-chart-wrapper aside,
|
|
485
|
-
.carbon-chart-wrapper audio,
|
|
486
|
-
.carbon-chart-wrapper b,
|
|
487
|
-
.carbon-chart-wrapper big,
|
|
488
|
-
.carbon-chart-wrapper blockquote,
|
|
489
|
-
.carbon-chart-wrapper body,
|
|
490
|
-
.carbon-chart-wrapper canvas,
|
|
491
|
-
.carbon-chart-wrapper caption,
|
|
492
|
-
.carbon-chart-wrapper center,
|
|
493
|
-
.carbon-chart-wrapper cite,
|
|
494
|
-
.carbon-chart-wrapper code,
|
|
495
|
-
.carbon-chart-wrapper dd,
|
|
496
|
-
.carbon-chart-wrapper del,
|
|
497
|
-
.carbon-chart-wrapper details,
|
|
498
|
-
.carbon-chart-wrapper dfn,
|
|
499
|
-
.carbon-chart-wrapper div,
|
|
500
|
-
.carbon-chart-wrapper dl,
|
|
501
|
-
.carbon-chart-wrapper dt,
|
|
502
|
-
.carbon-chart-wrapper em,
|
|
503
|
-
.carbon-chart-wrapper embed,
|
|
504
|
-
.carbon-chart-wrapper fieldset,
|
|
505
|
-
.carbon-chart-wrapper figcaption,
|
|
506
|
-
.carbon-chart-wrapper figure,
|
|
507
|
-
.carbon-chart-wrapper footer,
|
|
508
|
-
.carbon-chart-wrapper form,
|
|
509
|
-
.carbon-chart-wrapper h1,
|
|
510
|
-
.carbon-chart-wrapper h2,
|
|
511
|
-
.carbon-chart-wrapper h3,
|
|
512
|
-
.carbon-chart-wrapper h4,
|
|
513
|
-
.carbon-chart-wrapper h5,
|
|
514
|
-
.carbon-chart-wrapper h6,
|
|
515
|
-
.carbon-chart-wrapper header,
|
|
516
|
-
.carbon-chart-wrapper hgroup,
|
|
517
|
-
.carbon-chart-wrapper html,
|
|
518
|
-
.carbon-chart-wrapper i,
|
|
519
|
-
.carbon-chart-wrapper iframe,
|
|
520
|
-
.carbon-chart-wrapper img,
|
|
521
|
-
.carbon-chart-wrapper ins,
|
|
522
|
-
.carbon-chart-wrapper kbd,
|
|
523
|
-
.carbon-chart-wrapper label,
|
|
524
|
-
.carbon-chart-wrapper legend,
|
|
525
|
-
.carbon-chart-wrapper li,
|
|
526
|
-
.carbon-chart-wrapper mark,
|
|
527
|
-
.carbon-chart-wrapper menu,
|
|
528
|
-
.carbon-chart-wrapper nav,
|
|
529
|
-
.carbon-chart-wrapper object,
|
|
530
|
-
.carbon-chart-wrapper ol,
|
|
531
|
-
.carbon-chart-wrapper output,
|
|
532
|
-
.carbon-chart-wrapper p,
|
|
533
|
-
.carbon-chart-wrapper pre,
|
|
534
|
-
.carbon-chart-wrapper q,
|
|
535
|
-
.carbon-chart-wrapper ruby,
|
|
536
|
-
.carbon-chart-wrapper s,
|
|
537
|
-
.carbon-chart-wrapper samp,
|
|
538
|
-
.carbon-chart-wrapper section,
|
|
539
|
-
.carbon-chart-wrapper small,
|
|
540
|
-
.carbon-chart-wrapper span,
|
|
541
|
-
.carbon-chart-wrapper strike,
|
|
542
|
-
.carbon-chart-wrapper strong,
|
|
543
|
-
.carbon-chart-wrapper sub,
|
|
544
|
-
.carbon-chart-wrapper summary,
|
|
545
|
-
.carbon-chart-wrapper sup,
|
|
546
|
-
.carbon-chart-wrapper table,
|
|
547
|
-
.carbon-chart-wrapper tbody,
|
|
548
|
-
.carbon-chart-wrapper td,
|
|
549
|
-
.carbon-chart-wrapper tfoot,
|
|
550
|
-
.carbon-chart-wrapper th,
|
|
551
|
-
.carbon-chart-wrapper thead,
|
|
552
|
-
.carbon-chart-wrapper time,
|
|
553
|
-
.carbon-chart-wrapper tr,
|
|
554
|
-
.carbon-chart-wrapper tt,
|
|
555
|
-
.carbon-chart-wrapper u,
|
|
556
|
-
.carbon-chart-wrapper ul,
|
|
557
|
-
.carbon-chart-wrapper var,
|
|
558
|
-
.carbon-chart-wrapper video {
|
|
478
|
+
.carbon-chart-wrapper a:not(.magma-chart-slot *),
|
|
479
|
+
.carbon-chart-wrapper abbr:not(.magma-chart-slot *),
|
|
480
|
+
.carbon-chart-wrapper acronym:not(.magma-chart-slot *),
|
|
481
|
+
.carbon-chart-wrapper address:not(.magma-chart-slot *),
|
|
482
|
+
.carbon-chart-wrapper applet:not(.magma-chart-slot *),
|
|
483
|
+
.carbon-chart-wrapper article:not(.magma-chart-slot *),
|
|
484
|
+
.carbon-chart-wrapper aside:not(.magma-chart-slot *),
|
|
485
|
+
.carbon-chart-wrapper audio:not(.magma-chart-slot *),
|
|
486
|
+
.carbon-chart-wrapper b:not(.magma-chart-slot *),
|
|
487
|
+
.carbon-chart-wrapper big:not(.magma-chart-slot *),
|
|
488
|
+
.carbon-chart-wrapper blockquote:not(.magma-chart-slot *),
|
|
489
|
+
.carbon-chart-wrapper body:not(.magma-chart-slot *),
|
|
490
|
+
.carbon-chart-wrapper canvas:not(.magma-chart-slot *),
|
|
491
|
+
.carbon-chart-wrapper caption:not(.magma-chart-slot *),
|
|
492
|
+
.carbon-chart-wrapper center:not(.magma-chart-slot *),
|
|
493
|
+
.carbon-chart-wrapper cite:not(.magma-chart-slot *),
|
|
494
|
+
.carbon-chart-wrapper code:not(.magma-chart-slot *),
|
|
495
|
+
.carbon-chart-wrapper dd:not(.magma-chart-slot *),
|
|
496
|
+
.carbon-chart-wrapper del:not(.magma-chart-slot *),
|
|
497
|
+
.carbon-chart-wrapper details:not(.magma-chart-slot *),
|
|
498
|
+
.carbon-chart-wrapper dfn:not(.magma-chart-slot *),
|
|
499
|
+
.carbon-chart-wrapper div:not(.magma-chart-slot *),
|
|
500
|
+
.carbon-chart-wrapper dl:not(.magma-chart-slot *),
|
|
501
|
+
.carbon-chart-wrapper dt:not(.magma-chart-slot *),
|
|
502
|
+
.carbon-chart-wrapper em:not(.magma-chart-slot *),
|
|
503
|
+
.carbon-chart-wrapper embed:not(.magma-chart-slot *),
|
|
504
|
+
.carbon-chart-wrapper fieldset:not(.magma-chart-slot *),
|
|
505
|
+
.carbon-chart-wrapper figcaption:not(.magma-chart-slot *),
|
|
506
|
+
.carbon-chart-wrapper figure:not(.magma-chart-slot *),
|
|
507
|
+
.carbon-chart-wrapper footer:not(.magma-chart-slot *),
|
|
508
|
+
.carbon-chart-wrapper form:not(.magma-chart-slot *),
|
|
509
|
+
.carbon-chart-wrapper h1:not(.magma-chart-slot *),
|
|
510
|
+
.carbon-chart-wrapper h2:not(.magma-chart-slot *),
|
|
511
|
+
.carbon-chart-wrapper h3:not(.magma-chart-slot *),
|
|
512
|
+
.carbon-chart-wrapper h4:not(.magma-chart-slot *),
|
|
513
|
+
.carbon-chart-wrapper h5:not(.magma-chart-slot *),
|
|
514
|
+
.carbon-chart-wrapper h6:not(.magma-chart-slot *),
|
|
515
|
+
.carbon-chart-wrapper header:not(.magma-chart-slot *),
|
|
516
|
+
.carbon-chart-wrapper hgroup:not(.magma-chart-slot *),
|
|
517
|
+
.carbon-chart-wrapper html:not(.magma-chart-slot *),
|
|
518
|
+
.carbon-chart-wrapper i:not(.magma-chart-slot *),
|
|
519
|
+
.carbon-chart-wrapper iframe:not(.magma-chart-slot *),
|
|
520
|
+
.carbon-chart-wrapper img:not(.magma-chart-slot *),
|
|
521
|
+
.carbon-chart-wrapper ins:not(.magma-chart-slot *),
|
|
522
|
+
.carbon-chart-wrapper kbd:not(.magma-chart-slot *),
|
|
523
|
+
.carbon-chart-wrapper label:not(.magma-chart-slot *),
|
|
524
|
+
.carbon-chart-wrapper legend:not(.magma-chart-slot *),
|
|
525
|
+
.carbon-chart-wrapper li:not(.magma-chart-slot *),
|
|
526
|
+
.carbon-chart-wrapper mark:not(.magma-chart-slot *),
|
|
527
|
+
.carbon-chart-wrapper menu:not(.magma-chart-slot *),
|
|
528
|
+
.carbon-chart-wrapper nav:not(.magma-chart-slot *),
|
|
529
|
+
.carbon-chart-wrapper object:not(.magma-chart-slot *),
|
|
530
|
+
.carbon-chart-wrapper ol:not(.magma-chart-slot *),
|
|
531
|
+
.carbon-chart-wrapper output:not(.magma-chart-slot *),
|
|
532
|
+
.carbon-chart-wrapper p:not(.magma-chart-slot *),
|
|
533
|
+
.carbon-chart-wrapper pre:not(.magma-chart-slot *),
|
|
534
|
+
.carbon-chart-wrapper q:not(.magma-chart-slot *),
|
|
535
|
+
.carbon-chart-wrapper ruby:not(.magma-chart-slot *),
|
|
536
|
+
.carbon-chart-wrapper s:not(.magma-chart-slot *),
|
|
537
|
+
.carbon-chart-wrapper samp:not(.magma-chart-slot *),
|
|
538
|
+
.carbon-chart-wrapper section:not(.magma-chart-slot *),
|
|
539
|
+
.carbon-chart-wrapper small:not(.magma-chart-slot *),
|
|
540
|
+
.carbon-chart-wrapper span:not(.magma-chart-slot *),
|
|
541
|
+
.carbon-chart-wrapper strike:not(.magma-chart-slot *),
|
|
542
|
+
.carbon-chart-wrapper strong:not(.magma-chart-slot *),
|
|
543
|
+
.carbon-chart-wrapper sub:not(.magma-chart-slot *),
|
|
544
|
+
.carbon-chart-wrapper summary:not(.magma-chart-slot *),
|
|
545
|
+
.carbon-chart-wrapper sup:not(.magma-chart-slot *),
|
|
546
|
+
.carbon-chart-wrapper table:not(.magma-chart-slot *),
|
|
547
|
+
.carbon-chart-wrapper tbody:not(.magma-chart-slot *),
|
|
548
|
+
.carbon-chart-wrapper td:not(.magma-chart-slot *),
|
|
549
|
+
.carbon-chart-wrapper tfoot:not(.magma-chart-slot *),
|
|
550
|
+
.carbon-chart-wrapper th:not(.magma-chart-slot *),
|
|
551
|
+
.carbon-chart-wrapper thead:not(.magma-chart-slot *),
|
|
552
|
+
.carbon-chart-wrapper time:not(.magma-chart-slot *),
|
|
553
|
+
.carbon-chart-wrapper tr:not(.magma-chart-slot *),
|
|
554
|
+
.carbon-chart-wrapper tt:not(.magma-chart-slot *),
|
|
555
|
+
.carbon-chart-wrapper u:not(.magma-chart-slot *),
|
|
556
|
+
.carbon-chart-wrapper ul:not(.magma-chart-slot *),
|
|
557
|
+
.carbon-chart-wrapper var:not(.magma-chart-slot *),
|
|
558
|
+
.carbon-chart-wrapper video:not(.magma-chart-slot *) {
|
|
559
559
|
border: 0;
|
|
560
560
|
font: inherit;
|
|
561
561
|
font-size: 100%;
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
+
import { ScaleTypes } from '@carbon/charts-react';
|
|
3
4
|
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Badge,
|
|
7
|
+
BadgeColor,
|
|
8
|
+
ButtonSize,
|
|
9
|
+
ButtonType,
|
|
10
|
+
ButtonVariant,
|
|
11
|
+
Card,
|
|
12
|
+
IconButton,
|
|
13
|
+
Tooltip,
|
|
14
|
+
} from 'react-magma-dom';
|
|
15
|
+
import { InfoIcon } from 'react-magma-icons';
|
|
5
16
|
|
|
6
17
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '../CarbonChart';
|
|
7
18
|
|
|
@@ -150,3 +161,77 @@ export const TableOnly = {
|
|
|
150
161
|
},
|
|
151
162
|
},
|
|
152
163
|
};
|
|
164
|
+
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
// Custom content slots
|
|
167
|
+
// ---------------------------------------------------------------------------
|
|
168
|
+
|
|
169
|
+
const chartInfoLabel =
|
|
170
|
+
'Scores are averaged across all attempts in the selected term.';
|
|
171
|
+
|
|
172
|
+
const ChartInfoTooltip = () => (
|
|
173
|
+
<Tooltip content={chartInfoLabel}>
|
|
174
|
+
<IconButton
|
|
175
|
+
aria-label={chartInfoLabel}
|
|
176
|
+
icon={<InfoIcon />}
|
|
177
|
+
size={ButtonSize.small}
|
|
178
|
+
type={ButtonType.button}
|
|
179
|
+
variant={ButtonVariant.link}
|
|
180
|
+
/>
|
|
181
|
+
</Tooltip>
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const slotContent = {
|
|
185
|
+
tooltip: <ChartInfoTooltip />,
|
|
186
|
+
badge: <Badge color={BadgeColor.success}>Live</Badge>,
|
|
187
|
+
none: undefined,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
interface TitleSlotsArgs extends Omit<CarbonChartProps, 'options'> {
|
|
191
|
+
content: keyof typeof slotContent;
|
|
192
|
+
slotPosition: 'titleSuffix' | 'titlePrefix';
|
|
193
|
+
title: string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export const TitleSlots = {
|
|
197
|
+
render: ({ content, slotPosition, title, ...args }: TitleSlotsArgs) => (
|
|
198
|
+
<Card isInverse={args.isInverse} style={{ padding: '12px' }}>
|
|
199
|
+
<CarbonChart
|
|
200
|
+
{...args}
|
|
201
|
+
options={{
|
|
202
|
+
title,
|
|
203
|
+
axes: {
|
|
204
|
+
left: { mapsTo: 'value' },
|
|
205
|
+
bottom: { mapsTo: 'group', scaleType: ScaleTypes.LABELS },
|
|
206
|
+
},
|
|
207
|
+
height: '400px',
|
|
208
|
+
}}
|
|
209
|
+
chartToolbar={{
|
|
210
|
+
titlePrefix:
|
|
211
|
+
slotPosition === 'titlePrefix' ? slotContent[content] : undefined,
|
|
212
|
+
titleSuffix:
|
|
213
|
+
slotPosition === 'titleSuffix' ? slotContent[content] : undefined,
|
|
214
|
+
}}
|
|
215
|
+
/>
|
|
216
|
+
</Card>
|
|
217
|
+
),
|
|
218
|
+
argTypes: {
|
|
219
|
+
content: {
|
|
220
|
+
control: { type: 'radio' },
|
|
221
|
+
options: ['tooltip', 'badge', 'none'],
|
|
222
|
+
},
|
|
223
|
+
slotPosition: {
|
|
224
|
+
control: { type: 'radio' },
|
|
225
|
+
options: ['titleSuffix', 'titlePrefix'],
|
|
226
|
+
},
|
|
227
|
+
title: { control: { type: 'text' } },
|
|
228
|
+
},
|
|
229
|
+
args: {
|
|
230
|
+
content: 'tooltip',
|
|
231
|
+
isInverse: false,
|
|
232
|
+
slotPosition: 'titleSuffix',
|
|
233
|
+
title: 'Chapter Performance',
|
|
234
|
+
type: CarbonChartType.bar,
|
|
235
|
+
dataSet: barDataSet,
|
|
236
|
+
},
|
|
237
|
+
};
|