Невозможно сделать кнопку RichText с редактором WordPress Gutenberg - PullRequest
0 голосов
/ 08 апреля 2019

Я пытаюсь создать кнопку внутри блока макета, которая включает кнопку призыва к действию.Самое близкое, что я получил, - это наличие ссылки с текстом и URL-адресом, но не могу добавить className, и над ним есть пустой список ссылок.Вот мой код:

/**
 * External dependencies
 */
import classnames from 'classnames';
import { omit, pick } from 'lodash';

const { __, setLocaleData } = wp.i18n;
const { registerBlockType } = wp.blocks;
const { RichText,
                getColorClassName,
            } = wp.editor;

/**
 * Internal dependencies
 */
import edit from './edit';
import icon from './icon';

registerBlockType( 'my-blocks/button-link-example-not-working', {
    title: __( 'Layout with Button', 'my-blocks' ),
    icon: 'universal-access-alt',
    category: 'layout',
  attributes: {
        url: {
            type: 'string',
            source: 'attribute',
            selector: 'a',
            attribute: 'href',
        },
        title: {
            type: 'string',
            source: 'attribute',
            selector: 'a',
            attribute: 'title',
        },
        text: {
            type: 'string',
            source: 'html',
            selector: 'a',
        },
        backgroundColor: {
            type: 'string',
        },
        textColor: {
            type: 'string',
        },
        customBackgroundColor: {
            type: 'string',
        },
        customTextColor: {
            type: 'string',
        },
  },
  edit: ( props ) => {
      const { 
      attributes: { 
        text,
      }, attributes, setAttributes, className } = props;
      const onChangeText = ( newText ) => {
          setAttributes( { text: newText } );
      };
      return (
                <div>
          <RichText
            tagName="a"
                        className="button"
                        placeholder={ __( 'Button text...' ) }
            onChange={ ( text ) => setAttributes( { text } ) }
            value={ text }
          />
                </div>
      );
  },
  save: ( props ) => {
            const {
                className,
                attributes, 
                setAttributes, 
                attributes: {
                },
            } = props;
      return (
                <div>
                    <RichText.Content 
                        className="my-class" 
                        tagName="a"
                        href={ url }
                        title={ title } 
                        value={ props.attributes.text } 
                    />
                </div>
      );
  },
} );

Есть ли способ импортировать кнопку из элементов макета по умолчанию?

...