How to use the @wordpress/editor.withColors function in @wordpress/editor

To help you get started, we’ve selected a few @wordpress/editor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TomodomoCo / gutenberg-block-columns / src / block / editor.js View on Github external
withColors,
  getColorClassName,
} from '@wordpress/editor'
import { Fragment } from '@wordpress/element'

/**
 * Internal Dependencies
 */
import Inspector from './inspector'

const ALLOWED_BLOCKS = ['tomodomo/column']

/**
 * Block edit component
 */
const Editor = withColors('backgroundColor', 'textColor')((props) => {
  // Variables
  const {
    attributes: {
      columns,
      backgroundColor,
      textColor,
    },
    className,
  } = props

  const classes = classnames(
    className,
    `has-${columns.length}-columns`,
    getColorClassName('background', backgroundColor),
    getColorClassName('text', textColor),
  )
github front / gutenberg-js / src / js / blocks / post / edit.js View on Github external
if (attributes.id && attributes.id !== '') {
          res.post = getEntityRecord('postType', 'post', attributes.id);

          if (res.post) {
            attributes.imageId = res.post.featured_media;
          }
        }
        break;
    } */

    return {
      ...res,
      ...withSelectMedia(select, props),
    };
  }),
  withColors({ textColor: 'color' }),
  withFallbackStyles((node, ownProps) => {
    const { fontSize, customFontSize } = ownProps.attributes;
    const editableNode = node.querySelector('[contenteditable="true"]');
    // verify if editableNode is available, before using getComputedStyle.
    const computedStyles = editableNode ? getComputedStyle(editableNode) : null;
    return {
      fallbackFontSize: fontSize || customFontSize || ! computedStyles ? undefined : parseInt(computedStyles.fontSize) || undefined,
    };
  }),
  /* withAPIData(props => {
    if (props.attributes.type === 'auto') {
      const postQuery = stringify(pickBy({
        category_id: props.attributes.categoryId,
        order: 'desc',
        orderby: 'date',
        per_page: 1,
github front / gutenberg-js / src / js / gutenberg-overrides / @wordpress / block-library / build-module / media-text / edit.js View on Github external
/>
        
        <div style="{">
          { this.renderMediaArea() }
          
        </div>
      
    );
  }
}

export default withColors('backgroundColor')(MediaTextEdit);
github front / gutenberg-js / src / js / blocks / section / edit.js View on Github external
data-url={ url }
          className={ classes }
          style={ style }
          { ...data }
        &gt;
          <div>
            
          </div>
        
      
    );
  }
}

export default compose(
  withColors('backgroundColor'),
)(SectionBlockEdit);

export function dimRatioToClass (ratio) {
  return (ratio === 0 || ratio === 50) ?
    null :
    'has-background-dim-' + (10 * Math.round(ratio / 10));
}

export function backgroundImageStyles (url) {
  return url ?
    { backgroundImage: `url(${url})` } :
    {};
}
github Automattic / wp-calypso / packages / jetpack-blocks / src / utils / submit-button.js View on Github external
setTextButtonColor( nextColour );
									setAttributes( { customTextButtonColor: nextColour } );
								},
								label: __( 'Text Color' ),
							},
						] }
					/&gt;
					
				
			
		);
	}
}

export default compose( [
	withColors( 'backgroundButtonColor', { textButtonColor: 'color' } ),
	applyFallbackStyles,
] )( SubmitButton );
github WordPress / gutenberg / packages / block-library / src / container / edit.js View on Github external
{
							value: backgroundColor.color,
							onChange: setBackgroundColor,
							label: __( 'Background Color' ),
						},
					] }
				/&gt;
			
			<div style="{">
				
			</div>
		
	);
}

export default withColors( 'backgroundColor' )( ContainerEdit );
github WordPress / gutenberg / core-blocks / paragraph / edit.js View on Github external
content: nextContent,
						} );
					} }
					onSplit={ this.splitBlock }
					onMerge={ mergeBlocks }
					onReplace={ this.onReplace }
					onRemove={ () =&gt; onReplace( [] ) }
					placeholder={ placeholder || __( 'Add text or type / to add content' ) }
				/&gt;
			
		);
	}
}

const ParagraphEdit = compose( [
	withColors( 'backgroundColor', { textColor: 'color' } ),
	withFontSizes( 'fontSize' ),
	applyFallbackStyles,
] )( ParagraphBlock );

export default ParagraphEdit;
github WordPress / gutenberg / core-blocks / paragraph / index.js View on Github external
merge( attributes, attributesToMerge ) {
		return {
			content: concatChildren( attributes.content, attributesToMerge.content ),
		};
	},

	getEditWrapperProps( attributes ) {
		const { width } = attributes;
		if ( [ 'wide', 'full', 'left', 'right' ].indexOf( width ) !== -1 ) {
			return { 'data-align': width };
		}
	},

	edit: compose(
		withColors( ( getColor, setColor, { attributes } ) => {
			return {
				backgroundColor: getColor( attributes.backgroundColor, attributes.customBackgroundColor, 'background-color' ),
				setBackgroundColor: setColor( 'backgroundColor', 'customBackgroundColor' ),
				textColor: getColor( attributes.textColor, attributes.customTextColor, 'color' ),
				setTextColor: setColor( 'textColor', 'customTextColor' ),
			};
		} ),
		FallbackStyles,
	)( ParagraphBlock ),

	save( { attributes } ) {
		const {
			align,
			content,
			dropCap,
			backgroundColor,