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 / TypographyControls.js

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

125 lines 5.6 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 SelectControl,
5 TextControl,
6 Popover,
7 Button,
8 Icon
9 } from '@wordpress/components';
10
11 const TypographyControls = ({ label, attributes, setAttributes, attributeKey, nextDefaultSize }) => {
12 const [isVisible, setIsVisible] = useState(false);
13 const typography = attributes[attributeKey] || {};
14
15 const _nextDefaultSize = nextDefaultSize || false;
16
17 const toggleVisible = () => {
18 setIsVisible((state) => !state);
19 };
20
21 const updateTypography = (newAttrs) => {
22 const nextTypography = {
23 ...typography,
24 ...newAttrs
25 };
26
27 setAttributes({
28 [attributeKey]: nextTypography
29 });
30 };
31
32 return (
33 <div className="eshb-typography-control" style={{ position: 'relative' }}>
34 <Button
35 variant="secondary"
36 onClick={toggleVisible}
37 style={{ width: '100%', justifyContent: 'space-between', marginBottom: '15px', boxShadow: 'none' }}
38 >
39 {label}
40 <Icon icon="plus" />
41 </Button>
42 {isVisible && (
43 <Popover
44 position="bottom center"
45 onFocusOutside={() => setIsVisible(false)}
46 >
47 <div style={{ padding: '20px', width: '260px' }}>
48 <TextControl
49 label={__('Font Size', 'easy-hotel')}
50 value={typography.fontSize}
51 onChange={(val) => updateTypography({ fontSize: val })}
52 help={__('Include unit (e.g., 14px, 1.2rem)', 'easy-hotel')}
53 />
54 <SelectControl
55 label={__('Font Weight', 'easy-hotel')}
56 value={typography.fontWeight}
57 options={[
58 { label: __('Default', 'easy-hotel'), value: 'inherit' },
59 { label: __('Thin (100)', 'easy-hotel'), value: '100' },
60 { label: __('Light (300)', 'easy-hotel'), value: '300' },
61 { label: __('Regular (400)', 'easy-hotel'), value: '400' },
62 { label: __('Medium (500)', 'easy-hotel'), value: '500' },
63 { label: __('Semi Bold (600)', 'easy-hotel'), value: '600' },
64 { label: __('Bold (700)', 'easy-hotel'), value: '700' },
65 { label: __('Extra Bold (800)', 'easy-hotel'), value: '800' },
66 { label: __('Black (900)', 'easy-hotel'), value: '900' },
67 ]}
68 onChange={(val) => updateTypography({ fontWeight: val })}
69 __next40pxDefaultSize={true}
70 __nextHasNoMarginBottom={true}
71 />
72 <SelectControl
73 label={__('Text Transform', 'easy-hotel')}
74 value={typography.textTransform}
75 options={[
76 { label: __('None', 'easy-hotel'), value: 'none' },
77 { label: __('Uppercase', 'easy-hotel'), value: 'uppercase' },
78 { label: __('Lowercase', 'easy-hotel'), value: 'lowercase' },
79 { label: __('Capitalize', 'easy-hotel'), value: 'capitalize' },
80 ]}
81 onChange={(val) => updateTypography({ textTransform: val })}
82 __next40pxDefaultSize={true}
83 __nextHasNoMarginBottom={true}
84 />
85 <TextControl
86 __next40pxDefaultSize={_nextDefaultSize}
87 label={__('Line Height', 'easy-hotel')}
88 value={typography.lineHeight}
89 onChange={(val) => updateTypography({ lineHeight: val })}
90 />
91 <TextControl
92 __next40pxDefaultSize={_nextDefaultSize}
93 label={__('Letter Spacing', 'easy-hotel')}
94 value={typography.letterSpacing}
95 onChange={(val) => updateTypography({ letterSpacing: val })}
96 help={__('Include unit (e.g., 1px)', 'easy-hotel')}
97 />
98 <Button
99 variant="secondary"
100 isSmall
101 onClick={() => {
102 setAttributes({
103 [attributeKey]: {
104 fontSize: '',
105 fontWeight: 'inherit',
106 lineHeight: '',
107 textTransform: 'none',
108 letterSpacing: ''
109 }
110 });
111 setIsVisible(false);
112 }}
113 style={{ marginTop: '10px', width: '100%', justifyContent: 'center' }}
114 >
115 {__('Reset Typography', 'easy-hotel')}
116 </Button>
117 </div>
118 </Popover>
119 )}
120 </div>
121 );
122 };
123
124 export default TypographyControls;
125