Skip to content

Commit

Permalink
Update color palette popover style (#41900)
Browse files Browse the repository at this point in the history
Increases padding on the popover, and calculates a total width based on swatch dimensions to eliminate whitespace.

Co-authored-by: Lena Morita <lena@jaguchi.com>
  • Loading branch information
jameskoster and mirka authored Jul 26, 2022
1 parent 570230d commit 2f1e1dc
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
font-size: 13px;
}
.emotion-2 {
margin-bottom: calc(4px * 2);
}
.components-panel__row .emotion-2 {
margin-bottom: inherit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ function ColorGradientControlInner( {

return (
<BaseControl
__nextHasNoMarginBottom
className={ classnames(
'block-editor-color-gradient-control',
className
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ColorIndicator,
Dropdown,
FlexItem,
__experimentalDropdownContentWrapper as DropdownContentWrapper,
__experimentalHStack as HStack,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
Expand Down Expand Up @@ -155,10 +156,15 @@ export default function ColorGradientSettingsDropdown( {
<Dropdown
popoverProps={ popoverProps }
className="block-editor-tools-panel-color-gradient-settings__dropdown"
contentClassName="block-editor-panel-color-gradient-settings__dropdown-content"
renderToggle={ renderToggle( toggleSettings ) }
renderContent={ () => (
<ColorGradientControl { ...controlProps } />
<DropdownContentWrapper paddingSize="medium">
<div className="block-editor-panel-color-gradient-settings__dropdown-content">
<ColorGradientControl
{ ...controlProps }
/>
</div>
</DropdownContentWrapper>
) }
/>
</WithToolsPanelItem>
Expand Down
15 changes: 7 additions & 8 deletions packages/block-editor/src/components/colors-gradients/style.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Must equal $color-palette-circle-size from:
// @wordpress/components/src/circular-option-picker/style.scss
$swatch-size: 28px;
$swatch-gap: 12px;

.block-editor-color-gradient-control {
.block-editor-color-gradient-control__color-indicator {
margin-bottom: $grid-unit-15;
Expand All @@ -18,11 +23,6 @@
}

.block-editor-panel-color-gradient-settings {

// Must equal $color-palette-circle-size from:
// @wordpress/components/src/circular-option-picker/style.scss
$swatch-size: 28px;

@media screen and (min-width: $break-medium) {
.components-circular-option-picker__swatches {
display: grid;
Expand All @@ -40,11 +40,10 @@

}

.block-editor-panel-color-gradient-settings__dropdown-content .components-popover__content {
width: $sidebar-width;
.block-editor-panel-color-gradient-settings__dropdown-content {
width: ( $swatch-size * 6 ) + ( $swatch-gap * 5 ); // Ensure the popover perfectly wraps the swatches.
}


.block-editor-panel-color-gradient-settings__color-indicator {
// Show a diagonal line (crossed out) for empty swatches.
background: linear-gradient(-45deg, transparent 48%, $gray-300 48%, $gray-300 52%, transparent 52%);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { VStack } from '../../v-stack';
import { contextConnect, WordPressComponentProps } from '../../ui/context';
import { useBorderControlDropdown } from './hook';
import { StyledLabel } from '../../base-control/styles/base-control-styles';
import DropdownContentWrapper from '../../dropdown/dropdown-content-wrapper';

import type {
Color,
Expand Down Expand Up @@ -141,7 +142,6 @@ const BorderControlDropdown = (
onReset,
onColorChange,
onStyleChange,
popoverClassName,
popoverContentClassName,
popoverControlsClassName,
resetButtonClassName,
Expand Down Expand Up @@ -190,51 +190,55 @@ const BorderControlDropdown = (

const renderContent = ( { onClose }: PopoverProps ) => (
<>
<VStack className={ popoverControlsClassName } spacing={ 6 }>
{ showDropdownHeader ? (
<HStack>
<StyledLabel>{ __( 'Border color' ) }</StyledLabel>
<Button
isSmall
label={ __( 'Close border color' ) }
icon={ closeSmall }
onClick={ onClose }
/>
</HStack>
) : undefined }
<ColorPalette
className={ popoverContentClassName }
value={ color }
onChange={ onColorChange }
{ ...{ colors, disableCustomColors } }
__experimentalHasMultipleOrigins={
__experimentalHasMultipleOrigins
}
__experimentalIsRenderedInSidebar={
__experimentalIsRenderedInSidebar
}
clearable={ false }
enableAlpha={ enableAlpha }
/>
{ enableStyle && (
<BorderControlStylePicker
label={ __( 'Style' ) }
value={ style }
onChange={ onStyleChange }
<DropdownContentWrapper paddingSize="medium">
<VStack className={ popoverControlsClassName } spacing={ 6 }>
{ showDropdownHeader ? (
<HStack>
<StyledLabel>{ __( 'Border color' ) }</StyledLabel>
<Button
isSmall
label={ __( 'Close border color' ) }
icon={ closeSmall }
onClick={ onClose }
/>
</HStack>
) : undefined }
<ColorPalette
className={ popoverContentClassName }
value={ color }
onChange={ onColorChange }
{ ...{ colors, disableCustomColors } }
__experimentalHasMultipleOrigins={
__experimentalHasMultipleOrigins
}
__experimentalIsRenderedInSidebar={
__experimentalIsRenderedInSidebar
}
clearable={ false }
enableAlpha={ enableAlpha }
/>
) }
</VStack>
{ enableStyle && (
<BorderControlStylePicker
label={ __( 'Style' ) }
value={ style }
onChange={ onStyleChange }
/>
) }
</VStack>
</DropdownContentWrapper>
{ showResetButton && (
<Button
className={ resetButtonClassName }
variant="tertiary"
onClick={ () => {
onReset();
onClose();
} }
>
{ __( 'Reset to default' ) }
</Button>
<DropdownContentWrapper paddingSize="none">
<Button
className={ resetButtonClassName }
variant="tertiary"
onClick={ () => {
onReset();
onClose();
} }
>
{ __( 'Reset to default' ) }
</Button>
</DropdownContentWrapper>
) }
</>
);
Expand All @@ -245,7 +249,6 @@ const BorderControlDropdown = (
renderContent={ renderContent }
popoverProps={ {
...__unstablePopoverProps,
className: popoverClassName,
} }
{ ...otherProps }
ref={ forwardedRef }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ export function useBorderControlDropdown(
);
}, [ border, cx, __next36pxDefaultSize ] );

const popoverClassName = useMemo( () => {
return cx( styles.borderControlPopover );
}, [ cx ] );

const popoverControlsClassName = useMemo( () => {
return cx( styles.borderControlPopoverControls );
}, [ cx ] );
Expand All @@ -92,7 +88,6 @@ export function useBorderControlDropdown(
onColorChange,
onStyleChange,
onReset,
popoverClassName,
popoverContentClassName,
popoverControlsClassName,
resetButtonClassName,
Expand Down
3 changes: 3 additions & 0 deletions packages/components/src/border-control/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const colors = [
{ name: 'Blue', color: '#72aee6' },
{ name: 'Red', color: '#e65054' },
{ name: 'Yellow', color: '#f2d675' },
{ name: 'Blue', color: '#72aee6' },
{ name: 'Red', color: '#e65054' },
{ name: 'Yellow', color: '#f2d675' },
];

// Multiple origin colors.
Expand Down
15 changes: 7 additions & 8 deletions packages/components/src/border-control/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,13 @@ export const colorIndicatorWrapper = (
`;
};

export const borderControlPopover = css`
/* Remove padding from content, this will be re-added via inner elements*/
&& .components-popover__content {
padding: 0;
width: 264px;
}
`;
// Must equal $color-palette-circle-size from:
// @wordpress/components/src/circular-option-picker/style.scss
const swatchSize = 28;
const swatchGap = 12;

export const borderControlPopoverControls = css`
padding: ${ space( 2 ) };
width: ${ swatchSize * 6 + swatchGap * 5 }px;
> div:first-of-type > ${ StyledLabel } {
margin-bottom: 0;
Expand All @@ -174,6 +171,8 @@ export const resetButton = css`
/* Override button component styling */
&& {
border-top: ${ CONFIG.borderWidth } solid ${ COLORS.gray[ 200 ] };
border-top-left-radius: 0;
border-top-right-radius: 0;
height: 46px;
}
`;
Expand Down
9 changes: 8 additions & 1 deletion packages/components/src/dropdown/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ const padding = ( { paddingSize = 'small' }: DropdownContentWrapperProps ) => {

export const DropdownContentWrapperDiv = styled.div< DropdownContentWrapperProps >`
// Negative margin to reset (offset) the default padding on .components-popover__content
margin: ${ space( -2 ) };
margin-left: ${ space( -2 ) };
margin-right: ${ space( -2 ) };
&:first-of-type {
margin-top: ${ space( -2 ) };
}
&:last-of-type {
margin-bottom: ${ space( -2 ) };
}
${ padding };
`;

0 comments on commit 2f1e1dc

Please sign in to comment.