@react-magma/charts 15.0.0-rc.3 → 15.0.0-rc.4

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.
@@ -56,6 +56,11 @@ export interface ChartToolbarConfig {
56
56
  * @default 2
57
57
  */
58
58
  tableHeaderLevel?: 1 | 2 | 3 | 4 | 5 | 6;
59
+ /**
60
+ * Heading level for the chart title.
61
+ * @default 2
62
+ */
63
+ titleLevel?: 1 | 2 | 3 | 4 | 5 | 6;
59
64
  }
60
65
  export interface CarbonChartProps extends React.HTMLAttributes<HTMLDivElement> {
61
66
  dataSet: Array<object>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-magma/charts",
3
- "version": "15.0.0-rc.3",
3
+ "version": "15.0.0-rc.4",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -853,6 +853,27 @@ describe('CarbonChart', () => {
853
853
  ).not.toBeInTheDocument();
854
854
  });
855
855
 
856
+ it('should render the chart title as h2 by default', () => {
857
+ render(<CarbonChart {...toolbarProps} />);
858
+
859
+ expect(
860
+ screen.getByRole('heading', { level: 2, name: chartOptions.title })
861
+ ).toBeInTheDocument();
862
+ });
863
+
864
+ it('should render the chart title at the level set by titleLevel', () => {
865
+ render(
866
+ <CarbonChart {...toolbarProps} chartToolbar={{ titleLevel: 3 }} />
867
+ );
868
+
869
+ expect(
870
+ screen.getByRole('heading', { level: 3, name: chartOptions.title })
871
+ ).toBeInTheDocument();
872
+ expect(
873
+ screen.queryByRole('heading', { level: 2, name: chartOptions.title })
874
+ ).not.toBeInTheDocument();
875
+ });
876
+
856
877
  it('should always render the more options dropdown with built-in download items', () => {
857
878
  render(<CarbonChart {...toolbarProps} />);
858
879
 
@@ -105,6 +105,11 @@ export interface ChartToolbarConfig {
105
105
  * @default 2
106
106
  */
107
107
  tableHeaderLevel?: 1 | 2 | 3 | 4 | 5 | 6;
108
+ /**
109
+ * Heading level for the chart title.
110
+ * @default 2
111
+ */
112
+ titleLevel?: 1 | 2 | 3 | 4 | 5 | 6;
108
113
  }
109
114
 
110
115
  export interface CarbonChartProps extends React.HTMLAttributes<HTMLDivElement> {
@@ -1024,7 +1029,11 @@ function CarbonChartToolbar({
1024
1029
  isInverse={isInverse}
1025
1030
  theme={theme}
1026
1031
  >
1027
- <ChartTitle isInverse={isInverse} theme={theme}>
1032
+ <ChartTitle
1033
+ as={`h${config.titleLevel ?? 2}` as keyof JSX.IntrinsicElements}
1034
+ isInverse={isInverse}
1035
+ theme={theme}
1036
+ >
1028
1037
  {resolvedTitle}
1029
1038
  </ChartTitle>
1030
1039
  <ToolbarActions theme={theme}>
@@ -18,12 +18,19 @@ export default {
18
18
  control: { type: 'select' },
19
19
  options: Object.values(CarbonChartType),
20
20
  },
21
+ titleLevel: {
22
+ control: { type: 'select' },
23
+ options: [1, 2, 3, 4, 5, 6],
24
+ description: 'Heading level for the chart title (h1–h6).',
25
+ },
21
26
  },
22
27
  } as Meta;
23
28
 
24
- const Template: StoryFn<CarbonChartProps> = args => (
29
+ const Template: StoryFn<
30
+ CarbonChartProps & { titleLevel?: 1 | 2 | 3 | 4 | 5 | 6 }
31
+ > = ({ titleLevel, ...args }) => (
25
32
  <Card isInverse={args.isInverse} style={{ padding: '12px' }}>
26
- <CarbonChart {...args} />
33
+ <CarbonChart {...args} chartToolbar={{ titleLevel }} />
27
34
  </Card>
28
35
  );
29
36