Skip to content

Commit

Permalink
Add ref forwarding and add util exports (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomi-msft authored Sep 18, 2023
1 parent efc3112 commit f217d9d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/react-icons/convert-font.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async function processFiles(src, dest) {
indexContents.push('export { FluentIconsProps } from \'../utils/FluentIconsProps.types\'');
indexContents.push('export { default as wrapIcon } from \'../utils/wrapIcon\'');
indexContents.push('export { default as bundleIcon } from \'../utils/bundleIcon\'');
indexContents.push('export { createFluentFontIcon } from \'../utils/fonts/createFluentFontIcon\'');
indexContents.push('export * from \'../utils/useIconState\'');
indexContents.push('export * from \'../utils/constants\'');
indexContents.push('export { IconDirectionContextProvider, useIconContext } from \'../contexts/index\'');
Expand Down
1 change: 1 addition & 0 deletions packages/react-icons/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function processFiles(src, dest) {
indexContents.push('export { FluentIconsProps } from \'./utils/FluentIconsProps.types\'');
indexContents.push('export { default as wrapIcon } from \'./utils/wrapIcon\'');
indexContents.push('export { default as bundleIcon } from \'./utils/bundleIcon\'');
indexContents.push('export { createFluentIcon } from \'./utils/createFluentIcon\'');
indexContents.push('export * from \'./utils/useIconState\'');
indexContents.push('export * from \'./utils/constants\'');
indexContents.push('export { IconDirectionContextProvider, useIconContext } from \'./contexts/index\'');
Expand Down
12 changes: 8 additions & 4 deletions packages/react-icons/src/utils/wrapIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import * as React from "react";
import { FluentIconsProps } from "./FluentIconsProps.types";
import { useIconState } from "./useIconState";
import { CreateFluentIconOptions, FluentIcon } from "./createFluentIcon";

const wrapIcon = (Icon: (iconProps: FluentIconsProps) => JSX.Element, displayName?: string) => {
const WrappedIcon = (props: FluentIconsProps) => {
const state = useIconState(props);
const wrapIcon = (Icon: (iconProps: FluentIconsProps) => JSX.Element, displayName?: string, options?: CreateFluentIconOptions) => {
const WrappedIcon = React.forwardRef((props: FluentIconsProps, ref: React.Ref<HTMLElement>) => {
const state = {
...useIconState(props, { flipInRtl: options?.flipInRtl }),
ref
};
return <Icon {...state} />
}
}) as FluentIcon
WrappedIcon.displayName = displayName;
return WrappedIcon;
}
Expand Down

0 comments on commit f217d9d

Please sign in to comment.