-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathcomponent-map.tsx
85 lines (78 loc) · 2.34 KB
/
component-map.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
import Link from '@docusaurus/Link'
import { forwardRef, ReactNode, MouseEvent } from 'react'
interface CommonProps {
children: ReactNode
className?: string
ref?: React.Ref<any>
}
interface ButtonProps extends CommonProps {
onClick?: (event: MouseEvent<HTMLButtonElement>) => void
ariaLabel?: string
[key: string]: any
}
interface LinkProps extends CommonProps {
href?: string
target?: string
to?: string
[key: string]: any
}
interface DivProps extends CommonProps {
onClick?: (event: MouseEvent<HTMLDivElement>) => void
[key: string]: any
}
interface SectionProps extends CommonProps {
[key: string]: any
}
interface AsideProps extends CommonProps {
[key: string]: any
}
export const linkComponentMap = {
// eslint-disable-next-line react/display-name
['button']: forwardRef<HTMLButtonElement, ButtonProps>(
({ children, onClick, ariaLabel, ...props }, ref) => (
<button onClick={onClick} ref={ref} {...props}>
{children}
</button>
)
),
// eslint-disable-next-line react/display-name
['link']: forwardRef<HTMLAnchorElement, LinkProps>(
({ children, href, target, className, ...props }, ref) => (
<Link to={href} target={target} className={className} {...props} ref={ref}>
{children}
</Link>
)
),
// eslint-disable-next-line react/display-name
['a']: forwardRef<HTMLAnchorElement, LinkProps>(
({ children, href, target, className, ...props }, ref) => (
<Link href={href} target={target} className={className} ref={ref} {...props}>
{children}
</Link>
)
),
// eslint-disable-next-line react/display-name
['div']: forwardRef<HTMLDivElement, DivProps>(
({ children, onClick, className, ...props }, ref) => (
<div className={className} onClick={onClick} ref={ref} {...props}>
{children}
</div>
)
),
// eslint-disable-next-line react/display-name
['section']: forwardRef<HTMLElement, SectionProps>(
({ children, onClick, className, ...props }, ref) => (
<section className={className} ref={ref} {...props}>
{children}
</section>
)
),
// eslint-disable-next-line react/display-name
['aside']: forwardRef<HTMLElement, AsideProps>(
({ children, onClick, className, ...props }, ref) => (
<aside className={className} ref={ref} {...props}>
{children}
</aside>
)
),
}