Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/dataviews/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- DataViews table layout: only apply hover styles when bulk actions are available. [#73248](https://github.com/WordPress/gutenberg/pull/73248)
- DataViews: add support for activity layout. [#72780](https://github.com/WordPress/gutenberg/pull/72780)
- DataViews: Add grid keyboard navigation. [#72997](https://github.com/WordPress/gutenberg/pull/72997)
- DataViews: Introduce CSS var to enable users to apply a different background color to DataViews containers. [#73390](https://github.com/WordPress/gutenberg/pull/73390)
- Field API: introduce the `format` prop to format the `date` field type. [#72999](https://github.com/WordPress/gutenberg/pull/72999)
- Field API: fix display format for date. [#73538](https://github.com/WordPress/gutenberg/pull/73538)
- Documentation: improve Edit component. [#73202](https://github.com/WordPress/gutenberg/pull/73202)
Expand Down
6 changes: 6 additions & 0 deletions packages/dataviews/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ Optional. Pass an object with a list of `perPageSizes` to control the available

An element to display when the `data` prop is empty. Defaults to `<p>No results</p>`.

### Styling

These are the CSS Custom Properties that can be used to tweak the appearance of the component:

`--wp-dataviews-color-background`: sets the background color.

### Composition modes

The `DataViews` component supports two composition modes:
Expand Down
2 changes: 1 addition & 1 deletion packages/dataviews/src/components/dataviews/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
flex-direction: column;
font-size: $default-font-size;
line-height: $default-line-height;
background-color: inherit;
background-color: var(--wp-dataviews-color-background, $white);
Copy link
Member

@oandregal oandregal Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jameskoster I don't know how standard all of this is, but I've noticed that we're using --wp-* in existing components, and --wpds- in other places. When do we use one, and when do we use another? I haven't found anything that clarifies that, and would like to understand which one should we use here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wpds is the prefix for the new theme package. I think here the name is right and similar to the vars of components package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was discussed at #72989 (comment)

}

.dataviews__view-actions,
Expand Down
70 changes: 48 additions & 22 deletions packages/dataviews/src/stories/dataviews.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ const defaultLayouts = {
export const Default = ( {
perPageSizes = [ 10, 25, 50, 100 ],
hasClickableItems = true,
backgroundColor,
}: {
perPageSizes?: number[];
hasClickableItems?: boolean;
backgroundColor?: string;
} ) => {
const [ view, setView ] = useState< View >( {
...DEFAULT_VIEW,
Expand All @@ -94,28 +99,45 @@ export const Default = ( {
return filterSortAndPaginate( data, view, fields );
}, [ view ] );
return (
<DataViews
getItemId={ ( item ) => item.id.toString() }
paginationInfo={ paginationInfo }
data={ shownData }
view={ view }
fields={ fields }
onChangeView={ setView }
actions={ actions }
renderItemLink={ ( { item, ...props }: { item: SpaceObject } ) => (
<button
style={ { background: 'none', border: 'none', padding: 0 } }
onClick={ () => {
// eslint-disable-next-line no-alert
alert( 'Clicked: ' + item.name.title );
} }
{ ...props }
/>
) }
isItemClickable={ () => hasClickableItems }
defaultLayouts={ defaultLayouts }
config={ { perPageSizes } }
/>
<div
style={
{
'--wp-dataviews-color-background': backgroundColor,
} as React.CSSProperties
}
>
<DataViews
getItemId={ ( item ) => item.id.toString() }
paginationInfo={ paginationInfo }
data={ shownData }
view={ view }
fields={ fields }
onChangeView={ setView }
actions={ actions }
renderItemLink={ ( {
item,
...props
}: {
item: SpaceObject;
} ) => (
<button
style={ {
background: 'none',
border: 'none',
padding: 0,
} }
onClick={ () => {
// eslint-disable-next-line no-alert
alert( 'Clicked: ' + item.name.title );
} }
{ ...props }
/>
) }
isItemClickable={ () => hasClickableItems }
defaultLayouts={ defaultLayouts }
config={ { perPageSizes } }
/>
</div>
);
};

Expand All @@ -133,6 +155,10 @@ Default.argTypes = {
control: 'boolean',
description: 'Are the items clickable',
},
backgroundColor: {
control: 'color',
description: 'Background color of the DataViews component',
},
};

export const Empty = () => {
Expand Down
Loading