PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / trunk
Secure Custom Fields vtrunk
6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / assets / src / js / pro / blocks-v3 / high-order-components / with-align-text.js
secure-custom-fields / assets / src / js / pro / blocks-v3 / high-order-components Last commit date
with-align-content.js 8 months ago with-align-text.js 8 months ago with-full-height.js 8 months ago
with-align-text.js
60 lines
1 /**
2 * withAlignText Higher-Order Component
3 * Adds text alignment toolbar controls to ACF blocks
4 */
5
6 const { Fragment, Component } = wp.element;
7 const { BlockControls, AlignmentToolbar } = wp.blockEditor;
8
9 /**
10 * Gets the default text alignment based on RTL setting
11 *
12 * @param {string} alignment - Current alignment value
13 * @returns {string} - Normalized alignment value (left, center, or right)
14 */
15 const getDefaultAlignment = ( alignment ) => {
16 const defaultAlign = acf.get( 'rtl' ) ? 'right' : 'left';
17 return [ 'left', 'center', 'right' ].includes( alignment )
18 ? alignment
19 : defaultAlign;
20 };
21
22 /**
23 * Higher-order component that adds text alignment controls
24 * Wraps a block component and adds AlignmentToolbar to BlockControls
25 *
26 * @param {React.Component} BlockComponent - The component to wrap
27 * @param {Object} blockConfig - ACF block configuration
28 * @returns {React.Component} - Enhanced component with text alignment controls
29 */
30 export const withAlignText = ( BlockComponent, blockConfig ) => {
31 const normalizeAlignment = getDefaultAlignment;
32
33 // Set default alignment on block config
34 blockConfig.alignText = normalizeAlignment( blockConfig.alignText );
35
36 return class extends Component {
37 render() {
38 const { attributes, setAttributes } = this.props;
39 const { alignText } = attributes;
40
41 return (
42 <Fragment>
43 <BlockControls group="block">
44 <AlignmentToolbar
45 value={ normalizeAlignment( alignText ) }
46 onChange={ function ( newAlignment ) {
47 setAttributes( {
48 alignText:
49 normalizeAlignment( newAlignment ),
50 } );
51 } }
52 />
53 </BlockControls>
54 <BlockComponent { ...this.props } />
55 </Fragment>
56 );
57 }
58 };
59 };
60