Skip to content

Commit 248556e

Browse files
committed
made the icon size helper a forward ref
1 parent 9d17623 commit 248556e

File tree

1 file changed

+40
-28
lines changed

1 file changed

+40
-28
lines changed
Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
import { css } from "@emotion/css"
2-
import React, { type ComponentPropsWithoutRef } from "react"
2+
import {
3+
type ForwardedRef,
4+
forwardRef,
5+
type ComponentPropsWithRef,
6+
} from "react"
37
import { twMerge } from "tailwind-merge"
48

59
/**
610
* IconSizeHelper helps to set a size for an icon.
711
* It can size spans, svgs and spans with svgs inside.
812
*/
9-
export function IconSizeHelper({
10-
size,
11-
children,
12-
style,
13-
className,
14-
...props
15-
}: {
16-
size?: number | string
17-
} & ComponentPropsWithoutRef<"div">) {
18-
const sizeProp = typeof size === "number" ? `${size}px` : size
13+
const IconSizeHelper = forwardRef(
14+
(
15+
{
16+
size,
17+
children,
18+
style,
19+
className,
20+
...props
21+
}: {
22+
size?: number | string
23+
} & ComponentPropsWithRef<"div">,
24+
ref: ForwardedRef<HTMLDivElement>,
25+
) => {
26+
const sizeProp = typeof size === "number" ? `${size}px` : size
1927

20-
const centerHelperClass = css`
28+
const centerHelperClass = css`
2129
span {
2230
display: inline-flex;
2331
}
2432
`
2533

26-
const sizeHelperClass = css`
34+
const sizeHelperClass = css`
2735
width: ${sizeProp};
2836
height: ${sizeProp};
2937
@@ -35,18 +43,22 @@ export function IconSizeHelper({
3543
}
3644
`
3745

38-
return (
39-
<div
40-
className={twMerge(
41-
centerHelperClass,
42-
sizeProp != null ? sizeHelperClass : undefined,
43-
"inline-flex flex-none items-center justify-center",
44-
className,
45-
)}
46-
style={style}
47-
{...props}
48-
>
49-
{children}
50-
</div>
51-
)
52-
}
46+
return (
47+
<div
48+
className={twMerge(
49+
centerHelperClass,
50+
sizeProp != null ? sizeHelperClass : undefined,
51+
"inline-flex flex-none items-center justify-center",
52+
className,
53+
)}
54+
style={style}
55+
ref={ref}
56+
{...props}
57+
>
58+
{children}
59+
</div>
60+
)
61+
},
62+
)
63+
64+
export { IconSizeHelper }

0 commit comments

Comments
 (0)