Kit Link
UI8Kit 3 Link primitive (unstyled), from @ui8kit/registry
Install
npx ui8kit add kit-linkPulls in: utils
Preview
No static preview for this item: it needs content or a parent that this page cannot supply. The code is below.
Code
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework svelte --dir src --registry-url https://registry.buildy.tw/svelte --strict-cdnnpx ui8kit add kit-link<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Link renders an anchor; External opens a new tab with rel=noopener noreferrer.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
export type LinkProps = {
target?: string;
rel?: string;
external?: boolean;
class?: string;
children?: Snippet;
[key: string]: unknown;
};
</script>
<script lang="ts">
import { linkClasses } from "./link.shared";
import { eqStr, isSetStr, orUndef, safeRest } from "../../utils/expr";
let {
target,
rel,
external,
class: className,
children,
...rawRest
}: LinkProps = $props();
const rest = $derived(safeRest(rawRest, { blank: ["href", "download", "aria-current", "aria-label"] }));
const cls = $derived(linkClasses({ className }));
const targetValue = $derived((isSetStr(target) ? target : (external ? "_blank" : "")));
const relValue = $derived((isSetStr(rel) ? rel : ((external || eqStr(targetValue, "_blank")) ? "noopener noreferrer" : "")));
</script>
<a {...(cls ? { class: cls } : {})} target={orUndef(targetValue)} rel={orUndef(relValue)} {...rest}>
{@render children?.()}
</a>
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.link — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Link renders an anchor; External opens a new tab with rel=noopener noreferrer. */
export type LinkBaseProps = {
target?: string;
rel?: string;
external?: boolean;
};
export type LinkClassesInput = {
className?: string;
};
/** Compose Link classes without rendering — the cross-runtime `asChild` substitute. */
export function linkClasses(input: LinkClassesInput = {}): string {
return cn(input.className);
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework react --dir src --registry-url https://registry.buildy.tw/react --strict-cdnnpx ui8kit add kit-link// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.link — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Link renders an anchor; External opens a new tab with rel=noopener noreferrer. */
export type LinkBaseProps = {
target?: string;
rel?: string;
external?: boolean;
};
export type LinkClassesInput = {
className?: string;
};
/** Compose Link classes without rendering — the cross-runtime `asChild` substitute. */
export function linkClasses(input: LinkClassesInput = {}): string {
return cn(input.className);
}
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
* Link renders a semantic anchor for navigation. Use Button for actions.
*/
import { forwardRef, type ReactNode, type AnchorHTMLAttributes } from "react";
import { linkClasses } from "./link.shared";
import { eqStr, isSetStr, orUndef, safeRest } from "../../utils/expr";
/**
* Link renders an anchor; External opens a new tab with rel=noopener noreferrer.
*/
export type LinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "className" | "children" | "target" | "rel" | "external"> & {
target?: string;
rel?: string;
external?: boolean;
className?: string;
children?: ReactNode;
};
export const Link = forwardRef<HTMLAnchorElement, LinkProps>(function Link(
{ target, rel, external, className, children, ...rawRest },
ref
) {
const rest = safeRest(rawRest, { blank: ["href", "download", "aria-current", "aria-label"] });
const cls = linkClasses({ className });
const targetValue = (isSetStr(target) ? target : (external ? "_blank" : ""));
const relValue = (isSetStr(rel) ? rel : ((external || eqStr(targetValue, "_blank")) ? "noopener noreferrer" : ""));
return (
<a ref={ref} className={cls || undefined} target={orUndef(targetValue)} rel={orUndef(relValue)} {...rest}>
{children}
</a>
);
});
Link.displayName = "Link";
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework vue --dir src --registry-url https://registry.buildy.tw/vue --strict-cdnnpx ui8kit add kit-link<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Link renders an anchor; External opens a new tab with rel=noopener noreferrer.
-->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import { linkClasses } from "./link.shared";
import { eqStr, isSetStr, orUndef, safeRest } from "../../utils/expr";
defineOptions({ name: "Link", inheritAttrs: false });
const props = defineProps<{
target?: string;
rel?: string;
external?: boolean;
}>();
const attrs = useAttrs();
const callerClass = computed(() => attrs.class as string | undefined);
const restAttrs = computed(() => {
const { class: _class, ...restEntries } = attrs;
return safeRest(restEntries, { blank: ["href", "download", "aria-current", "aria-label"] });
});
const cls = computed(() => linkClasses({ className: callerClass.value }));
const targetValue = computed(() => (isSetStr(props.target) ? props.target : (props.external ? "_blank" : "")));
const relValue = computed(() => (isSetStr(props.rel) ? props.rel : ((props.external || eqStr(targetValue.value, "_blank")) ? "noopener noreferrer" : "")));
</script>
<template>
<a :class="cls || undefined" :target="orUndef(targetValue)" :rel="orUndef(relValue)" v-bind="restAttrs">
<slot />
</a>
</template>
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.link — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Link renders an anchor; External opens a new tab with rel=noopener noreferrer. */
export type LinkBaseProps = {
target?: string;
rel?: string;
external?: boolean;
};
export type LinkClassesInput = {
className?: string;
};
/** Compose Link classes without rendering — the cross-runtime `asChild` substitute. */
export function linkClasses(input: LinkClassesInput = {}): string {
return cn(input.className);
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework solid --dir src --registry-url https://registry.buildy.tw/solid --strict-cdnnpx ui8kit add kit-link// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.link — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Link renders an anchor; External opens a new tab with rel=noopener noreferrer. */
export type LinkBaseProps = {
target?: string;
rel?: string;
external?: boolean;
};
export type LinkClassesInput = {
className?: string;
};
/** Compose Link classes without rendering — the cross-runtime `asChild` substitute. */
export function linkClasses(input: LinkClassesInput = {}): string {
return cn(input.className);
}
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
* Link renders a semantic anchor for navigation. Use Button for actions.
*/
import { splitProps, type JSX, type Component } from "solid-js";
import { linkClasses } from "./link.shared";
import { eqStr, isSetStr, orUndef, safeRest } from "../../utils/expr";
/**
* Link renders an anchor; External opens a new tab with rel=noopener noreferrer.
*/
export type LinkProps = Omit<JSX.AnchorHTMLAttributes<HTMLAnchorElement>, "class" | "className" | "children" | "target" | "rel" | "external"> & {
target?: string;
rel?: string;
external?: boolean;
class?: string;
className?: string;
children?: JSX.Element;
};
export const Link: Component<LinkProps> = (props) => {
const [local, rest] = splitProps(props, ["target", "rel", "external", "class", "className", "children"]);
const targetValue = () => (isSetStr(local.target) ? local.target : (local.external ? "_blank" : ""));
const relValue = () => (isSetStr(local.rel) ? local.rel : ((local.external || eqStr(targetValue(), "_blank")) ? "noopener noreferrer" : ""));
const cls = () => linkClasses({ className: local.class ?? local.className });
return (
<a {...(cls() ? { class: cls() } : {})} target={orUndef(targetValue())} rel={orUndef(relValue())} {...safeRest(rest, { blank: ["href", "download", "aria-current", "aria-label"] })}>
{local.children}
</a>
);
};
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework templ --dir src --registry-url https://registry.buildy.tw/templ --strict-cdnnpx ui8kit add kit-link// Code generated by @ui8kit/codegen. DO NOT EDIT.
/*
Link renders a semantic anchor for navigation. Use Button for actions.
*/
package link
import (
uiutils "github.com/ui8kit/codegen/generated/templ/utils"
)
// LinkProps configures Link.
type LinkProps struct {
// Class — token class names supplied by the consumer
Class string
Href string
// Target — explicit target; External implies _blank
Target string
// Rel — explicit rel; External defaults to noopener noreferrer
Rel string
// External — opens in a new tab with safe rel defaults
External bool
Download string
AriaCurrent string
AriaLabel string
Attrs templ.Attributes
}
// LinkClasses composes Link classes without rendering —
// the server-composition escape hatch for custom root elements (no asChild in templ).
func LinkClasses(p LinkProps) string {
return uiutils.Cn(p.Class)
}
func linkTarget(p LinkProps) string {
return uiutils.If(uiutils.IsSetStr(p.Target), p.Target, uiutils.If(p.External, "_blank", ""))
}
func linkRel(p LinkProps) string {
return uiutils.If(uiutils.IsSetStr(p.Rel), p.Rel, uiutils.If((p.External || (linkTarget(p) == "_blank")), "noopener noreferrer", ""))
}
// Link renders the Link contract.
templ Link(p LinkProps) {
<a
if !uiutils.HasAttr(p.Attrs, "href") {
if uiutils.IsSetStr(uiutils.SafeURL(p.Href)) {
href={ uiutils.SafeURL(p.Href) }
}
}
if LinkClasses(p) != "" {
class={ LinkClasses(p) }
}
if !uiutils.HasAttr(p.Attrs, "target") {
if uiutils.IsSetStr(linkTarget(p)) {
target={ linkTarget(p) }
}
}
if !uiutils.HasAttr(p.Attrs, "rel") {
if uiutils.IsSetStr(linkRel(p)) {
rel={ linkRel(p) }
}
}
if !uiutils.HasAttr(p.Attrs, "download") {
if uiutils.IsSetStr(p.Download) {
download={ p.Download }
}
}
if !uiutils.HasAttr(p.Attrs, "aria-current") {
if uiutils.IsSetStr(p.AriaCurrent) {
aria-current={ p.AriaCurrent }
}
}
if !uiutils.HasAttr(p.Attrs, "aria-label") {
if uiutils.IsSetStr(p.AriaLabel) {
aria-label={ p.AriaLabel }
}
}
{ uiutils.RestAttrs(p.Attrs, false, "href", "download", "aria-current", "aria-label")... }
>
{ children... }
</a>
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework twig --dir src --registry-url https://registry.buildy.tw/twig --strict-cdnnpx ui8kit add kit-link{# Code generated by @ui8kit/codegen. DO NOT EDIT. #}
{# Link — Link renders an anchor; External opens a new tab with rel=noopener noreferrer. #}
{# @param class (string) #}
{# @param href (string) #}
{# @param target (string) #}
{# @param rel (string) #}
{# @param external (bool) #}
{# @param download (string) #}
{# @param ariaCurrent (string) #}
{# @param ariaLabel (string) #}
{# @param attrs (attrs) #}
{# @param children (children) #}
{% set class = class|default('') %}
{% set href = href ?? null %}
{% set target = target|default('') %}
{% set rel = rel|default('') %}
{% set external = external|default(false) %}
{% set download = download ?? null %}
{% set ariaCurrent = ariaCurrent ?? null %}
{% set ariaLabel = ariaLabel ?? null %}
{% set attrs = attrs|default([]) %}
{% set children = children|default('') %}
{% set uiTarget = (ui8kit_is_set_str(target) ? target : (external ? '_blank' : '')) %}
{% set uiRel = (ui8kit_is_set_str(rel) ? rel : ((external or (uiTarget is same as('_blank'))) ? 'noopener noreferrer' : '')) %}
<a{{ ui8kit_attrs({'href': ui8kit_url_or_null(href), 'class': ui8kit_or_null(ui8kit_classes('linkClasses', {'class': class, 'href': href, 'target': target, 'rel': rel, 'external': external, 'download': download, 'ariaCurrent': ariaCurrent, 'ariaLabel': ariaLabel})), 'target': ui8kit_or_null(uiTarget), 'rel': ui8kit_or_null(uiRel), 'download': ui8kit_or_null(download), 'aria-current': ui8kit_or_null(ariaCurrent), 'aria-label': ui8kit_or_null(ariaLabel)}, attrs, false, ['href', 'download', 'aria-current', 'aria-label']) }}>{{ children|raw }}</a>
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework latte --dir src --registry-url https://registry.buildy.tw/latte --strict-cdnnpx ui8kit add kit-link{* Code generated by @ui8kit/codegen. DO NOT EDIT. *}
{* Link — Link renders an anchor; External opens a new tab with rel=noopener noreferrer. *}
{parameters
string $class = '',
?string $href = null,
string $target = '',
string $rel = '',
bool $external = false,
?string $download = null,
?string $ariaCurrent = null,
?string $ariaLabel = null,
array $attrs = [],
string $children = '',
}
{var $uiTarget = (\UI8Kit\Latte\Rt::isSetStr($target) ? $target : ($external ? '_blank' : ''))}
{var $uiRel = (\UI8Kit\Latte\Rt::isSetStr($rel) ? $rel : (($external || ($uiTarget === '_blank')) ? 'noopener noreferrer' : ''))}
<a n:attr="[
'href' => \UI8Kit\Latte\Rt::urlOrNull($href),
'class' => \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Classes::linkClasses(['class' => $class, 'href' => $href, 'target' => $target, 'rel' => $rel, 'external' => $external, 'download' => $download, 'ariaCurrent' => $ariaCurrent, 'ariaLabel' => $ariaLabel])),
'target' => \UI8Kit\Latte\Rt::orNull($uiTarget),
'rel' => \UI8Kit\Latte\Rt::orNull($uiRel),
'download' => \UI8Kit\Latte\Rt::orNull($download),
'aria-current' => \UI8Kit\Latte\Rt::orNull($ariaCurrent),
'aria-label' => \UI8Kit\Latte\Rt::orNull($ariaLabel),
...\UI8Kit\Latte\Rt::restAttrs($attrs, false, ['href', 'download', 'aria-current', 'aria-label']),
]">{$children|noescape}</a>Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework jinja2 --dir src --registry-url https://registry.buildy.tw/jinja2 --strict-cdnnpx ui8kit add kit-link{#- Code generated by @ui8kit/codegen. DO NOT EDIT.
Link: Link renders an anchor; External opens a new tab with rel=noopener noreferrer.
Props (p): Class (string), Href (string), Target (string), Rel (string), External (bool), Download (string), AriaCurrent (string), AriaLabel (string), Attrs (attrs), Children (children).
children: TRUSTED HTML printed with |safe — never pass unescaped user input.
Classes without rendering: link_classes(p) (no asChild in Jinja2). -#}
<a
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'href') %}{%- if ui_is_set_str(p['Href']) and ui_safe_url(p['Href']) != '' %} href="{{ p['Href'] }}"{%- endif %}{%- endif %}
{%- with cls = link_classes(p) %}{%- if cls %} class="{{ cls }}"{%- endif %}{%- endwith %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'target') %}{%- if ui_is_set_str(((ui_def(p['Target'], '') if ui_is_set_str(ui_def(p['Target'], '')) else ('_blank' if ui_def(p['External'], false) else '')))) %} target="{{ ((ui_def(p['Target'], '') if ui_is_set_str(ui_def(p['Target'], '')) else ('_blank' if ui_def(p['External'], false) else ''))) }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'rel') %}{%- if ui_is_set_str(((ui_def(p['Rel'], '') if ui_is_set_str(ui_def(p['Rel'], '')) else ('noopener noreferrer' if (ui_def(p['External'], false) or ui_eq(((ui_def(p['Target'], '') if ui_is_set_str(ui_def(p['Target'], '')) else ('_blank' if ui_def(p['External'], false) else ''))), '_blank')) else '')))) %} rel="{{ ((ui_def(p['Rel'], '') if ui_is_set_str(ui_def(p['Rel'], '')) else ('noopener noreferrer' if (ui_def(p['External'], false) or ui_eq(((ui_def(p['Target'], '') if ui_is_set_str(ui_def(p['Target'], '')) else ('_blank' if ui_def(p['External'], false) else ''))), '_blank')) else ''))) }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'download') %}{%- if ui_is_set_str(p['Download']) %} download="{{ p['Download'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-current') %}{%- if ui_is_set_str(p['AriaCurrent']) %} aria-current="{{ p['AriaCurrent'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-label') %}{%- if ui_is_set_str(p['AriaLabel']) %} aria-label="{{ p['AriaLabel'] }}"{%- endif %}{%- endif %}
{{ ui_attr_html(ui_def(p['Attrs'], {}), false, ['href', 'download', 'aria-current', 'aria-label']) }}
>{{ children|default('', true)|safe }}</a>
Props
Names and types come from the xgen specs of the source. Standard HTML attributes (id, role, tabIndex, aria-*) pass through to the root element; the class prop is className in React.
No props data for this item.