Skip to content

Commit

Permalink
PaletteEdit: Use ItemGroup and Item, and avoid custom styles (Wor…
Browse files Browse the repository at this point in the history
…dPress#66164)

* PaletteEdit: Use Item directly

* PaletteEdit: Cleanup legacy PaletteItem styles

* CHANGELOG

Co-authored-by: tyxla <[email protected]>
Co-authored-by: ciampo <[email protected]>
Co-authored-by: mirka <[email protected]>
  • Loading branch information
4 people authored Oct 17, 2024
1 parent c34cf88 commit b8bfe71
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 72 deletions.
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- `ColorPalette`: prevent overflow of custom color button background ([#66152](https://github.com/WordPress/gutenberg/pull/66152)).

### Enhancements

- `PaletteEdit`: use `Item` internally instead of custom styles ([#66164](https://github.com/WordPress/gutenberg/pull/66164)).

## 28.10.0 (2024-10-16)

### Bug Fixes
Expand Down
9 changes: 4 additions & 5 deletions packages/components/src/palette-edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Button from '../button';
import { ColorPicker } from '../color-picker';
import { FlexItem } from '../flex';
import { HStack } from '../h-stack';
import { ItemGroup } from '../item-group';
import { Item, ItemGroup } from '../item-group';
import { VStack } from '../v-stack';
import GradientPicker from '../gradient-picker';
import ColorPalette from '../color-palette';
Expand All @@ -35,7 +35,6 @@ import {
PaletteEditStyles,
PaletteHeading,
IndicatorStyled,
PaletteItem,
NameContainer,
NameInputControl,
DoneButton,
Expand Down Expand Up @@ -213,7 +212,7 @@ function Option< T extends PaletteElement >( {
);

return (
<PaletteItem ref={ setPopoverAnchor } as="div">
<Item ref={ setPopoverAnchor } size="small">
<HStack justify="flex-start">
<Button
onClick={ () => {
Expand Down Expand Up @@ -282,7 +281,7 @@ function Option< T extends PaletteElement >( {
onClose={ () => setIsEditingColor( false ) }
/>
) }
</PaletteItem>
</Item>
);
}

Expand All @@ -309,7 +308,7 @@ function PaletteEditListView< T extends PaletteElement >( {

return (
<VStack spacing={ 3 }>
<ItemGroup isRounded>
<ItemGroup isRounded isBordered isSeparated>
{ elements.map( ( element, index ) => (
<Option
isGradient={ isGradient }
Expand Down
68 changes: 1 addition & 67 deletions packages/components/src/palette-edit/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
* External dependencies
*/
import styled from '@emotion/styled';
import { css } from '@emotion/react';

/**
* Internal dependencies
*/
import Button from '../button';
import { Heading } from '../heading';
import { space } from '../utils/space';
import { COLORS, CONFIG, font } from '../utils';
import { COLORS, CONFIG } from '../utils';
import { View } from '../view';
import InputControl from '../input-control';
import {
Expand Down Expand Up @@ -42,71 +41,6 @@ export const NameInputControl = styled( InputControl )`
}
`;

const buttonStyleReset = ( {
as,
}: {
as: React.ComponentProps< typeof View >[ 'as' ];
} ) => {
if ( as === 'button' ) {
return css`
display: flex;
align-items: center;
width: 100%;
appearance: none;
background: transparent;
border: none;
border-radius: 0;
padding: 0;
cursor: pointer;
&:hover {
color: ${ COLORS.theme.accent };
}
`;
}
return null;
};

export const PaletteItem = styled( View )`
${ buttonStyleReset }
padding-block: 3px;
padding-inline-start: ${ space( 3 ) };
border: 1px solid ${ CONFIG.surfaceBorderColor };
border-bottom-color: transparent;
font-size: ${ font( 'default.fontSize' ) };
&:focus-visible {
border-color: transparent;
box-shadow: 0 0 0 var( --wp-admin-border-width-focus )
${ COLORS.theme.accent };
// Windows high contrast mode.
outline: 2px solid transparent;
outline-offset: 0;
}
border-top-left-radius: ${ CONFIG.radiusSmall };
border-top-right-radius: ${ CONFIG.radiusSmall };
& + & {
border-top-left-radius: 0;
border-top-right-radius: 0;
}
&:last-child {
border-bottom-left-radius: ${ CONFIG.radiusSmall };
border-bottom-right-radius: ${ CONFIG.radiusSmall };
border-bottom-color: ${ CONFIG.surfaceBorderColor };
}
&.is-selected + & {
border-top-color: transparent;
}
&.is-selected {
border-color: ${ COLORS.theme.accent };
}
`;

export const NameContainer = styled.div`
line-height: ${ space( 8 ) };
margin-left: ${ space( 2 ) };
Expand Down

0 comments on commit b8bfe71

Please sign in to comment.