|
1 | 1 | import { |
2 | 2 | ComponentType, |
3 | 3 | ButtonHTMLAttributes, |
4 | | - forwardRef, |
5 | | - PropsWithChildren, |
6 | 4 | AnchorHTMLAttributes, |
7 | 5 | } from 'react'; |
8 | 6 | import { styled, DefaultTheme } from 'styled-components'; |
@@ -30,52 +28,51 @@ type BaseProps = { |
30 | 28 | }; |
31 | 29 |
|
32 | 30 | export type IconButtonProps = BaseProps & |
33 | | - ButtonHTMLAttributes<HTMLButtonElement>; |
| 31 | + ButtonHTMLAttributes<HTMLButtonElement> & { |
| 32 | + ref?: React.Ref<HTMLButtonElement | null>; |
| 33 | + }; |
34 | 34 |
|
35 | | -export const IconButton = forwardRef< |
36 | | - HTMLButtonElement, |
37 | | - PropsWithChildren<IconButtonProps> |
38 | | ->(({ variant, children, color, ...props }, ref) => { |
| 35 | +export const IconButton: React.FC<React.PropsWithChildren<IconButtonProps>> = ({ |
| 36 | + variant = IconButtonVariant.Simple, |
| 37 | + color = 'inherit', |
| 38 | + size = '1em', |
| 39 | + children, |
| 40 | + ref, |
| 41 | + ...props |
| 42 | +}) => { |
39 | 43 | const Comp = ComponentMap.get(variant!) ?? SimpleIconButton; |
40 | 44 |
|
41 | 45 | return ( |
42 | | - <Comp ref={ref} color={color!} {...props}> |
| 46 | + <Comp ref={ref} color={color} size={size} {...props}> |
43 | 47 | {children} |
44 | 48 | </Comp> |
45 | 49 | ); |
46 | | -}); |
47 | | - |
48 | | -IconButton.displayName = 'IconButton'; |
49 | | - |
50 | | -const defaultProps = { |
51 | | - variant: IconButtonVariant.Simple, |
52 | | - color: 'inherit', |
53 | | - size: '1em', |
54 | | -} as IconButtonProps; |
55 | | - |
56 | | -IconButton.defaultProps = defaultProps; |
| 50 | +}; |
57 | 51 |
|
58 | 52 | export type IconButtonLinkProps = BaseProps & |
59 | 53 | AnchorHTMLAttributes<HTMLAnchorElement> & { |
60 | 54 | href: string; |
| 55 | + ref?: React.Ref<HTMLAnchorElement | null>; |
61 | 56 | }; |
62 | 57 |
|
63 | | -export const IconButtonLink = forwardRef< |
64 | | - HTMLAnchorElement, |
65 | | - PropsWithChildren<IconButtonLinkProps> |
66 | | ->(({ variant, children, color, ...props }, ref) => { |
| 58 | +export const IconButtonLink: React.FC< |
| 59 | + React.PropsWithChildren<IconButtonLinkProps> |
| 60 | +> = ({ |
| 61 | + variant = IconButtonVariant.Simple, |
| 62 | + color = 'inherit', |
| 63 | + size = '1em', |
| 64 | + ref, |
| 65 | + children, |
| 66 | + ...props |
| 67 | +}) => { |
67 | 68 | const Comp = ComponentMap.get(variant ?? IconButtonVariant.Simple)!; |
68 | 69 |
|
69 | 70 | return ( |
70 | | - <Comp ref={ref} color={color!} as='a' {...props}> |
| 71 | + <Comp ref={ref} color={color!} size={size} as='a' {...props}> |
71 | 72 | {children} |
72 | 73 | </Comp> |
73 | 74 | ); |
74 | | -}); |
75 | | - |
76 | | -IconButtonLink.displayName = 'IconButtonLink'; |
77 | | - |
78 | | -IconButtonLink.defaultProps = defaultProps as IconButtonLinkProps; |
| 75 | +}; |
79 | 76 |
|
80 | 77 | interface ButtonBaseProps { |
81 | 78 | size?: string; |
|
0 commit comments