-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
46 lines (40 loc) · 1.42 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
import { Link as UtrechtLink } from '@utrecht/component-library-react';
import { UtrechtIconArrow, UtrechtIconChevronLeft } from '@utrecht/web-component-library-react';
import classnames from 'classnames/bind';
import React, { ComponentType, ForwardedRef, forwardRef, PropsWithChildren } from 'react';
import styles from './index.module.scss';
const css = classnames.bind(styles);
interface AdvancedLinkProps extends React.ComponentProps<typeof UtrechtLink> {
color?: 'red';
icon?: 'arrow' | 'chevronLeft';
Link?: ComponentType<any>;
}
const mappedIcons = {
arrow: UtrechtIconArrow,
chevronLeft: UtrechtIconChevronLeft,
};
export const AdvancedLink = forwardRef(
(
{ href, children, icon, color, Link = UtrechtLink, ...restProps }: PropsWithChildren<AdvancedLinkProps>,
ref: ForwardedRef<HTMLAnchorElement>,
) => {
const Icon = mappedIcons[icon as keyof typeof mappedIcons];
const DefaultLinkComponent = Link;
const LinkComponent = Link || DefaultLinkComponent;
return (
<LinkComponent
ref={ref}
className={css('utrecht-advanced-link', {
'utrecht-advanced-link--with-icon': icon,
'utrecht-advanced-link--color-red': color === 'red',
})}
href={href}
{...restProps}
>
{icon && <Icon className={css('utrecht-advanced-link__icon')} />}
{children}
</LinkComponent>
);
},
);
AdvancedLink.displayName = 'AdvancedLink';