2020-05-25 16:45:38 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classNames from 'classnames';
|
2022-03-29 10:16:17 +00:00
|
|
|
import { ReactNode } from 'react';
|
2020-05-25 16:45:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2022-03-29 10:16:17 +00:00
|
|
|
const Title = ( {
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
headingLevel,
|
|
|
|
...props
|
|
|
|
}: TitleProps ): JSX.Element => {
|
2020-05-25 16:45:38 +00:00
|
|
|
const buttonClassName = classNames(
|
2020-06-17 09:53:42 +00:00
|
|
|
'wc-block-components-title',
|
2020-05-25 16:45:38 +00:00
|
|
|
className
|
|
|
|
);
|
2022-03-29 10:16:17 +00:00
|
|
|
const TagName = `h${ headingLevel }` as keyof JSX.IntrinsicElements;
|
2020-05-25 16:45:38 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TagName className={ buttonClassName } { ...props }>
|
|
|
|
{ children }
|
|
|
|
</TagName>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-03-29 10:16:17 +00:00
|
|
|
interface TitleProps {
|
|
|
|
headingLevel: '1' | '2' | '3' | '4' | '5' | '6';
|
|
|
|
className: string;
|
|
|
|
children: ReactNode;
|
|
|
|
}
|
2020-05-25 16:45:38 +00:00
|
|
|
|
|
|
|
export default Title;
|