diff --git a/packages/js/components/changelog/dev-migrate-section-component-to-ts b/packages/js/components/changelog/dev-migrate-section-component-to-ts new file mode 100644 index 00000000000..66400fa1063 --- /dev/null +++ b/packages/js/components/changelog/dev-migrate-section-component-to-ts @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Migrate Section component to TS \ No newline at end of file diff --git a/packages/js/components/src/section/context.js b/packages/js/components/src/section/context.tsx similarity index 100% rename from packages/js/components/src/section/context.js rename to packages/js/components/src/section/context.tsx diff --git a/packages/js/components/src/section/header.js b/packages/js/components/src/section/header.tsx similarity index 89% rename from packages/js/components/src/section/header.js rename to packages/js/components/src/section/header.tsx index 2b19bb9bb1c..e3d5bcb32ad 100644 --- a/packages/js/components/src/section/header.js +++ b/packages/js/components/src/section/header.tsx @@ -15,7 +15,7 @@ import { Level } from './context'; * * @type {HTMLElement} */ -export function H( props ) { +export function H( props: React.HTMLAttributes< HTMLHeadingElement > ) { const level = useContext( Level ); const Heading = 'h' + Math.min( level, 6 ); diff --git a/packages/js/components/src/section/index.js b/packages/js/components/src/section/index.tsx similarity index 100% rename from packages/js/components/src/section/index.js rename to packages/js/components/src/section/index.tsx diff --git a/packages/js/components/src/section/section.js b/packages/js/components/src/section/section.js deleted file mode 100644 index 43e1ad0849e..00000000000 --- a/packages/js/components/src/section/section.js +++ /dev/null @@ -1,56 +0,0 @@ -/** - * External dependencies - */ -import PropTypes from 'prop-types'; -import { createElement } from '@wordpress/element'; - -/** - * Internal dependencies - */ -import { Level } from './context'; - -/** - * The section wrapper, used to indicate a sub-section (and change the header level context). - * - * @param {Object} props - * @param {import('react').ComponentType=} props.component - * @param {import('react').ReactNode} props.children Children to render in the tip. - * @param {string=} props.className - * @return {JSX.Element} - - */ -export function Section( { component, children, ...props } ) { - const Component = component || 'div'; - return ( - - { ( level ) => ( - - { component === false ? ( - children - ) : ( - { children } - ) } - - ) } - - ); -} - -Section.propTypes = { - /** - * The wrapper component for this section. Optional, defaults to `div`. If passed false, no wrapper is used. Additional props - * passed to Section are passed on to the component. - */ - component: PropTypes.oneOfType( [ - PropTypes.func, - PropTypes.string, - PropTypes.bool, - ] ), - /** - * The children inside this section, rendered in the `component`. This increases the context level for the next heading used. - */ - children: PropTypes.node, - /** - * Optional classname - */ - className: PropTypes.string, -}; diff --git a/packages/js/components/src/section/section.tsx b/packages/js/components/src/section/section.tsx new file mode 100644 index 00000000000..408c6e9937b --- /dev/null +++ b/packages/js/components/src/section/section.tsx @@ -0,0 +1,42 @@ +/** + * External dependencies + */ +import { createElement } from '@wordpress/element'; + +/** + * Internal dependencies + */ +import { Level } from './context'; + +type SectionProps = { + /** The wrapper component for this section. Optional, defaults to `div`. If passed false, no wrapper is used. Additional props passed to Section are passed on to the component. */ + component?: React.ComponentType | string | false; + /** Optional classname */ + className?: string; + /** The children inside this section, rendered in the `component`. This increases the context level for the next heading used. */ + children: React.ReactNode; +}; + +/** + * The section wrapper, used to indicate a sub-section (and change the header level context). + */ +export const Section: React.VFC< SectionProps > = ( { + component, + children, + ...props +} ) => { + const Component = component || 'div'; + return ( + + { ( level ) => ( + + { component === false ? ( + children + ) : ( + { children } + ) } + + ) } + + ); +}; diff --git a/packages/js/components/src/section/stories/index.js b/packages/js/components/src/section/stories/index.tsx similarity index 91% rename from packages/js/components/src/section/stories/index.js rename to packages/js/components/src/section/stories/index.tsx index c651b742921..866faa39001 100644 --- a/packages/js/components/src/section/stories/index.js +++ b/packages/js/components/src/section/stories/index.tsx @@ -2,6 +2,7 @@ * External dependencies */ import { H, Section } from '@woocommerce/components'; +import { createElement } from '@wordpress/element'; export const Basic = () => (