Skip to content

Commit 16c0f54

Browse files
Add basic toolbar for community projects
1 parent f79daea commit 16c0f54

File tree

12 files changed

+49
-7
lines changed

12 files changed

+49
-7
lines changed

docs/data/charts/toolbar/toolbar.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ This feature is unstable and its API, visuals and/or behavior may change in futu
1414

1515
Charts provide a toolbar that can be enabled to give users quick access to certain features.
1616

17+
The toolbar is available on scatter, bar, line, pie and radar charts.
18+
1719
To enable the toolbar, set the `showToolbar` prop to `true` on the chart component.
1820

1921
:::info

docs/pages/x/api/charts/pie-chart.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
}
3535
},
3636
"onItemClick": { "type": { "name": "func" } },
37+
"showToolbar": { "type": { "name": "bool" }, "default": "false" },
3738
"skipAnimation": { "type": { "name": "bool" } },
3839
"slotProps": { "type": { "name": "object" }, "default": "{}" },
3940
"slots": {

docs/pages/x/api/charts/radar-chart.json

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"type": { "name": "enum", "description": "'circular'<br>&#124;&nbsp;'sharp'" },
5353
"default": "'sharp'"
5454
},
55+
"showToolbar": { "type": { "name": "bool" }, "default": "false" },
5556
"skipAnimation": { "type": { "name": "bool" } },
5657
"slotProps": { "type": { "name": "object" }, "default": "{}" },
5758
"slots": {

docs/translations/api-docs/charts/pie-chart/pie-chart.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"series": {
2929
"description": "The series to display in the pie chart. An array of <a href='/x/api/charts/pie-series-type/'>PieSeriesType</a> objects."
3030
},
31+
"showToolbar": { "description": "If true, shows the default chart toolbar." },
3132
"skipAnimation": {
3233
"description": "If <code>true</code>, animations are skipped. If unset or <code>false</code>, the animations respects the user&#39;s <code>prefers-reduced-motion</code> setting."
3334
},

docs/translations/api-docs/charts/radar-chart/radar-chart.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"description": "The series to display in the bar chart. An array of RadarSeriesType objects."
3434
},
3535
"shape": { "description": "The grid shape." },
36+
"showToolbar": { "description": "If true, shows the default chart toolbar." },
3637
"skipAnimation": {
3738
"description": "If <code>true</code>, animations are skipped. If unset or <code>false</code>, the animations respects the user&#39;s <code>prefers-reduced-motion</code> setting."
3839
},

packages/x-charts/src/BarChart/BarChart.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as React from 'react';
33
import PropTypes from 'prop-types';
44
import { useThemeProps } from '@mui/material/styles';
55
import { MakeOptional } from '@mui/x-internals/types';
6+
import { ChartsToolbar } from '../Toolbar/internals/ChartsToolbar';
67
import { ChartsToolbarSlotProps, ChartsToolbarSlots } from '../material';
78
import { ChartsToolbarProps } from '../Toolbar';
89
import { BarPlot, BarPlotProps, BarPlotSlotProps, BarPlotSlots } from './BarPlot';
@@ -141,10 +142,12 @@ const BarChart = React.forwardRef(function BarChart(
141142
);
142143

143144
const Tooltip = props.slots?.tooltip ?? ChartsTooltip;
145+
const Toolbar = props.slots?.toolbar ?? ChartsToolbar;
144146

145147
return (
146148
<ChartDataProvider<'bar', BarChartPluginsSignatures> {...chartDataProviderProps}>
147149
<ChartsWrapper {...chartsWrapperProps}>
150+
{props.showToolbar ? <Toolbar /> : null}
148151
{!props.hideLegend && <ChartsLegend {...legendProps} />}
149152
<ChartsSurface {...chartsSurfaceProps}>
150153
<ChartsGrid {...gridProps} />

packages/x-charts/src/BarChart/useBarChartProps.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const useBarChartProps = (props: BarChartProps) => {
4848
barLabel,
4949
className,
5050
hideLegend,
51+
showToolbar,
5152
...rest
5253
} = props;
5354

packages/x-charts/src/LineChart/LineChart.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as React from 'react';
33
import PropTypes from 'prop-types';
44
import { useThemeProps } from '@mui/material/styles';
55
import { MakeOptional } from '@mui/x-internals/types';
6+
import { ChartsToolbar } from '../Toolbar/internals/ChartsToolbar';
67
import { ChartsToolbarSlots, ChartsToolbarSlotProps } from '../material';
78
import { AreaPlot, AreaPlotProps, AreaPlotSlotProps, AreaPlotSlots } from './AreaPlot';
89
import { LinePlot, LinePlotProps, LinePlotSlotProps, LinePlotSlots } from './LinePlot';
@@ -169,10 +170,12 @@ const LineChart = React.forwardRef(function LineChart(
169170
);
170171

171172
const Tooltip = props.slots?.tooltip ?? ChartsTooltip;
173+
const Toolbar = props.slots?.toolbar ?? ChartsToolbar;
172174

173175
return (
174176
<ChartDataProvider<'line', LineChartPluginsSignatures> {...chartDataProviderProps}>
175177
<ChartsWrapper {...chartsWrapperProps}>
178+
{props.showToolbar ? <Toolbar /> : null}
176179
{!props.hideLegend && <ChartsLegend {...legendProps} />}
177180
<ChartsSurface {...chartsSurfaceProps}>
178181
<ChartsGrid {...gridProps} />

packages/x-charts/src/PieChart/PieChart.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as React from 'react';
33
import PropTypes from 'prop-types';
44
import { useThemeProps } from '@mui/material/styles';
55
import { MakeOptional } from '@mui/x-internals/types';
6+
import { ChartsToolbar } from '../Toolbar/internals/ChartsToolbar';
67
import { ChartsToolbarProps } from '../Toolbar';
78
import { ChartsToolbarSlotProps, ChartsToolbarSlots } from '../material';
89
import { ChartContainerProps } from '../ChartContainer';
@@ -70,6 +71,11 @@ export interface PieChartProps
7071
* Callback fired when a pie arc is clicked.
7172
*/
7273
onItemClick?: PiePlotProps['onItemClick'];
74+
/**
75+
* If true, shows the default chart toolbar.
76+
* @default false
77+
*/
78+
showToolbar?: boolean;
7379
/**
7480
* Overridable component slots.
7581
* @default {}
@@ -116,6 +122,7 @@ const PieChart = React.forwardRef(function PieChart(
116122
highlightedItem,
117123
onHighlightChange,
118124
className,
125+
showToolbar,
119126
...other
120127
} = props;
121128
const margin = defaultizeMargin(marginProps, defaultMargin);
@@ -141,13 +148,16 @@ const PieChart = React.forwardRef(function PieChart(
141148
);
142149

143150
const Tooltip = slots?.tooltip ?? ChartsTooltip;
151+
const Toolbar = props.slots?.toolbar ?? ChartsToolbar;
152+
144153
return (
145154
<ChartDataProvider<'pie', PieChartPluginSignatures> {...chartDataProviderProps}>
146155
<ChartsWrapper
147156
legendPosition={props.slotProps?.legend?.position}
148157
legendDirection={props?.slotProps?.legend?.direction ?? 'vertical'}
149158
sx={sx}
150159
>
160+
{showToolbar ? <Toolbar /> : null}
151161
{!hideLegend && (
152162
<ChartsLegend
153163
direction={props?.slotProps?.legend?.direction ?? 'vertical'}
@@ -246,6 +256,11 @@ PieChart.propTypes = {
246256
* An array of [[PieSeriesType]] objects.
247257
*/
248258
series: PropTypes.arrayOf(PropTypes.object).isRequired,
259+
/**
260+
* If true, shows the default chart toolbar.
261+
* @default false
262+
*/
263+
showToolbar: PropTypes.bool,
249264
/**
250265
* If `true`, animations are skipped.
251266
* If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.

packages/x-charts/src/RadarChart/RadarChart.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import * as React from 'react';
33
import PropTypes from 'prop-types';
44
import { useThemeProps } from '@mui/material/styles';
5+
import { ChartsToolbar } from '@mui/x-charts/Toolbar/internals/ChartsToolbar';
56
import { ChartsLegend, ChartsLegendSlotProps, ChartsLegendSlots } from '../ChartsLegend';
67
import {
78
ChartsOverlay,
@@ -53,6 +54,11 @@ export interface RadarChartProps
5354
* If `true`, the legend is not rendered.
5455
*/
5556
hideLegend?: boolean;
57+
/**
58+
* If true, shows the default chart toolbar.
59+
* @default false
60+
*/
61+
showToolbar?: boolean;
5662
/**
5763
* Overridable component slots.
5864
* @default {}
@@ -82,10 +88,12 @@ const RadarChart = React.forwardRef(function RadarChart(
8288
} = useRadarChartProps(props);
8389

8490
const Tooltip = props.slots?.tooltip ?? ChartsTooltip;
91+
const Toolbar = props.slots?.toolbar ?? ChartsToolbar;
8592

8693
return (
8794
<RadarDataProvider {...radarDataProviderProps}>
8895
<ChartsWrapper {...chartsWrapperProps}>
96+
{props.showToolbar ? <Toolbar /> : null}
8997
{!props.hideLegend && <ChartsLegend {...legendProps} />}
9098
<ChartsSurface {...chartsSurfaceProps} ref={ref}>
9199
<RadarGrid {...radarGrid} />
@@ -214,6 +222,11 @@ RadarChart.propTypes = {
214222
* @default 'sharp'
215223
*/
216224
shape: PropTypes.oneOf(['circular', 'sharp']),
225+
/**
226+
* If true, shows the default chart toolbar.
227+
* @default false
228+
*/
229+
showToolbar: PropTypes.bool,
217230
/**
218231
* If `true`, animations are skipped.
219232
* If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.

packages/x-charts/src/RadarChart/useRadarChartProps.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const useRadarChartProps = (props: RadarChartProps) => {
3535
shape,
3636
stripeColor,
3737
highlight = 'axis',
38+
showToolbar,
3839
...other
3940
} = props;
4041

packages/x-charts/src/ScatterChart/ScatterChart.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as React from 'react';
33
import PropTypes from 'prop-types';
44
import { useThemeProps } from '@mui/material/styles';
55
import { MakeOptional } from '@mui/x-internals/types';
6-
import { ChartsToolbarPro } from '@mui/x-charts-pro/ChartsToolbarPro';
76
import { ChartsToolbarProps } from '../Toolbar';
87
import { ChartsToolbarSlots, ChartsToolbarSlotProps } from '../material';
98
import {
@@ -34,6 +33,7 @@ import { ChartsSurface } from '../ChartsSurface';
3433
import { ChartsWrapper } from '../internals/components/ChartsWrapper';
3534
import { UseChartVoronoiSignature } from '../internals/plugins/featurePlugins/useChartVoronoi';
3635
import { ScatterChartPluginsSignatures } from './ScatterChart.plugins';
36+
import { ChartsToolbar } from '../Toolbar/internals/ChartsToolbar';
3737

3838
export interface ScatterChartSlots
3939
extends ChartsAxisSlots,
@@ -92,6 +92,11 @@ export interface ScatterChartProps
9292
* If `true`, the legend is not rendered.
9393
*/
9494
hideLegend?: boolean;
95+
/**
96+
* If true, shows the default chart toolbar.
97+
* @default false
98+
*/
99+
showToolbar?: boolean;
95100
/**
96101
* Overridable component slots.
97102
* @default {}
@@ -108,11 +113,6 @@ export interface ScatterChartProps
108113
* @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier.
109114
*/
110115
onItemClick?: ScatterPlotProps['onItemClick'] | UseChartVoronoiSignature['params']['onItemClick'];
111-
/**
112-
* If true, shows the default chart toolbar.
113-
* @default false
114-
*/
115-
showToolbar?: boolean;
116116
}
117117

118118
/**
@@ -147,7 +147,7 @@ const ScatterChart = React.forwardRef(function ScatterChart(
147147
);
148148

149149
const Tooltip = props.slots?.tooltip ?? ChartsTooltip;
150-
const Toolbar = props.slots?.toolbar ?? ChartsToolbarPro;
150+
const Toolbar = props.slots?.toolbar ?? ChartsToolbar;
151151

152152
return (
153153
<ChartDataProvider<'scatter', ScatterChartPluginsSignatures> {...chartDataProviderProps}>

0 commit comments

Comments
 (0)