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

Remove the duplicated title in background, text and link views in Global Styles #35583

Merged
merged 5 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
74 changes: 12 additions & 62 deletions packages/block-editor/src/components/colors-gradients/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,71 +13,23 @@ import {
__experimentalVStack as VStack,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
ColorIndicator,
ColorPalette,
GradientPicker,
} from '@wordpress/components';
import { sprintf, __ } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { getColorObjectByColorValue } from '../colors';
import { __experimentalGetGradientObjectByGradientValue } from '../gradients';
import useSetting from '../use-setting';

// translators: first %s: the color name or value (e.g. red or #ff0000)
const colorIndicatorAriaLabel = __( '(Color: %s)' );

// translators: first %s: the gradient name or value (e.g. red to green or linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)
const gradientIndicatorAriaLabel = __( '(Gradient: %s)' );

const colorsAndGradientKeys = [
'colors',
'disableCustomColors',
'gradients',
'disableCustomGradients',
];

function VisualLabel( {
colors,
gradients,
label,
currentTab,
colorValue,
gradientValue,
} ) {
let value, ariaLabel;
if ( currentTab === 'color' ) {
if ( colorValue ) {
value = colorValue;
const colorObject = getColorObjectByColorValue( colors, value );
const colorName = colorObject && colorObject.name;
ariaLabel = sprintf( colorIndicatorAriaLabel, colorName || value );
}
} else if ( currentTab === 'gradient' && gradientValue ) {
value = gradientValue;
const gradientObject = __experimentalGetGradientObjectByGradientValue(
gradients,
value
);
const gradientName = gradientObject && gradientObject.name;
ariaLabel = sprintf(
gradientIndicatorAriaLabel,
gradientName || value
);
}

return (
<>
{ label }
{ !! value && (
<ColorIndicator colorValue={ value } aria-label={ ariaLabel } />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would deleting the code that computes an accessible color label be an accessibility regression?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know for sure but I don't feel like it since that label is only read when the element is reached which is not the case here but.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I guess we still need to work on replacing / consolidating the color indicator components (tracked in #35093), so probably adding solid accessible text should be done there as well

) }
</>
);
}

function ColorGradientControlInner( {
colors,
gradients,
Expand All @@ -90,6 +42,7 @@ function ColorGradientControlInner( {
colorValue,
gradientValue,
clearable,
showTitle = true,
} ) {
const canChooseAColor =
onColorChange && ( ! isEmpty( colors ) || ! disableCustomColors );
Expand All @@ -111,19 +64,16 @@ function ColorGradientControlInner( {
) }
>
<fieldset>
<VStack space={ 3 }>
<legend>
<div className="block-editor-color-gradient-control__color-indicator">
<BaseControl.VisualLabel>
<VisualLabel
currentTab={ currentTab }
label={ label }
colorValue={ colorValue }
gradientValue={ gradientValue }
/>
</BaseControl.VisualLabel>
</div>
</legend>
<VStack spacing={ 1 }>
{ showTitle && (
<legend>
<div className="block-editor-color-gradient-control__color-indicator">
<BaseControl.VisualLabel>
{ label }
</BaseControl.VisualLabel>
</div>
</legend>
) }
{ canChooseAColor && canChooseAGradient && (
<ToggleGroupControl
value={ currentTab }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const PanelColorGradientSettingsInner = ( {
>
{ settings.map( ( setting, index ) => (
<ColorGradientControl
showTitle={ showTitle }
key={ index }
{ ...{
colors,
Expand Down
50 changes: 28 additions & 22 deletions packages/components/src/color-palette/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import { useCallback, useMemo } from '@wordpress/element';
/**
* Internal dependencies
*/
import Dropdown from '../dropdown';
import { ColorPicker } from '../color-picker';
import CircularOptionPicker from '../circular-option-picker';
import { VStack } from '../v-stack';

extend( [ namesPlugin, a11yPlugin ] );

Expand Down Expand Up @@ -76,33 +78,37 @@ export default function ColorPalette( {
);

return (
<CircularOptionPicker
className={ className }
options={ colorOptions }
actions={
<>
{ ! disableCustomColors && (
<CircularOptionPicker.DropdownLinkAction
dropdownProps={ {
renderContent: renderCustomColorPicker,
contentClassName:
'components-color-palette__picker',
} }
buttonProps={ {
'aria-label': __( 'Custom color picker' ),
} }
linkText={ __( 'Custom color' ) }
/>
<VStack spacing={ 3 }>
{ ! disableCustomColors && (
<Dropdown
renderContent={ renderCustomColorPicker }
renderToggle={ ( { isOpen, onToggle } ) => (
<button
className="components-color-palette__custom-color"
aria-expanded={ isOpen }
aria-haspopup="true"
onClick={ onToggle }
aria-label={ __( 'Custom color picker' ) }
style={ { background: value } }
>
{ value }
</button>
) }
{ !! clearable && (
/>
) }
<CircularOptionPicker
className={ className }
options={ colorOptions }
actions={
!! clearable && (
<CircularOptionPicker.ButtonAction
onClick={ clearColor }
>
{ __( 'Clear' ) }
</CircularOptionPicker.ButtonAction>
) }
</>
}
/>
)
}
/>
</VStack>
);
}
18 changes: 18 additions & 0 deletions packages/components/src/color-palette/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.components-color-palette__custom-color {
border: none;
background: none;
outline: 0;
display: block;
border-radius: $radius-block-ui;
height: $grid-unit-60;
text-align: right;
width: 100%;
background-image:
repeating-linear-gradient(45deg, $gray-200 25%, transparent 25%, transparent 75%, $gray-200 75%, $gray-200),
repeating-linear-gradient(45deg, $gray-200 25%, transparent 25%, transparent 75%, $gray-200 75%, $gray-200);
background-position: 0 0, 25px 25px;
background-size: calc(2 * 25px) calc(2 * 25px);
box-sizing: border-box;
color: $white;
cursor: pointer;
}
1 change: 1 addition & 0 deletions packages/components/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@import "./color-indicator/style.scss";
@import "./combobox-control/style.scss";
@import "./color-list-picker/style.scss";
@import "./color-palette/style.scss";
@import "./custom-gradient-picker/style.scss";
@import "./custom-select-control/style.scss";
@import "./date-time/style.scss";
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/global-styles/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import NavigationButton from './navigation-button';

function ScreenHeader( { back, title, description } ) {
return (
<VStack spacing={ 2 }>
<VStack spacing={ 2 } className="edit-site-global-styles-header">
<HStack spacing={ 2 }>
<View>
<NavigationButton
Expand Down
17 changes: 11 additions & 6 deletions packages/edit-site/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@
margin: $grid-unit-20;

.component-color-indicator {
display: block;
border-radius: 50%;
border: 0;
height: 24px;
width: 24px;
margin-left: 0;
padding: 0;
}
}


.edit-site-global-styles-screen-colors .component-color-indicator,
.edit-site-global-styles-header .component-color-indicator {
display: block;
border-radius: 50%;
border: 0;
height: 24px;
width: 24px;
padding: 0;
}

.edit-site-global-styles-header__description {
padding: 0 $grid-unit-20;
}
Expand Down