From 4d01937f1b451995225c4dee20f80e54db7e7aba Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Sat, 20 Apr 2024 02:35:48 +0900 Subject: [PATCH 01/11] View: Fix TypeScript types --- packages/components/src/view/component.tsx | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/components/src/view/component.tsx b/packages/components/src/view/component.tsx index a970c5c757431..e692bed8a81c3 100644 --- a/packages/components/src/view/component.tsx +++ b/packages/components/src/view/component.tsx @@ -2,14 +2,27 @@ * External dependencies */ import styled from '@emotion/styled'; -import type { RefAttributes } from 'react'; + +/** + * WordPress dependencies + */ +import { forwardRef } from '@wordpress/element'; /** * Internal dependencies */ -import type { WordPressComponent } from '../context/wordpress-component'; +import type { WordPressComponentProps } from '../context/wordpress-component'; import type { ViewProps } from './types'; +const PolymorphicDiv = styled.div``; + +function UnforwardedView( + props: WordPressComponentProps< ViewProps, 'div', true >, + ref: React.ForwardedRef< any > +) { + return ; +} + /** * `View` is a core component that renders everything in the library. * It is the principle component in the entire library. @@ -26,13 +39,6 @@ import type { ViewProps } from './types'; * } * ``` */ -export const View: WordPressComponent< - 'div', - ViewProps & RefAttributes< any >, - true -> = styled.div``; - -View.selector = '.components-view'; -View.displayName = 'View'; +export const View = forwardRef( UnforwardedView ); export default View; From b19f87324dadcfb569ae8386b57164aa5f7dfc37 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Sat, 20 Apr 2024 02:36:41 +0900 Subject: [PATCH 02/11] ItemGroup: Remove unneeded typecasting --- packages/components/src/item-group/item/hook.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/components/src/item-group/item/hook.ts b/packages/components/src/item-group/item/hook.ts index 188b575e072c8..be817a24dcbb1 100644 --- a/packages/components/src/item-group/item/hook.ts +++ b/packages/components/src/item-group/item/hook.ts @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import type { ElementType } from 'react'; - /** * WordPress dependencies */ @@ -32,11 +27,7 @@ export function useItem( props: WordPressComponentProps< ItemProps, 'div' > ) { const size = sizeProp || contextSize; - const as = - asProp || - ( ( typeof onClick !== 'undefined' - ? 'button' - : 'div' ) as ElementType ); + const as = asProp || ( typeof onClick !== 'undefined' ? 'button' : 'div' ); const cx = useCx(); From ee09e5d28c5b3a90434afb415ac35adeda6fc668 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Sat, 20 Apr 2024 02:36:48 +0900 Subject: [PATCH 03/11] Navigator: Fix View-related types --- .../src/navigator/navigator-back-button/component.tsx | 4 ++-- .../components/src/navigator/navigator-back-button/hook.ts | 3 --- .../components/src/navigator/navigator-button/component.tsx | 4 ++-- packages/components/src/navigator/navigator-button/hook.ts | 3 --- .../src/navigator/navigator-to-parent-button/component.tsx | 4 ++-- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/components/src/navigator/navigator-back-button/component.tsx b/packages/components/src/navigator/navigator-back-button/component.tsx index 71c5ac14cd00d..66f9a539a5bcd 100644 --- a/packages/components/src/navigator/navigator-back-button/component.tsx +++ b/packages/components/src/navigator/navigator-back-button/component.tsx @@ -8,9 +8,9 @@ import type { ForwardedRef } from 'react'; */ import type { WordPressComponentProps } from '../../context'; import { contextConnect } from '../../context'; -import { View } from '../../view'; import { useNavigatorBackButton } from './hook'; import type { NavigatorBackButtonProps } from '../types'; +import Button from '../../button'; function UnconnectedNavigatorBackButton( props: WordPressComponentProps< NavigatorBackButtonProps, 'button' >, @@ -18,7 +18,7 @@ function UnconnectedNavigatorBackButton( ) { const navigatorBackButtonProps = useNavigatorBackButton( props ); - return ; + return