/** * Hybrid Link Component * Automatically chooses between Tailwind and styled-components based on props. * * Link's underlying Container is `styled(Text)`, so it accepts typography props * (e.g. `fontSize`). `hasStyledProps` does not include typography props, so we * additionally route to the styled-components path when any typography prop is * present — mirroring Text — so font sizing is never silently dropped. */ import * as React from "react"; import Container from "./styles"; // Styled-components version import { LinkTailwind } from "./LinkTailwind"; // Tailwind version import { hasStyledProps } from "@sproutsocial/seeds-react-system-props"; import type { TypeLinkProps } from "./LinkTypes"; const TYPOGRAPHY_KEYS = [ "fontSize", "typeScale", "fontWeight", "textAlign", "lineHeight", "isItalicized", "fontFamily", "fontStyle", ] as const; const hasLinkStyledProps = (props: Record): boolean => hasStyledProps(props) || TYPOGRAPHY_KEYS.some((key) => props[key] !== undefined); const LinkHybrid = React.forwardRef< HTMLAnchorElement | HTMLButtonElement, TypeLinkProps >( ( { href, external, children, disabled, onClick, as, underline = true, qa = {}, ...rest }, ref ) => { if (!href && external) { // eslint-disable-next-line no-console console.warn( "Warning: external prop cannot be set without a href declaration" ); } const type = as || (href ? "a" : "button"); if (hasLinkStyledProps(rest)) { return ( {children} ); } // Use Tailwind version (preferred - better performance) return ( {children} ); } ); LinkHybrid.displayName = "Link"; export default LinkHybrid;