Skip to content

Commit

Permalink
(Custom)GradientPicker: Add flag to remove margins (#43387)
Browse files Browse the repository at this point in the history
* (Custom)GradientPicker: Add flag to remove margins

* Simplify

* Add changelog
  • Loading branch information
mirka authored Aug 19, 2022
1 parent 85ef6fb commit 330f1f4
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ $swatch-columns: math.floor(math.div($popover-width + $swatch-gap - 2 * $popover
padding: 0;
}

.components-custom-gradient-picker__gradient-bar {
margin: $grid-unit-20 0 $grid-unit-15;
}

.components-circular-option-picker__swatches {
display: grid;
grid-template-columns: repeat($swatch-columns, $swatch-size);
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

### Enhancements

- `CustomGradientPicker`, `GradientPicker`: Add `__nextHasNoMargin` prop for opting into the new margin-free styles ([#43387](https://github.com/WordPress/gutenberg/pull/43387)).
- `ToggleGroupControl`: Improve TypeScript documentation ([#43265](https://github.com/WordPress/gutenberg/pull/43265)).
- `ComboboxControl`: Normalize hyphen-like characters to an ASCII hyphen ([#42942](https://github.com/WordPress/gutenberg/pull/42942)).
- `FormTokenField`: Refactor away from `_.difference()` ([#43224](https://github.com/WordPress/gutenberg/pull/43224/)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import { LEFT, RIGHT } from '@wordpress/keycodes';
/**
* Internal dependencies
*/
import Button from '../button';
import { HStack } from '../h-stack';
import { ColorPicker } from '../color-picker';
import { VisuallyHidden } from '../visually-hidden';
import { CustomColorPickerDropdown } from '../color-palette';
import Button from '../../button';
import { HStack } from '../../h-stack';
import { ColorPicker } from '../../color-picker';
import { VisuallyHidden } from '../../visually-hidden';
import { CustomColorPickerDropdown } from '../../color-palette';

import {
addControlPoint,
Expand Down
21 changes: 18 additions & 3 deletions packages/components/src/custom-gradient-picker/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand All @@ -7,9 +12,10 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import AnglePickerControl from '../angle-picker-control';
import CustomGradientBar from '../custom-gradient-bar';
import CustomGradientBar from './gradient-bar';
import { Flex } from '../flex';
import SelectControl from '../select-control';
import { VStack } from '../v-stack';
import {
getGradientAstWithDefault,
getLinearGradientRepresentation,
Expand Down Expand Up @@ -44,6 +50,7 @@ const GradientAnglePicker = ( { gradientAST, hasGradient, onChange } ) => {
};
return (
<AnglePickerControl
__nextHasNoMarginBottom
onChange={ onAngleChange }
labelPosition="top"
value={ hasGradient ? angle : '' }
Expand Down Expand Up @@ -86,6 +93,7 @@ const GradientTypePicker = ( { gradientAST, hasGradient, onChange } ) => {

return (
<SelectControl
__nextHasNoMarginBottom
className="components-custom-gradient-picker__type-picker"
label={ __( 'Type' ) }
labelPosition="top"
Expand All @@ -98,6 +106,8 @@ const GradientTypePicker = ( { gradientAST, hasGradient, onChange } ) => {
};

export default function CustomGradientPicker( {
/** Start opting into the new margin-free styles that will become the default in a future version. */
__nextHasNoMargin = false,
value,
onChange,
__experimentalIsRenderedInSidebar,
Expand All @@ -116,7 +126,12 @@ export default function CustomGradientPicker( {
} ) );

return (
<div className="components-custom-gradient-picker">
<VStack
spacing={ 5 }
className={ classnames( 'components-custom-gradient-picker', {
'is-next-has-no-margin': __nextHasNoMargin,
} ) }
>
<CustomGradientBar
__experimentalIsRenderedInSidebar={
__experimentalIsRenderedInSidebar
Expand Down Expand Up @@ -156,6 +171,6 @@ export default function CustomGradientPicker( {
) }
</AccessoryWrapper>
</Flex>
</div>
</VStack>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import CustomGradientPicker from '../';
export default {
title: 'Components/CustomGradientPicker',
component: CustomGradientPicker,
argTypes: {
__nextHasNoMargin: { control: { type: 'boolean' } },
},
};

const CustomGradientPickerWithState = ( props ) => {
Expand All @@ -24,6 +27,4 @@ const CustomGradientPickerWithState = ( props ) => {
);
};

export const _default = () => {
return <CustomGradientPickerWithState />;
};
export const Default = CustomGradientPickerWithState.bind( {} );
18 changes: 7 additions & 11 deletions packages/components/src/custom-gradient-picker/style.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
$components-custom-gradient-picker__padding: $grid-unit-20; // 48px container, 16px handles inside, that leaves 32px padding, half of which is 1å6.

.components-custom-gradient-picker {
&:not(.is-next-has-no-margin) {
margin-top: $grid-unit-15;
margin-bottom: $grid-unit-30;
}
}

.components-custom-gradient-picker__gradient-bar:not(.has-gradient) {
opacity: 0.4;
}

.components-custom-gradient-picker__gradient-bar {
border-radius: $radius-block-ui;
margin-top: $grid-unit-15;
width: 100%;
height: $grid-unit-60;
margin-bottom: $grid-unit-20+$grid-unit-05;

.components-custom-gradient-picker__markers-container {
position: relative;
Expand Down Expand Up @@ -86,15 +91,6 @@ $components-custom-gradient-picker__padding: $grid-unit-20; // 48px container, 1
height: 20px;
}

.components-custom-gradient-picker .components-custom-gradient-picker__ui-line {
margin-bottom: $grid-unit-20;

.components-base-control.components-angle-picker,
.components-base-control.components-custom-gradient-picker__type-picker {
margin-bottom: 0;
}
}

.components-custom-gradient-picker .components-custom-gradient-picker__toolbar {
border: none;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
import CustomGradientBar from '../custom-gradient-bar';
import CustomGradientBar from '../custom-gradient-picker/gradient-bar';

import {
getColorStopsFromColors,
Expand Down
60 changes: 34 additions & 26 deletions packages/components/src/duotone-picker/duotone-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import { __, sprintf } from '@wordpress/i18n';
*/
import ColorListPicker from '../color-list-picker';
import CircularOptionPicker from '../circular-option-picker';
import { VStack } from '../v-stack';

import CustomDuotoneBar from './custom-duotone-bar';
import { getDefaultColors, getGradientFromCSSColors } from './utils';
import { Spacer } from '../spacer';

function DuotonePicker( {
clearable = true,
Expand Down Expand Up @@ -97,32 +99,38 @@ function DuotonePicker( {
)
}
>
{ ! disableCustomColors && ! disableCustomDuotone && (
<CustomDuotoneBar
value={ isUnset ? undefined : value }
onChange={ onChange }
/>
) }
{ ! disableCustomDuotone && (
<ColorListPicker
labels={ [ __( 'Shadows' ), __( 'Highlights' ) ] }
colors={ colorPalette }
value={ isUnset ? undefined : value }
disableCustomColors={ disableCustomColors }
enableAlpha
onChange={ ( newColors ) => {
if ( ! newColors[ 0 ] ) {
newColors[ 0 ] = defaultDark;
}
if ( ! newColors[ 1 ] ) {
newColors[ 1 ] = defaultLight;
}
const newValue =
newColors.length >= 2 ? newColors : undefined;
onChange( newValue );
} }
/>
) }
<Spacer paddingTop={ 4 }>
<VStack spacing={ 3 }>
{ ! disableCustomColors && ! disableCustomDuotone && (
<CustomDuotoneBar
value={ isUnset ? undefined : value }
onChange={ onChange }
/>
) }
{ ! disableCustomDuotone && (
<ColorListPicker
labels={ [ __( 'Shadows' ), __( 'Highlights' ) ] }
colors={ colorPalette }
value={ isUnset ? undefined : value }
disableCustomColors={ disableCustomColors }
enableAlpha
onChange={ ( newColors ) => {
if ( ! newColors[ 0 ] ) {
newColors[ 0 ] = defaultDark;
}
if ( ! newColors[ 1 ] ) {
newColors[ 1 ] = defaultLight;
}
const newValue =
newColors.length >= 2
? newColors
: undefined;
onChange( newValue );
} }
/>
) }
</VStack>
</Spacer>
</CircularOptionPicker>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export default {
component: DuotonePicker,
argTypes: {
clearable: { control: { type: 'boolean' } },
disableCustomColors: { control: { type: 'boolean' } },
disableCustomDuotone: { control: { type: 'boolean' } },
onChange: { action: 'onChange' },
unsetable: { control: { type: 'boolean' } },
},
Expand Down
29 changes: 22 additions & 7 deletions packages/components/src/gradient-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import CircularOptionPicker from '../circular-option-picker';
import CustomGradientPicker from '../custom-gradient-picker';
import { VStack } from '../v-stack';
import { ColorHeading } from '../color-palette/styles';
import { Spacer } from '../spacer';

function SingleOrigin( {
className,
Expand Down Expand Up @@ -99,6 +100,8 @@ function MultipleOrigin( {
}

export default function GradientPicker( {
/** Start opting into the new margin-free styles that will become the default in a future version. */
__nextHasNoMargin = false,
className,
gradients,
onChange,
Expand All @@ -117,6 +120,11 @@ export default function GradientPicker( {
? MultipleOrigin
: SingleOrigin;

// Can be removed when deprecation period is over
const deprecatedMarginSpacerProps = ! __nextHasNoMargin
? { marginTop: 3 }
: {};

return (
<Component
className={ className }
Expand All @@ -137,13 +145,20 @@ export default function GradientPicker( {
}
content={
! disableCustomGradients && (
<CustomGradientPicker
__experimentalIsRenderedInSidebar={
__experimentalIsRenderedInSidebar
}
value={ value }
onChange={ onChange }
/>
<Spacer
marginTop={ gradients?.length ? 3 : 0 }
marginBottom={ 0 }
{ ...deprecatedMarginSpacerProps }
>
<CustomGradientPicker
__nextHasNoMargin={ __nextHasNoMargin }
__experimentalIsRenderedInSidebar={
__experimentalIsRenderedInSidebar
}
value={ value }
onChange={ onChange }
/>
</Spacer>
)
}
/>
Expand Down
Loading

0 comments on commit 330f1f4

Please sign in to comment.