Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Migrate Block Title component to TypeScript (#9712)
Browse files Browse the repository at this point in the history
Co-authored-by: Niels Lange <[email protected]>
Co-authored-by: Alba Rincón <[email protected]>
Co-authored-by: Manish Menaria <[email protected]>
  • Loading branch information
4 people authored Jun 13, 2023
1 parent eafc6b4 commit 0a89436
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import PropTypes from 'prop-types';
import { PlainText } from '@wordpress/block-editor';
import { withInstanceId } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
Expand All @@ -10,15 +9,21 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import './editor.scss';

interface BlockTitleProps {
className: string;
headingLevel: number;
onChange: ( value: string ) => void;
heading: string;
instanceId: number;
}
const BlockTitle = ( {
className,
headingLevel,
onChange,
heading,
instanceId,
} ) => {
const TagName = `h${ headingLevel }`;
}: BlockTitleProps ) => {
const TagName = `h${ headingLevel }` as keyof JSX.IntrinsicElements;
return (
<TagName className={ className }>
<label
Expand All @@ -38,23 +43,4 @@ const BlockTitle = ( {
);
};

BlockTitle.propTypes = {
/**
* Classname to add to title in addition to the defaults.
*/
className: PropTypes.string,
/**
* The value of the heading.
*/
value: PropTypes.string,
/**
* Callback to update the attribute when text is changed.
*/
onChange: PropTypes.func,
/**
* Level of the heading tag (1, 2, 3... will render <h1>, <h2>, <h3>... elements).
*/
headingLevel: PropTypes.number,
};

export default withInstanceId( BlockTitle );
2 changes: 1 addition & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1982,7 +1982,7 @@
<error line="174" column="35" severity="error" message="Argument of type &apos;unknown&apos; is not assignable to parameter of type &apos;StoreAttributes[]&apos;." source="TS2345" />
<error line="182" column="35" severity="error" message="Parameter &apos;attribute&apos; implicitly has an &apos;any&apos; type." source="TS7006" />
</file>
<file name="assets/js/editor-components/block-title/index.js">
<file name="assets/js/editor-components/block-title/index.tsx">
<error line="15" column="2" severity="error" message="Binding element &apos;className&apos; implicitly has an &apos;any&apos; type." source="TS7031" />
<error line="16" column="2" severity="error" message="Binding element &apos;headingLevel&apos; implicitly has an &apos;any&apos; type." source="TS7031" />
<error line="17" column="2" severity="error" message="Binding element &apos;onChange&apos; implicitly has an &apos;any&apos; type." source="TS7031" />
Expand Down

0 comments on commit 0a89436

Please sign in to comment.