PluginProbe
Easy Hotel – Powerful Hotel Booking / 2.0.2
Easy Hotel – Powerful Hotel Booking v2.0.2
2.0.8 2.0.7 2.0.6 2.0.5 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.9.9 1.9.8 1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 All 110 releases
easy-hotel / public / includes / gutenberg / blocks / custom-components / BackgroundControl.js

BackgroundControl.js in Easy Hotel – Powerful Hotel Booking 2.0.2, at public/includes/gutenberg/blocks/custom-components/BackgroundControl.js

153 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from '@wordpress/i18n';
2 import { useState } from '@wordpress/element';
3 import {
4 ColorPicker,
5 GradientPicker,
6 Popover,
7 Button,
8 Icon,
9 TabPanel
10 } from '@wordpress/components';
11
12 const BackgroundControl = ({
13 label,
14 colorValue,
15 gradientValue,
16 onColorChange,
17 onGradientChange,
18 defaultColor = '',
19 defaultGradient = ''
20 }) => {
21 const [isVisible, setIsVisible] = useState(false);
22
23 const toggleVisible = () => {
24 setIsVisible((state) => !state);
25 };
26
27 // Determine what to show in the preview
28 // If gradient is present, show it. Otherwise show color.
29 const previewStyle = {};
30 if (gradientValue) {
31 previewStyle.background = gradientValue;
32 } else if (colorValue) {
33 previewStyle.backgroundColor = colorValue;
34 } else {
35 previewStyle.background = 'transparent';
36 }
37
38 return (
39 <div className="eshb-background-control" style={{ position: 'relative', marginBottom: '15px' }}>
40 <Button
41 variant="secondary"
42 onClick={toggleVisible}
43 style={{ width: '100%', justifyContent: 'space-between', boxShadow: 'none' }}
44 >
45 <div style={{ display: 'flex', alignItems: 'center', gap: '8px', overflow: 'hidden' }}>
46 <div style={{
47 width: '16px',
48 height: '16px',
49 borderRadius: '4px',
50 border: '1px solid #ccc',
51 flexShrink: 0,
52 ...previewStyle
53 }} />
54 <span style={{
55 whiteSpace: 'nowrap',
56 overflow: 'hidden',
57 textOverflow: 'ellipsis',
58 display: 'block'
59 }}>
60 {label}
61 </span>
62 </div>
63 <Icon icon="plus" />
64 </Button>
65 {isVisible && (
66 <Popover
67 position="bottom center"
68 onFocusOutside={() => setIsVisible(false)}
69 >
70 <div style={{ padding: '0', width: '280px' }}>
71 <TabPanel
72 className="eshb-background-tabs"
73 activeClass="is-active"
74 tabs={[
75 { name: 'solid', title: __('Solid', 'easy-hotel'), className: 'eshb-bg-tab-solid' },
76 { name: 'gradient', title: __('Gradient', 'easy-hotel'), className: 'eshb-bg-tab-gradient' },
77 ]}
78 >
79 {(tab) => {
80 if (tab.name === 'solid') {
81 return (
82 <div style={{ padding: '16px' }}>
83 <ColorPicker
84 color={colorValue}
85 onChange={onColorChange}
86 enableAlpha
87 />
88 <Button
89 variant="secondary"
90 isSmall
91 onClick={() => onColorChange(defaultColor)}
92 style={{ marginTop: '10px', width: '100%', justifyContent: 'center' }}
93 >
94 {__('Reset Color', 'easy-hotel')}
95 </Button>
96 </div>
97 );
98 } else if (tab.name === 'gradient') {
99 return (
100 <div style={{ padding: '16px' }}>
101 <GradientPicker
102 value={gradientValue || undefined}
103 onChange={onGradientChange}
104 gradients={[
105 {
106 name: 'Primary',
107 gradient: 'linear-gradient(180deg, rgba(171, 137, 101, 0) 0%, var(--eshb-primary-color) 100%)',
108 slug: 'primary',
109 },
110 {
111 name: 'Warm Morning',
112 gradient: 'linear-gradient(135deg, #ff9a9e 0%, #fad0c4 99%, #fad0c4 100%)',
113 slug: 'warm-morning',
114 },
115 {
116 name: 'Sunny Days',
117 gradient: 'linear-gradient(135deg, #f6d365 0%, #fda085 100%)',
118 slug: 'sunny-days',
119 },
120 {
121 name: 'Deep Blue',
122 gradient: 'linear-gradient(135deg, #2b5876 0%, #4e4376 100%)',
123 slug: 'deep-blue',
124 },
125 {
126 name: 'Premium Dark',
127 gradient: 'linear-gradient(135deg, #232526 0%, #414345 100%)',
128 slug: 'premium-dark',
129 }
130 ]}
131 />
132 <Button
133 variant="secondary"
134 isSmall
135 onClick={() => onGradientChange(defaultGradient)}
136 style={{ marginTop: '10px', width: '100%', justifyContent: 'center' }}
137 >
138 {__('Reset Gradient', 'easy-hotel')}
139 </Button>
140 </div>
141 );
142 }
143 }}
144 </TabPanel>
145 </div>
146 </Popover>
147 )}
148 </div>
149 );
150 };
151
152 export default BackgroundControl;
153