Skip to content

Latest commit

 

History

History
177 lines (123 loc) · 5.85 KB

text.md

File metadata and controls

177 lines (123 loc) · 5.85 KB

Text

ui.text · parts: Text · elements: <p>

Purpose

Text is the polymorphic text primitive. tag accepts HTML5 text elements only (p, span, h1–h6, blockquote, code, …); anything else falls back to p.

Notes

  • Headings: tag="h1"…h6; never style a p to look like a heading.

Text renders the requested text element (default p).

Props

Canonical (templ, Jinja2, MiniJinja) React / Solid HTML (Svelte, Vue, WC) Type Default Kind Description
Tag tag tag "p" | "span" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "blockquote" | "figcaption" | "pre" | "code" | "small" | "strong" | "em" | "time" | "legend" | "del" | "ins" — prop HTML5 text tag (default p)

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

  • No ARIA attributes are rendered by the primitive; rely on native semantics. Pass extra aria-* through attrs.

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 textClasses({ ... }) from text/text.shared.ts
templ text.TextClasses(text.TextProps{...})
Twig ui8kit_classes('textClasses', { class: '…' })
Latte \UI8Kit\Latte\Classes::textClasses(['class' => '…'])
Jinja2 text_classes(p)
MiniJinja text_classes(p) (registered by ui8kit_minijinja::register)

React additionally supports asChild (merges props onto the single child via Slot).

Rendered DOM per state

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

State Props HTML
defaults — <p>Content</p>
h1 {"Tag":"h1","Class":"text-2xl font-semibold"} <h1 class="text-2xl font-semibold">Content</h1>
code {"Tag":"code"} <code>Content</code>
legend {"Tag":"legend"} <legend>Content</legend>
rejected {"Tag":"title"} <p>Content</p>
Tag=p {"Tag":"p"} <p>Content</p>
Tag=span {"Tag":"span"} <span>Content</span>
Tag=h1 {"Tag":"h1"} <h1>Content</h1>
Tag=h2 {"Tag":"h2"} <h2>Content</h2>
Tag=h3 {"Tag":"h3"} <h3>Content</h3>
Tag=h4 {"Tag":"h4"} <h4>Content</h4>
Tag=h5 {"Tag":"h5"} <h5>Content</h5>
Tag=h6 {"Tag":"h6"} <h6>Content</h6>
Tag=blockquote {"Tag":"blockquote"} <blockquote>Content</blockquote>
Tag=figcaption {"Tag":"figcaption"} <figcaption>Content</figcaption>
Tag=pre {"Tag":"pre"} <pre>Content</pre>
Tag=code {"Tag":"code"} <code>Content</code>
Tag=small {"Tag":"small"} <small>Content</small>
Tag=strong {"Tag":"strong"} <strong>Content</strong>
Tag=em {"Tag":"em"} <em>Content</em>
Tag=time {"Tag":"time"} <time>Content</time>
Tag=legend {"Tag":"legend"} <legend>Content</legend>
Tag=del {"Tag":"del"} <del>Content</del>
Tag=ins {"Tag":"ins"} <ins>Content</ins>

Usage

Fixture h1 ({"Tag":"h1","Class":"text-2xl font-semibold"}) — every snippet renders:

<h1 class="text-2xl font-semibold">Content</h1>

React (runtime notes)

import { Text } from "./ui/text/text";

<Text tag="h1" className="text-2xl font-semibold">Content</Text>

Vue 3 (runtime notes)

<script setup lang="ts">
import Text from "./ui/text/Text.vue";
</script>

<template>
  <Text tag="h1" class="text-2xl font-semibold">Content</Text>
</template>

Svelte 5 (runtime notes)

<script lang="ts">
  import Text from "./ui/text/Text.svelte";
</script>

<Text tag="h1" class="text-2xl font-semibold">Content</Text>

SolidJS (runtime notes)

import { Text } from "./ui/text/text.solid";

<Text tag="h1" class="text-2xl font-semibold">Content</Text>

Web Components (runtime notes)

import { renderText } from "./ui/text/text.wc";

document.body.append(renderText({ tag: "h1", class: "text-2xl font-semibold" }, "Content"));

Go templ (runtime notes)

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

@text.Text(text.TextProps{Tag: "h1", Class: "text-2xl font-semibold"}) {
	Content
}

Twig (runtime notes)

{% include 'text/Text.html.twig' with { tag: 'h1', class: 'text-2xl font-semibold', children: 'Content' } only %}

Latte (runtime notes)

{include 'text/Text.latte', tag: 'h1', class: 'text-2xl font-semibold', children: 'Content'}

Jinja2 (runtime notes)

{% with p = {'Tag': 'h1', 'Class': 'text-2xl font-semibold'}, children = 'Content' %}{% include 'ui/text/text.html.j2' %}{% endwith %}

MiniJinja (Rust) (runtime notes)

{% import 'ui8kit.html' as ui %}
{{ ui.text({'Tag': 'h1', 'Class': 'text-2xl font-semibold'}, children='Content') }}

Rules: contract · Index: docs