forked from hashicorp/dev-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
97 lines (89 loc) · 2.17 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import classNames from 'classnames'
import Link from 'components/link'
import { ToastColor, developmentToast } from 'components/toast'
import {
type StandaloneLinkContentsProps,
type StandaloneLinkProps,
} from './types'
import s from './standalone-link.module.css'
const DEFAULT_COLOR_VARIANT = 'primary'
const DEFAULT_SIZE_VARIANT = 'medium'
const StandaloneLinkContents = ({
className,
color,
icon,
iconPosition,
inheritColor = false,
size = DEFAULT_SIZE_VARIANT,
text,
textClassName,
}: StandaloneLinkContentsProps) => {
if (color && inheritColor) {
developmentToast({
color: ToastColor.warning,
title: 'Warning in `StandaloneLinkContents`',
description:
'`StandaloneLinkContents` does not accept both `color` and `inheritColor`; `inheritColor` takes precedence.',
})
}
const containerClasses = classNames(
s.standaloneLinkContents,
s[size],
!inheritColor && s[color ?? DEFAULT_COLOR_VARIANT],
className
)
const textClasses = classNames(s.text, textClassName)
return (
<div className={containerClasses}>
{iconPosition === 'leading' && icon}
<span className={textClasses}>{text}</span>
{iconPosition === 'trailing' && icon}
</div>
)
}
const StandaloneLink = ({
ariaLabel,
className,
color = DEFAULT_COLOR_VARIANT,
'data-heap-track': dataHeapTrack,
download,
href,
icon,
iconPosition,
onClick,
opensInNewTab = false,
size = DEFAULT_SIZE_VARIANT,
text,
textClassName,
}: StandaloneLinkProps) => {
const classes = classNames(s.standaloneLink, s[color], className)
const rel = opensInNewTab ? 'noreferrer noopener' : undefined
return (
<Link
aria-label={ariaLabel}
className={classes}
data-heap-track={`standalone-link ${dataHeapTrack ?? ''}`}
download={download}
href={href}
onClick={onClick}
rel={rel}
opensInNewTab={opensInNewTab}
>
<StandaloneLinkContents
icon={icon}
iconPosition={iconPosition}
inheritColor
size={size}
text={text}
textClassName={textClassName}
/>
</Link>
)
}
export type { StandaloneLinkContentsProps, StandaloneLinkProps }
export { StandaloneLinkContents }
export default StandaloneLink