diff --git a/packages/react-icons/src/utils/FluentIconsProps.types.ts b/packages/react-icons/src/utils/FluentIconsProps.types.ts index 60c138075a..77f89de433 100644 --- a/packages/react-icons/src/utils/FluentIconsProps.types.ts +++ b/packages/react-icons/src/utils/FluentIconsProps.types.ts @@ -1,9 +1,14 @@ import * as React from "react"; -export type FluentIconsProps | React.HTMLAttributes) = React.SVGAttributes> -= TBaseAttributes & React.RefAttributes & { - primaryFill?: string - className?: string - filled?: boolean - title?: string -} \ No newline at end of file +export type FluentIconsProps< + TBaseAttributes extends + | React.SVGAttributes + | React.HTMLAttributes = React.SVGAttributes, + TRefType extends HTMLElement | SVGSVGElement = SVGSVGElement +> = TBaseAttributes & + React.RefAttributes & { + primaryFill?: string; + className?: string; + filled?: boolean; + title?: string; + }; diff --git a/packages/react-icons/src/utils/fonts/createFluentFontIcon.tsx b/packages/react-icons/src/utils/fonts/createFluentFontIcon.tsx index a594b406fa..b0283c323a 100644 --- a/packages/react-icons/src/utils/fonts/createFluentFontIcon.tsx +++ b/packages/react-icons/src/utils/fonts/createFluentFontIcon.tsx @@ -76,12 +76,12 @@ export type CreateFluentFontIconOptions = { flipInRtl?: boolean; } -export function createFluentFontIcon(displayName: string, codepoint: string, font: FontFile, fontSize?: number, options?: CreateFluentFontIconOptions): React.FC>> & { codepoint: string} { - const Component: React.FC>> & { codepoint: string} = (props) => { +export function createFluentFontIcon(displayName: string, codepoint: string, font: FontFile, fontSize?: number, options?: CreateFluentFontIconOptions): React.FC, HTMLElement>> & { codepoint: string} { + const Component: React.FC, HTMLElement>> & { codepoint: string} = (props) => { useStaticStyles(); const styles = useRootStyles(); const className = mergeClasses(styles.root, styles[font], props.className); - const state = useIconState>({...props, className}, { flipInRtl: options?.flipInRtl }); + const state = useIconState, HTMLElement>({...props, className}, { flipInRtl: options?.flipInRtl }); // We want to keep the same API surface as the SVG icons, so translate `primaryFill` to `color` diff --git a/packages/react-icons/src/utils/useIconState.tsx b/packages/react-icons/src/utils/useIconState.tsx index 8b29de49d5..6e6640f818 100644 --- a/packages/react-icons/src/utils/useIconState.tsx +++ b/packages/react-icons/src/utils/useIconState.tsx @@ -20,13 +20,21 @@ export type UseIconStateOptions = { flipInRtl?: boolean; } -export const useIconState = | React.HTMLAttributes) = React.SVGAttributes>(props: FluentIconsProps, options?: UseIconStateOptions): Omit, 'primaryFill'> => { +export const useIconState = < + TBaseAttributes extends + | React.SVGAttributes + | React.HTMLAttributes = React.SVGAttributes, + TRefType extends HTMLElement | SVGSVGElement = SVGSVGElement, +>( + props: FluentIconsProps, + options?: UseIconStateOptions, +): Omit, 'primaryFill'> => { const { title, primaryFill = "currentColor", ...rest } = props; const state = { ...rest, title: undefined, fill: primaryFill - } as Omit, 'primaryFill'>; + } as Omit, 'primaryFill'>; const styles = useRootStyles(); const iconContext = useIconContext(); diff --git a/packages/react-icons/src/utils/wrapIcon.tsx b/packages/react-icons/src/utils/wrapIcon.tsx index 18c3301e28..54e154326a 100644 --- a/packages/react-icons/src/utils/wrapIcon.tsx +++ b/packages/react-icons/src/utils/wrapIcon.tsx @@ -4,7 +4,7 @@ import { useIconState } from "./useIconState"; import { CreateFluentIconOptions, FluentIcon } from "./createFluentIcon"; const wrapIcon = (Icon: (iconProps: FluentIconsProps) => JSX.Element, displayName?: string, options?: CreateFluentIconOptions) => { - const WrappedIcon = React.forwardRef((props: FluentIconsProps, ref: React.Ref) => { + const WrappedIcon = React.forwardRef((props: FluentIconsProps, ref: FluentIconsProps["ref"]) => { const state = { ...useIconState(props, { flipInRtl: options?.flipInRtl }), ref @@ -14,5 +14,6 @@ const wrapIcon = (Icon: (iconProps: FluentIconsProps) => JSX.Element, displayNam WrappedIcon.displayName = displayName; return WrappedIcon; } + export default wrapIcon; \ No newline at end of file