-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
link.tsx
51 lines (47 loc) · 1.12 KB
/
link.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {
chakra,
forwardRef,
omitThemingProps,
ThemingProps,
useStyleConfig,
HTMLChakraProps,
} from "@chakra-ui/system"
import { cx, __DEV__ } from "@chakra-ui/utils"
import * as React from "react"
export interface LinkProps extends HTMLChakraProps<"a">, ThemingProps<"Link"> {
/**
* If `true`, the link will open in new tab
*/
isExternal?: boolean
}
/**
* Links are accessible elements used primarily for navigation.
*
* It integrates well with other routing libraries like
* React Router, Reach Router and Next.js Link.
*
* @example
*
* ```jsx
* <Link as={ReactRouterLink} to="/home">Home</Link>
* ```
*
* @see Docs https://chakra-ui.com/link
*/
export const Link = forwardRef<LinkProps, "a">((props, ref) => {
const styles = useStyleConfig("Link", props)
const { className, isExternal, ...rest } = omitThemingProps(props)
return (
<chakra.a
target={isExternal ? "_blank" : undefined}
rel={isExternal ? "noopener" : undefined}
ref={ref}
className={cx("chakra-link", className)}
{...rest}
__css={styles}
/>
)
})
if (__DEV__) {
Link.displayName = "Link"
}