2020-05-25 16:45:38 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
|
2020-09-20 23:54:08 +00:00
|
|
|
/** @typedef {import('react')} React */
|
|
|
|
|
2020-05-25 16:45:38 +00:00
|
|
|
/**
|
|
|
|
* Component that renders a block title.
|
2020-09-20 23:54:08 +00:00
|
|
|
*
|
|
|
|
* @param {Object} props Incoming props for the component.
|
2021-03-09 10:55:24 +00:00
|
|
|
* @param {React.ReactNode} [props.children] Children elements this component wraps.
|
2020-10-08 09:21:47 +00:00
|
|
|
* @param {string} [props.className] CSS class used.
|
2020-09-20 23:54:08 +00:00
|
|
|
* @param {string} props.headingLevel Heading level for title.
|
2020-10-08 09:21:47 +00:00
|
|
|
* @param {Object} [props.props] Rest of props passed through to component.
|
2020-05-25 16:45:38 +00:00
|
|
|
*/
|
|
|
|
const Title = ( { children, className, headingLevel, ...props } ) => {
|
|
|
|
const buttonClassName = classNames(
|
2020-06-17 09:53:42 +00:00
|
|
|
'wc-block-components-title',
|
2020-05-25 16:45:38 +00:00
|
|
|
className
|
|
|
|
);
|
|
|
|
const TagName = `h${ headingLevel }`;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TagName className={ buttonClassName } { ...props }>
|
|
|
|
{ children }
|
|
|
|
</TagName>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Title.propTypes = {
|
|
|
|
headingLevel: PropTypes.oneOf( [ '1', '2', '3', '4', '5', '6' ] )
|
|
|
|
.isRequired,
|
|
|
|
className: PropTypes.string,
|
|
|
|
children: PropTypes.node,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Title;
|