Skip to content

Commit

Permalink
[Data views]: Update icons and design tweaks (#55391)
Browse files Browse the repository at this point in the history
* [Data views]: Update icons and design tweaks

* Button variants

* tooltips

* spacing

* fix pagination from conflicts

* pagination at the bottom of the frame

* fix styles

---------

Co-authored-by: James Koster <[email protected]>
  • Loading branch information
ntsekouras and jameskoster authored Oct 30, 2023
1 parent 3d51806 commit 62ec891
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 81 deletions.
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/dataviews/dataviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function DataViews( {
}, [ fields ] );
return (
<div className="dataviews-wrapper">
<VStack spacing={ 4 }>
<VStack spacing={ 4 } justify="flex-start">
<HStack>
<HStack justify="start">
<Filters
Expand Down
127 changes: 53 additions & 74 deletions packages/edit-site/src/components/dataviews/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,11 @@ import {
__experimentalHStack as HStack,
__experimentalText as Text,
__experimentalNumberControl as NumberControl,
__experimentalInputControlPrefixWrapper as InputControlPrefixWrapper,
SelectControl,
} from '@wordpress/components';
import { createInterpolateElement } from '@wordpress/element';
import { sprintf, __, _x, _n } from '@wordpress/i18n';
import { chevronRight, chevronLeft, previous, next } from '@wordpress/icons';

const PAGE_SIZE_VALUES = [ 5, 20, 50 ];
function PageSizeControl( { view, onChangeView } ) {
const label = __( 'Rows per page:' );
return (
<SelectControl
__nextHasNoMarginBottom
label={ label }
hideLabelFromVision
// TODO: This should probably use a label based on the wanted design
// and we could remove InputControlPrefixWrapper usage.
prefix={
<InputControlPrefixWrapper
as="span"
className="dataviews__select-control-prefix"
>
{ label }
</InputControlPrefixWrapper>
}
value={ view.perPage }
options={ PAGE_SIZE_VALUES.map( ( pageSize ) => ( {
value: pageSize,
label: pageSize,
} ) ) }
onChange={ ( value ) =>
onChangeView( { ...view, perPage: value, page: 1 } )
}
/>
);
}

// For now this is copied from the patterns list Pagination component, because
// the datatable pagination starts from index zero(`0`). Eventually all lists will be
// using this one.
function Pagination( {
view,
onChangeView,
Expand All @@ -71,29 +37,37 @@ function Pagination( {
}
</Text>
{ !! totalItems && (
<HStack expanded={ false } spacing={ 1 }>
<Button
variant="tertiary"
onClick={ () => onChangeView( { ...view, page: 1 } ) }
disabled={ view.page === 1 }
aria-label={ __( 'First page' ) }
>
«
</Button>
<Button
variant="tertiary"
onClick={ () =>
onChangeView( { ...view, page: view.page - 1 } )
}
disabled={ view.page === 1 }
aria-label={ __( 'Previous page' ) }
>
</Button>
<HStack expanded={ false } spacing={ 3 }>
<HStack
justify="flex-start"
expanded={ false }
spacing={ 1 }
>
<Button
onClick={ () =>
onChangeView( { ...view, page: 1 } )
}
disabled={ view.page === 1 }
label={ __( 'First page' ) }
icon={ previous }
showTooltip
size="compact"
/>
<Button
onClick={ () =>
onChangeView( { ...view, page: view.page - 1 } )
}
disabled={ view.page === 1 }
label={ __( 'Previous page' ) }
icon={ chevronLeft }
showTooltip
size="compact"
/>
</HStack>
<HStack
justify="flex-start"
expanded={ false }
spacing={ 2 }
>
{ createInterpolateElement(
sprintf(
Expand Down Expand Up @@ -130,29 +104,34 @@ function Pagination( {
}
) }
</HStack>
<Button
variant="tertiary"
onClick={ () =>
onChangeView( { ...view, page: view.page + 1 } )
}
disabled={ view.page >= totalPages }
aria-label={ __( 'Next page' ) }
>
</Button>
<Button
variant="tertiary"
onClick={ () =>
onChangeView( { ...view, page: totalPages } )
}
disabled={ view.page >= totalPages }
aria-label={ __( 'Last page' ) }
<HStack
justify="flex-start"
expanded={ false }
spacing={ 1 }
>
»
</Button>
<Button
onClick={ () =>
onChangeView( { ...view, page: view.page + 1 } )
}
disabled={ view.page >= totalPages }
label={ __( 'Next page' ) }
icon={ chevronRight }
showTooltip
size="compact"
/>
<Button
onClick={ () =>
onChangeView( { ...view, page: totalPages } )
}
disabled={ view.page >= totalPages }
label={ __( 'Last page' ) }
icon={ next }
showTooltip
size="compact"
/>
</HStack>
</HStack>
) }
<PageSizeControl view={ view } onChangeView={ onChangeView } />
</HStack>
);
}
Expand Down
15 changes: 10 additions & 5 deletions packages/edit-site/src/components/dataviews/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
.dataviews-wrapper {
width: 100%;
height: 100%;
overflow: auto;
padding: $grid-unit-40;

> div {
min-height: 100%;
}
}

.dataviews-pagination {
margin-top: auto;
}

.dataviews-list-view {
Expand Down Expand Up @@ -30,11 +40,6 @@
}
}

.dataviews__select-control-prefix {
color: $gray-700;
text-wrap: nowrap;
}

.dataviews-view-grid__media {
width: 100%;
min-height: 200px;
Expand Down
7 changes: 6 additions & 1 deletion packages/edit-site/src/components/dataviews/view-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export function ViewGrid( { data, fields, view, actions } ) {
) ) }
</VStack>
</FlexBlock>
<ItemActions item={ item } actions={ actions } />
<FlexBlock>
<ItemActions
item={ item }
actions={ actions }
/>
</FlexBlock>
</HStack>
</VStack>
);
Expand Down

0 comments on commit 62ec891

Please sign in to comment.