Kit Label
UI8Kit 3 Label primitive (unstyled), from @ui8kit/registry
Install
npx ui8kit add kit-labelPulls 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-label<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Label renders a native label element.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
export type LabelProps = {
class?: string;
children?: Snippet;
[key: string]: unknown;
};
</script>
<script lang="ts">
import { labelClasses } from "./label.shared";
import { safeRest } from "../../utils/expr";
let {
class: className,
children,
...rawRest
}: LabelProps = $props();
const rest = $derived(safeRest(rawRest, { blank: ["for", "htmlfor"] }));
const cls = $derived(labelClasses({ className }));
</script>
<label {...(cls ? { class: cls } : {})} {...rest}>
{@render children?.()}
</label>
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.label — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Label renders a native label element. */
export type LabelBaseProps = {
};
export type LabelClassesInput = {
className?: string;
};
/** Compose Label classes without rendering — the cross-runtime `asChild` substitute. */
export function labelClasses(input: LabelClassesInput = {}): 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-label// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.label — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Label renders a native label element. */
export type LabelBaseProps = {
};
export type LabelClassesInput = {
className?: string;
};
/** Compose Label classes without rendering — the cross-runtime `asChild` substitute. */
export function labelClasses(input: LabelClassesInput = {}): string {
return cn(input.className);
}
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
* Label names a form control.
*/
import { forwardRef, type ReactNode, type LabelHTMLAttributes } from "react";
import { labelClasses } from "./label.shared";
import { safeRest } from "../../utils/expr";
/**
* Label renders a native label element.
*/
export type LabelProps = Omit<LabelHTMLAttributes<HTMLLabelElement>, "className" | "children"> & {
className?: string;
children?: ReactNode;
};
export const Label = forwardRef<HTMLLabelElement, LabelProps>(function Label(
{ className, children, ...rawRest },
ref
) {
const rest = safeRest(rawRest, { blank: ["for", "htmlfor"] });
const cls = labelClasses({ className });
return (
<label ref={ref} className={cls || undefined} {...rest}>
{children}
</label>
);
});
Label.displayName = "Label";
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-label<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Label renders a native label element.
-->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import { labelClasses } from "./label.shared";
import { safeRest } from "../../utils/expr";
defineOptions({ name: "Label", inheritAttrs: false });
const attrs = useAttrs();
const callerClass = computed(() => attrs.class as string | undefined);
const restAttrs = computed(() => {
const { class: _class, ...restEntries } = attrs;
return safeRest(restEntries, { blank: ["for", "htmlfor"] });
});
const cls = computed(() => labelClasses({ className: callerClass.value }));
</script>
<template>
<label :class="cls || undefined" v-bind="restAttrs">
<slot />
</label>
</template>
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.label — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Label renders a native label element. */
export type LabelBaseProps = {
};
export type LabelClassesInput = {
className?: string;
};
/** Compose Label classes without rendering — the cross-runtime `asChild` substitute. */
export function labelClasses(input: LabelClassesInput = {}): 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-label// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.label — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Label renders a native label element. */
export type LabelBaseProps = {
};
export type LabelClassesInput = {
className?: string;
};
/** Compose Label classes without rendering — the cross-runtime `asChild` substitute. */
export function labelClasses(input: LabelClassesInput = {}): string {
return cn(input.className);
}
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
* Label names a form control.
*/
import { splitProps, type JSX, type Component } from "solid-js";
import { labelClasses } from "./label.shared";
import { safeRest } from "../../utils/expr";
/**
* Label renders a native label element.
*/
export type LabelProps = Omit<JSX.LabelHTMLAttributes<HTMLLabelElement>, "class" | "className" | "children"> & {
class?: string;
className?: string;
children?: JSX.Element;
};
export const Label: Component<LabelProps> = (props) => {
const [local, rest] = splitProps(props, ["class", "className", "children"]);
const cls = () => labelClasses({ className: local.class ?? local.className });
return (
<label {...(cls() ? { class: cls() } : {})} {...safeRest(rest, { blank: ["for", "htmlfor"] })}>
{local.children}
</label>
);
};
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-label// Code generated by @ui8kit/codegen. DO NOT EDIT.
/*
Label names a form control.
*/
package label
import (
uiutils "github.com/ui8kit/codegen/generated/templ/utils"
)
// LabelProps configures Label.
type LabelProps struct {
// Class — token class names supplied by the consumer
Class string
// For — id of the labeled control
For string
Attrs templ.Attributes
}
// LabelClasses composes Label classes without rendering —
// the server-composition escape hatch for custom root elements (no asChild in templ).
func LabelClasses(p LabelProps) string {
return uiutils.Cn(p.Class)
}
// Label renders the Label contract.
templ Label(p LabelProps) {
<label
if LabelClasses(p) != "" {
class={ LabelClasses(p) }
}
if !uiutils.HasAttr(p.Attrs, "for") {
if uiutils.IsSetStr(p.For) {
for={ p.For }
}
}
{ uiutils.RestAttrs(p.Attrs, false, "for")... }
>
{ children... }
</label>
}
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-label{# Code generated by @ui8kit/codegen. DO NOT EDIT. #}
{# Label — Label renders a native label element. #}
{# @param class (string) #}
{# @param htmlFor (string) #}
{# @param attrs (attrs) #}
{# @param children (children) #}
{% set class = class|default('') %}
{% set htmlFor = htmlFor ?? null %}
{% set attrs = attrs|default([]) %}
{% set children = children|default('') %}
<label{{ ui8kit_attrs({'class': ui8kit_or_null(ui8kit_classes('labelClasses', {'class': class, 'htmlFor': htmlFor})), 'for': ui8kit_or_null(htmlFor)}, attrs, false, ['for']) }}>{{ children|raw }}</label>
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-label{* Code generated by @ui8kit/codegen. DO NOT EDIT. *}
{* Label — Label renders a native label element. *}
{parameters
string $class = '',
?string $htmlFor = null,
array $attrs = [],
string $children = '',
}
<label n:attr="[
'class' => \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Classes::labelClasses(['class' => $class, 'htmlFor' => $htmlFor])),
'for' => \UI8Kit\Latte\Rt::orNull($htmlFor),
...\UI8Kit\Latte\Rt::restAttrs($attrs, false, ['for']),
]">{$children|noescape}</label>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-label{#- Code generated by @ui8kit/codegen. DO NOT EDIT.
Label: Label renders a native label element.
Props (p): Class (string), For (string), Attrs (attrs), Children (children).
children: TRUSTED HTML printed with |safe — never pass unescaped user input.
Classes without rendering: label_classes(p) (no asChild in Jinja2). -#}
<label
{%- with cls = label_classes(p) %}{%- if cls %} class="{{ cls }}"{%- endif %}{%- endwith %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'for') %}{%- if ui_is_set_str(p['For']) %} for="{{ p['For'] }}"{%- endif %}{%- endif %}
{{ ui_attr_html(ui_def(p['Attrs'], {}), false, ['for']) }}
>{{ children|default('', true)|safe }}</label>
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.