1
- import React , { useCallback } from 'react' ;
1
+ import React from 'react' ;
2
2
import styled from 'styled-components' ;
3
3
4
4
import { Colors , Radius } from '../../foundations' ;
5
- import { useHistory } from '../../history' ;
6
- import { RoutePath } from '../../routes' ;
7
- import { buttonReset } from '../../styles' ;
8
5
import { Text , TextProps } from './Text' ;
9
6
10
- export interface LinkProps extends Omit < TextProps < 'button' > , 'color' > {
11
- to : RoutePath ;
12
- color ?: Colors ;
13
- }
7
+ export type LinkProps < T extends React . ElementType > = TextProps < T > & {
8
+ onClick ?: ( e : React . MouseEvent < HTMLAnchorElement > ) => void ;
9
+ } ;
14
10
15
11
const StyledText = styled ( Text ) < {
16
12
$hoverColor : Colors | undefined ;
17
13
} > ( ( props ) => ( {
18
- ...buttonReset ,
19
14
background : 'transparent' ,
15
+ cursor : 'default' ,
16
+ textDecoration : 'none' ,
17
+ display : 'inline' ,
20
18
21
- '&:hover' : {
19
+ '&& :hover' : {
22
20
textDecorationLine : 'underline' ,
23
21
textUnderlineOffset : '2px' ,
24
22
color : props . $hoverColor ,
25
23
} ,
26
- '&:focus-visible' : {
24
+ '&& :focus-visible' : {
27
25
borderRadius : Radius . radius4 ,
28
26
outline : `2px solid ${ Colors . white } ` ,
29
27
outlineOffset : '2px' ,
@@ -39,25 +37,8 @@ const getHoverColor = (color: Colors | undefined) => {
39
37
}
40
38
} ;
41
39
42
- export const Link = ( { to, children, color, onClick, ...props } : LinkProps ) => {
43
- const history = useHistory ( ) ;
44
- const navigate = useCallback (
45
- ( e : React . MouseEvent < HTMLButtonElement > ) => {
46
- if ( onClick ) {
47
- onClick ( e ) ;
48
- }
49
- return history . push ( to ) ;
50
- } ,
51
- [ history , to , onClick ] ,
52
- ) ;
40
+ export const Link = < T extends React . ElementType = 'a' > ( { as, color, ...props } : LinkProps < T > ) => {
53
41
return (
54
- < StyledText
55
- onClick = { navigate }
56
- as = { 'button' }
57
- color = { color }
58
- $hoverColor = { getHoverColor ( color ) }
59
- { ...props } >
60
- { children }
61
- </ StyledText >
42
+ < StyledText forwardedAs = { as } color = { color } $hoverColor = { getHoverColor ( color ) } { ...props } />
62
43
) ;
63
44
} ;
0 commit comments