Skip to content

Commit

Permalink
Switch to PolymorphicComponentProps type
Browse files Browse the repository at this point in the history
  • Loading branch information
Glen Davies committed Aug 16, 2021
1 parent b80b745 commit 16f6def
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
import type { Ref } from 'react';

/**
* WordPress dependencies
*/
Expand All @@ -11,12 +17,12 @@ import DropdownMenu from '../../dropdown-menu';
import MenuGroup from '../../menu-group';
import MenuItem from '../../menu-item';
import { useToolsPanelHeader } from './hook';
import { contextConnect } from '../../ui/context';
import type { ToolsPanelHeaderProps, forwardRef } from '../types';
import { contextConnect, PolymorphicComponentProps } from '../../ui/context';
import type { ToolsPanelHeaderProps } from '../types';

const ToolsPanelHeader = (
props: ToolsPanelHeaderProps,
forwardedRef: forwardRef
props: PolymorphicComponentProps< ToolsPanelHeaderProps, 'h2' >,
forwardedRef: Ref< any >
) => {
const {
hasMenuItems,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { useMemo } from '@wordpress/element';
*/
import * as styles from '../styles';
import { useToolsPanelContext } from '../context';
import { useContextSystem } from '../../ui/context';
import { useContextSystem, PolymorphicComponentProps } from '../../ui/context';
import { useCx } from '../../utils/hooks/use-cx';
import type { ToolsPanelHeaderProps } from '../types';

export function useToolsPanelHeader( props: ToolsPanelHeaderProps ) {
export function useToolsPanelHeader(
props: PolymorphicComponentProps< ToolsPanelHeaderProps, 'h2' >
) {
const { className, ...otherProps } = useContextSystem(
props,
'ToolsPanelHeader'
Expand Down
14 changes: 10 additions & 4 deletions packages/components/src/tools-panel/tools-panel-item/component.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
/**
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
import type { Ref } from 'react';

/**
* Internal dependencies
*/
import { useToolsPanelItem } from './hook';
import { View } from '../../view';
import { contextConnect } from '../../ui/context';
import type { forwardRef, ToolsPanelItemProps } from '../types';
import { contextConnect, PolymorphicComponentProps } from '../../ui/context';
import type { ToolsPanelItemProps } from '../types';

// This wraps controls to be conditionally displayed within a tools panel. It
// prevents props being applied to HTML elements that would make them invalid.
const ToolsPanelItem = (
props: ToolsPanelItemProps,
forwardedRef: forwardRef
props: PolymorphicComponentProps< ToolsPanelItemProps, 'div' >,
forwardedRef: Ref< any >
) => {
const { children, isShown, ...toolsPanelItemProps } = useToolsPanelItem(
props
Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/tools-panel/tools-panel-item/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { useEffect, useMemo } from '@wordpress/element';
*/
import * as styles from '../styles';
import { useToolsPanelContext } from '../context';
import { useContextSystem } from '../../ui/context';
import { useContextSystem, PolymorphicComponentProps } from '../../ui/context';
import { useCx } from '../../utils/hooks/use-cx';
import type { ToolsPanelItemProps } from '../types';

export function useToolsPanelItem( props: ToolsPanelItemProps ) {
export function useToolsPanelItem(
props: PolymorphicComponentProps< ToolsPanelItemProps, 'div' >
) {
const {
className,
hasValue,
Expand Down
15 changes: 12 additions & 3 deletions packages/components/src/tools-panel/tools-panel/component.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
/**
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
import type { Ref } from 'react';

/**
* Internal dependencies
*/
import ToolsPanelHeader from '../tools-panel-header';
import { ToolsPanelContext } from '../context';
import { useToolsPanel } from './hook';
import { View } from '../../view';
import { contextConnect } from '../../ui/context';
import type { ToolsPanelProps, forwardRef } from '../types';
import { contextConnect, PolymorphicComponentProps } from '../../ui/context';
import type { ToolsPanelProps } from '../types';

const ToolsPanel = ( props: ToolsPanelProps, forwardedRef: forwardRef ) => {
const ToolsPanel = (
props: PolymorphicComponentProps< ToolsPanelProps, 'div' >,
forwardedRef: Ref< any >
) => {
const {
children,
header,
Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/tools-panel/tools-panel/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import { useEffect, useMemo, useState } from '@wordpress/element';
* Internal dependencies
*/
import * as styles from '../styles';
import { useContextSystem } from '../../ui/context';
import { useContextSystem, PolymorphicComponentProps } from '../../ui/context';
import { useCx } from '../../utils/hooks/use-cx';
import type { ToolsPanelProps, ToolsPanelItem } from '../types';

export function useToolsPanel( props: ToolsPanelProps ) {
export function useToolsPanel(
props: PolymorphicComponentProps< ToolsPanelProps, 'div' >
) {
const { className, resetAll, ...otherProps } = useContextSystem(
props,
'ToolsPanel'
Expand Down
4 changes: 1 addition & 3 deletions packages/components/src/tools-panel/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
import type { ReactNode, Ref } from 'react';

export type forwardRef = Ref< any >;
import type { ReactNode } from 'react';

export interface ToolsPanelProps {
label: string;
Expand Down

0 comments on commit 16f6def

Please sign in to comment.