1
1
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"
3
7
import { twMerge } from "tailwind-merge"
4
8
5
9
/**
6
10
* IconSizeHelper helps to set a size for an icon.
7
11
* It can size spans, svgs and spans with svgs inside.
8
12
*/
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
19
27
20
- const centerHelperClass = css `
28
+ const centerHelperClass = css `
21
29
span {
22
30
display : inline-flex;
23
31
}
24
32
`
25
33
26
- const sizeHelperClass = css `
34
+ const sizeHelperClass = css `
27
35
width : ${ sizeProp } ;
28
36
height : ${ sizeProp } ;
29
37
@@ -35,18 +43,22 @@ export function IconSizeHelper({
35
43
}
36
44
`
37
45
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