Skip to content
ui8kit

primitive / primitives

Title

Title primitive

Install

npx ui8kit add title

Pulls in: kit-text, recipes, utils

Preview

size: xs

size: sm

size: base

size: lg

size: xl

size: 2xl

size: 3xl

size: 4xl

size: 5xl

size: inherit

weight: regular

weight: medium

weight: semibold

weight: bold

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-cdn
npx ui8kit add title
compose/Title.svelte
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Title: Text + recipe title. -->
<script lang="ts">
  import type { ComponentProps, Snippet } from "svelte";
  import Prim from "../kit/ui/text/Text.svelte";
  import { cn } from "../kit/utils";
  import { rc } from "./recipes";

  let { "size": v_size, "weight": v_weight, as, class: className, children, ...rest }: Omit<ComponentProps<typeof Prim>, "tag"> & { "size"?: string | number; "weight"?: string | number; as?: string | number; class?: string; children?: Snippet } = $props();
  const cls = $derived(cn(rc("title", { "size": v_size, "weight": v_weight }), className));
</script>

<Prim tag={(as && Number(as) >= 1 && Number(as) <= 6 ? `h${as}` : "h2") as never} class={cls} {...rest}>{@render children?.()}</Prim>

Svelte registry item (JSON)

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-cdn
npx ui8kit add title
compose/title.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import type { ComponentProps } from "react";
import { Text as Prim } from "../kit/ui/text/text";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

export type TitleProps = Omit<ComponentProps<typeof Prim>, "tag" | "size" | "weight"> & { "size"?: string | number; "weight"?: string | number; as?: number | string; className?: string };

/** Title: Text + recipe title. */
export function Title({ "size": v_size, "weight": v_weight, as, className, ...rest }: TitleProps) {
  return <Prim tag={(as && Number(as) >= 1 && Number(as) <= 6 ? `h${as}` : "h2") as never} className={cn(rc("title", { "size": v_size, "weight": v_weight }), className)} {...rest} />;
}

React registry item (JSON)

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-cdn
npx ui8kit add title
compose/Title.vue
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Title: Text + recipe title. -->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import Prim from "../kit/ui/text/Text.vue";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

defineOptions({ name: "Title", inheritAttrs: false });
const props = defineProps<{ "size"?: string | number; "weight"?: string | number; as?: string | number }>();
const attrs = useAttrs();
const rest = computed(() => {
  const { class: _class, ...r } = attrs;
  return r;
});
const cls = computed(() => cn(rc("title", { "size": props["size"], "weight": props["weight"] }), attrs.class as string | undefined));
const tagValue = computed(() => (props.as && Number(props.as) >= 1 && Number(props.as) <= 6 ? `h${props.as}` : "h2"));
</script>

<template>
  <Prim :tag="tagValue as never" :class="cls" v-bind="rest"><slot /></Prim>
</template>

Vue registry item (JSON)

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-cdn
npx ui8kit add title
compose/title.solid.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import { splitProps, type ComponentProps } from "solid-js";
import { Text as Prim } from "../kit/ui/text/text.solid";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

export type TitleProps = Omit<ComponentProps<typeof Prim>, "tag" | "class" | "className" | "size" | "weight"> & { "size"?: string | number; "weight"?: string | number; as?: number | string; class?: string; className?: string };

/** Title: Text + recipe title. */
export function Title(props: TitleProps) {
  const [local, rest] = splitProps(props, ["size", "weight", "as", "class", "className"]);
  return <Prim tag={(local.as && Number(local.as) >= 1 && Number(local.as) <= 6 ? `h${local.as}` : "h2") as never} class={cn(rc("title", { "size": local["size"], "weight": local["weight"] }), local.class ?? local.className)} {...rest} />;
}

Solid registry item (JSON)

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-cdn
npx ui8kit add title
compose/title.templ
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.

package compose

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

// TitleProps: Title: Text + recipe title.
type TitleProps struct {
	Size string
	Weight string
	// As — heading level 1..6 (h1..h6), else h2
	As string
	text.TextProps
}

func titleInner(p TitleProps) text.TextProps {
	in := p.TextProps
	in.Class = Join(Rc("title", map[string]string{"size": p.Size, "weight": p.Weight}), p.TextProps.Class)
	in.Tag = Heading(p.As, "h2")
	return in
}

// Title renders Text with the composition classes.
templ Title(p TitleProps) {
	@text.Text(titleInner(p)) {
		{ children... }
	}
}

templ registry item (JSON)

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-cdn
npx ui8kit add title
compose/Title.html.twig
{# Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. #}
{# Title: Text + recipe title. Params: size, weight, as, class, attrs + the params of Text. #}
{% include 'ui/text/Text.html.twig' with compose_props('Title', _context) only %}

Twig registry item (JSON)

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-cdn
npx ui8kit add title
compose/Title.latte
{* Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. *}
{* Title: Text + recipe title. *}
{parameters
  string $class = '',
  string $tag = '',
  array $attrs = [],
  string $children = '',
  $size = null,
  $weight = null,
  $as = null,
}
{include '../ui/text/Text.latte', ...\CodegenX\Compose\Latte\Compose::props('Title', ['class' => $class, 'tag' => $tag, 'attrs' => $attrs, 'children' => $children, 'size' => $size, 'weight' => $weight, 'as' => $as])}

Latte registry item (JSON)

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-cdn
npx ui8kit add title
compose/title.html.j2
{#- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
    Title: Text + recipe title. Props (p): Size, Weight, As, Class, Attrs + the props of Text. -#}
{%- with p = compose_props('Title', p) %}{% include 'ui/text/text.html.j2' %}{% endwith %}

Jinja2 registry item (JSON)

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.