Skip to content

Commit

Permalink
Dataviews config dropdown: remove style overrides (#65373)
Browse files Browse the repository at this point in the history
* Remove duplicate classname

* Use `DropdownContentWrapper` and avoid style overrides

* Extract popover props to const object

* Move Dropdown under DataviewsViewConfigDropdown component

* Add aria-expanded and aria-controls attributes to the dropdown toggle

* Sort imports

* Move DATAVIEWS_CONFIG_POPOVER_PROPS declaration at the top of the file

* Do not memoize popover props

---

Co-authored-by: ciampo <[email protected]>
Co-authored-by: stokesman <[email protected]>
Co-authored-by: tyxla <[email protected]>
  • Loading branch information
4 people authored Sep 19, 2024
1 parent 56bfef8 commit 3910eab
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 48 deletions.
92 changes: 52 additions & 40 deletions packages/dataviews/src/components/dataviews-view-config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { ChangeEvent } from 'react';
*/
import {
Button,
__experimentalDropdownContentWrapper as DropdownContentWrapper,
Dropdown,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
Expand All @@ -27,6 +28,7 @@ import { __, _x, sprintf } from '@wordpress/i18n';
import { memo, useContext, useMemo } from '@wordpress/element';
import { chevronDown, chevronUp, cog, seen, unseen } from '@wordpress/icons';
import warning from '@wordpress/warning';
import { useInstanceId } from '@wordpress/compose';

/**
* Internal dependencies
Expand Down Expand Up @@ -55,6 +57,8 @@ interface ViewTypeMenuProps {
defaultLayouts?: SupportedLayouts;
}

const DATAVIEWS_CONFIG_POPOVER_PROPS = { placement: 'bottom-end', offset: 9 };

function ViewTypeMenu( {
defaultLayouts = { list: {}, grid: {}, table: {} },
}: ViewTypeMenuProps ) {
Expand Down Expand Up @@ -510,33 +514,60 @@ function SettingsSection( {
);
}

function DataviewsViewConfigContent( {
function DataviewsViewConfigDropdown( {
density,
setDensity,
}: {
density: number;
setDensity: React.Dispatch< React.SetStateAction< number > >;
} ) {
const { view } = useContext( DataViewsContext );
const popoverId = useInstanceId(
_DataViewsViewConfig,
'dataviews-view-config-dropdown'
);

return (
<VStack className="dataviews-view-config" spacing={ 6 }>
<SettingsSection title={ __( 'Appearance' ) }>
<HStack expanded className="is-divided-in-two">
<SortFieldControl />
<SortDirectionControl />
</HStack>
{ view.type === LAYOUT_GRID && (
<DensityPicker
density={ density }
setDensity={ setDensity }
<Dropdown
popoverProps={ {
...DATAVIEWS_CONFIG_POPOVER_PROPS,
id: popoverId,
} }
renderToggle={ ( { onToggle, isOpen } ) => {
return (
<Button
size="compact"
icon={ cog }
label={ _x( 'View options', 'View is used as a noun' ) }
onClick={ onToggle }
aria-expanded={ isOpen ? 'true' : 'false' }
aria-controls={ popoverId }
/>
) }
<ItemsPerPageControl />
</SettingsSection>
<SettingsSection title={ __( 'Properties' ) }>
<FieldControl />
</SettingsSection>
</VStack>
);
} }
renderContent={ () => (
<DropdownContentWrapper paddingSize="medium">
<VStack className="dataviews-view-config" spacing={ 6 }>
<SettingsSection title={ __( 'Appearance' ) }>
<HStack expanded className="is-divided-in-two">
<SortFieldControl />
<SortDirectionControl />
</HStack>
{ view.type === LAYOUT_GRID && (
<DensityPicker
density={ density }
setDensity={ setDensity }
/>
) }
<ItemsPerPageControl />
</SettingsSection>
<SettingsSection title={ __( 'Properties' ) }>
<FieldControl />
</SettingsSection>
</VStack>
</DropdownContentWrapper>
) }
/>
);
}

Expand All @@ -552,28 +583,9 @@ function _DataViewsViewConfig( {
return (
<>
<ViewTypeMenu defaultLayouts={ defaultLayouts } />
<Dropdown
popoverProps={ { placement: 'bottom-end', offset: 9 } }
contentClassName="dataviews-view-config"
renderToggle={ ( { onToggle } ) => {
return (
<Button
size="compact"
icon={ cog }
label={ _x(
'View options',
'View is used as a noun'
) }
onClick={ onToggle }
/>
);
} }
renderContent={ () => (
<DataviewsViewConfigContent
density={ density }
setDensity={ setDensity }
/>
) }
<DataviewsViewConfigDropdown
density={ density }
setDensity={ setDensity }
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
.dataviews-view-config {
.components-popover__content {
width: 320px;
/* stylelint-disable-next-line property-no-unknown -- the linter needs to be updated to accepted the container-type property */
container-type: inline-size;
padding: $grid-unit-20;
font-size: $default-font-size;
line-height: $default-line-height;
}
width: 320px;
/* stylelint-disable-next-line property-no-unknown -- the linter needs to be updated to accepted the container-type property */
container-type: inline-size;
font-size: $default-font-size;
line-height: $default-line-height;
}

.dataviews-view-config__sort-direction .components-toggle-group-control-option-base {
Expand Down

0 comments on commit 3910eab

Please sign in to comment.