Skip to content

Commit

Permalink
fixes tooltip TS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bruugey committed Jul 10, 2023
1 parent c26e85d commit 686d908
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 10 additions & 6 deletions packages/icon/src/isComponentGlyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ import { ComponentType, isValidElement, ReactNode } from 'react';

import { LGGlyph } from './types';

type ExtendedComponentType = ComponentType<React.PropsWithChildren<any>> & {
[key: string]: any;
};
type ExtendedComponentType =
| ComponentType<React.PropsWithChildren<any>> & {
[key: string]: any;
};
/**
* Helper type to check if element is a LeafyGreen UI Glyph
* @internal
*/
function isComponentGlyph<P>(
node: {} | null | undefined,
): node is React.ReactElement<P>;
function isComponentGlyph(node: ReactNode): node is LGGlyph.Element;
function isComponentGlyph(
component: ExtendedComponentType,
): component is LGGlyph.Component;
function isComponentGlyph(
child: ReactNode | ExtendedComponentType,
child: ReactNode | ExtendedComponentType | unknown,
): child is LGGlyph.Element | LGGlyph.Component {
// If we're received a rendered component (i.e. ReactNode)
if (isValidElement(child)) {
Expand All @@ -26,12 +30,12 @@ function isComponentGlyph(
);
}

// If we've recieved a component function
// If we've received a component function
return (
child != null &&
typeof child === 'function' &&
'isGlyph' in child &&
child.isGlyph === true
(child as LGGlyph.Component).isGlyph === true
);
}

Expand Down
6 changes: 5 additions & 1 deletion packages/tooltip/src/Tooltip/Tooltip.types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

import { HTMLElementProps } from '@leafygreen-ui/lib';
import {
Align as PopoverAlign,
Expand Down Expand Up @@ -26,7 +28,7 @@ export type Align = typeof Align[keyof typeof Align];
export { Justify };

export interface PopoverFunctionParameters {
align: Align;
align: PopoverAlign;
justify: Justify;
referenceElPos: ElementPosition;
}
Expand Down Expand Up @@ -94,4 +96,6 @@ export type TooltipProps = Omit<
*
*/
baseFontSize?: BaseFontSize;

children?: React.ReactNode;
};

0 comments on commit 686d908

Please sign in to comment.