Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomGradientPicker / Cover: Update UI #20099

Merged
merged 7 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
>
<fieldset>
<legend>
<span
className="components-base-control__label"
<div
className="block-editor-color-gradient-control__color-indicator"
>
Test Color
<span
aria-label="(Color: #f00)"
className="component-color-indicator"
style={
Object {
"background": "#f00",
className="components-base-control__label"
>
Test Color
<span
aria-label="(Color: #f00)"
className="component-color-indicator"
style={
Object {
"background": "#f00",
}
}
}
/>
</span>
/>
</span>
</div>
</legend>
<div
className="components-circular-option-picker"
Expand Down
24 changes: 13 additions & 11 deletions packages/block-editor/src/components/colors-gradients/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,29 @@ function ColorGradientControlInner( {
>
<fieldset>
<legend>
<BaseControl.VisualLabel>
<VisualLabel
currentTab={ currentTab }
label={ label }
colorValue={ colorValue }
gradientValue={ gradientValue }
/>
</BaseControl.VisualLabel>
<div className="block-editor-color-gradient-control__color-indicator">
<BaseControl.VisualLabel>
<VisualLabel
currentTab={ currentTab }
label={ label }
colorValue={ colorValue }
gradientValue={ gradientValue }
/>
</BaseControl.VisualLabel>
</div>
</legend>
{ canChooseAColor && canChooseAGradient && (
<ButtonGroup className="block-editor-color-gradient-control__button-tabs">
<Button
isLarge
isSmall
isPrimary={ currentTab === 'color' }
isSecondary={ currentTab !== 'color' }
onClick={ () => setCurrentTab( 'color' ) }
>
{ __( 'Solid Color' ) }
{ __( 'Solid' ) }
</Button>
<Button
isLarge
isSmall
isPrimary={ currentTab === 'gradient' }
isSecondary={ currentTab !== 'gradient' }
onClick={ () => setCurrentTab( 'gradient' ) }
Expand Down
17 changes: 13 additions & 4 deletions packages/block-editor/src/components/colors-gradients/style.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
.block-editor-color-gradient-control__button-tabs {
display: block;
.block-editor-color-gradient-control {
&__color-indicator {
margin-bottom: $grid-size;
}

&__button-tabs {
display: block;
margin-bottom: $grid-size;
}
}

.block-editor-panel-color-gradient-settings {
.component-color-indicator {
vertical-align: text-bottom;
}

&__panel-title .component-color-indicator {
display: inline-block;
&__panel-title {
.component-color-indicator {
display: inline-block;
}
}

&.is-opened &__panel-title .component-color-indicator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const getButtonWithAriaLabelStartPredicate = ( ariaLabelStart ) => (
);
};

const colorTabButtonPredicate = getButtonWithTestPredicate( 'Solid Color' );
const colorTabButtonPredicate = getButtonWithTestPredicate( 'Solid' );
const gradientTabButtonPredicate = getButtonWithTestPredicate( 'Gradient' );

describe( 'ColorPaletteControl', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/cover/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ function CoverEdit( {
gradientValue,
onColorChange: setOverlayColor,
onGradientChange: setGradient,
label: __( 'Overlay' ),
label: __( 'Color' ),
},
] }
>
Expand Down
95 changes: 47 additions & 48 deletions packages/components/src/custom-gradient-picker/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
*/
import { withInstanceId } from '@wordpress/compose';
import {
SVG,
G,
Rect,
Defs,
RadialGradient,
Circle,
LinearGradient,
Path,
RadialGradient,
Stop,
SVG,
} from '@wordpress/primitives';

/**
Expand All @@ -18,56 +17,56 @@ import {
export const LinearGradientIcon = withInstanceId( ( { instanceId } ) => {
const linerGradientId = `linear-gradient-${ instanceId }`;
return (
<SVG width="20" height="20" xmlns="http://www.w3.org/2000/svg">
<Defs>
<LinearGradient
y2="0"
x2="0.5"
y1="1"
x1="0.5"
id={ linerGradientId }
>
<Stop offset="0" stopColor="#000000" />
<Stop offset="1" stopColor="#fff" />
</LinearGradient>
</Defs>
<G>
<Rect
fill={ `url(#${ linerGradientId })` }
height="20"
width="20"
y="-1"
x="-1"
/>
</G>
<SVG
fill="none"
height="20"
viewBox="0 0 20 20"
width="20"
xmlns="http://www.w3.org/2000/svg"
>
<LinearGradient
id={ linerGradientId }
gradientUnits="userSpaceOnUse"
x1="10"
x2="10"
y1="1"
y2="19"
>
<Stop offset="0" stopColor="#000000" />
<Stop offset="1" stopColor="#ffffff" />
</LinearGradient>
<Path d="m1 1h18v18h-18z" fill={ `url(#${ linerGradientId })` } />
</SVG>
);
} );

export const RadialGradientIcon = withInstanceId( ( { instanceId } ) => {
const radialGradientId = `radial-gradient-${ instanceId }`;
return (
<SVG width="20" height="20" xmlns="http://www.w3.org/2000/svg">
<Defs>
<RadialGradient
cy="0.5"
cx="0.5"
spreadMethod="pad"
id={ radialGradientId }
>
<Stop offset="0" stopColor="#fff" />
<Stop offset="1" stopColor="#000000" />
</RadialGradient>
</Defs>
<G>
<Rect
fill={ `url(#${ radialGradientId })` }
height="20"
width="20"
y="-1"
x="-1"
/>
</G>
<SVG
fill="none"
height="20"
viewBox="0 0 20 20"
width="20"
xmlns="http://www.w3.org/2000/svg"
>
<RadialGradient
id={ radialGradientId }
cx="0"
cy="0"
gradientTransform="matrix(0 9 -9 0 10 10)"
gradientUnits="userSpaceOnUse"
r="1"
>
<Stop offset="0" stopColor="#000000" />
<Stop offset="1" stopColor="#ffffff" />
</RadialGradient>
<Circle
cx="10"
cy="10"
fill={ `url(#${ radialGradientId })` }
r="9"
/>
</SVG>
);
} );
1 change: 1 addition & 0 deletions packages/components/src/custom-gradient-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const GradientTypePicker = ( { gradientAST, hasGradient, onChange } ) => {
<BaseControl className="components-custom-gradient-picker__type-picker">
<BaseControl.VisualLabel>{ __( 'Type' ) }</BaseControl.VisualLabel>
<ToolbarGroup
className="components-custom-gradient-picker__toolbar"
controls={ [
{
icon: <LinearGradientIcon />,
Expand Down
30 changes: 22 additions & 8 deletions packages/components/src/custom-gradient-picker/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
$components-custom-gradient-picker__padding: 3px; // 24px container, 18px handles inside, that leaves 6px padding, half of which is 3.

.components-custom-gradient-picker {
margin-top: $grid-size;
}

.components-custom-gradient-picker__gradient-bar:not(.has-gradient) {
opacity: 0.4;
}
Expand All @@ -8,7 +12,7 @@ $components-custom-gradient-picker__padding: 3px; // 24px container, 18px handle
width: 100%;
height: $icon-button-size-small;
border-radius: $icon-button-size-small;
margin-bottom: $grid-size;
margin-bottom: $grid-size-large;
padding-left: $components-custom-gradient-picker__padding;
padding-right: $icon-button-size-small - $components-custom-gradient-picker__padding;

Expand Down Expand Up @@ -69,17 +73,27 @@ $components-custom-gradient-picker__padding: 3px; // 24px container, 18px handle
}

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

.components-custom-gradient-picker__angle-picker-field {
display: block;
width: 100%;
}
.components-custom-gradient-picker .components-custom-gradient-picker__toolbar {
border: none;

.components-custom-gradient-picker__angle-picker {
width: 50%;
// Work-around to target the inner button containers rendered by <ToolbarGroup />
> div + div {
margin-left: 1px;
}

button {
&.is-pressed {
> svg {
background: $white;
border: 1px solid $dark-gray-200;
border-radius: 2px;
}
}
}
}