PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.5
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 All 203 releases
betterdocs / react-src / gutenberg / blocks / reactions / src / inspector.js

inspector.js in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.5, at react-src/gutenberg/blocks/reactions/src/inspector.js

397 lines 29.3 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 { InspectorControls } from '@wordpress/block-editor';
3 import {
4 TabPanel,
5 PanelBody,
6 TextControl,
7 BaseControl,
8 SelectControl,
9 ToggleControl,
10 Button
11 } from '@wordpress/components';
12
13 import { MediaPlaceholder } from '@wordpress/block-editor';
14 import upload from '../../../util/upload';
15 import cross from '../../../util/cross';
16 import objAttributes from './attributes';
17 import ColorControl from '../../../util/color-control';
18 import ResponsiveRangeController from '../../../util/responsive-range-control';
19 import ResponsiveDimensionsControl from '../../../util/dimensions-control-v2';
20 import TypographyDropdown from '../../../util/typography-control-v2';
21 import BorderShadowControl from '../../../util/border-shadow-control';
22 import { typoPrefix_reaction_icon_text_layout_3, typoPrefix_title, typoPrefix_title_layout_2, typoPrefix_title_layout_3 } from './typographyPrefixConstants';
23 import { REACTION_ICON_WIDTH, REACTION_TITLE_PADDING, REACTION_TITLE_MARGIN, REACTION_ICON_HEIGHT, REACTION_ICON_BORDER, REACTION_BOX_PADDING, REACTION_BOX_MARGIN, REACTION_BOX_BORDER, LAYOUT, REACTION_TITLE_PADDING_LAYOUT_2, REACTION_TITLE_MARGIN_LAYOUT_2, REACTION_ICON_WIDTH_LAYOUT_2, REACTION_ICON_HEIGHT_LAYOUT_2, REACTION_ICON_BORDER_LAYOUT_2, REACTION_BOX_PADDING_LAYOUT_2, REACTION_BOX_MARGIN_LAYOUT_2, REACTION_BOX_BORDER_LAYOUT_2, REACTION_TITLE_PADDING_LAYOUT_3, REACTION_TITLE_MARGIN_LAYOUT_3, REACTION_ICON_WIDTH_LAYOUT_3, REACTION_ICON_HEIGHT_LAYOUT_3, REACTION_ICON_BORDER_LAYOUT_3, REACTION_BOX_PADDING_LAYOUT_3, REACTION_BOX_MARGIN_LAYOUT_3, REACTION_BOX_BORDER_LAYOUT_3 } from './constants';
24
25 const Inspector = ({attributes, setAttributes}) => {
26
27 const { resOption, reaction_text, reaction_text_tag, reaction_text_color, reaction_text_color_layout_2, reaction_icon_color, reaction_icon_text_color_layout_3, reaction_icon_hover_color, reaction_inner_icon_color, reaction_inner_icon_hover_color, reaction_box_color, reaction_box_color_layout_2, reaction_box_hover_color, layout, reaction_box_hover_color_layout_2, reaction_text_color_layout_3, reaction_box_color_layout_3, reaction_box_hover_color_layout_3, show_happy_icon, happy_icon_url, show_neutral_icon, neutral_icon_url, show_sad_icon, sad_icon_url } = attributes;
28
29 const resRequiredProps = {
30 setAttributes,
31 resOption,
32 attributes,
33 objAttributes
34 };
35
36 return (
37 <InspectorControls key="controls">
38 <div className="eb-panel-control">
39 <TabPanel className="eb-parent-tab-panel" activeClass="active-tab" tabs={[
40 {
41 name: "general",
42 title: __("General", "betterdocs"),
43 className: "eb-tab styles",
44 },
45 {
46 name: "styles",
47 title: __("Styles", "betterdocs"),
48 className: "eb-tab styles",
49 }
50 ]}>
51 {
52 (tab) => {
53 return (
54 <div className={"eb-tab-controls " + tab.name}>
55 { tab.name === 'general' && (
56 <PanelBody title={__("Layout", "betterdocs")} initialOpen={true}>
57 <SelectControl
58 label={__("Select layout", "betterdocs")}
59 value={layout}
60 options={LAYOUT}
61 onChange={(newLayout) =>
62 setAttributes({
63 layout: newLayout,
64 })
65 }
66 __next40pxDefaultSize
67 __nextHasNoMarginBottom
68 />
69 </PanelBody>
70 )}
71 {
72 tab.name === 'styles' && (
73 <>
74 <PanelBody title={__("Reaction Box", "betterdocs")} initialOpen={true}>
75 <ColorControl
76 label={__("Background Color", "betterdocs")}
77 color={layout == 'layout-1' ? reaction_box_color : ( layout == 'layout-2' ? reaction_box_color_layout_2 : reaction_box_color_layout_3 )}
78 onChange={((color) =>{
79 if( layout == 'layout-1' ) {
80 setAttributes({reaction_box_color:color});
81 }else if( layout == 'layout-2') {
82 setAttributes({reaction_box_color_layout_2:color});
83 } else {
84 setAttributes({reaction_box_color_layout_3:color});
85 }
86 })}
87 />
88 <ColorControl
89 label={__("Background Hover Color", "betterdocs")}
90 color={layout == 'layout-1' ? reaction_box_hover_color : ( layout == 'layout-2' ? reaction_box_hover_color_layout_2 : reaction_box_hover_color_layout_3 )}
91 onChange={((color) =>{
92 if( layout == 'layout-1' ) {
93 setAttributes({reaction_box_hover_color:color})
94 } else if( layout == 'layout-2' ) {
95 setAttributes({reaction_box_hover_color_layout_2:color})
96 } else {
97 setAttributes({reaction_box_hover_color_layout_3:color})
98 }
99 })}
100 />
101 <ResponsiveDimensionsControl
102 baseLabel={__("Box Padding", "betterdocs")}
103 resRequiredProps={resRequiredProps}
104 controlName={layout == 'layout-1' ? REACTION_BOX_PADDING : ( layout == 'layout-2' ? REACTION_BOX_PADDING_LAYOUT_2 : REACTION_BOX_PADDING_LAYOUT_3 )}
105 />
106 <ResponsiveDimensionsControl
107 baseLabel={__("Box Margin", "betterdocs")}
108 resRequiredProps={resRequiredProps}
109 controlName={layout == 'layout-1' ? REACTION_BOX_MARGIN : ( layout == 'layout-2' ? REACTION_BOX_MARGIN_LAYOUT_2 : REACTION_BOX_MARGIN_LAYOUT_3 )}
110 />
111 <BaseControl>
112 <h3 className='eb-control-title'>
113 {__("Border", "betterdocs")}
114 </h3>
115 </BaseControl>
116 <BorderShadowControl
117 controlName={layout == 'layout-1' ? REACTION_BOX_BORDER : ( layout == 'layout-2' ? REACTION_BOX_BORDER_LAYOUT_2 : REACTION_BOX_BORDER_LAYOUT_3)}
118 resRequiredProps={resRequiredProps}
119 />
120 </PanelBody>
121 <PanelBody title={__("Reaction Title", "betterdocs")} initialOpen={false}>
122 <TextControl
123 label={__("Title Content", "betterdocs")}
124 value={reaction_text}
125 onChange={(value) =>
126 setAttributes({
127 reaction_text:value,
128 })
129 }
130 >
131 </TextControl>
132 <SelectControl
133 label={__("Title Tag", "betterdocs")}
134 value={reaction_text_tag}
135 options={[
136 { label: 'H1', value: 'h1' },
137 { label: 'H2', value: 'h2' },
138 { label: 'H3', value: 'h3' },
139 { label: 'H4', value: 'h4' },
140 { label: 'H5', value: 'h5' },
141 { label: 'H6', value: 'h6' },
142 ]}
143 onChange={(value) => setAttributes({reaction_text_tag: value})}
144 />
145 <ColorControl
146 label={__('Title Color', 'betterdocs')}
147 color={layout == 'layout-1' ? reaction_text_color : ( layout == 'layout-2' ? reaction_text_color_layout_2 : reaction_text_color_layout_3 )}
148 onChange={((color) => {
149 if( layout == 'layout-1' ) {
150 setAttributes({reaction_text_color: color});
151 } else if( layout == 'layout-2' ) {
152 setAttributes({reaction_text_color_layout_2:color})
153 } else {
154 setAttributes({reaction_text_color_layout_3:color})
155 }
156 })}
157 />
158 <TypographyDropdown
159 baseLabel={__('Typography', 'betterdocs')}
160 typographyPrefixConstant={layout == 'layout-1' ? typoPrefix_title : ( layout == 'layout-2' ? typoPrefix_title_layout_2 : typoPrefix_title_layout_3 )}
161 resRequiredProps={resRequiredProps}
162 defaultFontSize={layout == 'layout-1' ? 15 : (layout == 'layout-2' ? 18 : 15)}
163 />
164 <ResponsiveDimensionsControl
165 baseLabel={__("Title Padding", "betterdocs")}
166 resRequiredProps={resRequiredProps}
167 controlName={layout == 'layout-1' ? REACTION_TITLE_PADDING : ( layout == 'layout-2' ? REACTION_TITLE_PADDING_LAYOUT_2 : REACTION_TITLE_PADDING_LAYOUT_3)}
168 />
169 <ResponsiveDimensionsControl
170 baseLabel={__("Title Margin", "betterdocs")}
171 resRequiredProps={resRequiredProps}
172 controlName={layout == 'layout-1' ? REACTION_TITLE_MARGIN : ( layout == 'layout-2' ? REACTION_TITLE_MARGIN_LAYOUT_2 : REACTION_TITLE_MARGIN_LAYOUT_3 )}
173 />
174 </PanelBody>
175 <PanelBody title={__('Reaction Icon', 'betterdocs')} initialOpen={false}>
176 <ResponsiveRangeController
177 baseLabel={__('Icon Width', 'betterdocs')}
178 controlName={layout == 'layout-1' ? REACTION_ICON_WIDTH : (layout == 'layout-2' ? REACTION_ICON_WIDTH_LAYOUT_2 : REACTION_ICON_WIDTH_LAYOUT_3 )}
179 resRequiredProps={resRequiredProps}
180 min={0}
181 max={100}
182 step={1}
183 />
184 <ResponsiveRangeController
185 baseLabel={__('Icon Height', 'betterdocs')}
186 controlName={layout == 'layout-1' ? REACTION_ICON_HEIGHT : ( layout == 'layout-2' ? REACTION_ICON_HEIGHT_LAYOUT_2 : REACTION_ICON_HEIGHT_LAYOUT_3 )}
187 resRequiredProps={resRequiredProps}
188 min={0}
189 max={100}
190 step={1}
191 />
192 {layout == 'layout-1' && <><ColorControl
193 label={__("Icon Color", "betterdocs")}
194 color={reaction_icon_color}
195 onChange={((color) => setAttributes({reaction_icon_color:color}))}
196 />
197 <ColorControl
198 label={__("Icon Hover Color", "betterdocs")}
199 color={reaction_icon_hover_color}
200 onChange={((color) => setAttributes({reaction_icon_hover_color:color}))}
201 />
202 <ColorControl
203 label={__("Inner Icon Color", "betterdocs")}
204 color={reaction_inner_icon_color}
205 onChange={((color) => setAttributes({reaction_inner_icon_color:color}))}
206 />
207 <ColorControl
208 label={__("Inner Icon Hover Color", "betterdocs")}
209 color={reaction_inner_icon_hover_color}
210 onChange={((color) => setAttributes({reaction_inner_icon_hover_color:color}))}
211 /></>}
212 <BaseControl>
213 <h3 className='eb-control-title'>
214 {__("Border", "betterdocs")}
215 </h3>
216 </BaseControl>
217 <BorderShadowControl
218 controlName={layout == 'layout-1' ? REACTION_ICON_BORDER : ( layout == 'layout-2' ? REACTION_ICON_BORDER_LAYOUT_2 : REACTION_ICON_BORDER_LAYOUT_3 )}
219 resRequiredProps={resRequiredProps}
220 />
221 {layout == 'layout-3' &&
222 <>
223 <ColorControl
224 label={__("Icon Text Color", "betterdocs")}
225 color={reaction_icon_text_color_layout_3}
226 onChange={((color) => setAttributes({reaction_icon_text_color_layout_3:color}))}
227 />
228 <TypographyDropdown
229 baseLabel={__('Typography', 'betterdocs')}
230 typographyPrefixConstant={typoPrefix_reaction_icon_text_layout_3}
231 resRequiredProps={resRequiredProps}
232 defaultFontSize={14}
233 />
234 </>
235 }
236 {
237 ( layout == 'layout-1' || layout == 'layout-2' || layout == 'layout-3' ) &&
238 <>
239 <ToggleControl
240 label={__("Enable Happy", "betterdocs")}
241 checked={show_happy_icon}
242 onChange={() => {
243 setAttributes({
244 show_happy_icon: !show_happy_icon,
245 });
246 }}
247 />
248 {show_happy_icon && <>
249 <MediaPlaceholder
250 onSelect={(image) => {
251 setAttributes({
252 happy_icon_url:image?.url
253 })
254 }}
255 value={happy_icon_url}
256 accept="image/*"
257 allowedTypes={["image"]}
258 mediaLibraryButton={({ open }) => {
259 return (
260 <>
261 <Button
262 icon={upload}
263 variant="primary"
264 label={__('Add image from media')}
265 showTooltip
266 tooltipPosition="top center"
267 onClick={() => {
268 open();
269 }}
270 />
271 {happy_icon_url?.length > 0 && <div className="preview-wrapper-controller" style={{position:'relative'}}>
272 <img src={happy_icon_url} />
273 <div className="preview-wrapper" style={{position:'absolute', top:'0px', right:'0px', height:'30px', width:'30px', backgroundColor:'#1e1e1e', borderRadius:'5px', cursor:'pointer'}} onClick={(e) => {
274 setAttributes({
275 happy_icon_url:''
276 })
277 }}>
278 {cross()}
279 </div>
280 </div>}
281 </>
282 );
283 }}
284 />
285 </>}
286 <ToggleControl
287 label={__("Enable Neutral", "betterdocs")}
288 checked={show_neutral_icon}
289 onChange={() => {
290 setAttributes({
291 show_neutral_icon: !show_neutral_icon,
292 });
293 }}
294 />
295 {show_neutral_icon && <>
296 <MediaPlaceholder
297 onSelect={(image) => {
298 setAttributes({
299 neutral_icon_url:image?.url
300 })
301 }}
302 value={neutral_icon_url}
303 accept="image/*"
304 allowedTypes={["image"]}
305 mediaLibraryButton={({ open }) => {
306 return (
307 <>
308 <Button
309 icon={upload}
310 variant="primary"
311 label={__('Add image from media')}
312 showTooltip
313 tooltipPosition="top center"
314 onClick={() => {
315 open();
316 }}
317 />
318 {neutral_icon_url?.length > 0 && <div className="preview-wrapper-controller" style={{position:'relative'}}>
319 <img src={neutral_icon_url} />
320 <div className="preview-wrapper" style={{position:'absolute', top:'0px', right:'0px', height:'30px', width:'30px', backgroundColor:'#1e1e1e', borderRadius:'5px', cursor:'pointer'}} onClick={(e) => {
321 setAttributes({
322 neutral_icon_url:''
323 })
324 }}>
325 {cross()}
326 </div>
327 </div>}
328 </>
329 );
330 }}
331 />
332 </>}
333 <ToggleControl
334 label={__("Enable Sad", "betterdocs")}
335 checked={show_sad_icon}
336 onChange={() => {
337 setAttributes({
338 show_sad_icon: !show_sad_icon,
339 });
340 }}
341 />
342 {show_sad_icon && <>
343 <MediaPlaceholder
344 onSelect={(image) => {
345 setAttributes({
346 sad_icon_url:image?.url
347 })
348 }}
349 value={sad_icon_url}
350 accept="image/*"
351 allowedTypes={["image"]}
352 mediaLibraryButton={({ open }) => {
353 return (
354 <>
355 <Button
356 icon={upload}
357 variant="primary"
358 label={__('Add image from media')}
359 showTooltip
360 tooltipPosition="top center"
361 onClick={() => {
362 open();
363 }}
364 />
365 {sad_icon_url?.length > 0 && <div className="preview-wrapper-controller" style={{position:'relative'}}>
366 <img src={sad_icon_url} />
367 <div className="preview-wrapper" style={{position:'absolute', top:'0px', right:'0px', height:'30px', width:'30px', backgroundColor:'#1e1e1e', borderRadius:'5px', cursor:'pointer'}} onClick={(e) => {
368 setAttributes({
369 sad_icon_url:''
370 })
371 }}>
372 {cross()}
373 </div>
374 </div>}
375 </>
376 );
377 }}
378 />
379 </>}
380 </>
381 }
382 </PanelBody>
383 </>
384 )
385 }
386 </div>
387 )
388 }
389 }
390 </TabPanel>
391 </div>
392 </InspectorControls>
393 )
394 }
395
396 export default Inspector;
397