Skip to content

Commit

Permalink
started interface to edit caption colors in Global Styles
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieCabrera committed Sep 12, 2022
1 parent 74cd9f9 commit cc6fcc4
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __experimentalColorGradientControl as ColorGradientControl } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import ScreenHeader from './header';
import {
getSupportedGlobalStylesPanels,
useSetting,
useStyle,
useColorsPerOrigin,
} from './hooks';

function ScreenCaptionColor( { name } ) {
const supports = getSupportedGlobalStylesPanels( name );
const colorsPerOrigin = useColorsPerOrigin( name );
const [ solids ] = useSetting( 'color.palette', name );
const [ areCustomSolidsEnabled ] = useSetting( 'color.custom', name );

const hasCaptionColor =
supports.includes( 'color' ) &&
( solids.length > 0 || areCustomSolidsEnabled );

const [ captionTextColor, setCaptionTextColor ] = useStyle(
'elements.caption.color.text',
name
);
const [ userCaptionTextColor ] = useStyle(
'elements.caption.color.text',
name,
'user'
);

const [ captionBgColor, setCaptionBgColor ] = useStyle(
'elements.caption.color.background',
name
);
const [ userCaptionBgColor ] = useStyle(
'elements.caption.color.background',
name,
'user'
);

if ( ! hasCaptionColor ) {
return null;
}

return (
<>
<ScreenHeader
title={ __( 'Captions' ) }
description={ __(
'Set the colors used for captions across the site.'
) }
/>
<div className="edit-site-global-styles-screen-caption-color">
<h4 className="edit-site-global-styles-section-title">
{ __( 'Text color' ) }
</h4>

<ColorGradientControl
className="edit-site-screen-caption-color__control"
colors={ colorsPerOrigin }
disableCustomColors={ ! areCustomSolidsEnabled }
__experimentalHasMultipleOrigins
showTitle={ false }
enableAlpha
__experimentalIsRenderedInSidebar
colorValue={ captionTextColor }
onColorChange={ setCaptionTextColor }
clearable={ captionTextColor === userCaptionTextColor }
/>

<h4 className="edit-site-global-styles-section-title">
{ __( 'Background color' ) }
</h4>

<ColorGradientControl
className="edit-site-screen-caption-color__control"
colors={ colorsPerOrigin }
disableCustomColors={ ! areCustomSolidsEnabled }
__experimentalHasMultipleOrigins
showTitle={ false }
enableAlpha
__experimentalIsRenderedInSidebar
colorValue={ captionBgColor }
onColorChange={ setCaptionBgColor }
clearable={ captionBgColor === userCaptionBgColor }
/>
</div>
</>
);
}

export default ScreenCaptionColor;
34 changes: 34 additions & 0 deletions packages/edit-site/src/components/global-styles/screen-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,36 @@ function LinkColorItem( { name, parentMenu } ) {
);
}

function CaptionColorItem( { name, parentMenu } ) {
const supports = getSupportedGlobalStylesPanels( name );
const hasSupport = supports.includes( 'color' );
const [ color ] = useStyle( 'elements.caption.color.text', name );
const [ bgColor ] = useStyle( 'elements.caption.color.background', name );

if ( ! hasSupport ) {
return null;
}

return (
<NavigationButtonAsItem
path={ parentMenu + '/colors/caption' }
aria-label={ __( 'Colors caption styles' ) }
>
<HStack justify="flex-start">
<ZStack isLayered={ false } offset={ -8 }>
<ColorIndicatorWrapper expanded={ false }>
<ColorIndicator colorValue={ bgColor } />
</ColorIndicatorWrapper>
<ColorIndicatorWrapper expanded={ false }>
<ColorIndicator colorValue={ color } />
</ColorIndicatorWrapper>
</ZStack>
<FlexItem>{ __( 'Captions' ) }</FlexItem>
</HStack>
</NavigationButtonAsItem>
);
}

function HeadingColorItem( { name, parentMenu } ) {
const supports = getSupportedGlobalStylesPanels( name );
const hasSupport = supports.includes( 'color' );
Expand Down Expand Up @@ -204,6 +234,10 @@ function ScreenColors( { name } ) {
name={ name }
parentMenu={ parentMenu }
/>
<CaptionColorItem
name={ name }
parentMenu={ parentMenu }
/>
<HeadingColorItem
name={ name }
parentMenu={ parentMenu }
Expand Down
1 change: 1 addition & 0 deletions packages/edit-site/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
max-width: 100%;
}

.edit-site-global-styles-screen-caption-color,
.edit-site-global-styles-screen-heading-color,
.edit-site-global-styles-screen-typography {
margin: $grid-unit-20;
Expand Down
7 changes: 7 additions & 0 deletions packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ScreenTypographyElement from './screen-typography-element';
import ScreenColors from './screen-colors';
import ScreenColorPalette from './screen-color-palette';
import ScreenBackgroundColor from './screen-background-color';
import ScreenCaptionColor from './screen-caption-color';
import ScreenTextColor from './screen-text-color';
import ScreenLinkColor from './screen-link-color';
import ScreenHeadingColor from './screen-heading-color';
Expand Down Expand Up @@ -102,6 +103,12 @@ function ContextScreens( { name } ) {
<ScreenHeadingColor name={ name } />
</GlobalStylesNavigationScreen>

<GlobalStylesNavigationScreen
path={ parentMenu + '/colors/caption' }
>
<ScreenCaptionColor name={ name } />
</GlobalStylesNavigationScreen>

<GlobalStylesNavigationScreen
path={ parentMenu + '/colors/button' }
>
Expand Down
3 changes: 3 additions & 0 deletions packages/edit-site/src/components/global-styles/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ const STYLE_PATH_TO_CSS_VAR_INFIX = {
'elements.link.color.text': 'color',
'elements.button.color.text': 'color',
'elements.button.backgroundColor': 'background-color',
'elements.caption.color.text': 'color',
'elements.caption.backgroundColor': 'background-color',
'elements.caption.gradient': 'gradient',
'elements.heading.color': 'color',
'elements.heading.backgroundColor': 'background-color',
'elements.heading.gradient': 'gradient',
Expand Down

0 comments on commit cc6fcc4

Please sign in to comment.