Skip to content

Commit

Permalink
refactored text into element component
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieCabrera authored and scruffian committed Oct 19, 2022
1 parent cba3235 commit 80a3760
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {

const elements = {
text: {
description: __( '' ),
description: __(
'Set the default color used for text across the site.'
),
title: __( 'Text' ),
},
link: {
Expand Down Expand Up @@ -44,36 +46,56 @@ function ScreenColorElement( { name, element } ) {
const colorsPerOrigin = useColorsPerOrigin( name );
const [ solids ] = useSetting( 'color.palette', name );
const [ areCustomSolidsEnabled ] = useSetting( 'color.custom', name );
const [ isBackgroundEnabled ] = useSetting( 'color.background', name );
let [ isBackgroundEnabled ] = useSetting( 'color.background', name );
const [ isTextEnabled ] = useSetting( 'color.text', name );

let textColorElementSelector = 'elements.' + element + '.color.text';
const backgroundColorElementSelector =
'elements.' + element + '.color.background';

let hasElementColor = false;

let hasElementColor =
supports.includes( 'color' ) &&
( solids.length > 0 || areCustomSolidsEnabled );
switch ( element ) {
case 'button':
hasElementColor =
supports.includes( 'buttonColor' ) &&
isBackgroundEnabled &&
( solids.length > 0 || areCustomSolidsEnabled );
break;
case 'text':
hasElementColor =
supports.includes( 'color' ) &&
isTextEnabled &&
( solids.length > 0 || areCustomSolidsEnabled );
textColorElementSelector = 'color.text';
isBackgroundEnabled = false;
break;

if ( supports.includes( 'buttonColor' ) ) {
hasElementColor =
supports.includes( 'buttonColor' ) &&
isBackgroundEnabled &&
( solids.length > 0 || areCustomSolidsEnabled );
default:
hasElementColor =
supports.includes( 'color' ) &&
( solids.length > 0 || areCustomSolidsEnabled );
break;
}

const [ elementTextColor, setElementTextColor ] = useStyle(
'elements.' + element + '.color.text',
textColorElementSelector,
name
);

const [ userElementTextColor ] = useStyle(
'elements.' + element + '.color.text',
textColorElementSelector,
name,
'user'
);

const [ elementBgColor, setElementBgColor ] = useStyle(
'elements.' + element + '.color.background',
backgroundColorElementSelector,
name
);

const [ userElementBgColor ] = useStyle(
'elements.' + element + '.color.background',
backgroundColorElementSelector,
name,
'user'
);
Expand Down Expand Up @@ -103,22 +125,25 @@ function ScreenColorElement( { name, element } ) {
onColorChange={ setElementTextColor }
clearable={ elementTextColor === userElementTextColor }
/>

<h4>{ __( 'Background color' ) }</h4>

<ColorGradientControl
className="edit-site-screen-element-color__control"
colors={ colorsPerOrigin }
disableCustomColors={ ! areCustomSolidsEnabled }
__experimentalHasMultipleOrigins
showTitle={ false }
enableAlpha
__experimentalIsRenderedInSidebar
colorValue={ elementBgColor }
onColorChange={ setElementBgColor }
clearable={ elementBgColor === userElementBgColor }
/>
</div>
{ isBackgroundEnabled && (
<div className="edit-site-global-styles-screen-element-color">
<h4>{ __( 'Background color' ) }</h4>

<ColorGradientControl
className="edit-site-screen-element-color__control"
colors={ colorsPerOrigin }
disableCustomColors={ ! areCustomSolidsEnabled }
__experimentalHasMultipleOrigins
showTitle={ false }
enableAlpha
__experimentalIsRenderedInSidebar
colorValue={ elementBgColor }
onColorChange={ setElementBgColor }
clearable={ elementBgColor === userElementBgColor }
/>
</div>
) }
</>
);
}
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import ScreenColors from './screen-colors';
import ScreenColorPalette from './screen-color-palette';
import ScreenBackgroundColor from './screen-background-color';
import ScreenColorElement from './screen-color-element';
import ScreenTextColor from './screen-text-color';
import ScreenLinkColor from './screen-link-color';
import ScreenHeadingColor from './screen-heading-color';
import ScreenLayout from './screen-layout';
Expand Down Expand Up @@ -95,7 +94,7 @@ function ContextScreens( { name } ) {
</GlobalStylesNavigationScreen>

<GlobalStylesNavigationScreen path={ parentMenu + '/colors/text' }>
<ScreenTextColor name={ name } />
<ScreenColorElement name={ name } element="text" />
</GlobalStylesNavigationScreen>

<GlobalStylesNavigationScreen path={ parentMenu + '/colors/link' }>
Expand Down

0 comments on commit 80a3760

Please sign in to comment.