diff --git a/src-docs/src/views/datagrid/toolbar/datagrid_custom_toolbar.tsx b/src-docs/src/views/datagrid/toolbar/datagrid_custom_toolbar.tsx index 71a4f29e864..29b3d27ce48 100644 --- a/src-docs/src/views/datagrid/toolbar/datagrid_custom_toolbar.tsx +++ b/src-docs/src/views/datagrid/toolbar/datagrid_custom_toolbar.tsx @@ -10,6 +10,8 @@ import { EuiDataGridToolbarProps, EuiFormRow, EuiRange, + EuiFlexGroup, + EuiFlexItem, } from '../../../../../src'; const raw_data: Array<{ [key: string]: string }> = []; @@ -117,18 +119,28 @@ export default () => { fullScreenControl, keyboardShortcutsControl, }) => { - return { - left: hasRoomForGridControls ? 'Custom left side' : null, - right: ( - <> - {columnControl} - {columnSortingControl} - {keyboardShortcutsControl} - {displayControl} - {fullScreenControl} - - ), - }; + return ( + + + {hasRoomForGridControls && `Custom left side`} + + + + + {columnControl} + {columnSortingControl} + {keyboardShortcutsControl} + {displayControl} + {fullScreenControl} + + + + ); }; return ( diff --git a/src-docs/src/views/datagrid/toolbar/datagrid_toolbar_example.js b/src-docs/src/views/datagrid/toolbar/datagrid_toolbar_example.js index 6b8f172a8b1..50589378441 100644 --- a/src-docs/src/views/datagrid/toolbar/datagrid_toolbar_example.js +++ b/src-docs/src/views/datagrid/toolbar/datagrid_toolbar_example.js @@ -201,14 +201,12 @@ export const DataGridToolbarExample = { text: ( <>

- For advanced use cases, the renderCustomToolbar{' '} + For advanced use cases, the renderCustomToolbar prop for EuiDataGrid may be used to take complete - control over the placement of the toolbar controls (by returning{' '} - left and right) or the whole - toolbar element (by returning a react element). This may be useful - where custom layout (e.g., all buttons on the right side) are - required. The default individual controls will be available as - function parameters. + control over the whole toolbar element (by returning a react + element). This may be useful where a custom layout (e.g., all + buttons on the right side) is required. The default individual + controls will be available as function parameters.

), diff --git a/src/components/datagrid/controls/data_grid_toolbar.test.tsx b/src/components/datagrid/controls/data_grid_toolbar.test.tsx index 606f64962c0..2d7bfa9299f 100644 --- a/src/components/datagrid/controls/data_grid_toolbar.test.tsx +++ b/src/components/datagrid/controls/data_grid_toolbar.test.tsx @@ -32,31 +32,34 @@ describe('EuiDataGridToolbar', () => { const component = shallow(); expect(component).toMatchInlineSnapshot(` - -
- mock column selector -
-
- mock column sorting -
- - } - right={ - -
- mock keyboard shortcuts -
-
- mock style selector -
-
- mock fullscreen selector -
-
- } - /> +
+
+
+ mock column selector +
+
+ mock column sorting +
+
+
+
+ mock keyboard shortcuts +
+
+ mock style selector +
+
+ mock fullscreen selector +
+
+
`); }); @@ -66,22 +69,27 @@ describe('EuiDataGridToolbar', () => { ); expect(component).toMatchInlineSnapshot(` - } - right={ - - - -
- mock keyboard shortcuts -
-
-
-
- } - /> +
+
+
+ + +
+ mock keyboard shortcuts +
+
+
+
+
`); }); @@ -103,25 +111,28 @@ describe('EuiDataGridToolbar', () => { ); expect(component).toMatchInlineSnapshot(` - -
- hello -
- - } - right={ - -
- world -
-
- mock keyboard shortcuts -
-
- } - /> +
+
+
+ hello +
+
+
+
+ world +
+
+ mock keyboard shortcuts +
+
+
`); }); }); diff --git a/src/components/datagrid/controls/data_grid_toolbar.tsx b/src/components/datagrid/controls/data_grid_toolbar.tsx index 31c70206f80..f00722d1014 100644 --- a/src/components/datagrid/controls/data_grid_toolbar.tsx +++ b/src/components/datagrid/controls/data_grid_toolbar.tsx @@ -73,7 +73,7 @@ export const EuiDataGridToolbar = ({ : null; if (renderCustomToolbar) { - const customToolbar = renderCustomToolbar({ + return renderCustomToolbar({ hasRoomForGridControls, columnControl, columnSortingControl, @@ -81,60 +81,24 @@ export const EuiDataGridToolbar = ({ displayControl, fullScreenControl, }); - - if (isValidElement(customToolbar)) { - return customToolbar; - } - - return ( - - ); } - return ( - - {renderAdditionalControls(toolbarVisibility, 'left.prepend')} - {columnControl} - {columnSortingControl} - {renderAdditionalControls(toolbarVisibility, 'left.append')} - - ) : null - } - right={ - <> - {renderAdditionalControls(toolbarVisibility, 'right')} - {keyboardShortcutsControl} - {displayControl} - {fullScreenControl} - - } - /> - ); -}; - -/** - * Toolbar container component - * @param left - * @param right - * @constructor - */ -const EuiDataGridToolbarContainer = ({ - left, - right, -}: { - left?: ReactNode; - right?: ReactNode; -}) => { return (
- {left &&
{left}
} - {right &&
{right}
} + {hasRoomForGridControls && ( +
+ {renderAdditionalControls(toolbarVisibility, 'left.prepend')} + {columnControl} + {columnSortingControl} + {renderAdditionalControls(toolbarVisibility, 'left.append')} +
+ )} +
+ {renderAdditionalControls(toolbarVisibility, 'right')} + {keyboardShortcutsControl} + {displayControl} + {fullScreenControl} +
); }; diff --git a/src/components/datagrid/data_grid_types.ts b/src/components/datagrid/data_grid_types.ts index 71bb7b9a257..340eb8f2780 100644 --- a/src/components/datagrid/data_grid_types.ts +++ b/src/components/datagrid/data_grid_types.ts @@ -47,13 +47,7 @@ export interface EuiDataGridToolbarProps { displaySelector: ReactNode; columnSelector: ReactNode; columnSorting: ReactNode; - renderCustomToolbar?: (props: EuiDataGridCustomToolbarProps) => - | { - // to replace only controls inside the toolbar, use `left` and `right` - left?: ReactNode; - right?: ReactNode; - } - | ReactElement; // to replace the whole toolbar + renderCustomToolbar?: (props: EuiDataGridCustomToolbarProps) => ReactElement; } /** diff --git a/upcoming_changelogs/7190.md b/upcoming_changelogs/7190.md index eaccad03f5c..d2e715b0ed7 100644 --- a/upcoming_changelogs/7190.md +++ b/upcoming_changelogs/7190.md @@ -1,4 +1,4 @@ -- Added a new `renderCustomToolbar` prop to `EuiDataGrid`, which allows custom rendering of the toolbar or a custom placement of the default toolbar controls. +- Added a new `renderCustomToolbar` prop to `EuiDataGrid`, which allows custom rendering of the toolbar. - Added a new `allowResetButton` prop to `toolbarVisibility.showDisplaySelector` of `EuiDataGrid`, which allows to hide "Reset to default" button from the display settings popover. - Added a new `additionalDisplaySettings` prop to `toolbarVisibility.showDisplaySelector` of `EuiDataGrid`, which allows to render extra settings inside the display settings popover. - Replaced the display setting popover icon in `EuiDataGrid` toolbar from `tableDensityCompact`/`tableDensityExpanded`/`tableDensityNormal` with `controlsHorizontal`.