-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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] Add Density selector #606
[DataGrid] Add Density selector #606
Conversation
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.
It looks like a great start.
- I don't think that the state approach can scale: 1. the
options
are overriding by props when the grid rerender with different props and 2.rowHeight
can be changed after the first render. - I think that the feature should be opt-in. We might start now to ask the developers to import and inject the component explicitly.
- There is a new scrollbar on the header
- It could be interesting to use the icon on the Density toolbar button to signal the current state of the density.
- @dtassone DataGrid or XGrid?
const DensityShortIcon = icons!.densityShort!; | ||
const DensityMediumIcon = icons!.densityMedium!; | ||
const DensityTallIcon = icons!.densityTall!; |
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 appreciate the reference to Airtable. In the core components' API, we use the following names: small, medium; large. I would suggest we do the same here
const DensityShortIcon = icons!.densityShort!; | |
const DensityMediumIcon = icons!.densityMedium!; | |
const DensityTallIcon = icons!.densityTall!; | |
const DensitySmallIcon = icons!.densitySmall!; | |
const DensityMediumIcon = icons!.densityMedium!; | |
const DensityLargeIcon = icons!.densityLarge!; |
cc @mbrookes.
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.
Density is normally high/medium/low (size is small/medium/large)
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.
https://material-density.glitch.me/
vs.
https://material-ui.com/components/tables/#dense-table <Table size="small">
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.
What if we call the prop size
?
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.
"density" is more accurate, but if consistency with the Table is important, then sure. (Although I'd be tempted to go the other way, and change table. 😄 )
Is it a prop here though?
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.
It's mostly either margin: dense
, or size: small
, with one instance of dense: true
, and one of variant: dense
.
Of the first two, size
is closest, even if it doesn't quite describe the purpose.
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.
Ok so I kept the prop name density
, should I change it to size
and also if yes then the same will apply to the button label right?
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 personally like the approach of using:
- "density" for the documentation, because it's how Material Design documents it http://material.io/design/layout/applying-density.html or https://medium.com/nextux/design-better-data-tables-4ecc99d23356
- "row height", "short", "medium", "tall" for end-users, because it's close to what it does in the UI, at least now, it could change in the future. It's what Airtable does. It will up to the developers to customize it.
- "size", "small", "medium", "large" for developers, because it's generic. It's what Chakra does with its components and what we have been doing in the core most recently: https://next.material-ui.com/components/tables/#dense-table.
<Table size="small">
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.
The hook is called useDensity
, the component is densityPicker
and the label in the toolbar is density
so why would we name it size in the prop?
We should call it density as it's less confusing for us as well as for users and also, it's easier to find and understand in the list of props. Button density in the toolbar matches the density prop, it's logical and straightforward.
Otherwise, we can rename everything as useSize
, SizePicker
, and size
in the label, and have a size property.
It doesn't make sense to me to have something named useFoo
, Foo
and expose it as Bar
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.
The hook is called useDensity, the component is densityPicker and the label in the toolbar is density so why would we name it size in the prop?
We can rename them all to size.
I think that size is superior in the code because it's more generic and allows consistency with the rest of the API. We will need to clean this "mess": https://next.material-ui.com/customization/density/ at some point.
Why do we call <Button size="small">
and not <Button density="dense">
? I think that it's because the intrinsic size of the button changes when the prop is applied.
In the case of the data grid, it's a bit different. Because of its structure, the intrinsic size is invariant, unless autoHeight
is specified, only the size of the cells changes.
Size seems popular in the other libraries:
- https://ant.design/components/table/#components-table-demo-size called size
- https://garden.zendesk.com/components/table#size called size
- https://www.carbondesignsystem.com/components/data-table/usage called size
- https://react-bootstrap.github.io/components/table/#table-small called size
- https://elastic.github.io/eui/#/tabular-content/data-grid called size in the class names
- https://semantic-ui.com/collections/table.html#size called size
- https://material-ui.com/components/tables/#dense-table called size
@@ -94,6 +94,8 @@ const stories = [ | |||
'/story/x-grid-tests-styling--column-header-class', | |||
'/story/x-grid-tests-styling--column-cell-class-rules', | |||
'/story/x-grid-tests-styling--column-cell-renderer', | |||
|
|||
'/story/x-grid-tests-toolbar--density-picker', |
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.
A side note, we have a great new visual regression runner by @eps1lon in mui/material-ui#23500 :D that we will be able to replace this once we have battle-tested it in the core.
Yes I agree, the current density icon should be used in the toolbar
XGrid |
Ok I checked all the comments and did some additional tests to see how to rework the PR. I'll update the PR with all the requests in bulk. Regarding the state - I think we will need to keep what the current density is in the state. The reason for this is that because the the There is another interesting question tho - if we go with the approach of having an API to change the density then we don't need to expose a prop for the |
Things need to be built in a uniform manner. |
Ok, it took a but of time but the PR is now ready to be reviewed. The biggest change is that I need to separate the props that the density affects so I created a In addition I also added the missing docs and unit tests. PS: The unit tests that I added are failing because there is a warning in the console (only happens on the tests) that is
If someone has any ideas how to solve this I would really appreciate it. |
@mbrookes Oh, do you mean for example that the compact density is x% of the |
Not sure it has to list the specific percentages, but it currently doesn't say that it controls the density. Maybe it doesn't need to? I don't know. |
Isn't it the opposite? |
Since I'm talking about the documentation, I'm obviously talking about the prop, not the internal state. 🙂 (Kind of ironic that you said it wasn't confusing†, and are now getting confused by it. 😄 ) |
Ok, I think I see where you are getting to. You want to document that:
|
I'm not sure the ratios are too important, just noting the relationship between the prop and density. |
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
…ilH/material-ui-x into feature/DataGrid-567-density-picker
To summarise, @mbrookes . It's not that the |
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.
The open animation direction is wrong, it should start from the top, not the bottom.fixed it in [DataGrid] Improve the DX of popups #686- The regression on
master
was fixed, we can rebase now.
|
||
return ( | ||
<div style={{ height: 300, width: '100%' }}> | ||
<DataGrid {...data} hideToolbar={false} disableDensitySelector /> |
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 think that we should document the opposite, make the toolbar opt-in and document how to render the density toolbar.
import * as React from 'react';
import { DataGrid, GridToolbar, GridToolbarDensitySelector } from '@material-ui/data-grid';
import { useDemoData } from '@material-ui/x-grid-data-generator';
function Header() {
return (
<GridToolbar>
<GridToolbarDensitySelector />
</GridToolbar>
);
}
export default function DensitySelectorToolbar() {
const { data } = useDemoData({
dataSet: 'Commodity',
rowLength: 10,
maxColumns: 6,
});
return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid {...data} components={{ Header }} density="compact" />
</div>
);
}
@oliviertassinari so change the |
@DanailH I wanted to share with @mbrookes a counter-proposal. It's point 7. of #606 (comment). I think that we can handle this once this pull request is merged and before the next release. To answer your question, it was about the idea to remove the |
Yes
Yes, I know it's mentioned in the documentation, and you know that I know, because we've been discussing the best wording to use. 😀 I was talking about the |
@oliviertassinari I really don't think squeezing this functionality as part of that PR is a good idea. This PR is already to bloated and the composable toolbar is a feature by itself which will bring even more discussions IMO. It is better to merge it as it is (maybe change the |
@DanailH Agree, this is part of item 7. for another iteration. |
I have fixed it in #686 |
@dtassone should I merge it ? |
|
||
return ( | ||
<div style={{ height: 300, width: '100%' }}> | ||
<DataGrid {...data} hideToolbar={false} disableDensitySelector /> |
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.
hideToolbar={false}
is redundant, not sure the effect it will have on ppl looking at the source. But I would ask myself why did they put that.
I think we should remove them and wait until/if/when we do the refactoring. We should not think ahead of ourselves.
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 sure that it really matters, we talked about deferring this problem to a second pull request in #606 (comment).
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 see, but yeah normally you leave things clean because if you change your plan, and defer this refactoring as other priorities come first, then you will have this weird prop for some time in your documentation.
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.
Ok why not
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.
However, I don't think that developers will ever see this prop as the plan is to remove it before the next release.
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.
Well we should release tomorrow or wednesday if we follow our plan...
Also I would argue that if we do showToolbar, we should consider doing showFooter...
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.
showToolbar, we should consider doing showFooter.
I disagree, I think that https://material-ui.com/guides/api/#property-naming is more important for consistency. I also think that we don't need showToolbar
nor hideToolbar
.
Well we should release tomorrow or wednesday if we follow our plan...
I think that we should either delay the release of refactor the toolbar before merging this one.
Closes #567
I have added a new property on the DataGrid ->
density
that can be one of 3 options:compact
,standard
andcomfortable
. The default value isstandard
. In addition, the density property also works with therowHeight
andheaderHeight
in a way that if those are provided it will take them into account when adjusting the size of the grid.Density options:
compact
size -> the height of the rows is lowered by 1/3 of their original value.comfortable
size -> the height of the rows is increased by 1/3 of their original value.All the logic is contained within the new
DensitySelector
component.https://deploy-preview-606--material-ui-x.netlify.app/components/data-grid/rendering/#density
TODO:
draft
status from the PR.