Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upkeep: Add TS support for PostTitle component #301

Merged
merged 13 commits into from
May 3, 2024
Merged
21 changes: 10 additions & 11 deletions components/post-title/index.js → components/post-title/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { useEntityProp } from '@wordpress/core-data';
import { RichText, store as blockEditorStore } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import PropTypes from 'prop-types';
import { usePost } from '../../hooks';

export const PostTitle = (props) => {
const { tagName: TagName = 'h1', ...rest } = props;
interface PostTitleProps<TElementType extends React.ElementType> {
tagName?: TElementType | keyof JSX.IntrinsicElements;
}

type PostTitlePropsWithOmit<TElementType extends React.ElementType> = PostTitleProps<TElementType> & Omit<React.ComponentPropsWithoutRef<TElementType>, keyof PostTitleProps<TElementType>>;

export const PostTitle = <TElementType extends React.ElementType = 'h1'>({
tagName: TagName = 'h1',
...rest
}: PostTitlePropsWithOmit<TElementType> ) => {
const { postId, postType, isEditable } = usePost();

const [rawTitle = '', setTitle, fullTitle] = useEntityProp(
Expand Down Expand Up @@ -36,11 +43,3 @@ export const PostTitle = (props) => {
/>
);
};

PostTitle.propTypes = {
tagName: PropTypes.string,
};

PostTitle.defaultProps = {
tagName: 'h1',
};
Loading