Add render prop to Link

Signed-off-by: Charles de Dreuille <charles.dedreuille@gmail.com>
This commit is contained in:
Charles de Dreuille
2025-03-17 06:38:50 +00:00
parent d25e8e7c15
commit 7909300e75
2 changed files with 20 additions and 16 deletions
+19 -16
View File
@@ -28,28 +28,31 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
weight = 'regular',
style,
className,
render,
...restProps
} = props;
// Get the responsive values for the variant and weight
const responsiveVariant = useResponsiveValue(variant);
const responsiveWeight = useResponsiveValue(weight);
return (
<a
ref={ref}
className={clsx(
'canon-Link',
responsiveVariant && `canon-Link--variant-${responsiveVariant}`,
responsiveWeight && `canon-Link--weight-${responsiveWeight}`,
className,
)}
style={style}
{...restProps}
>
{children}
</a>
);
const linkProps = {
ref,
className: clsx(
'canon-Link',
responsiveVariant && `canon-Link--variant-${responsiveVariant}`,
responsiveWeight && `canon-Link--weight-${responsiveWeight}`,
className,
),
style,
children,
...restProps,
};
if (render) {
return render(linkProps);
}
return <a {...linkProps} />;
});
Link.displayName = 'Link';
@@ -30,4 +30,5 @@ export interface LinkProps
weight?: 'regular' | 'bold' | Partial<Record<Breakpoint, 'regular' | 'bold'>>;
className?: string;
style?: CSSProperties;
render?: (props: Omit<LinkProps, 'render'>) => ReactNode;
}