-
Notifications
You must be signed in to change notification settings - Fork 4.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
DataViews: Add density option to table
layout
#67170
Changes from all commits
12f6740
33863e4
e3e6352
c08fa7f
e41a211
2f533b8
e657fc8
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,57 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
__experimentalToggleGroupControl as ToggleGroupControl, | ||
__experimentalToggleGroupControlOption as ToggleGroupControlOption, | ||
} from '@wordpress/components'; | ||
import { __, _x } from '@wordpress/i18n'; | ||
import { useContext } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import DataViewsContext from '../../components/dataviews-context'; | ||
import type { ViewTable, Density } from '../../types'; | ||
|
||
export default function DensityPicker() { | ||
const context = useContext( DataViewsContext ); | ||
const view = context.view as ViewTable; | ||
return ( | ||
<ToggleGroupControl | ||
__nextHasNoMarginBottom | ||
size="__unstable-large" | ||
label={ __( 'Density' ) } | ||
value={ view.layout?.density || 'balanced' } | ||
onChange={ ( value ) => { | ||
context.onChangeView( { | ||
...view, | ||
layout: { | ||
...view.layout, | ||
density: value as Density, | ||
}, | ||
} ); | ||
} } | ||
isBlock | ||
> | ||
<ToggleGroupControlOption | ||
key="comfortable" | ||
value="comfortable" | ||
label={ _x( | ||
'Comfortable', | ||
'Density option for DataView layout' | ||
) } | ||
/> | ||
<ToggleGroupControlOption | ||
key="balanced" | ||
value="balanced" | ||
label={ _x( 'Balanced', 'Density option for DataView layout' ) } | ||
/> | ||
<ToggleGroupControlOption | ||
key="compact" | ||
value="compact" | ||
label={ _x( 'Compact', 'Density option for DataView layout' ) } | ||
/> | ||
</ToggleGroupControl> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,6 +169,38 @@ | |
opacity: 1; | ||
} | ||
} | ||
|
||
// Density style overrides. | ||
&.has-compact-density { | ||
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. This is where we'll add the density styles. 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.
@ntsekourasI was wondering if it’s possible for a density style to include a different type size (within the defined typesscale), or is it limited to just spacing variants like padding? 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.
You mean font sizes? In general I added these changes as a placeholder and designers will decide how the table should look per density. |
||
thead { | ||
th { | ||
&:has(.dataviews-view-table-header-button):not(:first-child) { | ||
padding-left: 0; | ||
} | ||
} | ||
} | ||
td, | ||
th { | ||
padding: $grid-unit-05 $grid-unit-10; | ||
} | ||
} | ||
|
||
&.has-comfortable-density { | ||
td, | ||
th { | ||
padding: $grid-unit-20 $grid-unit-15; | ||
} | ||
} | ||
|
||
&.has-compact-density, | ||
&.has-comfortable-density { | ||
td, | ||
th { | ||
&.dataviews-view-table__checkbox-column { | ||
padding-right: 0; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/* stylelint-disable-next-line scss/at-rule-no-unknown -- '@container' not globally permitted */ | ||
|
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.
This is an improvement: we have only the LAYOUT_TABLE dependency here. 🎉