Skip to content

Commit

Permalink
added explicitly declared return type to createIcon
Browse files Browse the repository at this point in the history
also added explicit types to the call to `React.forwardRef`
within `createIcon`
  • Loading branch information
telamonian committed Oct 9, 2019
1 parent 4c2b6a9 commit 9a524d2
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions packages/ui-components/src/icon/jlicon.tsx
@@ -1,12 +1,17 @@
import React from 'react';
import React, {
ForwardRefExoticComponent,
PropsWithoutRef,
RefAttributes,
RefObject
} from 'react';
import { classes } from 'typestyle';
import { iconStyle, IIconStyle } from '../style/icon';

export function createIcon(
svgname: string,
svgstr: string,
debug: boolean = false
) {
): JLIcon.IComponent {
function resolveSvg(svgstr: string, title?: string): HTMLElement | null {
const svgElement = new DOMParser().parseFromString(svgstr, 'image/svg+xml')
.documentElement;
Expand All @@ -33,8 +38,11 @@ export function createIcon(
}
}

const _JLIcon = React.forwardRef(
(props: JLIcon.IProps, ref: React.RefObject<HTMLDivElement>) => {
const JLIcon: JLIcon.IComponent = React.forwardRef<
HTMLDivElement,
JLIcon.IProps
>(
(props: JLIcon.IProps, ref: RefObject<HTMLDivElement>): JSX.Element => {
const { className, title, tag = 'div', ...propsStyle } = props;
const Tag = tag;
const classNames = classes(
Expand All @@ -59,11 +67,6 @@ export function createIcon(
}
);

// widen type to include .element
let JLIcon: typeof _JLIcon & {
element: (props: JLIcon.IProps) => HTMLElement;
} = _JLIcon as any;

JLIcon.element = ({
className,
title,
Expand Down Expand Up @@ -114,6 +117,13 @@ export namespace JLIcon {
*/
title?: string;
}

export interface IComponent
extends ForwardRefExoticComponent<
PropsWithoutRef<IProps> & RefAttributes<HTMLDivElement>
> {
element?: (props: IProps) => HTMLElement;
}
}

namespace Private {
Expand Down

0 comments on commit 9a524d2

Please sign in to comment.