-
Notifications
You must be signed in to change notification settings - Fork 4k
/
screen-colors.js
130 lines (115 loc) · 3.11 KB
/
screen-colors.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
__experimentalItemGroup as ItemGroup,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
FlexItem,
ColorIndicator,
} from '@wordpress/components';
/**
* Internal dependencies
*/
import ScreenHeader from './header';
import Palette from './palette';
import NavigationButton from './navigation-button';
import { getSupportedGlobalStylesPanels, useStyle } from './hooks';
import Subtitle from './subtitle';
function BackgroundColorItem( { name, parentMenu } ) {
const supports = getSupportedGlobalStylesPanels( name );
const hasSupport =
supports.includes( 'backgroundColor' ) ||
supports.includes( 'background' );
const [ backgroundColor ] = useStyle( 'color.background', name );
const [ gradientValue ] = useStyle( 'color.gradient', name );
if ( ! hasSupport ) {
return null;
}
return (
<NavigationButton path={ parentMenu + '/colors/background' }>
<HStack justify="flex-start">
<FlexItem>
<ColorIndicator
colorValue={ gradientValue ?? backgroundColor }
/>
</FlexItem>
<FlexItem>{ __( 'Background' ) }</FlexItem>
</HStack>
</NavigationButton>
);
}
function TextColorItem( { name, parentMenu } ) {
const supports = getSupportedGlobalStylesPanels( name );
const hasSupport = supports.includes( 'color' );
const [ color ] = useStyle( 'color.text', name );
if ( ! hasSupport ) {
return null;
}
return (
<NavigationButton path={ parentMenu + '/colors/text' }>
<HStack justify="flex-start">
<FlexItem>
<ColorIndicator colorValue={ color } />
</FlexItem>
<FlexItem>{ __( 'Text' ) }</FlexItem>
</HStack>
</NavigationButton>
);
}
function LinkColorItem( { name, parentMenu } ) {
const supports = getSupportedGlobalStylesPanels( name );
const hasSupport = supports.includes( 'linkColor' );
const [ color ] = useStyle( 'elements.link.color.text', name );
if ( ! hasSupport ) {
return null;
}
return (
<NavigationButton path={ parentMenu + '/colors/link' }>
<HStack justify="flex-start">
<FlexItem>
<ColorIndicator colorValue={ color } />
</FlexItem>
<FlexItem>{ __( 'Link' ) }</FlexItem>
</HStack>
</NavigationButton>
);
}
function ScreenColors( { name } ) {
const parentMenu = name === undefined ? '' : '/blocks/' + name;
return (
<>
<ScreenHeader
back={ parentMenu ? parentMenu : '/' }
title={ __( 'Colors' ) }
description={ __(
'Manage color palettes and how they affect the different elements of the site.'
) }
/>
<div className="edit-site-global-styles-screen-colors">
<VStack spacing={ 10 }>
<Palette contextName={ name } />
<VStack spacing={ 3 }>
<Subtitle>{ __( 'Elements' ) }</Subtitle>
<ItemGroup isBordered isSeparated>
<BackgroundColorItem
name={ name }
parentMenu={ parentMenu }
/>
<TextColorItem
name={ name }
parentMenu={ parentMenu }
/>
<LinkColorItem
name={ name }
parentMenu={ parentMenu }
/>
</ItemGroup>
</VStack>
</VStack>
</div>
</>
);
}
export default ScreenColors;