All files / components/ButtonsAndLinks/Route Route.tsx

100% Statements 5/5
100% Branches 23/23
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                    116x                           774x               774x   381x                                 393x                                  
import Link, { LinkProps } from 'next/link'
import { buttonsAndLinksService } from '../../../services/buttonsAndLinks/buttonsAndLinks'
import { CommonProps } from '../../../types/buttonLinkCommonProps'
import { InnerContent } from '../InnerContent/InnerContent'
 
type RouteProps = CommonProps & LinkProps & React.AnchorHTMLAttributes<HTMLAnchorElement>
 
/**
 * Link component
 */
export const Route: React.FC<RouteProps> = ({
	kind = 'primary',
	disabled = false,
	dimOpacityWhenDisabled = true,
	icon,
	datacy,
	iconSlot = 'start',
	loading = false,
	className = '',
	children,
	href,
	isColoredTertiary = false,
	...props
}) => {
	const calculatedProps = buttonsAndLinksService({
		disabled,
		isColoredTertiary,
		loading,
		dimOpacityWhenDisabled,
		className,
	})
 
	if (kind !== 'tertiary') {
		/* Primary or Secondary as link */
		return (
			<Link
				datacy={datacy}
				href={calculatedProps.disabled ? '#' : href}
				tabIndex={calculatedProps.disabled ? -1 : 0}
				className={`${calculatedProps.twButtonBaseClasses} ${
					kind === 'primary' ? calculatedProps.twPrimaryClasses : calculatedProps.twSecondaryClasses
				}${calculatedProps.disabled ? ' pointer-events-none' : ''}${calculatedProps.className}`}
				{...props}
			>
				<InnerContent icon={icon} iconSlot={iconSlot} loading={loading}>
					{children}
				</InnerContent>
			</Link>
		)
	} else {
		/* Tertiary (link style) as link */
		return (
			<Link
				datacy={datacy}
				href={calculatedProps.disabled ? '#' : href}
				tabIndex={calculatedProps.disabled ? -1 : 0}
				className={`${calculatedProps.twLinkBaseClasses} w-max ${calculatedProps.twDisabledTertiary}${
					calculatedProps.disabled ? ' pointer-events-none' : ''
				}${calculatedProps.className}`}
				{...props}
			>
				<InnerContent icon={icon} iconSlot={iconSlot} loading={loading}>
					{children}
				</InnerContent>
			</Link>
		)
	}
}