2019-11-21 17:21:14 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { PlainText } from '@wordpress/block-editor';
|
2021-08-17 15:21:07 +00:00
|
|
|
import { withInstanceId } from '@wordpress/compose';
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-11-21 17:21:14 +00:00
|
|
|
|
2019-11-26 10:56:14 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './editor.scss';
|
|
|
|
|
2021-08-17 15:21:07 +00:00
|
|
|
const BlockTitle = ( {
|
|
|
|
className,
|
|
|
|
headingLevel,
|
|
|
|
onChange,
|
|
|
|
heading,
|
|
|
|
instanceId,
|
|
|
|
} ) => {
|
2019-11-21 17:21:14 +00:00
|
|
|
const TagName = `h${ headingLevel }`;
|
|
|
|
return (
|
2021-09-15 11:35:06 +00:00
|
|
|
<TagName className={ className }>
|
2021-08-17 16:09:04 +00:00
|
|
|
<label
|
|
|
|
className="screen-reader-text"
|
|
|
|
htmlFor={ `block-title-${ instanceId }` }
|
|
|
|
>
|
2021-08-17 15:21:07 +00:00
|
|
|
{ __( 'Block title', 'woo-gutenberg-products-block' ) }
|
|
|
|
</label>
|
2019-11-21 17:21:14 +00:00
|
|
|
<PlainText
|
2021-08-17 15:21:07 +00:00
|
|
|
id={ `block-title-${ instanceId }` }
|
2021-09-15 11:35:06 +00:00
|
|
|
className="wc-block-editor-components-title"
|
2019-11-21 17:21:14 +00:00
|
|
|
value={ heading }
|
|
|
|
onChange={ onChange }
|
|
|
|
/>
|
|
|
|
</TagName>
|
|
|
|
);
|
|
|
|
};
|
2019-11-26 11:16:28 +00:00
|
|
|
|
2019-11-21 17:21:14 +00:00
|
|
|
BlockTitle.propTypes = {
|
|
|
|
/**
|
|
|
|
* Classname to add to title in addition to the defaults.
|
|
|
|
*/
|
|
|
|
className: PropTypes.string,
|
|
|
|
/**
|
2019-11-26 11:16:28 +00:00
|
|
|
* The value of the heading.
|
2019-11-21 17:21:14 +00:00
|
|
|
*/
|
|
|
|
value: PropTypes.string,
|
|
|
|
/**
|
2019-11-26 11:16:28 +00:00
|
|
|
* Callback to update the attribute when text is changed.
|
2019-11-21 17:21:14 +00:00
|
|
|
*/
|
|
|
|
onChange: PropTypes.func,
|
|
|
|
/**
|
2019-11-26 11:16:28 +00:00
|
|
|
* Level of the heading tag (1, 2, 3... will render <h1>, <h2>, <h3>... elements).
|
2019-11-21 17:21:14 +00:00
|
|
|
*/
|
2019-11-26 11:16:28 +00:00
|
|
|
headingLevel: PropTypes.number,
|
2019-11-21 17:21:14 +00:00
|
|
|
};
|
|
|
|
|
2021-08-17 15:21:07 +00:00
|
|
|
export default withInstanceId( BlockTitle );
|