/
screen-text-color.js
71 lines (61 loc) · 1.66 KB
/
screen-text-color.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __experimentalPanelColorGradientSettings as PanelColorGradientSettings } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import ScreenHeader from './header';
import {
getSupportedGlobalStylesPanels,
useSetting,
useStyle,
useColorsPerOrigin,
} from './hooks';
function ScreenTextColor( { name } ) {
const parentMenu = name === undefined ? '' : '/blocks/' + name;
const supports = getSupportedGlobalStylesPanels( name );
const [ solids ] = useSetting( 'color.palette', name );
const [ areCustomSolidsEnabled ] = useSetting( 'color.custom', name );
const [ isTextEnabled ] = useSetting( 'color.text', name );
const colorsPerOrigin = useColorsPerOrigin( name );
const hasTextColor =
supports.includes( 'color' ) &&
isTextEnabled &&
( solids.length > 0 || areCustomSolidsEnabled );
const [ color, setColor ] = useStyle( 'color.text', name );
const [ userColor ] = useStyle( 'color.text', name, 'user' );
if ( ! hasTextColor ) {
return null;
}
const settings = [
{
colorValue: color,
onColorChange: setColor,
label: __( 'Text color' ),
clearable: color === userColor,
},
];
return (
<>
<ScreenHeader
back={ parentMenu + '/colors' }
title={ __( 'Text' ) }
description={ __(
'Set the default color used for text across the site.'
) }
/>
<PanelColorGradientSettings
title={ __( 'Color' ) }
settings={ settings }
colors={ colorsPerOrigin }
disableCustomColors={ ! areCustomSolidsEnabled }
__experimentalHasMultipleOrigins
showTitle={ false }
enableAlpha
/>
</>
);
}
export default ScreenTextColor;