Skip to content

Commit

Permalink
Add remaining types
Browse files Browse the repository at this point in the history
  • Loading branch information
Glen Davies committed Aug 12, 2021
1 parent a50de89 commit 87d8e54
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import MenuGroup from '../../menu-group';
import MenuItem from '../../menu-item';
import { useToolsPanelHeader } from './hook';
import { contextConnect } from '../../ui/context';
import type { ToolsPanelHeaderProps, toolsPanelforwardRef } from '../types';
import type { ToolsPanelHeaderProps, forwardRef } from '../types';

const ToolsPanelHeader = (
props: ToolsPanelHeaderProps,
forwardedRef: toolsPanelforwardRef
forwardedRef: forwardRef
) => {
const {
hasMenuItems,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import { useToolsPanelItem } from './hook';
import { View } from '../../view';
import { contextConnect } from '../../ui/context';
import type { forwardRef, 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, forwardedRef ) => {
const ToolsPanelItem = (
props: ToolsPanelItemProps,
forwardedRef: forwardRef
) => {
const { children, isShown, ...toolsPanelItemProps } = useToolsPanelItem(
props
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import * as styles from '../styles';
import { useToolsPanelContext } from '../context';
import { useContextSystem } from '../../ui/context';
import { useCx } from '../../utils/hooks/use-cx';
import type { ToolsPanelItemProps } from '../types';

export function useToolsPanelItem( props ) {
export function useToolsPanelItem( props: ToolsPanelItemProps ) {
const {
className,
hasValue,
Expand All @@ -26,7 +27,7 @@ export function useToolsPanelItem( props ) {
const cx = useCx();
const classes = useMemo( () => {
return cx( styles.ToolsPanelItem, className );
} );
}, [ styles.ToolsPanelItem, className ] );

const { menuItems, registerPanelItem } = useToolsPanelContext();

Expand Down
7 changes: 2 additions & 5 deletions packages/components/src/tools-panel/tools-panel/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import { ToolsPanelContext } from '../context';
import { useToolsPanel } from './hook';
import { View } from '../../view';
import { contextConnect } from '../../ui/context';
import type { ToolsPanelProps, toolsPanelforwardRef } from '../types';
import type { ToolsPanelProps, forwardRef } from '../types';

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

export function useToolsPanel( props: ToolsPanelProps ) {
const { className, resetAll, ...otherProps } = useContextSystem(
Expand All @@ -25,7 +25,7 @@ export function useToolsPanel( props: ToolsPanelProps ) {
// Allow panel items to register themselves.
const [ panelItems, setPanelItems ] = useState( [] );

const registerPanelItem = ( item: ToolPanelItem ) => {
const registerPanelItem = ( item: ToolsPanelItem ) => {
setPanelItems( ( items ) => [ ...items, item ] );
};

Expand Down
18 changes: 13 additions & 5 deletions packages/components/src/tools-panel/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,38 @@
// eslint-disable-next-line no-restricted-imports
import type { ReactNode, Ref } from 'react';

export type toolsPanelforwardRef = Ref< any >;
export type forwardRef = Ref< any >;

export interface ToolsPanelProps {
label: string;
header: string;
children: ReactNode;
resetAll: () => undefined;
resetAll: () => void;
className?: string;
}

export interface ToolsPanelHeaderProps {
menuLabel: string;
header: string;
resetAll: () => undefined;
toggleItem: ( label: string ) => undefined;
resetAll: () => void;
toggleItem: ( label: string ) => void;
className?: string;
}

export interface ToolPanelItem {
export interface ToolsPanelItem {
hasValue: () => boolean;
isShownByDefault: boolean;
label: string;
}

export interface ToolsPanelItemProps extends ToolsPanelItem {
children?: ReactNode;
onDeselect?: () => void;
onSelect?: () => void;
className?: string;
}

export interface TPContext {
menuItems?: { [ key: string ]: boolean };
registerPanelItem?: ( item: ToolsPanelItem ) => void;
}

0 comments on commit 87d8e54

Please sign in to comment.