2020-05-25 16:45:38 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classNames from 'classnames';
|
2023-03-02 14:26:00 +00:00
|
|
|
import type { 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
|
|
|
*
|
2022-04-08 13:47:19 +00:00
|
|
|
* @param {Object} props Incoming props for the component.
|
|
|
|
* @param {React.ReactNode} [props.children] Children elements this component wraps.
|
|
|
|
* @param {string} [props.className] CSS class used.
|
|
|
|
* @param {string} props.headingLevel Heading level for title.
|
|
|
|
* @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;
|