/** * External dependencies */ import classnames from 'classnames'; import { animationsClasses, transitionTypes, buttonShapes, buttonSizes } from './data'; /** * WordPress dependencies */ const { __ } = wp.i18n; const { Component, Fragment, } = wp.element; const { compose } = wp.compose; const { Dashicon, IconButton, withFallbackStyles, TextControl, TextareaControl, SelectControl, PanelBody, ToggleControl, } = wp.components; const { URLInput, RichText, ContrastChecker, InspectorControls, withColors, PanelColorSettings, } = wp.editor; const { getComputedStyle } = window; const FallbackStyles = withFallbackStyles( ( node, ownProps ) => { const { textColor, backgroundColor } = ownProps; const backgroundColorValue = backgroundColor && backgroundColor.color; const textColorValue = textColor && textColor.color; //avoid the use of querySelector if textColor color is known and verify if node is available. const textNode = ! textColorValue && node ? node.querySelector( '[contenteditable="true"]' ) : null; return { fallbackBackgroundColor: backgroundColorValue || ! node ? undefined : getComputedStyle( node ).backgroundColor, fallbackTextColor: textColorValue || ! textNode ? undefined : getComputedStyle( textNode ).color, }; } ); class AnimationButtonEdit extends Component { constructor() { super( ...arguments ); this.nodeRef = null; this.bindRef = this.bindRef.bind( this ); } bindRef( node ) { if ( ! node ) { return; } this.nodeRef = node; } render() { const { attributes, backgroundColor, textColor, setBackgroundColor, setTextColor, fallbackBackgroundColor, fallbackTextColor, setAttributes, isSelected, className, } = this.props; const { text, url, title, animation, backgroundHoverColor, textHoverColor, transition, transitionType, extraClassName, extraStyles, extraHoverStyles, opensInNewWindow, buttonShape, buttonSize, } = attributes; const hoverClass = ( backgroundHoverColor ? backgroundHoverColor.replace( '#', '' ) + '-' : '' ) + ( textHoverColor ? textHoverColor.replace( '#', '' ) : '' ); const hoverStyles = ( backgroundHoverColor ? `background-color: #${backgroundHoverColor.replace( '#', '' )}!important;` : '' ) + ( textHoverColor ? `color: #${textHoverColor.replace( '#', '' )}!important;` : '' ); const uniqueClass = extraStyles ? extraStyles.replace( /[^a-z0-9]/gi, '' ) : ''; const uniqueHoverClass = extraHoverStyles ? extraHoverStyles.replace( /[^a-z0-9]/gi, '' ) : ''; let buttonStyles = { backgroundColor: backgroundColor.color, color: textColor.color, }; if ( transition ) { buttonStyles.transition = `${transition}s ${transitionType ? transitionType : ''}`; } return (
{ hoverClass &&