Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7e79847
Start refactor of ToolsPanel component to typescript
Sep 15, 2021
b1e2fc0
Add typing for dropdown menu
Aug 12, 2021
65fa4f6
Start typing the ToolsPanelHeader component
Sep 15, 2021
74ddbd8
Add types for ToolsPanelHeader
Aug 12, 2021
15c0ae3
Add remaining types
Aug 12, 2021
336efba
More conflict resolution
Sep 15, 2021
a1fe287
Update PolymorphicComponent* references to WordPressComponentProps*
Sep 2, 2021
8d9d8d7
Fix type issues following rebase
Sep 15, 2021
ee69bf8
fix remaining menu item type issues
Sep 15, 2021
1174878
Improve menu item types
Sep 16, 2021
19dec18
Move remaining eligible ToolsPanel files to TS
aaronrobertshaw Sep 17, 2021
bb89386
Revert "Improve menu item types"
aaronrobertshaw Sep 17, 2021
8369760
Revert "Add typing for dropdown menu"
aaronrobertshaw Sep 17, 2021
d853e9a
Remove menu group and item type doc block annotations
aaronrobertshaw Sep 17, 2021
19bdce7
Add ts-nocheck to ToolsPanelHeader
aaronrobertshaw Sep 17, 2021
bce9e12
Move ts-nocheck to dependencies and fix type errors
aaronrobertshaw Sep 20, 2021
87127db
Improve typing of ToolsPanel
aaronrobertshaw Sep 21, 2021
6c4180e
Add missing dependencies to tools panel item hook
aaronrobertshaw Sep 21, 2021
19cd494
Use optional chaining for onSelect and onDeselect calls
aaronrobertshaw Sep 22, 2021
f061db7
Add TypeScript types for function props in READMEs
aaronrobertshaw Sep 22, 2021
d4674f1
Enforce boolean for hasMenuItems in ToolsPanelContext
aaronrobertshaw Sep 22, 2021
1f833ab
Make all properties except panelId mandatory in ToolsPanelContext
aaronrobertshaw Sep 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More conflict resolution
  • Loading branch information
Glen Davies authored and aaronrobertshaw committed Sep 23, 2021
commit 336efbae318c2c836c051e0ce3a5956da62e8824
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,8 +17,8 @@ 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 DefaultControlsGroup = ( { items, onClose, toggleItem } ) => {
if ( ! items.length ) {
Expand Down Expand Up @@ -93,8 +99,8 @@ const OptionalControlsGroup = ( { items, onClose, toggleItem } ) => {
};

const ToolsPanelHeader = (
props: ToolsPanelHeaderProps,
forwardedRef: forwardRef
props: PolymorphicComponentProps< ToolsPanelHeaderProps, 'h2' >,
forwardedRef: Ref< any >
) => {
const {
dropdownMenuClassName,
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
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
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,
label,
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,7 +7,7 @@ import { useEffect, useMemo, useRef, 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';

Expand All @@ -22,7 +22,9 @@ const generateMenuItems = ( { panelItems, reset } ) => {
return menuItems;
};

export function useToolsPanel( props: ToolsPanelProps ) {
export function useToolsPanel(
props: PolymorphicComponentProps< ToolsPanelProps, 'div' >
) {
const { className, resetAll, panelId, ...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