Skip to content

Commit

Permalink
Merge pull request #301 from 10up/upkeep/component-post-title
Browse files Browse the repository at this point in the history
upkeep:  Add TS support for `PostTitle` component
  • Loading branch information
fabiankaegy authored May 3, 2024
2 parents b4257aa + 54f3f98 commit 8e5c592
Showing 1 changed file with 10 additions and 11 deletions.
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',
};

0 comments on commit 8e5c592

Please sign in to comment.