PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.2.7
LatePoint – Calendar Booking Plugin for Appointments and Events v5.2.7
5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / blocks / controls / FontSizeControl.js
latepoint / blocks / controls Last commit date
BorderControl.js 1 year ago BoxShadowControl.js 1 year ago ColorSelectorControl.js 1 year ago FontSizeControl.js 1 year ago LatepointIcons.js 1 year ago LetterSpacingControl.js 1 year ago LineHeightControl.js 1 year ago PaddingBoxControl.js 1 year ago TypographyControl.js 1 year ago
FontSizeControl.js
86 lines
1 import {
2 Button,
3 RangeControl,
4 ButtonGroup
5 } from '@wordpress/components';
6 import {useState} from '@wordpress/element';
7 import React from "react";
8
9 const FontSizeControl = ({attributes, setAttributes, fontSizeAttr}) => {
10
11 const unitOptions = ['px', 'rem', 'em'];
12
13 const getFontSizeUnit = () => {
14 const fontSize = attributes[fontSizeAttr];
15 if (fontSize) {
16 const match = fontSize.match(/[a-zA-Z%]+$/);
17 return match ? match[0] : 'px';
18 }
19 return 'px';
20 };
21
22 const [unit, setUnit] = useState(getFontSizeUnit());
23 const getFontSizeValue = () => {
24 if (attributes[fontSizeAttr]) {
25 return parseFloat(attributes[fontSizeAttr]);
26 }
27 return "";
28 };
29
30 const handleFontSizeChange = (newSize) => {
31 if (!newSize) {
32 setAttributes({[fontSizeAttr]: ''});
33 return;
34 }
35 setAttributes({[fontSizeAttr]: `${newSize}${unit}`});
36 };
37
38 const handleUnitChange = (newUnit) => {
39 setUnit(newUnit);
40 let newSize;
41 const currentSize = parseFloat(attributes[fontSizeAttr]);
42 if (unit === 'px' && newUnit !== 'px') {
43 newSize = (currentSize / 16).toFixed(2);
44 } else if (unit !== 'px' && newUnit === 'px') {
45 newSize = Math.round(currentSize * 16);
46 } else {
47 newSize = currentSize;
48 }
49 setAttributes({[fontSizeAttr]: `${newSize}${newUnit}`});
50 };
51
52 return (
53 <div className="font-size-control">
54 <div className="latepoint-block-header">
55 <label className="latepoint-control-label">Font Size</label>
56
57 <div className="latepoint-block-header-actions">
58
59 <Button className="latepoint-block-reset"
60 onClick={() => handleFontSizeChange("")}
61 isSmall
62 disabled={attributes[fontSizeAttr] === ''}
63 icon="dashicon dashicons dashicons-image-rotate"
64 />
65
66 <ButtonGroup className="latepoint-unit-selector">
67 {unitOptions.map((option) => (
68 <Button key={option} isPrimary={unit === option} onClick={() => handleUnitChange(option)}>
69 {option}
70 </Button>
71 ))}
72 </ButtonGroup>
73 </div>
74 </div>
75 <RangeControl
76 value={getFontSizeValue()}
77 onChange={handleFontSizeChange}
78 min={unit === 'px' ? 5 : 0.3125}
79 max={unit === 'px' ? 80 : 8}
80 step={unit === 'px' ? 1 : 0.1}
81 />
82 </div>
83 );
84 };
85
86 export default FontSizeControl;