diff --git a/packages/grid/_modules_/grid/components/toolbar/GridToolbarExport.tsx b/packages/grid/_modules_/grid/components/toolbar/GridToolbarExport.tsx index bf1408ac66b9a..a3c2f2c0a2b5b 100644 --- a/packages/grid/_modules_/grid/components/toolbar/GridToolbarExport.tsx +++ b/packages/grid/_modules_/grid/components/toolbar/GridToolbarExport.tsx @@ -7,31 +7,44 @@ import MenuItem from '@material-ui/core/MenuItem'; import { isHideMenuKey, isTabKey } from '../../utils/keyboardUtils'; import { GridApiContext } from '../GridApiContext'; import { GridMenu } from '../menu/GridMenu'; -import { GridExportOption, GridExportFormat, GridExportConfiguration } from '../../models'; +import { GridExportCsvOptions } from '../../models/gridExport'; -type GridToolbarExportProps = ButtonProps & { exportConfiguration?: GridExportConfiguration }; +interface GridExportFormatCsv { + format: 'csv'; + formatOptions?: GridExportCsvOptions; +} + +type GridExportFormatOption = GridExportFormatCsv; + +type GridExportOption = GridExportFormatOption & { + label: React.ReactNode; +}; + +export interface GridToolbarExportProps extends ButtonProps { + csvOptions?: GridExportCsvOptions; +} export const GridToolbarExport = React.forwardRef( - function GridToolbarExport({ exportConfiguration, ...other }, ref) { + function GridToolbarExport(props, ref) { + const { csvOptions, ...other } = props; const apiRef = React.useContext(GridApiContext); - const exportButtonId = useId(); - const exportMenuId = useId(); + const buttonId = useId(); + const menuId = useId(); const [anchorEl, setAnchorEl] = React.useState(null); const ExportIcon = apiRef!.current.components!.ExportIcon!; - const ExportOptions: Array = []; - - ExportOptions.push({ + const exportOptions: Array = []; + exportOptions.push({ label: apiRef!.current.getLocaleText('toolbarExportCSV'), format: 'csv', - options: exportConfiguration?.csv, + formatOptions: csvOptions, }); - const handleExportSelectorOpen = (event) => setAnchorEl(event.currentTarget); - const handleExportSelectorClose = () => setAnchorEl(null); - const handleExport = (option: GridExportFormat, fileName?: string) => { + const handleMenuOpen = (event) => setAnchorEl(event.currentTarget); + const handleMenuClose = () => setAnchorEl(null); + const handleExport = (option: GridExportFormatOption) => () => { if (option.format === 'csv') { - apiRef!.current.exportDataAsCsv(option.options, fileName); + apiRef!.current.exportDataAsCsv(option.formatOptions); } setAnchorEl(null); @@ -42,16 +55,10 @@ export const GridToolbarExport = React.forwardRef = ExportOptions.map((option, index) => ( - handleExport(option, exportConfiguration?.fileName)}> - {option.label} - - )); - return (