-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataGrid] New Toolbar component #14611
Changes from 167 commits
658c881
cbf114e
a363c4b
a789cec
94cf2db
dfcae22
ed540c5
370af60
0a57490
ef8f266
a96e5fc
b1d2eb2
9e84da1
cf939e9
b7c8f44
76ba05e
e7ed369
206faaa
cfee71e
fe3f01d
2c7b3c8
31820e7
d5048c4
dbdada0
5ac669e
3718ecb
0e15924
e0bfa62
e7ab35e
eace306
090ebc2
3a0cc25
9d74c74
acb9fac
1833e8e
5855682
1647cda
1840154
3801949
06d5c21
8574d88
b23080a
cf78651
0bd0f67
831757a
6c46f21
d03b5cc
5b47719
973e02d
2ac3298
ae6400e
2532d3e
afffa0f
7d830b2
670fca0
fef5ad5
0fe1a5d
f4c9226
9d98f2e
40a0b51
f012c29
1fa341a
172db4f
570b637
9a299af
f544cd7
5dda068
f3a46dd
887bf51
a47cd74
37204a1
8b1755e
b29a245
824ad70
6f15efd
cc047e6
fed2fe0
c9fbc00
72c9e3e
8e39938
7394d92
323f27b
3bb5075
1d03444
59bd3e1
7aad32b
d706535
2982e00
009bfbe
918f892
4557963
4fab879
ef4b122
5133ce7
6bac61b
69fb092
038d646
c1f376d
afc4d4f
6478ded
14d9c91
65318ef
7d7d895
aa9c393
d8dec4f
fa9ace2
ea374fa
c6951af
d7c48b7
4c1e4c5
23d8625
c23a4b5
2b970ba
53ffc1c
fc79365
d2f41b9
88835b0
66d6c57
f05d65b
bdb4025
b678b27
5b8ee69
64af410
76fd657
8c11fcd
2a49afd
a0a2cae
c47155b
d649dec
4a9a970
3da0eae
83d3dc0
95f7d64
6be7b5e
611ad3a
326e81f
e5b947b
0f8f9a4
7facd64
259c1fc
9f8f8ee
346b04b
d9cec1b
2415af4
19b0b6a
019a197
f68c9fb
b4f22f1
ab36a17
fbd6062
60f6346
fcb4f9a
a4152de
95de00a
365c3e1
a6d5af6
d4f974e
f235ac8
a9e4558
24fc5a2
bd68a81
db41624
c9b2919
013c677
860ccb6
9fcfef3
87755c8
067f6b1
fbf0a77
2ea33a9
7444e32
156ad05
d51530e
e3426ab
ed1d50a
581940d
7380c84
561df77
4844209
51f4b63
a611325
f7b1915
7b016cf
07fc89e
456a5f9
ea49f71
6398a67
eae23b1
b582ff3
fc25f34
1756f26
17bc6ac
db3b127
b518508
98dd066
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as React from 'react'; | ||
import { DataGrid, Toolbar, ColumnsPanel } from '@mui/x-data-grid'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
import Tooltip from '@mui/material/Tooltip'; | ||
import ViewColumnIcon from '@mui/icons-material/ViewColumn'; | ||
|
||
function CustomToolbar() { | ||
return ( | ||
<Toolbar.Root> | ||
<Tooltip title="Columns"> | ||
<ColumnsPanel.Trigger render={<Toolbar.Button />}> | ||
<ViewColumnIcon fontSize="small" /> | ||
</ColumnsPanel.Trigger> | ||
</Tooltip> | ||
</Toolbar.Root> | ||
); | ||
} | ||
|
||
export default function GridColumnsPanelTrigger() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 10, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid {...data} loading={loading} slots={{ toolbar: CustomToolbar }} /> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as React from 'react'; | ||
import { DataGrid, Toolbar, ColumnsPanel } from '@mui/x-data-grid'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
import Tooltip from '@mui/material/Tooltip'; | ||
import ViewColumnIcon from '@mui/icons-material/ViewColumn'; | ||
|
||
function CustomToolbar() { | ||
return ( | ||
<Toolbar.Root> | ||
<Tooltip title="Columns"> | ||
<ColumnsPanel.Trigger render={<Toolbar.Button />}> | ||
<ViewColumnIcon fontSize="small" /> | ||
</ColumnsPanel.Trigger> | ||
</Tooltip> | ||
</Toolbar.Root> | ||
); | ||
} | ||
|
||
export default function GridColumnsPanelTrigger() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 10, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid {...data} loading={loading} slots={{ toolbar: CustomToolbar }} /> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<DataGrid {...data} loading={loading} slots={{ toolbar: CustomToolbar }} /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
title: React Data Grid - Columns Panel component | ||
productId: x-data-grid | ||
components: ColumnsPanelTrigger | ||
packageName: '@mui/x-data-grid' | ||
githubLabel: 'component: data grid' | ||
--- | ||
|
||
# Data Grid - Columns Panel 🚧 | ||
|
||
<p class="description">Customize the Data Grid's columns panel.</p> | ||
|
||
:::warning | ||
This component is incomplete. | ||
|
||
Currently, the Trigger is the only composable part of the Columns Panel available. | ||
Future versions of the Columns Panel component will make it possible to compose each of its parts to create a custom columns panel. | ||
Check warning on line 17 in docs/data/data-grid/components/columns-panel/columns-panel.md
|
||
|
||
In the meantime, it's still possible to deeply customize the panel's subcomponents using custom slots. | ||
See [Custom subcomponents—Columns panel](/x/react-data-grid/components/#columns-panel) for more details. | ||
|
||
::: | ||
|
||
## Basic usage | ||
|
||
The demo below shows how to add a columns panel trigger to a custom toolbar. | ||
|
||
{{"demo": "GridColumnsPanelTrigger.js", "bg": "inline", "defaultCodeOpen": false}} | ||
|
||
## Anatomy | ||
|
||
```tsx | ||
import { ColumnsPanel } from '@mui/x-data-grid'; | ||
|
||
<ColumnsPanel.Trigger />; | ||
``` | ||
|
||
### Trigger | ||
|
||
`Trigger` is a button that opens/closes the columns panel. | ||
It renders the `baseButton` slot. | ||
|
||
## Custom elements | ||
|
||
Use the `render` prop to replace default elements. | ||
See [Components usage—Customization](/x/react-data-grid/components/usage/#customization) for more details, and [Toolbar—Custom elements demo](/x/react-data-grid/components/toolbar/#custom-elements) for an example of a custom Columns Panel Trigger. | ||
|
||
## Accessibility | ||
|
||
### ARIA | ||
|
||
You must apply a text label or an `aria-label` attribute to the `<ColumnsPanel.Trigger />`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,13 @@ | |
|
||
### Toolbar | ||
|
||
:::warning | ||
|
||
The examples below use the `<GridToolbar />`, `<GridToolbarContainer />`, and various toolbar button components. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. solid example of the component case in action - this text could be harder to understand if it was plain text 👍 |
||
These components will be deprecated in v8 and replaced by the new [Toolbar component](/x/react-data-grid/components/toolbar/). | ||
Check warning on line 56 in docs/data/data-grid/components/components.md
|
||
|
||
::: | ||
|
||
To enable the toolbar you need to add the `toolbar: GridToolbar` to the Data Grid `slots` prop. | ||
This demo showcases how this can be achieved. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import * as React from 'react'; | ||
import { DataGridPremium, Toolbar, Export } from '@mui/x-data-grid-premium'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
import Tooltip from '@mui/material/Tooltip'; | ||
import Menu from '@mui/material/Menu'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import FileDownloadIcon from '@mui/icons-material/FileDownload'; | ||
|
||
function ExportMenu() { | ||
const [open, setOpen] = React.useState(false); | ||
const triggerRef = React.useRef(null); | ||
|
||
return ( | ||
<React.Fragment> | ||
<Tooltip title="Export"> | ||
<Toolbar.Button | ||
ref={triggerRef} | ||
id="export-menu-trigger" | ||
aria-controls="export-menu" | ||
aria-haspopup="true" | ||
aria-expanded={open ? 'true' : undefined} | ||
onClick={() => setOpen(true)} | ||
> | ||
<FileDownloadIcon fontSize="small" /> | ||
</Toolbar.Button> | ||
</Tooltip> | ||
<Menu | ||
id="export-menu" | ||
anchorEl={triggerRef.current} | ||
open={open} | ||
onClose={() => setOpen(false)} | ||
MenuListProps={{ | ||
'aria-labelledby': 'export-menu-trigger', | ||
}} | ||
> | ||
<Export.Csv render={<MenuItem />}>Download as CSV</Export.Csv> | ||
<Export.Excel render={<MenuItem />}>Download as Excel</Export.Excel> | ||
<Export.Print render={<MenuItem />}>Print</Export.Print> | ||
</Menu> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
function CustomToolbar() { | ||
return ( | ||
<Toolbar.Root> | ||
<ExportMenu /> | ||
</Toolbar.Root> | ||
); | ||
} | ||
|
||
export default function GridExportMenu() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 10, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPremium | ||
{...data} | ||
loading={loading} | ||
slots={{ toolbar: CustomToolbar }} | ||
/> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import * as React from 'react'; | ||
import { DataGridPremium, Toolbar, Export } from '@mui/x-data-grid-premium'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
import Tooltip from '@mui/material/Tooltip'; | ||
import Menu from '@mui/material/Menu'; | ||
import MenuItem from '@mui/material/MenuItem'; | ||
import FileDownloadIcon from '@mui/icons-material/FileDownload'; | ||
|
||
function ExportMenu() { | ||
const [open, setOpen] = React.useState(false); | ||
const triggerRef = React.useRef<HTMLButtonElement>(null); | ||
|
||
return ( | ||
<React.Fragment> | ||
<Tooltip title="Export"> | ||
<Toolbar.Button | ||
ref={triggerRef} | ||
id="export-menu-trigger" | ||
aria-controls="export-menu" | ||
aria-haspopup="true" | ||
aria-expanded={open ? 'true' : undefined} | ||
onClick={() => setOpen(true)} | ||
> | ||
<FileDownloadIcon fontSize="small" /> | ||
</Toolbar.Button> | ||
</Tooltip> | ||
<Menu | ||
id="export-menu" | ||
anchorEl={triggerRef.current} | ||
open={open} | ||
onClose={() => setOpen(false)} | ||
MenuListProps={{ | ||
'aria-labelledby': 'export-menu-trigger', | ||
}} | ||
> | ||
<Export.Csv render={<MenuItem />}>Download as CSV</Export.Csv> | ||
<Export.Excel render={<MenuItem />}>Download as Excel</Export.Excel> | ||
<Export.Print render={<MenuItem />}>Print</Export.Print> | ||
</Menu> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
function CustomToolbar() { | ||
return ( | ||
<Toolbar.Root> | ||
<ExportMenu /> | ||
</Toolbar.Root> | ||
); | ||
} | ||
|
||
export default function GridExportMenu() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 10, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPremium | ||
{...data} | ||
loading={loading} | ||
slots={{ toolbar: CustomToolbar }} | ||
/> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<DataGridPremium | ||
{...data} | ||
loading={loading} | ||
slots={{ toolbar: CustomToolbar }} | ||
/> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as React from 'react'; | ||
import { DataGrid, Toolbar, Export } from '@mui/x-data-grid'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
import Tooltip from '@mui/material/Tooltip'; | ||
import FileDownloadIcon from '@mui/icons-material/FileDownload'; | ||
import PrintIcon from '@mui/icons-material/Print'; | ||
|
||
function CustomToolbar() { | ||
return ( | ||
<Toolbar.Root> | ||
<Tooltip title="Download as CSV"> | ||
<Export.Csv render={<Toolbar.Button />}> | ||
<FileDownloadIcon fontSize="small" /> | ||
</Export.Csv> | ||
</Tooltip> | ||
<Tooltip title="Print"> | ||
<Export.Print render={<Toolbar.Button />}> | ||
<PrintIcon fontSize="small" /> | ||
</Export.Print> | ||
</Tooltip> | ||
</Toolbar.Root> | ||
); | ||
} | ||
|
||
export default function GridExportTrigger() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 10, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid {...data} loading={loading} slots={{ toolbar: CustomToolbar }} /> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as React from 'react'; | ||
import { DataGrid, Toolbar, Export } from '@mui/x-data-grid'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
import Tooltip from '@mui/material/Tooltip'; | ||
import FileDownloadIcon from '@mui/icons-material/FileDownload'; | ||
import PrintIcon from '@mui/icons-material/Print'; | ||
|
||
function CustomToolbar() { | ||
return ( | ||
<Toolbar.Root> | ||
<Tooltip title="Download as CSV"> | ||
<Export.Csv render={<Toolbar.Button />}> | ||
<FileDownloadIcon fontSize="small" /> | ||
</Export.Csv> | ||
</Tooltip> | ||
<Tooltip title="Print"> | ||
<Export.Print render={<Toolbar.Button />}> | ||
<PrintIcon fontSize="small" /> | ||
</Export.Print> | ||
</Tooltip> | ||
</Toolbar.Root> | ||
); | ||
} | ||
|
||
export default function GridExportTrigger() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 10, | ||
maxColumns: 10, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid {...data} loading={loading} slots={{ toolbar: CustomToolbar }} /> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<DataGrid {...data} loading={loading} slots={{ toolbar: CustomToolbar }} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this makes sense under the Anatomy h2 so let's bump it up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not so sure 🤔
The snippet provides an example composition using the component parts, and these headings describe each part of the component anatomy.