Carnation is now in early alpha. Read more

Docs
Link

Link

<c.a href="/series/1396">
  <c.span>Breaking Bad</c.span>
</c.a>

The <c.a> component links users to new screens within your app.

Configuration

Web

On the web, by default we will render an <a> element. If you're using a framework like Next.js (opens in a new tab), you can substitute the default-rendered element by passing it to CarnationProvider:

apps/native/pages/_app.tsx
import Link from "next/link";
import { CarnationConfig, CarnationProvider } from "carnation-ds";
 
export default function App({ Component, pageProps }: AppProps) {
  const config: CarnationConfig = {
    link: {
      component: Link,
    },
  };
 
  return (
    <CarnationProvider config={config}>
      <Component {...pageProps} />
    </CarnationProvider>
  );
}

Native

On native, by default we will render a Pressable component that routes via the onPress prop. Follow your navigation library's docs to pass the navigation function to CarnationProvider. The following example uses Expo Router (opens in a new tab):

apps/web/app/_layout.tsx
import { Slot, useRouter } from "expo-router";
import { CarnationConfig, CarnationProvider } from "carnation-ds";
 
export default function Layout() {
  const router = useRouter();
 
  const config: CarnationConfig = {
    link: {
      navigate(href) {
        router.push(href);
      },
    },
  };
 
  return (
    <CarnationProvider config={config}>
      <Slot />
    </CarnationProvider>
  );
}

API Reference

PropTypeDefaultDescription
childrenReactNode | ((state: PressableState) => ReactNode)The rendered children node. Pass a function to render based on the pressed state.
hrefstringThe URL that the hyperlink points to.
target"_blank" | "_parent" | "_top"Where to display the linked URL.
relstringThe relationship of the linked URL.