Weighted Title
Weighted Title component
Install
npx ui8kit add weighted-titlePulls in: compose, inline, kit-text, presets, title, 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 weighted-title<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!-- A display title, one span per word; word i takes weights[i] (from the preset). The words wrap like text. -->
<script lang="ts" module>
import type { Snippet } from "svelte";
export type WeightedTitleProps = {
id: string;
title: string;
weights?: readonly string[];
level?: 1 | 2;
};
</script>
<script lang="ts">
import Inline from "../compose/Inline.svelte";
import Title from "../compose/Title.svelte";
import { defaults } from "../presets/defaults";
import { cn } from "../utils";
let { id, title, weights, level = 1 }: WeightedTitleProps = $props();
</script>
<Title
as={level}
size="5xl"
weight="semibold"
class={cn("text-center tracking-tight text-background", defaults.hero.title)}
id={id}
data-slot="weighted-title"
>
{#each (title ?? "").split(" ") as word, i (i)}
<Inline class={weights?.[i]} data-slot="items-row">
{word}
</Inline>
{" "}
{/each}
</Title>
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 weighted-title// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/** A display title, one span per word; word i takes weights[i] (from the preset). The words wrap like text. */
import { Fragment, type ReactNode } from "react";
import { Inline, Title } from "../compose";
import { defaults } from "../presets/defaults";
import { cn } from "../utils";
export type WeightedTitleProps = {
id: string;
title: string;
weights?: readonly string[];
level?: 1 | 2;
};
export function WeightedTitle({ id, title, weights, level = 1 }: WeightedTitleProps) {
return (
<Title
as={level}
size="5xl"
weight="semibold"
className={cn("text-center tracking-tight text-background", defaults.hero.title)}
id={id}
data-slot="weighted-title"
>
{((title ?? "").split(" ") ?? []).map((word, i) => (
<Fragment key={i}>
<Inline className={weights?.[i]} data-slot="items-row">
{word}
</Inline>
{" "}
</Fragment>
))}
</Title>
);
}
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 weighted-title<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!-- A display title, one span per word; word i takes weights[i] (from the preset). The words wrap like text. -->
<script lang="ts">
export type WeightedTitleProps = {
id: string;
title: string;
weights?: readonly string[];
level?: 1 | 2;
};
</script>
<script setup lang="ts">
import Inline from "../compose/Inline.vue";
import Title from "../compose/Title.vue";
import { defaults } from "../presets/defaults";
import { cn } from "../utils";
const { id, title, weights, level = 1 } = defineProps<WeightedTitleProps>();
</script>
<template>
<Title
:as="level"
size="5xl"
weight="semibold"
:class="cn('text-center tracking-tight text-background', defaults.hero.title)"
:id="id"
data-slot="weighted-title"
>
<template v-for="(word, i) in (title ?? '').split(' ')" :key="i">
<Inline :class="weights?.[i]" data-slot="items-row">
{{ word }}
</Inline>
{{ " " }}
</template>
</Title>
</template>
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 weighted-title// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/** A display title, one span per word; word i takes weights[i] (from the preset). The words wrap like text. */
import { For, type JSX } from "solid-js";
import { Inline, Title } from "../compose";
import { defaults } from "../presets/defaults";
import { cn } from "../utils";
export type WeightedTitleProps = {
id: string;
title: string;
weights?: readonly string[];
level?: 1 | 2;
};
export function WeightedTitle({ id, title, weights, level = 1 }: WeightedTitleProps) {
return (
<Title
as={level}
size="5xl"
weight="semibold"
class={cn("text-center tracking-tight text-background", defaults.hero.title)}
id={id}
data-slot="weighted-title"
>
<For each={(title ?? "").split(" ") ?? []}>{(word, iOf) => { const i = iOf(); return (
<>
<Inline class={weights?.[i]} data-slot="items-row">
{word}
</Inline>
{" "}
</>
); }}</For>
</Title>
);
}
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 weighted-title// Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Source: packages/compose-gen/specs/organisms/weighted-title.json
package blocks
import (
"github.com/ui8kit/codegen/generated/templ/compose"
"github.com/ui8kit/codegen/generated/templ/ui/text"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// WeightedTitleProps are the props of WeightedTitle; the values are the JSON shapes of the TypeScript props.
type WeightedTitleProps struct {
Id any `json:"id"`
Title any `json:"title"`
Weights any `json:"weights"`
Level any `json:"level"`
}
// A display title, one span per word; word i takes weights[i] (from the preset). The words wrap like text.
templ WeightedTitle(p WeightedTitleProps) {
{{ vId := p.Id }}
{{ vTitle := p.Title }}
{{ vWeights := p.Weights }}
{{ vLevel := uiutils.Def(p.Level, float64(1)) }}
@compose.Title(compose.TitleProps{As: uiutils.S(vLevel), Size: "5xl", Weight: "semibold", TextProps: text.TextProps{Class: uiutils.S(uiutils.Cnv("text-center tracking-tight text-background", uiutils.Get(presetDefaults, "hero", "title"))), Attrs: uiutils.Attrs("id", vId, "data-slot", "weighted-title")}}) {
for vI, vWord := range uiutils.L(uiutils.Words(vTitle)) {
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: uiutils.S(uiutils.Nth(vWeights, float64(vI))), Attrs: uiutils.Attrs("data-slot", "items-row")}}) {
{ uiutils.Text(vWord) }
}
{ uiutils.Text(" ") }
}
}
}
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 weighted-title{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/organisms/weighted-title.json
A display title, one span per word; word i takes weights[i] (from the preset). The words wrap like text.
Props (p): id, title, weights, level. -#}
{%- set v_id = (p.id ?? null) -%}
{%- set v_title = (p.title ?? null) -%}
{%- set v_weights = (p.weights ?? null) -%}
{%- set v_level = (p.level ?? 1) -%}
{%- set c_2 -%}
{%- for v_word in og_l(og_words(v_title)) %}
{%- set v_i = loop.index0 -%}
{%- set c_1 -%}
{{ og_text(v_word) }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': og_s(og_nth(v_weights, v_i)), 'attrs': og_attrs(['data-slot', 'items-row']), 'children': c_1}, with_context = false) }}
{{ og_text(' ') }}
{%- endfor %}
{%- endset -%}
{{ include('compose/Title.html.twig', {'as': og_i(v_level), 'size': '5xl', 'weight': 'semibold', 'class': og_s(og_cnv(['text-center tracking-tight text-background', og_preset('blocks/presets/defaults.json', ['hero', 'title'])])), 'attrs': og_attrs(['id', v_id, 'data-slot', 'weighted-title']), 'children': c_2}, with_context = false) }}
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 weighted-title{* Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/organisms/weighted-title.json
A display title, one span per word; word i takes weights[i] (from the preset). The words wrap like text.
Props (p): id, title, weights, level. *}
{var $v_id = ($p['id'] ?? null)}
{var $v_title = ($p['title'] ?? null)}
{var $v_weights = ($p['weights'] ?? null)}
{var $v_level = ($p['level'] ?? 1)}
{capture $c_2}
{foreach og_l(og_words($v_title)) as $v_word}
{var $v_i = $iterator->counter0}
{capture $c_1}
{=og_text($v_word)}
{/capture}
{=og_include('compose/Inline.latte', ['class' => og_s(og_nth($v_weights, $v_i)), 'attrs' => og_attrs(['data-slot', 'items-row']), 'children' => (string) $c_1])|noescape}
{=og_text(' ')}
{/foreach}
{/capture}
{=og_include('compose/Title.latte', ['as' => og_i($v_level), 'size' => '5xl', 'weight' => 'semibold', 'class' => og_s(og_cnv(['text-center tracking-tight text-background', og_preset('blocks/presets/defaults.json', ['hero', 'title'])])), 'attrs' => og_attrs(['id', $v_id, 'data-slot', 'weighted-title']), 'children' => (string) $c_2])|noescape}
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 weighted-title{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/organisms/weighted-title.json
A display title, one span per word; word i takes weights[i] (from the preset). The words wrap like text.
Props (p): id, title, weights, level. -#}
{%- set v_id = og_def(p['id'], none) -%}
{%- set v_title = og_def(p['title'], none) -%}
{%- set v_weights = og_def(p['weights'], none) -%}
{%- set v_level = og_def(p['level'], 1) -%}
{%- set c_2 -%}
{%- for v_word in og_l(og_words(v_title)) %}
{%- set v_i = loop.index0 -%}
{%- set c_1 -%}
{{ og_text(v_word) }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': og_s(og_nth(v_weights, v_i)), 'Attrs': og_attrs(['data-slot', 'items-row'])}, 'children': c_1}) }}
{{ og_text(' ') }}
{%- endfor %}
{%- endset -%}
{{ og_include('compose/title.html.j2', {'p': {'As': og_i(v_level), 'Size': '5xl', 'Weight': 'semibold', 'Class': og_s(og_cnv(['text-center tracking-tight text-background', og_preset('blocks/presets/defaults.json', ['hero', 'title'])])), 'Attrs': og_attrs(['id', v_id, 'data-slot', 'weighted-title'])}, 'children': c_2}) }}
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.
A display title, one span per word; word i takes weights[i] (from the preset). The words wrap like text.
| Prop | Type | Default | Description |
|---|---|---|---|
| id (required) | string | - | id of the heading (the band is labelled by it) |
| title (required) | string | - | the words, separated by spaces |
| weights | readonly string[] | - | a font-weight class per word |
| level | 1 | 2 | 1 |