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 / util / typography-control-v2 / index.js

index.js in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.5, at react-src/gutenberg/util/typography-control-v2/index.js

643 lines 32.7 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 {
3 BaseControl,
4 Button,
5 Dropdown,
6 RangeControl,
7 SelectControl,
8 } from "@wordpress/components";
9 import { useEffect, useState } from "@wordpress/element";
10
11 import UnitControl from "../unit-control";
12 import FontPicker from "./fontPicker";
13 import { TypographyIcon } from "../icons";
14 import WithResButtons from "../withResButtons";
15 import ResetControl from "../reset-control";
16 import {
17 sizeUnitTypes,
18 optionsFontWeights,
19 optionsFontStyles,
20 optionsTextTransforms,
21 optionsTextDecorations,
22 optionsLhLsp,
23 } from "./constants";
24 import { googleFonts } from "./fontPicker/googleFonts";
25
26 function TypographyDropdown({
27 baseLabel,
28 typographyPrefixConstant,
29 resRequiredProps,
30 defaultFontSize,
31 }) {
32 const { attributes, setAttributes, resOption, objAttributes } =
33 resRequiredProps;
34
35 const {
36 [`${typographyPrefixConstant}FontFamily`]: fontFamily,
37 [`${typographyPrefixConstant}FontWeight`]: fontWeight,
38 [`${typographyPrefixConstant}FontStyle`]: fontStyle,
39 [`${typographyPrefixConstant}TextTransform`]: textTransform,
40 [`${typographyPrefixConstant}TextDecoration`]: textDecoration,
41 [`${typographyPrefixConstant}FontSize`]: fontSize = defaultFontSize ||
42 undefined,
43 [`${typographyPrefixConstant}SizeUnit`]: sizeUnit,
44 [`${typographyPrefixConstant}LetterSpacing`]: letterSpacing,
45 [`${typographyPrefixConstant}LetterSpacingUnit`]: letterSpacingUnit,
46 [`${typographyPrefixConstant}LineHeight`]: lineHeight,
47 [`${typographyPrefixConstant}LineHeightUnit`]: lineHeightUnit,
48
49 [`TAB${typographyPrefixConstant}SizeUnit`]: TABsizeUnit,
50 [`TAB${typographyPrefixConstant}LetterSpacingUnit`]:
51 TABletterSpacingUnit,
52 [`TAB${typographyPrefixConstant}LineHeightUnit`]: TABlineHeightUnit,
53 [`TAB${typographyPrefixConstant}FontSize`]: TABfontSize,
54 [`TAB${typographyPrefixConstant}LetterSpacing`]: TABletterSpacing,
55 [`TAB${typographyPrefixConstant}LineHeight`]: TABlineHeight,
56
57 [`MOB${typographyPrefixConstant}SizeUnit`]: MOBsizeUnit,
58 [`MOB${typographyPrefixConstant}LetterSpacingUnit`]:
59 MOBletterSpacingUnit,
60 [`MOB${typographyPrefixConstant}LineHeightUnit`]: MOBlineHeightUnit,
61 [`MOB${typographyPrefixConstant}FontSize`]: MOBfontSize,
62 [`MOB${typographyPrefixConstant}LetterSpacing`]: MOBletterSpacing,
63 [`MOB${typographyPrefixConstant}LineHeight`]: MOBlineHeight,
64 } = attributes;
65
66 //Update Font Weight and Font Varient
67 const [ebFontWeight, setEbFontWeight] = useState(optionsFontWeights);
68 useEffect(() => {
69 const fontFamilyKey = (fontFamily || "").replace(/\s+/g, "-");
70 let googleFontWeight = googleFonts[fontFamilyKey]
71 ? googleFonts[fontFamilyKey].variants
72 : [];
73 let fontWeightVal = googleFontWeight.map((item) => ({
74 label: item,
75 value: item,
76 }));
77 const fontWeightwithDefault = [
78 { label: "Default", value: "" },
79 ...fontWeightVal,
80 ];
81 setEbFontWeight(fontWeightwithDefault);
82 }, [fontFamily]);
83
84 return (
85 <BaseControl label={__(baseLabel)} className="eb-typography-base">
86 <Dropdown
87 className="eb-typography-dropdown"
88 contentClassName="my-popover-content-classname"
89 position="bottom right"
90 renderToggle={({ isOpen, onToggle }) => (
91 <Button isSmall onClick={onToggle} aria-expanded={isOpen}>
92 <TypographyIcon />
93 </Button>
94 )}
95 renderContent={() => (
96 <div
97 className="eb-panel-control eb-typography-component-panel"
98 style={{ padding: "0.2rem" }}
99 >
100 <FontPicker
101 className="eb-fontpicker-fontfamily"
102 label={__("Font Family", "essential-blocks")}
103 value={fontFamily}
104 onChange={(FontFamily) => {
105 setAttributes({
106 [`${typographyPrefixConstant}FontFamily`]:
107 FontFamily,
108 });
109 }}
110 />
111
112 <WithResButtons
113 className="forFontSize"
114 resRequiredProps={resRequiredProps}
115 >
116 {resOption === "Desktop" && (
117 <>
118 <UnitControl
119 selectedUnit={sizeUnit}
120 unitTypes={sizeUnitTypes}
121 onClick={(sizeUnit) =>
122 setAttributes({
123 [`${typographyPrefixConstant}SizeUnit`]:
124 sizeUnit,
125 })
126 }
127 />
128 <ResetControl
129 onReset={() =>
130 setAttributes({
131 [`${typographyPrefixConstant}FontSize`]:
132 defaultFontSize ||
133 (
134 objAttributes[
135 `${typographyPrefixConstant}FontSize`
136 ] || {}
137 ).default,
138 })
139 }
140 >
141 <RangeControl
142 label={__(
143 "Font Size",
144 "essential-blocks",
145 )}
146 value={fontSize}
147 onChange={(FontSize) =>
148 setAttributes({
149 [`${typographyPrefixConstant}FontSize`]:
150 FontSize,
151 })
152 }
153 step={sizeUnit === "em" ? 0.1 : 1}
154 min={0}
155 max={sizeUnit === "em" ? 10 : 300}
156 />
157 </ResetControl>
158 </>
159 )}
160
161 {resOption === "Tablet" && (
162 <>
163 <UnitControl
164 selectedUnit={TABsizeUnit}
165 unitTypes={sizeUnitTypes}
166 onClick={(TABsizeUnit) =>
167 setAttributes({
168 [`TAB${typographyPrefixConstant}SizeUnit`]:
169 TABsizeUnit,
170 })
171 }
172 />
173
174 <ResetControl
175 onReset={() =>
176 setAttributes({
177 [`TAB${typographyPrefixConstant}FontSize`]:
178 (
179 objAttributes[
180 `TAB${typographyPrefixConstant}FontSize`
181 ] || {}
182 ).default,
183 })
184 }
185 >
186 <RangeControl
187 label={__(
188 "Font Size",
189 "essential-blocks",
190 )}
191 value={TABfontSize}
192 onChange={(FontSize) =>
193 setAttributes({
194 [`TAB${typographyPrefixConstant}FontSize`]:
195 FontSize,
196 })
197 }
198 step={
199 TABsizeUnit === "em" ? 0.1 : 1
200 }
201 min={0}
202 max={
203 TABsizeUnit === "em" ? 10 : 300
204 }
205 />
206 </ResetControl>
207 </>
208 )}
209
210 {resOption === "Mobile" && (
211 <>
212 <UnitControl
213 selectedUnit={MOBsizeUnit}
214 unitTypes={sizeUnitTypes}
215 onClick={(MOBsizeUnit) =>
216 setAttributes({
217 [`MOB${typographyPrefixConstant}SizeUnit`]:
218 MOBsizeUnit,
219 })
220 }
221 />
222
223 <ResetControl
224 onReset={() =>
225 setAttributes({
226 [`MOB${typographyPrefixConstant}FontSize`]:
227 (
228 objAttributes[
229 `MOB${typographyPrefixConstant}FontSize`
230 ] || {}
231 ).default,
232 })
233 }
234 >
235 <RangeControl
236 label={__(
237 "Font Size",
238 "essential-blocks",
239 )}
240 value={MOBfontSize}
241 onChange={(FontSize) =>
242 setAttributes({
243 [`MOB${typographyPrefixConstant}FontSize`]:
244 FontSize,
245 })
246 }
247 step={
248 MOBsizeUnit === "em" ? 0.1 : 1
249 }
250 min={0}
251 max={
252 MOBsizeUnit === "em" ? 10 : 300
253 }
254 />
255 </ResetControl>
256 </>
257 )}
258 </WithResButtons>
259
260 <SelectControl
261 label={__("Font Weight", "essential-blocks")}
262 value={fontWeight}
263 options={ebFontWeight}
264 onChange={(FontWeight) =>
265 setAttributes({
266 [`${typographyPrefixConstant}FontWeight`]:
267 FontWeight,
268 })
269 }
270 />
271
272 <SelectControl
273 label={__("Font Style", "essential-blocks")}
274 value={fontStyle}
275 options={optionsFontStyles}
276 onChange={(fontStyle) =>
277 setAttributes({
278 [`${typographyPrefixConstant}FontStyle`]:
279 fontStyle,
280 })
281 }
282 />
283
284 <SelectControl
285 label={__("Text Transform", "essential-blocks")}
286 value={textTransform}
287 options={optionsTextTransforms}
288 onChange={(TextTransform) =>
289 setAttributes({
290 [`${typographyPrefixConstant}TextTransform`]:
291 TextTransform,
292 })
293 }
294 />
295
296 <SelectControl
297 label={__("Text Decoration", "essential-blocks")}
298 value={textDecoration}
299 options={optionsTextDecorations}
300 onChange={(TextDecoration) =>
301 setAttributes({
302 [`${typographyPrefixConstant}TextDecoration`]:
303 TextDecoration,
304 })
305 }
306 />
307
308 <WithResButtons
309 className="forLetterSpacing"
310 resRequiredProps={resRequiredProps}
311 >
312 {resOption === "Desktop" && (
313 <>
314 <UnitControl
315 selectedUnit={letterSpacingUnit}
316 unitTypes={optionsLhLsp}
317 onClick={(LetterSpacingUnit) =>
318 setAttributes({
319 [`${typographyPrefixConstant}LetterSpacingUnit`]:
320 LetterSpacingUnit,
321 })
322 }
323 />
324
325 <ResetControl
326 onReset={() =>
327 setAttributes({
328 [`${typographyPrefixConstant}LetterSpacing`]:
329 (
330 objAttributes[
331 `${typographyPrefixConstant}LetterSpacing`
332 ] || {}
333 ).default,
334 })
335 }
336 >
337 <RangeControl
338 label={__(
339 "Letter Spacing",
340 "essential-blocks",
341 )}
342 value={letterSpacing}
343 onChange={(LetterSpacing) =>
344 setAttributes({
345 [`${typographyPrefixConstant}LetterSpacing`]:
346 LetterSpacing,
347 })
348 }
349 min={0}
350 max={
351 letterSpacingUnit === "em"
352 ? 10
353 : 100
354 }
355 step={
356 letterSpacingUnit === "em"
357 ? 0.1
358 : 1
359 }
360 />
361 </ResetControl>
362 </>
363 )}
364
365 {resOption === "Tablet" && (
366 <>
367 <UnitControl
368 selectedUnit={TABletterSpacingUnit}
369 unitTypes={optionsLhLsp}
370 onClick={(TABletterSpacingUnit) =>
371 setAttributes({
372 [`TAB${typographyPrefixConstant}LetterSpacingUnit`]:
373 TABletterSpacingUnit,
374 })
375 }
376 />
377
378 <ResetControl
379 onReset={() =>
380 setAttributes({
381 [`TAB${typographyPrefixConstant}LetterSpacing`]:
382 (
383 objAttributes[
384 `TAB${typographyPrefixConstant}LetterSpacing`
385 ] || {}
386 ).default,
387 })
388 }
389 >
390 <RangeControl
391 label={__(
392 "Letter Spacing",
393 "essential-blocks",
394 )}
395 value={TABletterSpacing}
396 onChange={(LetterSpacing) =>
397 setAttributes({
398 [`TAB${typographyPrefixConstant}LetterSpacing`]:
399 LetterSpacing,
400 })
401 }
402 min={0}
403 max={
404 TABletterSpacingUnit === "em"
405 ? 10
406 : 100
407 }
408 step={
409 TABletterSpacingUnit === "em"
410 ? 0.1
411 : 1
412 }
413 />
414 </ResetControl>
415 </>
416 )}
417
418 {resOption === "Mobile" && (
419 <>
420 <UnitControl
421 selectedUnit={MOBletterSpacingUnit}
422 unitTypes={optionsLhLsp}
423 onClick={(MOBletterSpacingUnit) =>
424 setAttributes({
425 [`MOB${typographyPrefixConstant}LetterSpacingUnit`]:
426 MOBletterSpacingUnit,
427 })
428 }
429 />
430
431 <ResetControl
432 onReset={() =>
433 setAttributes({
434 [`MOB${typographyPrefixConstant}LetterSpacing`]:
435 (
436 objAttributes[
437 `MOB${typographyPrefixConstant}LetterSpacing`
438 ] || {}
439 ).default,
440 })
441 }
442 >
443 <RangeControl
444 label={__(
445 "Letter Spacing",
446 "essential-blocks",
447 )}
448 value={MOBletterSpacing}
449 onChange={(LetterSpacing) =>
450 setAttributes({
451 [`MOB${typographyPrefixConstant}LetterSpacing`]:
452 LetterSpacing,
453 })
454 }
455 min={0}
456 max={
457 MOBletterSpacingUnit === "em"
458 ? 10
459 : 100
460 }
461 step={
462 MOBletterSpacingUnit === "em"
463 ? 0.1
464 : 1
465 }
466 />
467 </ResetControl>
468 </>
469 )}
470 </WithResButtons>
471
472 <WithResButtons
473 className="forLineHeight"
474 resRequiredProps={resRequiredProps}
475 >
476 {resOption === "Desktop" && (
477 <>
478 <UnitControl
479 selectedUnit={lineHeightUnit}
480 unitTypes={optionsLhLsp}
481 onClick={(LineHeightUnit) =>
482 setAttributes({
483 [`${typographyPrefixConstant}LineHeightUnit`]:
484 LineHeightUnit,
485 })
486 }
487 />
488
489 <ResetControl
490 onReset={() =>
491 setAttributes({
492 [`${typographyPrefixConstant}LineHeight`]:
493 (
494 objAttributes[
495 `${typographyPrefixConstant}LineHeight`
496 ] || {}
497 ).default,
498 })
499 }
500 >
501 <RangeControl
502 label={__(
503 "Line Height",
504 "essential-blocks",
505 )}
506 value={lineHeight}
507 onChange={(LineHeight) =>
508 setAttributes({
509 [`${typographyPrefixConstant}LineHeight`]:
510 LineHeight,
511 })
512 }
513 min={0}
514 max={
515 lineHeightUnit === "em"
516 ? 10
517 : 600
518 }
519 step={
520 lineHeightUnit === "em"
521 ? 0.1
522 : 1
523 }
524 />
525 </ResetControl>
526 </>
527 )}
528
529 {resOption === "Tablet" && (
530 <>
531 <UnitControl
532 selectedUnit={TABlineHeightUnit}
533 unitTypes={optionsLhLsp}
534 onClick={(TABlineHeightUnit) =>
535 setAttributes({
536 [`TAB${typographyPrefixConstant}LineHeightUnit`]:
537 TABlineHeightUnit,
538 })
539 }
540 />
541
542 <ResetControl
543 onReset={() =>
544 setAttributes({
545 [`TAB${typographyPrefixConstant}LineHeight`]:
546 (
547 objAttributes[
548 `TAB${typographyPrefixConstant}LineHeight`
549 ] || {}
550 ).default,
551 })
552 }
553 >
554 <RangeControl
555 label={__(
556 "Line Height",
557 "essential-blocks",
558 )}
559 value={TABlineHeight}
560 onChange={(LineHeight) =>
561 setAttributes({
562 [`TAB${typographyPrefixConstant}LineHeight`]:
563 LineHeight,
564 })
565 }
566 min={0}
567 max={
568 TABlineHeightUnit === "em"
569 ? 10
570 : 600
571 }
572 step={
573 TABlineHeightUnit === "em"
574 ? 0.1
575 : 1
576 }
577 />
578 </ResetControl>
579 </>
580 )}
581
582 {resOption === "Mobile" && (
583 <>
584 <UnitControl
585 selectedUnit={MOBlineHeightUnit}
586 unitTypes={optionsLhLsp}
587 onClick={(MOBlineHeightUnit) =>
588 setAttributes({
589 [`MOB${typographyPrefixConstant}LineHeightUnit`]:
590 MOBlineHeightUnit,
591 })
592 }
593 />
594
595 <ResetControl
596 onReset={() =>
597 setAttributes({
598 [`MOB${typographyPrefixConstant}LineHeight`]:
599 (
600 objAttributes[
601 `MOB${typographyPrefixConstant}LineHeight`
602 ] || {}
603 ).default,
604 })
605 }
606 >
607 <RangeControl
608 label={__(
609 "Line Height",
610 "essential-blocks",
611 )}
612 value={MOBlineHeight}
613 onChange={(LineHeight) =>
614 setAttributes({
615 [`MOB${typographyPrefixConstant}LineHeight`]:
616 LineHeight,
617 })
618 }
619 min={0}
620 max={
621 MOBlineHeightUnit === "em"
622 ? 10
623 : 600
624 }
625 step={
626 MOBlineHeightUnit === "em"
627 ? 0.1
628 : 1
629 }
630 />
631 </ResetControl>
632 </>
633 )}
634 </WithResButtons>
635 </div>
636 )}
637 />
638 </BaseControl>
639 );
640 }
641
642 export default TypographyDropdown;
643