Skip to content

Commit d6a7fa3

Browse files
jameskosteroandregalandrewserongntsekourasyouknowriad
authored
Apply background to DataViews wrapper (#73390)
Co-authored-by: jameskoster <[email protected]> Co-authored-by: oandregal <[email protected]> Co-authored-by: andrewserong <[email protected]> Co-authored-by: ntsekouras <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: t-hamano <[email protected]>
1 parent 36bcc49 commit d6a7fa3

File tree

4 files changed

+56
-23
lines changed

4 files changed

+56
-23
lines changed

packages/dataviews/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- DataViews table layout: only apply hover styles when bulk actions are available. [#73248](https://github.com/WordPress/gutenberg/pull/73248)
1212
- DataViews: add support for activity layout. [#72780](https://github.com/WordPress/gutenberg/pull/72780)
1313
- DataViews: Add grid keyboard navigation. [#72997](https://github.com/WordPress/gutenberg/pull/72997)
14+
- DataViews: Introduce CSS var to enable users to apply a different background color to DataViews containers. [#73390](https://github.com/WordPress/gutenberg/pull/73390)
1415
- Field API: introduce the `format` prop to format the `date` field type. [#72999](https://github.com/WordPress/gutenberg/pull/72999)
1516
- Field API: fix display format for date. [#73538](https://github.com/WordPress/gutenberg/pull/73538)
1617
- Documentation: improve Edit component. [#73202](https://github.com/WordPress/gutenberg/pull/73202)

packages/dataviews/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,12 @@ Optional. Pass an object with a list of `perPageSizes` to control the available
459459
460460
An element to display when the `data` prop is empty. Defaults to `<p>No results</p>`.
461461
462+
### Styling
463+
464+
These are the CSS Custom Properties that can be used to tweak the appearance of the component:
465+
466+
`--wp-dataviews-color-background`: sets the background color.
467+
462468
### Composition modes
463469
464470
The `DataViews` component supports two composition modes:

packages/dataviews/src/components/dataviews/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
flex-direction: column;
1515
font-size: $default-font-size;
1616
line-height: $default-line-height;
17-
background-color: inherit;
17+
background-color: var(--wp-dataviews-color-background, $white);
1818
}
1919

2020
.dataviews__view-actions,

packages/dataviews/src/stories/dataviews.story.tsx

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ const defaultLayouts = {
8282
export const Default = ( {
8383
perPageSizes = [ 10, 25, 50, 100 ],
8484
hasClickableItems = true,
85+
backgroundColor,
86+
}: {
87+
perPageSizes?: number[];
88+
hasClickableItems?: boolean;
89+
backgroundColor?: string;
8590
} ) => {
8691
const [ view, setView ] = useState< View >( {
8792
...DEFAULT_VIEW,
@@ -94,28 +99,45 @@ export const Default = ( {
9499
return filterSortAndPaginate( data, view, fields );
95100
}, [ view ] );
96101
return (
97-
<DataViews
98-
getItemId={ ( item ) => item.id.toString() }
99-
paginationInfo={ paginationInfo }
100-
data={ shownData }
101-
view={ view }
102-
fields={ fields }
103-
onChangeView={ setView }
104-
actions={ actions }
105-
renderItemLink={ ( { item, ...props }: { item: SpaceObject } ) => (
106-
<button
107-
style={ { background: 'none', border: 'none', padding: 0 } }
108-
onClick={ () => {
109-
// eslint-disable-next-line no-alert
110-
alert( 'Clicked: ' + item.name.title );
111-
} }
112-
{ ...props }
113-
/>
114-
) }
115-
isItemClickable={ () => hasClickableItems }
116-
defaultLayouts={ defaultLayouts }
117-
config={ { perPageSizes } }
118-
/>
102+
<div
103+
style={
104+
{
105+
'--wp-dataviews-color-background': backgroundColor,
106+
} as React.CSSProperties
107+
}
108+
>
109+
<DataViews
110+
getItemId={ ( item ) => item.id.toString() }
111+
paginationInfo={ paginationInfo }
112+
data={ shownData }
113+
view={ view }
114+
fields={ fields }
115+
onChangeView={ setView }
116+
actions={ actions }
117+
renderItemLink={ ( {
118+
item,
119+
...props
120+
}: {
121+
item: SpaceObject;
122+
} ) => (
123+
<button
124+
style={ {
125+
background: 'none',
126+
border: 'none',
127+
padding: 0,
128+
} }
129+
onClick={ () => {
130+
// eslint-disable-next-line no-alert
131+
alert( 'Clicked: ' + item.name.title );
132+
} }
133+
{ ...props }
134+
/>
135+
) }
136+
isItemClickable={ () => hasClickableItems }
137+
defaultLayouts={ defaultLayouts }
138+
config={ { perPageSizes } }
139+
/>
140+
</div>
119141
);
120142
};
121143

@@ -133,6 +155,10 @@ Default.argTypes = {
133155
control: 'boolean',
134156
description: 'Are the items clickable',
135157
},
158+
backgroundColor: {
159+
control: 'color',
160+
description: 'Background color of the DataViews component',
161+
},
136162
};
137163

138164
export const Empty = () => {

0 commit comments

Comments
 (0)