Skip to content

Latest commit

 

History

History
164 lines (111 loc) · 5.05 KB

link.md

File metadata and controls

164 lines (111 loc) · 5.05 KB

Link

ui.link · parts: Link · elements: <a>

Purpose

Link renders a semantic anchor for navigation. Use Button for actions.

Notes

No additional notes for Link yet.

Link renders an anchor; External opens a new tab with rel=noopener noreferrer.

Props

Canonical (templ, Jinja2, MiniJinja) React / Solid HTML (Svelte, Vue, WC) Type Default Kind Description
Href href href string — passthrough attr
Target target target string — prop explicit target; External implies _blank
Rel rel rel string — prop explicit rel; External defaults to noopener noreferrer
External external external boolean — prop opens in a new tab with safe rel defaults
Download download download string — passthrough attr
AriaCurrent aria-current aria-current string — passthrough attr
AriaLabel aria-label aria-label string — passthrough attr

Also accepts: class (className in React), extra attributes (rest props in UI frameworks, Attrs in templ/Jinja2/MiniJinja, attrs in Twig/Latte; caller wins), children.

Variants

No variants: the primitive ships no visual classes; style it with token classes via class.

Children

Accepts children (default slot / children / { children... } / trusted HTML string in Twig, Latte, Jinja2, MiniJinja — see runtimes). Void tags selected via tag render no children.

ARIA

  • Computed/forwarded: aria-current, aria-label (omitted when empty).
  • Typed ARIA props: aria-current, aria-label — static values only.

Classes escape hatch

Compose the part's classes without rendering it (custom root element, no asChild outside React):

Runtime Helper
React / Solid / Vue / Svelte / WC linkClasses({ ... }) from link/link.shared.ts
templ link.LinkClasses(link.LinkProps{...})
Twig ui8kit_classes('linkClasses', { class: '…' })
Latte \UI8Kit\Latte\Classes::linkClasses(['class' => '…'])
Jinja2 link_classes(p)
MiniJinja link_classes(p) (registered by ui8kit_minijinja::register)

Rendered DOM per state

Canonical renderer output (children = Content); all 10 runtimes are parity-tested to produce this DOM.

State Props HTML
defaults — <a>Content</a>
basic {"Href":"/a"} <a href="/a">Content</a>
external {"Href":"https://e.com","External":true} <a href="https://e.com" target="_blank" rel="noopener noreferrer">Content</a>
explicit {"Href":"/b","Target":"_self","Rel":"nofollow"} <a href="/b" target="_self" rel="nofollow">Content</a>
blank {"Href":"/c","Target":"_blank"} <a href="/c" target="_blank" rel="noopener noreferrer">Content</a>
current {"Href":"/d","AriaCurrent":"page","Download":"f.txt"} <a href="/d" download="f.txt" aria-current="page">Content</a>
External {"External":true} <a target="_blank" rel="noopener noreferrer">Content</a>

Usage

Fixture basic ({"Href":"/a"}) — every snippet renders:

<a href="/a">Content</a>

React (runtime notes)

import { Link } from "./ui/link/link";

<Link href="/a">Content</Link>

Vue 3 (runtime notes)

<script setup lang="ts">
import Link from "./ui/link/Link.vue";
</script>

<template>
  <Link href="/a">Content</Link>
</template>

Svelte 5 (runtime notes)

<script lang="ts">
  import Link from "./ui/link/Link.svelte";
</script>

<Link href="/a">Content</Link>

SolidJS (runtime notes)

import { Link } from "./ui/link/link.solid";

<Link href="/a">Content</Link>

Web Components (runtime notes)

import { renderLink } from "./ui/link/link.wc";

document.body.append(renderLink({ href: "/a" }, "Content"));

Go templ (runtime notes)

import "github.com/ui8kit/codegen/generated/templ/ui/link"

@link.Link(link.LinkProps{Href: "/a"}) {
	Content
}

Twig (runtime notes)

{% include 'link/Link.html.twig' with { href: '/a', children: 'Content' } only %}

Latte (runtime notes)

{include 'link/Link.latte', href: '/a', children: 'Content'}

Jinja2 (runtime notes)

{% with p = {'Href': '/a'}, children = 'Content' %}{% include 'ui/link/link.html.j2' %}{% endwith %}

MiniJinja (Rust) (runtime notes)

{% import 'ui8kit.html' as ui %}
{{ ui.link({'Href': '/a'}, children='Content') }}

Rules: contract · Index: docs