Skip to content

Commit 68e1026

Browse files
committed
disable color schemes in select control, fade out undefined schemes
1 parent 89952a9 commit 68e1026

4 files changed

Lines changed: 71 additions & 35 deletions

File tree

src/components/color-scheme-preview/editor.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,20 @@
5252
outline: 1px solid #e0e0e0;
5353
}
5454
}
55+
56+
.stk-global-color-scheme__preview {
57+
position: relative;
58+
&::before {
59+
content: "\f543";
60+
font-family: dashicons;
61+
font-size: 16px;
62+
position: absolute;
63+
top: 50%;
64+
left: 50%;
65+
transform: translate(-50%, -50%);
66+
}
67+
}
68+
69+
.stk-scheme--is-disabled {
70+
opacity: 0.1;
71+
}

src/components/color-scheme-preview/index.js

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Button, BaseControl } from '@wordpress/components'
2-
2+
import classnames from 'classnames'
33
export const DEFAULT_COLOR_SCHEME_COLORS = {
44
backgroundColor: { desktop: '' },
55
headingColor: { desktop: '' },
@@ -14,43 +14,50 @@ export const DEFAULT_COLOR_SCHEME_COLORS = {
1414
const NOOP = () => {}
1515

1616
const ColorSchemePreview = ( {
17-
colors, withWrapper = false, onClick = NOOP,
17+
colors, withWrapper = false, onClick = NOOP, isDisabled = false,
1818
} ) => {
1919
const TagName = onClick === NOOP ? 'div' : Button
2020
const additionalProps = onClick === NOOP ? {} : { onClick }
21+
22+
const classNames = classnames( 'stk-global-color-scheme__preview__background', {
23+
'stk-scheme--is-disabled': isDisabled,
24+
} )
25+
2126
return (
22-
<TagName
23-
className="stk-global-color-scheme__preview__background"
24-
style={ withWrapper ? {} : { background: colors?.backgroundColor } }
25-
{ ...additionalProps }
26-
>
27-
<div className="stk-global-color-scheme__preview__typography">
28-
<span style={ { color: colors?.headingColor } }>A</span>
29-
<span style={ { color: colors?.textColor } }>a</span>
30-
</div>
31-
<div>
32-
<div
33-
className="stk-global-color-scheme__preview__button"
34-
style={ { background: `${ colors?.buttonBackgroundColor || 'var(--stk-button-background-color)' }` } }
35-
/>
36-
<div
37-
className="stk-global-color-scheme__preview__button"
38-
style={ {
39-
borderStyle: 'solid',
40-
borderWidth: '1px',
41-
borderColor: `${ colors?.buttonOutlineColor || colors?.buttonBackgroundColor || 'var(--stk-button-background-color)' }`,
42-
} }
43-
/>
44-
<div
45-
className="stk-global-color-scheme__preview__circle"
46-
style={ { backgroundColor: `${ colors?.linkColor || colors?.textColor || 'var(--stk-container-color)' }` } }
47-
/>
48-
<div
49-
className="stk-global-color-scheme__preview__circle"
50-
style={ { backgroundColor: `${ colors?.accentColor || 'var(--stk-icon-color)' }` } }
51-
/>
52-
</div>
53-
</TagName>
27+
<div className="stk-global-color-scheme__preview">
28+
<TagName
29+
className={ classNames }
30+
style={ withWrapper ? {} : { background: colors?.backgroundColor } }
31+
{ ...additionalProps }
32+
>
33+
<div className="stk-global-color-scheme__preview__typography">
34+
<span style={ { color: colors?.headingColor } }>A</span>
35+
<span style={ { color: colors?.textColor } }>a</span>
36+
</div>
37+
<div>
38+
<div
39+
className="stk-global-color-scheme__preview__button"
40+
style={ { background: `${ colors?.buttonBackgroundColor || 'var(--stk-button-background-color)' }` } }
41+
/>
42+
<div
43+
className="stk-global-color-scheme__preview__button"
44+
style={ {
45+
borderStyle: 'solid',
46+
borderWidth: '1px',
47+
borderColor: `${ colors?.buttonOutlineColor || colors?.buttonBackgroundColor || 'var(--stk-button-background-color)' }`,
48+
} }
49+
/>
50+
<div
51+
className="stk-global-color-scheme__preview__circle"
52+
style={ { backgroundColor: `${ colors?.linkColor || colors?.textColor || 'var(--stk-container-color)' }` } }
53+
/>
54+
<div
55+
className="stk-global-color-scheme__preview__circle"
56+
style={ { backgroundColor: `${ colors?.accentColor || 'var(--stk-icon-color)' }` } }
57+
/>
58+
</div>
59+
</TagName>
60+
</div>
5461
)
5562
}
5663

src/hooks/use-block-color-schemes.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import { useSelect } from '@wordpress/data'
55
import { applyFilters } from '@wordpress/hooks'
66
import { __ } from '@wordpress/i18n'
77

8+
// Check if the color scheme contains a value for any of the states
9+
const schemeHasValue = scheme => {
10+
const hasValue = Object.values( scheme ).some( states => {
11+
return Object.values( states ).some( value => value !== '' )
12+
} )
13+
14+
return hasValue
15+
}
16+
817
export const useBlockColorSchemes = () => {
918
const {
1019
getScheme,
@@ -32,6 +41,7 @@ export const useBlockColorSchemes = () => {
3241
}, ...allColorSchemes?.map( scheme => ( {
3342
label: scheme.name,
3443
value: scheme.key,
44+
disabled: ! schemeHasValue( scheme.colorScheme ),
3545
} ) ) ]
3646

3747
// Returns the color scheme slug if it exists, otherwise return a fallback value

src/plugins/global-settings/color-schemes/color-scheme-picker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Internal dependencies
33
*/
44
import { hoverState } from '../utils'
5+
import { schemeHasValue } from './utils'
56
import PRESET_COLOR_SCHEMES from './preset-color-schemes.json'
67
/**
78
* External dependencies
@@ -314,7 +315,8 @@ const ColorSchemePicker = props => {
314315
buttonOutlineColor: getInheritedValue( item.colorScheme.buttonOutlineColor ) || defaults.buttonOutlineColor.desktop,
315316
}
316317

317-
const Preview = <ColorSchemePreview colors={ colors } withWrapper={ withWrapper } />
318+
const isDisabled = ! schemeHasValue( item.colorScheme ) || withWrapper
319+
const Preview = <ColorSchemePreview colors={ colors } withWrapper={ withWrapper } isDisabled={ isDisabled } />
318320

319321
return withWrapper ? <div
320322
className="stk-global-color-scheme__preview-wrapper"

0 commit comments

Comments
 (0)