From f8e933472eb7357cbfd4cdb123fc77480f9fa816 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Thu, 8 Aug 2024 17:49:25 +0100 Subject: [PATCH] Update: Move item size control to the new view config UI. --- .../dataviews-view-config/index.tsx | 40 +++++-- .../src/components/dataviews/index.tsx | 8 +- .../dataviews-layouts/grid/density-picker.tsx | 102 ++++++++++-------- 3 files changed, 90 insertions(+), 60 deletions(-) diff --git a/packages/dataviews/src/components/dataviews-view-config/index.tsx b/packages/dataviews/src/components/dataviews-view-config/index.tsx index 28e151079008eb..21aeac611e7ef1 100644 --- a/packages/dataviews/src/components/dataviews-view-config/index.tsx +++ b/packages/dataviews/src/components/dataviews-view-config/index.tsx @@ -30,11 +30,17 @@ import warning from '@wordpress/warning'; /** * Internal dependencies */ -import { SORTING_DIRECTIONS, sortIcons, sortLabels } from '../../constants'; +import { + SORTING_DIRECTIONS, + LAYOUT_GRID, + sortIcons, + sortLabels, +} from '../../constants'; import { VIEW_LAYOUTS, getMandatoryFields } from '../../dataviews-layouts'; import type { SupportedLayouts } from '../../types'; import DataViewsContext from '../dataviews-context'; import { unlock } from '../../lock-unlock'; +import DensityPicker from '../../dataviews-layouts/grid/density-picker'; const { DropdownMenuV2: DropdownMenu, @@ -101,10 +107,6 @@ function ViewTypeMenu( { ); } -interface ViewActionsProps { - defaultLayouts?: SupportedLayouts; -} - function SortFieldControl() { const { view, fields, onChangeView } = useContext( DataViewsContext ); const orderOptions = useMemo( () => { @@ -304,7 +306,14 @@ function SettingsSection( { ); } -function DataviewsViewConfigContent() { +function DataviewsViewConfigContent( { + density, + setDensity, +}: { + density: number; + setDensity: React.Dispatch< React.SetStateAction< number > >; +} ) { + const { view } = useContext( DataViewsContext ); return ( @@ -312,6 +321,12 @@ function DataviewsViewConfigContent() { + { view.type === LAYOUT_GRID && ( + + ) } @@ -322,8 +337,14 @@ function DataviewsViewConfigContent() { } function _DataViewsViewConfig( { + density, + setDensity, defaultLayouts = { list: {}, grid: {}, table: {} }, -}: ViewActionsProps ) { +}: { + density: number; + setDensity: React.Dispatch< React.SetStateAction< number > >; + defaultLayouts?: SupportedLayouts; +} ) { const [ isShowingViewPopover, setIsShowingViewPopover ] = useState< boolean >( false ); @@ -345,7 +366,10 @@ function _DataViewsViewConfig( { } } focusOnMount > - + ) } diff --git a/packages/dataviews/src/components/dataviews/index.tsx b/packages/dataviews/src/components/dataviews/index.tsx index 337912b04e59c5..aea2267a815eb5 100644 --- a/packages/dataviews/src/components/dataviews/index.tsx +++ b/packages/dataviews/src/components/dataviews/index.tsx @@ -133,12 +133,6 @@ export default function DataViews< Item >( { isShowingFilter={ isShowingFilter } /> - { view.type === LAYOUT_GRID && ( - - ) } ( { > { header } diff --git a/packages/dataviews/src/dataviews-layouts/grid/density-picker.tsx b/packages/dataviews/src/dataviews-layouts/grid/density-picker.tsx index 364d764e343470..0a96bb84821d3d 100644 --- a/packages/dataviews/src/dataviews-layouts/grid/density-picker.tsx +++ b/packages/dataviews/src/dataviews-layouts/grid/density-picker.tsx @@ -1,7 +1,12 @@ /** * WordPress dependencies */ -import { RangeControl, Button } from '@wordpress/components'; +import { + BaseControl, + RangeControl, + Button, + __experimentalHStack as HStack, +} from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { useViewportMatch } from '@wordpress/compose'; import { plus, reset } from '@wordpress/icons'; @@ -87,50 +92,55 @@ export default function DensityPicker( { const step = 100 / ( breakValues.max - breakValues.min + 1 ); return ( - <> -