| Server IP : 82.208.35.60 / Your IP : 216.73.216.168 Web Server : Apache/2.4.55 (FreeBSD) OpenSSL/1.1.1q-freebsd PHP/7.3.31 System : FreeBSD server7.d2m.cz 12.4-RELEASE-p9 FreeBSD 12.4-RELEASE-p9 GENERIC amd64 User : studiokobylisy_cz ( 1008) PHP Version : 7.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/studiokobylisy_cz/www/wp-content/plugins/wp-bootstrap-blocks/src/button/ |
Upload File : |
// WordPress dependencies
import { __ } from '@wordpress/i18n';
import { Component, Fragment } from '@wordpress/element';
import {
Dashicon,
IconButton,
SelectControl,
PanelBody,
ToggleControl,
TextControl,
} from '@wordpress/components';
import { applyFilters } from '@wordpress/hooks';
import * as BlockEditor from '@wordpress/block-editor';
import * as Editor from '@wordpress/editor';
const {
RichText,
URLInput,
InspectorControls,
BlockControls,
AlignmentToolbar,
} = BlockEditor || Editor; // Fallback to deprecated '@wordpress/editor' for backwards compatibility
const NEW_TAB_REL_DEFAULT_VALUE = 'noreferrer noopener';
class BootstrapButtonEdit extends Component {
render() {
const { attributes, className, setAttributes, isSelected } = this.props;
const { url, linkTarget, rel, text, style, alignment } = attributes;
let styleOptions = [
{ label: __( 'Primary', 'wp-bootstrap-blocks' ), value: 'primary' },
{
label: __( 'Secondary', 'wp-bootstrap-blocks' ),
value: 'secondary',
},
];
styleOptions = applyFilters(
'wpBootstrapBlocks.button.styleOptions',
styleOptions
);
// Open in new tab behavior from core/button (source: https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/button/edit.js)
const onToggleOpenInNewTab = ( value ) => {
const newLinkTarget = value ? '_blank' : undefined;
let updatedRel = rel;
if ( newLinkTarget && ! rel ) {
updatedRel = NEW_TAB_REL_DEFAULT_VALUE;
} else if ( ! newLinkTarget && rel === NEW_TAB_REL_DEFAULT_VALUE ) {
updatedRel = undefined;
}
setAttributes( {
linkTarget: newLinkTarget,
rel: updatedRel,
} );
};
return (
<Fragment>
<div className={ className } data-alignment={ alignment }>
<RichText
// eslint-disable-next-line @wordpress/i18n-ellipsis
placeholder={ __(
'Add text...',
'wp-bootstrap-blocks'
) }
value={ text }
onChange={ ( value ) =>
setAttributes( { text: value } )
}
formattingControls={ [] }
keepPlaceholderOnFocus
/>
<InspectorControls>
<PanelBody>
<SelectControl
label={ __( 'Style', 'wp-bootstrap-blocks' ) }
value={ style }
options={ styleOptions }
onChange={ ( selectedStyle ) => {
setAttributes( { style: selectedStyle } );
} }
/>
</PanelBody>
<PanelBody
title={ __(
'Link settings',
'wp-bootstrap-blocks'
) }
>
<ToggleControl
label={ __(
'Open in new tab',
'wp-bootstrap-blocks'
) }
onChange={ onToggleOpenInNewTab }
checked={ linkTarget === '_blank' }
/>
<TextControl
label={ __(
'Link rel',
'wp-bootstrap-blocks'
) }
value={ rel || '' }
onChange={ ( newRel ) => {
setAttributes( { rel: newRel } );
} }
/>
</PanelBody>
</InspectorControls>
<BlockControls>
<AlignmentToolbar
value={ alignment }
label={ __(
'Change button alignment',
'wp-bootstrap-blocks'
) }
onChange={ ( newAlignment ) =>
setAttributes( { alignment: newAlignment } )
}
/>
</BlockControls>
</div>
{ isSelected && (
<form
className="wp-block-wp-bootstrap-blocks-button-link"
onSubmit={ ( event ) => event.preventDefault() }
>
<Dashicon icon="admin-links" />
<URLInput
value={ url }
onChange={ ( value ) =>
setAttributes( { url: value } )
}
/>
<IconButton
icon="editor-break"
label={ __( 'Apply', 'wp-bootstrap-blocks' ) }
type="submit"
/>
</form>
) }
</Fragment>
);
}
}
export default BootstrapButtonEdit;