1
- import React , { useCallback } from 'react' ;
2
1
import styled from 'styled-components' ;
2
+ import { KnownTarget } from 'styled-components/dist/types' ;
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 KnownTarget = 'a' > = 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-flex' ,
18
+ width : 'fit-content' ,
20
19
21
- '&:hover' : {
20
+ '&& :hover' : {
22
21
textDecorationLine : 'underline' ,
23
22
textUnderlineOffset : '2px' ,
24
23
color : props . $hoverColor ,
25
24
} ,
26
- '&:focus-visible' : {
25
+ '&& :focus-visible' : {
27
26
borderRadius : Radius . radius4 ,
28
27
outline : `2px solid ${ Colors . white } ` ,
29
28
outlineOffset : '2px' ,
@@ -39,24 +38,14 @@ const getHoverColor = (color: Colors | undefined) => {
39
38
}
40
39
} ;
41
40
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
- ) ;
41
+ export const Link = < T extends KnownTarget = 'a' > ( {
42
+ as = 'a' as T ,
43
+ children,
44
+ color,
45
+ ...props
46
+ } : LinkProps < T > ) => {
53
47
return (
54
- < StyledText
55
- onClick = { navigate }
56
- as = { 'button' }
57
- color = { color }
58
- $hoverColor = { getHoverColor ( color ) }
59
- { ...props } >
48
+ < StyledText forwardedAs = { as } color = { color } $hoverColor = { getHoverColor ( color ) } { ...props } >
60
49
{ children }
61
50
</ StyledText >
62
51
) ;
0 commit comments