Skip to content
ui8kit

block / content

Article Body

A long read in one reading column, or beside a table of contents that links to the sections.

Install

npx ui8kit add article-body

Pulls in: box, compose, empty-state, grid, kit-box, kit-link, kit-text, link, list, list-item, nav-block, section-frame, stack, text, title, utils

Preview

Why pages should start from data

Why start with the data

A page that reads one source stays correct when the source changes. Everything else is layout, and layout is cheap to change.

Compose from blocks

Each block names its axes and its variants. A page is a list of blocks, so a new page is a few lines of data.

Pages are lists, not copies.

Check what you ship

Checks read the same specs as the generator, so a page cannot drift from its source without failing the build.

Where to go next

Open the gallery, pick a variant and put it on a page. The guides cover themes, data and deployment.

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 article-body
blocks/article-body.svelte
<!-- 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 long read: sections with headings, text and an optional pull quote, in one reading column or beside a table
  of contents that links to each section. Axes: layout (column, toc), quotes (show, hide), tone. Highlighting
  the section being read is a port contract.
-->
<script lang="ts" module>
  import type { Snippet } from "svelte";
  import type { Section } from "./article-body.types";

  export type ArticleBodyProps = {
    id: string;
    title: string;
    sections: Section[];
    empty?: string;
    tocTitle: string;
    layout?: "column" | "toc";
    quotes?: "show" | "hide";
    tone?: "default" | "muted";
    landmarkLabel?: string;
  };
</script>

<script lang="ts">
  import Box from "../compose/Box.svelte";
  import Grid from "../compose/Grid.svelte";
  import Link from "../compose/Link.svelte";
  import List from "../compose/List.svelte";
  import ListItem from "../compose/ListItem.svelte";
  import Stack from "../compose/Stack.svelte";
  import Text from "../compose/Text.svelte";
  import Title from "../compose/Title.svelte";
  import EmptyState from "../components/empty-state.svelte";
  import NavBlock from "../components/nav-block.svelte";
  import SectionFrame from "../components/section-frame.svelte";
  import { cn, tpl, uniqLabel, urlOf } from "../utils";

  let {
    id,
    title,
    sections,
    empty = "",
    tocTitle,
    layout = "column",
    quotes = "show",
    tone = "default",
    landmarkLabel,
  }: ArticleBodyProps = $props();
</script>

<SectionFrame id={id} title={title} tone={tone} landmarkLabel={landmarkLabel}>
  {#if ((sections?.length ?? 0) === 0)}
    <EmptyState icon="file-text" title={empty} />
  {:else}
    <Grid
      cols="1"
      class={cn(
        "items-start gap-8",
        (((layout as string) === "toc") ? "md:grid-cols-[14rem_minmax(0,1fr)]" : "")
      )}
    >
      {#if ((layout as string) === "toc")}
        <NavBlock
          label={(landmarkLabel ? uniqLabel(tpl("{0}, {1}", tocTitle, landmarkLabel)) : tocTitle)}
          class="md:sticky md:top-4"
          testid="toc"
        >
          <Stack gap="2">
            <Text size="sm" weight="semibold">
              {tocTitle}
            </Text>
            <List class="m-0 flex list-none flex-col gap-2 p-0">
              {#each sections as s (s.id)}
                <ListItem data-slot="sections-row">
                  <Link
                    href={urlOf(tpl("#{0}-{1}", id, s.id))}
                    variant="default"
                    class="text-sm text-muted-foreground"
                    data-slot="toc-link"
                  >
                    {s.title}
                  </Link>
                </ListItem>
              {/each}
            </List>
          </Stack>
        </NavBlock>
      {/if}
      <Stack gap="8" align="stretch" class="mx-auto w-full max-w-2xl min-w-0" data-slot="article">
        {#each sections as s (s.id)}
          <Box class="flex flex-col gap-4" id={tpl("{0}-{1}", id, s.id)} data-slot="item">
            <Title as={3} size="2xl" weight="bold">
              {s.title}
            </Title>
            <Text size="base">
              {s.text}
            </Text>
            {#if ((quotes as string) === "show")}
              {#if s.quote}
                <Text tag="blockquote" class="m-0 border-l border-border pl-4 text-lg" data-slot="quote">
                  {s.quote}
                </Text>
              {/if}
            {/if}
          </Box>
        {/each}
      </Stack>
    </Grid>
  {/if}
</SectionFrame>
blocks/article-body.types.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.

export type Section = {
  id: string;
  title: string;
  text: string;
  quote: string;
};

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 article-body
blocks/article-body.tsx
// 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 long read: sections with headings, text and an optional pull quote, in one reading column or beside a table
 * of contents that links to each section. Axes: layout (column, toc), quotes (show, hide), tone. Highlighting
 * the section being read is a port contract.
 */
import { type ReactNode } from "react";
import { Box, Grid, Link, List, ListItem, Stack, Text, Title } from "../compose";
import { EmptyState } from "../components/empty-state";
import { NavBlock } from "../components/nav-block";
import { SectionFrame } from "../components/section-frame";
import { cn, tpl, uniqLabel, urlOf } from "../utils";
import type { Section } from "./article-body.types";

export type ArticleBodyProps = {
  id: string;
  title: string;
  sections: Section[];
  empty?: string;
  tocTitle: string;
  layout?: "column" | "toc";
  quotes?: "show" | "hide";
  tone?: "default" | "muted";
  landmarkLabel?: string;
};

export function ArticleBody({
  id,
  title,
  sections,
  empty = "",
  tocTitle,
  layout = "column",
  quotes = "show",
  tone = "default",
  landmarkLabel,
}: ArticleBodyProps) {
  return (
    <SectionFrame id={id} title={title} tone={tone} landmarkLabel={landmarkLabel}>
      {((sections?.length ?? 0) === 0) ? (
        <EmptyState icon="file-text" title={empty} />
      ) : (
        <Grid
          cols="1"
          className={cn(
            "items-start gap-8",
            (((layout as string) === "toc") ? "md:grid-cols-[14rem_minmax(0,1fr)]" : "")
          )}
        >
          {((layout as string) === "toc") ? (
            <NavBlock
              label={(landmarkLabel ? uniqLabel(tpl("{0}, {1}", tocTitle, landmarkLabel)) : tocTitle)}
              className="md:sticky md:top-4"
              testid="toc"
            >
              <Stack gap="2">
                <Text size="sm" weight="semibold">
                  {tocTitle}
                </Text>
                <List className="m-0 flex list-none flex-col gap-2 p-0">
                  {(sections ?? []).map((s) => (
                    <ListItem key={s.id} data-slot="sections-row">
                      <Link
                        href={urlOf(tpl("#{0}-{1}", id, s.id))}
                        variant="default"
                        className="text-sm text-muted-foreground"
                        data-slot="toc-link"
                      >
                        {s.title}
                      </Link>
                    </ListItem>
                  ))}
                </List>
              </Stack>
            </NavBlock>
          ) : null}
          <Stack gap="8" align="stretch" className="mx-auto w-full max-w-2xl min-w-0" data-slot="article">
            {(sections ?? []).map((s) => (
              <Box key={s.id} className="flex flex-col gap-4" id={tpl("{0}-{1}", id, s.id)} data-slot="item">
                <Title as={3} size="2xl" weight="bold">
                  {s.title}
                </Title>
                <Text size="base">
                  {s.text}
                </Text>
                {((quotes as string) === "show") ? (
                  <>
                    {s.quote ? (
                      <Text tag="blockquote" className="m-0 border-l border-border pl-4 text-lg" data-slot="quote">
                        {s.quote}
                      </Text>
                    ) : null}
                  </>
                ) : null}
              </Box>
            ))}
          </Stack>
        </Grid>
      )}
    </SectionFrame>
  );
}
blocks/article-body.types.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.

export type Section = {
  id: string;
  title: string;
  text: string;
  quote: string;
};

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 article-body
blocks/article-body.types.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.

export type Section = {
  id: string;
  title: string;
  text: string;
  quote: string;
};
blocks/article-body.vue
<!-- 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 long read: sections with headings, text and an optional pull quote, in one reading column or beside a table
  of contents that links to each section. Axes: layout (column, toc), quotes (show, hide), tone. Highlighting
  the section being read is a port contract.
-->
<script lang="ts">
import type { Section } from "./article-body.types";

export type ArticleBodyProps = {
  id: string;
  title: string;
  sections: Section[];
  empty?: string;
  tocTitle: string;
  layout?: "column" | "toc";
  quotes?: "show" | "hide";
  tone?: "default" | "muted";
  landmarkLabel?: string;
};
</script>

<script setup lang="ts">
import Box from "../compose/Box.vue";
import Grid from "../compose/Grid.vue";
import Link from "../compose/Link.vue";
import List from "../compose/List.vue";
import ListItem from "../compose/ListItem.vue";
import Stack from "../compose/Stack.vue";
import Text from "../compose/Text.vue";
import Title from "../compose/Title.vue";
import EmptyState from "../components/empty-state.vue";
import NavBlock from "../components/nav-block.vue";
import SectionFrame from "../components/section-frame.vue";
import { cn, tpl, uniqLabel, urlOf } from "../utils";

const {
  id,
  title,
  sections,
  empty = "",
  tocTitle,
  layout = "column",
  quotes = "show",
  tone = "default",
  landmarkLabel,
} = defineProps<ArticleBodyProps>();
</script>

<template>
  <SectionFrame :id="id" :title="title" :tone="tone" :landmarkLabel="landmarkLabel">
    <EmptyState v-if="((sections?.length ?? 0) === 0)" icon="file-text" :title="empty" />
    <Grid v-else
      cols="1"
      :class="cn(
        'items-start gap-8',
        (((layout as string) === 'toc') ? 'md:grid-cols-[14rem_minmax(0,1fr)]' : '')
      )"
    >
      <NavBlock v-if="((layout as string) === 'toc')"
        :label="(landmarkLabel ? uniqLabel(tpl('{0}, {1}', tocTitle, landmarkLabel)) : tocTitle)"
        class="md:sticky md:top-4"
        testid="toc"
      >
        <Stack gap="2">
          <Text size="sm" weight="semibold">
            {{ tocTitle }}
          </Text>
          <List class="m-0 flex list-none flex-col gap-2 p-0">
            <ListItem v-for="s in sections" :key="s.id" data-slot="sections-row">
              <Link
                :href="urlOf(tpl('#{0}-{1}', id, s.id))"
                variant="default"
                class="text-sm text-muted-foreground"
                data-slot="toc-link"
              >
                {{ s.title }}
              </Link>
            </ListItem>
          </List>
        </Stack>
      </NavBlock>
      <Stack gap="8" align="stretch" class="mx-auto w-full max-w-2xl min-w-0" data-slot="article">
        <Box
          v-for="s in sections"
          :key="s.id"
          class="flex flex-col gap-4"
          :id="tpl('{0}-{1}', id, s.id)"
          data-slot="item"
        >
          <Title :as="3" size="2xl" weight="bold">
            {{ s.title }}
          </Title>
          <Text size="base">
            {{ s.text }}
          </Text>
          <template v-if="((quotes as string) === 'show')">
            <Text v-if="s.quote" tag="blockquote" class="m-0 border-l border-border pl-4 text-lg" data-slot="quote">
              {{ s.quote }}
            </Text>
          </template>
        </Box>
      </Stack>
    </Grid>
  </SectionFrame>
</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 article-body
blocks/article-body.tsx
// 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 long read: sections with headings, text and an optional pull quote, in one reading column or beside a table
 * of contents that links to each section. Axes: layout (column, toc), quotes (show, hide), tone. Highlighting
 * the section being read is a port contract.
 */
import { For, type JSX } from "solid-js";
import { Box, Grid, Link, List, ListItem, Stack, Text, Title } from "../compose";
import { EmptyState } from "../components/empty-state";
import { NavBlock } from "../components/nav-block";
import { SectionFrame } from "../components/section-frame";
import { cn, tpl, uniqLabel, urlOf } from "../utils";
import type { Section } from "./article-body.types";

export type ArticleBodyProps = {
  id: string;
  title: string;
  sections: Section[];
  empty?: string;
  tocTitle: string;
  layout?: "column" | "toc";
  quotes?: "show" | "hide";
  tone?: "default" | "muted";
  landmarkLabel?: string;
};

export function ArticleBody({
  id,
  title,
  sections,
  empty = "",
  tocTitle,
  layout = "column",
  quotes = "show",
  tone = "default",
  landmarkLabel,
}: ArticleBodyProps) {
  return (
    <SectionFrame id={id} title={title} tone={tone} landmarkLabel={landmarkLabel}>
      {((sections?.length ?? 0) === 0) ? (
        <EmptyState icon="file-text" title={empty} />
      ) : (
        <Grid
          cols="1"
          class={cn(
            "items-start gap-8",
            (((layout as string) === "toc") ? "md:grid-cols-[14rem_minmax(0,1fr)]" : "")
          )}
        >
          {((layout as string) === "toc") ? (
            <NavBlock
              label={(landmarkLabel ? uniqLabel(tpl("{0}, {1}", tocTitle, landmarkLabel)) : tocTitle)}
              class="md:sticky md:top-4"
              testid="toc"
            >
              <Stack gap="2">
                <Text size="sm" weight="semibold">
                  {tocTitle}
                </Text>
                <List class="m-0 flex list-none flex-col gap-2 p-0">
                  <For each={sections ?? []}>{(s) => (
                    <ListItem data-slot="sections-row">
                      <Link
                        href={urlOf(tpl("#{0}-{1}", id, s.id))}
                        variant="default"
                        class="text-sm text-muted-foreground"
                        data-slot="toc-link"
                      >
                        {s.title}
                      </Link>
                    </ListItem>
                  )}</For>
                </List>
              </Stack>
            </NavBlock>
          ) : null}
          <Stack gap="8" align="stretch" class="mx-auto w-full max-w-2xl min-w-0" data-slot="article">
            <For each={sections ?? []}>{(s) => (
              <Box class="flex flex-col gap-4" id={tpl("{0}-{1}", id, s.id)} data-slot="item">
                <Title as={3} size="2xl" weight="bold">
                  {s.title}
                </Title>
                <Text size="base">
                  {s.text}
                </Text>
                {((quotes as string) === "show") ? (
                  <>
                    {s.quote ? (
                      <Text tag="blockquote" class="m-0 border-l border-border pl-4 text-lg" data-slot="quote">
                        {s.quote}
                      </Text>
                    ) : null}
                  </>
                ) : null}
              </Box>
            )}</For>
          </Stack>
        </Grid>
      )}
    </SectionFrame>
  );
}
blocks/article-body.types.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.

export type Section = {
  id: string;
  title: string;
  text: string;
  quote: string;
};

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 article-body
blocks/article-body.templ
// 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/article-body.json

package blocks

import (
	"github.com/ui8kit/codegen/generated/templ/ui/box"
	"github.com/ui8kit/codegen/generated/templ/compose"
	"github.com/ui8kit/codegen/generated/templ/ui/link"
	"github.com/ui8kit/codegen/generated/templ/ui/text"
	uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)

// ArticleBodyProps are the props of ArticleBody; the values are the JSON shapes of the TypeScript props.
type ArticleBodyProps struct {
	Id any `json:"id"`
	Title any `json:"title"`
	Sections any `json:"sections"`
	Empty any `json:"empty"`
	TocTitle any `json:"tocTitle"`
	Layout any `json:"layout"`
	Quotes any `json:"quotes"`
	Tone any `json:"tone"`
	LandmarkLabel any `json:"landmarkLabel"`
}

// A long read: sections with headings, text and an optional pull quote, in one reading column or beside a table of contents that links to each section. Axes: layout (column, toc), quotes (show, hide), tone. Highlighting the section being read is a port contract.
templ ArticleBody(p ArticleBodyProps) {
	{{ vId := p.Id }}
	{{ vTitle := p.Title }}
	{{ vSections := p.Sections }}
	{{ vEmpty := uiutils.Def(p.Empty, "") }}
	{{ vTocTitle := p.TocTitle }}
	{{ vLayout := uiutils.Def(p.Layout, "column") }}
	{{ vQuotes := uiutils.Def(p.Quotes, "show") }}
	{{ vTone := uiutils.Def(p.Tone, "default") }}
	{{ vLandmarkLabel := p.LandmarkLabel }}
	@SectionFrame(SectionFrameProps{Id: vId, Title: vTitle, Tone: vTone, LandmarkLabel: vLandmarkLabel}) {
		if uiutils.Eq(uiutils.Len(vSections), float64(0)) {
			@EmptyState(EmptyStateProps{Icon: "file-text", Title: vEmpty})
		} else {
			@compose.Grid(compose.GridProps{Cols: "1", BoxProps: box.BoxProps{Class: uiutils.S(uiutils.Cnv("items-start gap-8", uiutils.Cond(uiutils.T(uiutils.Eq(vLayout, "toc")), "md:grid-cols-[14rem_minmax(0,1fr)]", "")))}}) {
				if uiutils.Eq(vLayout, "toc") {
					@NavBlock(NavBlockProps{Label: uiutils.Cond(uiutils.T(vLandmarkLabel), uiutils.Uniq(uiutils.Tpl("{0}, {1}", vTocTitle, vLandmarkLabel)), vTocTitle), Class: uiutils.Cnv("md:sticky md:top-4"), Testid: "toc"}) {
						@compose.Stack(compose.StackProps{Gap: "2", BoxProps: box.BoxProps{}}) {
							@compose.Text(compose.TextProps{Size: "sm", Weight: "semibold", TextProps: text.TextProps{}}) {
								{ uiutils.Text(vTocTitle) }
							}
							@compose.List(compose.ListProps{BoxProps: box.BoxProps{Class: "m-0 flex list-none flex-col gap-2 p-0"}}) {
								for _, vS := range uiutils.L(vSections) {
									@compose.ListItem(compose.ListItemProps{BoxProps: box.BoxProps{Attrs: uiutils.Attrs("data-slot", "sections-row")}}) {
										@compose.Link(compose.LinkProps{Variant: "default", LinkProps: link.LinkProps{Href: uiutils.URL(uiutils.Tpl("#{0}-{1}", vId, uiutils.Get(vS, "id")), false), Class: "text-sm text-muted-foreground", Attrs: uiutils.Attrs("data-slot", "toc-link")}}) {
											{ uiutils.Text(uiutils.Get(vS, "title")) }
										}
									}
								}
							}
						}
					}
				}
				@compose.Stack(compose.StackProps{Gap: "8", Align: "stretch", BoxProps: box.BoxProps{Class: "mx-auto w-full max-w-2xl min-w-0", Attrs: uiutils.Attrs("data-slot", "article")}}) {
					for _, vS := range uiutils.L(vSections) {
						@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: "flex flex-col gap-4", Attrs: uiutils.Attrs("id", uiutils.Tpl("{0}-{1}", vId, uiutils.Get(vS, "id")), "data-slot", "item")}}) {
							@compose.Title(compose.TitleProps{As: "3", Size: "2xl", Weight: "bold", TextProps: text.TextProps{}}) {
								{ uiutils.Text(uiutils.Get(vS, "title")) }
							}
							@compose.Text(compose.TextProps{Size: "base", TextProps: text.TextProps{}}) {
								{ uiutils.Text(uiutils.Get(vS, "text")) }
							}
							if uiutils.Eq(vQuotes, "show") {
								if uiutils.T(uiutils.Get(vS, "quote")) {
									@compose.Text(compose.TextProps{TextProps: text.TextProps{Tag: "blockquote", Class: "m-0 border-l border-border pl-4 text-lg", Attrs: uiutils.Attrs("data-slot", "quote")}}) {
										{ uiutils.Text(uiutils.Get(vS, "quote")) }
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

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 article-body
blocks/article-body.html.twig
{#- 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/article-body.json
    A long read: sections with headings, text and an optional pull quote, in one reading column or beside a table of contents that links to each section. Axes: layout (column, toc), quotes (show, hide), tone. Highlighting the section being read is a port contract.
    Props (p): id, title, sections, empty, tocTitle, layout, quotes, tone, landmarkLabel. -#}
{%- set v_id = (p.id ?? null) -%}
{%- set v_title = (p.title ?? null) -%}
{%- set v_sections = (p.sections ?? null) -%}
{%- set v_empty = (p.empty ?? '') -%}
{%- set v_tocTitle = (p.tocTitle ?? null) -%}
{%- set v_layout = (p.layout ?? 'column') -%}
{%- set v_quotes = (p.quotes ?? 'show') -%}
{%- set v_tone = (p.tone ?? 'default') -%}
{%- set v_landmarkLabel = (p.landmarkLabel ?? null) -%}
{%- set c_13 -%}
  {%- if og_t(og_eq(og_len(v_sections), 0)) %}
    {{ include('blocks/empty-state.html.twig', {'p': {'icon': 'file-text', 'title': v_empty}}, with_context = false) }}
  {%- else %}
    {%- set c_12 -%}
      {%- if og_t(og_eq(v_layout, 'toc')) %}
        {%- set c_6 -%}
          {%- set c_5 -%}
            {%- set c_1 -%}
              {{ og_text(v_tocTitle) }}
            {%- endset -%}
            {{ include('compose/Text.html.twig', {'size': 'sm', 'weight': 'semibold', 'children': c_1}, with_context = false) }}
            {%- set c_4 -%}
              {%- for v_s in og_l(v_sections) %}
                {%- set c_3 -%}
                  {%- set c_2 -%}
                    {{ og_text(og_get(v_s, ['title'])) }}
                  {%- endset -%}
                  {{ include('compose/Link.html.twig', {'href': og_url(og_s(og_tpl('#{0}-{1}', [v_id, og_get(v_s, ['id'])]))), 'variant': 'default', 'class': 'text-sm text-muted-foreground', 'attrs': og_attrs(['data-slot', 'toc-link']), 'children': c_2}, with_context = false) }}
                {%- endset -%}
                {{ include('compose/ListItem.html.twig', {'attrs': og_attrs(['data-slot', 'sections-row']), 'children': c_3}, with_context = false) }}
              {%- endfor %}
            {%- endset -%}
            {{ include('compose/List.html.twig', {'class': 'm-0 flex list-none flex-col gap-2 p-0', 'children': c_4}, with_context = false) }}
          {%- endset -%}
          {{ include('compose/Stack.html.twig', {'gap': '2', 'children': c_5}, with_context = false) }}
        {%- endset -%}
        {{ include('blocks/nav-block.html.twig', {'p': {'label': (og_t(v_landmarkLabel) ? og_uniq(og_tpl('{0}, {1}', [v_tocTitle, v_landmarkLabel])) : v_tocTitle), 'className': og_cnv(['md:sticky md:top-4']), 'testid': 'toc'}, 'children': og_markup(c_6)}, with_context = false) }}
      {%- endif %}
      {%- set c_11 -%}
        {%- for v_s in og_l(v_sections) %}
          {%- set c_10 -%}
            {%- set c_7 -%}
              {{ og_text(og_get(v_s, ['title'])) }}
            {%- endset -%}
            {{ include('compose/Title.html.twig', {'as': 3, 'size': '2xl', 'weight': 'bold', 'children': c_7}, with_context = false) }}
            {%- set c_8 -%}
              {{ og_text(og_get(v_s, ['text'])) }}
            {%- endset -%}
            {{ include('compose/Text.html.twig', {'size': 'base', 'children': c_8}, with_context = false) }}
            {%- if og_t(og_eq(v_quotes, 'show')) %}
              {%- if og_t(og_get(v_s, ['quote'])) %}
                {%- set c_9 -%}
                  {{ og_text(og_get(v_s, ['quote'])) }}
                {%- endset -%}
                {{ include('compose/Text.html.twig', {'tag': 'blockquote', 'class': 'm-0 border-l border-border pl-4 text-lg', 'attrs': og_attrs(['data-slot', 'quote']), 'children': c_9}, with_context = false) }}
              {%- endif %}
            {%- endif %}
          {%- endset -%}
          {{ include('compose/Box.html.twig', {'class': 'flex flex-col gap-4', 'attrs': og_attrs(['id', og_tpl('{0}-{1}', [v_id, og_get(v_s, ['id'])]), 'data-slot', 'item']), 'children': c_10}, with_context = false) }}
        {%- endfor %}
      {%- endset -%}
      {{ include('compose/Stack.html.twig', {'gap': '8', 'align': 'stretch', 'class': 'mx-auto w-full max-w-2xl min-w-0', 'attrs': og_attrs(['data-slot', 'article']), 'children': c_11}, with_context = false) }}
    {%- endset -%}
    {{ include('compose/Grid.html.twig', {'cols': '1', 'class': og_s(og_cnv(['items-start gap-8', (og_t(og_eq(v_layout, 'toc')) ? 'md:grid-cols-[14rem_minmax(0,1fr)]' : '')])), 'children': c_12}, with_context = false) }}
  {%- endif %}
{%- endset -%}
{{ include('blocks/section-frame.html.twig', {'p': {'id': v_id, 'title': v_title, 'tone': v_tone, 'landmarkLabel': v_landmarkLabel}, 'children': og_markup(c_13)}, with_context = false) }}

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 article-body
blocks/article-body.latte
{* 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/article-body.json
    A long read: sections with headings, text and an optional pull quote, in one reading column or beside a table of contents that links to each section. Axes: layout (column, toc), quotes (show, hide), tone. Highlighting the section being read is a port contract.
    Props (p): id, title, sections, empty, tocTitle, layout, quotes, tone, landmarkLabel. *}
{var $v_id = ($p['id'] ?? null)}
{var $v_title = ($p['title'] ?? null)}
{var $v_sections = ($p['sections'] ?? null)}
{var $v_empty = ($p['empty'] ?? '')}
{var $v_tocTitle = ($p['tocTitle'] ?? null)}
{var $v_layout = ($p['layout'] ?? 'column')}
{var $v_quotes = ($p['quotes'] ?? 'show')}
{var $v_tone = ($p['tone'] ?? 'default')}
{var $v_landmarkLabel = ($p['landmarkLabel'] ?? null)}
{capture $c_13}
  {if og_t(og_eq(og_len($v_sections), 0))}
    {=og_include('blocks/empty-state.latte', ['p' => ['icon' => 'file-text', 'title' => $v_empty]])|noescape}
  {else}
    {capture $c_12}
      {if og_t(og_eq($v_layout, 'toc'))}
        {capture $c_6}
          {capture $c_5}
            {capture $c_1}
              {=og_text($v_tocTitle)}
            {/capture}
            {=og_include('compose/Text.latte', ['size' => 'sm', 'weight' => 'semibold', 'children' => (string) $c_1])|noescape}
            {capture $c_4}
              {foreach og_l($v_sections) as $v_s}
                {capture $c_3}
                  {capture $c_2}
                    {=og_text(og_get($v_s, ['title']))}
                  {/capture}
                  {=og_include('compose/Link.latte', ['href' => og_url(og_s(og_tpl('#{0}-{1}', [$v_id, og_get($v_s, ['id'])]))), 'variant' => 'default', 'class' => 'text-sm text-muted-foreground', 'attrs' => og_attrs(['data-slot', 'toc-link']), 'children' => (string) $c_2])|noescape}
                {/capture}
                {=og_include('compose/ListItem.latte', ['attrs' => og_attrs(['data-slot', 'sections-row']), 'children' => (string) $c_3])|noescape}
              {/foreach}
            {/capture}
            {=og_include('compose/List.latte', ['class' => 'm-0 flex list-none flex-col gap-2 p-0', 'children' => (string) $c_4])|noescape}
          {/capture}
          {=og_include('compose/Stack.latte', ['gap' => '2', 'children' => (string) $c_5])|noescape}
        {/capture}
        {=og_include('blocks/nav-block.latte', ['p' => ['label' => (og_t($v_landmarkLabel) ? og_uniq(og_tpl('{0}, {1}', [$v_tocTitle, $v_landmarkLabel])) : $v_tocTitle), 'className' => og_cnv(['md:sticky md:top-4']), 'testid' => 'toc'], 'children' => og_markup($c_6)])|noescape}
      {/if}
      {capture $c_11}
        {foreach og_l($v_sections) as $v_s}
          {capture $c_10}
            {capture $c_7}
              {=og_text(og_get($v_s, ['title']))}
            {/capture}
            {=og_include('compose/Title.latte', ['as' => 3, 'size' => '2xl', 'weight' => 'bold', 'children' => (string) $c_7])|noescape}
            {capture $c_8}
              {=og_text(og_get($v_s, ['text']))}
            {/capture}
            {=og_include('compose/Text.latte', ['size' => 'base', 'children' => (string) $c_8])|noescape}
            {if og_t(og_eq($v_quotes, 'show'))}
              {if og_t(og_get($v_s, ['quote']))}
                {capture $c_9}
                  {=og_text(og_get($v_s, ['quote']))}
                {/capture}
                {=og_include('compose/Text.latte', ['tag' => 'blockquote', 'class' => 'm-0 border-l border-border pl-4 text-lg', 'attrs' => og_attrs(['data-slot', 'quote']), 'children' => (string) $c_9])|noescape}
              {/if}
            {/if}
          {/capture}
          {=og_include('compose/Box.latte', ['class' => 'flex flex-col gap-4', 'attrs' => og_attrs(['id', og_tpl('{0}-{1}', [$v_id, og_get($v_s, ['id'])]), 'data-slot', 'item']), 'children' => (string) $c_10])|noescape}
        {/foreach}
      {/capture}
      {=og_include('compose/Stack.latte', ['gap' => '8', 'align' => 'stretch', 'class' => 'mx-auto w-full max-w-2xl min-w-0', 'attrs' => og_attrs(['data-slot', 'article']), 'children' => (string) $c_11])|noescape}
    {/capture}
    {=og_include('compose/Grid.latte', ['cols' => '1', 'class' => og_s(og_cnv(['items-start gap-8', (og_t(og_eq($v_layout, 'toc')) ? 'md:grid-cols-[14rem_minmax(0,1fr)]' : '')])), 'children' => (string) $c_12])|noescape}
  {/if}
{/capture}
{=og_include('blocks/section-frame.latte', ['p' => ['id' => $v_id, 'title' => $v_title, 'tone' => $v_tone, 'landmarkLabel' => $v_landmarkLabel], 'children' => og_markup($c_13)])|noescape}

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 article-body
blocks/article-body.html.j2
{#- 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/article-body.json
    A long read: sections with headings, text and an optional pull quote, in one reading column or beside a table of contents that links to each section. Axes: layout (column, toc), quotes (show, hide), tone. Highlighting the section being read is a port contract.
    Props (p): id, title, sections, empty, tocTitle, layout, quotes, tone, landmarkLabel. -#}
{%- set v_id = og_def(p['id'], none) -%}
{%- set v_title = og_def(p['title'], none) -%}
{%- set v_sections = og_def(p['sections'], none) -%}
{%- set v_empty = og_def(p['empty'], '') -%}
{%- set v_tocTitle = og_def(p['tocTitle'], none) -%}
{%- set v_layout = og_def(p['layout'], 'column') -%}
{%- set v_quotes = og_def(p['quotes'], 'show') -%}
{%- set v_tone = og_def(p['tone'], 'default') -%}
{%- set v_landmarkLabel = og_def(p['landmarkLabel'], none) -%}
{%- set c_13 -%}
  {%- if og_t(og_eq(og_len(v_sections), 0)) %}
    {{ og_include('blocks/empty-state.html.j2', {'p': {'icon': 'file-text', 'title': v_empty}}) }}
  {%- else %}
    {%- set c_12 -%}
      {%- if og_t(og_eq(v_layout, 'toc')) %}
        {%- set c_6 -%}
          {%- set c_5 -%}
            {%- set c_1 -%}
              {{ og_text(v_tocTitle) }}
            {%- endset -%}
            {{ og_include('compose/text.html.j2', {'p': {'Size': 'sm', 'Weight': 'semibold'}, 'children': c_1}) }}
            {%- set c_4 -%}
              {%- for v_s in og_l(v_sections) %}
                {%- set c_3 -%}
                  {%- set c_2 -%}
                    {{ og_text(og_get(v_s, ['title'])) }}
                  {%- endset -%}
                  {{ og_include('compose/link.html.j2', {'p': {'Href': og_url(og_s(og_tpl('#{0}-{1}', [v_id, og_get(v_s, ['id'])]))), 'Variant': 'default', 'Class': 'text-sm text-muted-foreground', 'Attrs': og_attrs(['data-slot', 'toc-link'])}, 'children': c_2}) }}
                {%- endset -%}
                {{ og_include('compose/list-item.html.j2', {'p': {'Attrs': og_attrs(['data-slot', 'sections-row'])}, 'children': c_3}) }}
              {%- endfor %}
            {%- endset -%}
            {{ og_include('compose/list.html.j2', {'p': {'Class': 'm-0 flex list-none flex-col gap-2 p-0'}, 'children': c_4}) }}
          {%- endset -%}
          {{ og_include('compose/stack.html.j2', {'p': {'Gap': '2'}, 'children': c_5}) }}
        {%- endset -%}
        {{ og_include('blocks/nav-block.html.j2', {'p': {'label': (og_uniq(og_tpl('{0}, {1}', [v_tocTitle, v_landmarkLabel])) if og_t(v_landmarkLabel) else v_tocTitle), 'className': og_cnv(['md:sticky md:top-4']), 'testid': 'toc'}, 'children': og_markup(c_6)}) }}
      {%- endif %}
      {%- set c_11 -%}
        {%- for v_s in og_l(v_sections) %}
          {%- set c_10 -%}
            {%- set c_7 -%}
              {{ og_text(og_get(v_s, ['title'])) }}
            {%- endset -%}
            {{ og_include('compose/title.html.j2', {'p': {'As': 3, 'Size': '2xl', 'Weight': 'bold'}, 'children': c_7}) }}
            {%- set c_8 -%}
              {{ og_text(og_get(v_s, ['text'])) }}
            {%- endset -%}
            {{ og_include('compose/text.html.j2', {'p': {'Size': 'base'}, 'children': c_8}) }}
            {%- if og_t(og_eq(v_quotes, 'show')) %}
              {%- if og_t(og_get(v_s, ['quote'])) %}
                {%- set c_9 -%}
                  {{ og_text(og_get(v_s, ['quote'])) }}
                {%- endset -%}
                {{ og_include('compose/text.html.j2', {'p': {'Tag': 'blockquote', 'Class': 'm-0 border-l border-border pl-4 text-lg', 'Attrs': og_attrs(['data-slot', 'quote'])}, 'children': c_9}) }}
              {%- endif %}
            {%- endif %}
          {%- endset -%}
          {{ og_include('compose/box.html.j2', {'p': {'Class': 'flex flex-col gap-4', 'Attrs': og_attrs(['id', og_tpl('{0}-{1}', [v_id, og_get(v_s, ['id'])]), 'data-slot', 'item'])}, 'children': c_10}) }}
        {%- endfor %}
      {%- endset -%}
      {{ og_include('compose/stack.html.j2', {'p': {'Gap': '8', 'Align': 'stretch', 'Class': 'mx-auto w-full max-w-2xl min-w-0', 'Attrs': og_attrs(['data-slot', 'article'])}, 'children': c_11}) }}
    {%- endset -%}
    {{ og_include('compose/grid.html.j2', {'p': {'Cols': '1', 'Class': og_s(og_cnv(['items-start gap-8', ('md:grid-cols-[14rem_minmax(0,1fr)]' if og_t(og_eq(v_layout, 'toc')) else '')]))}, 'children': c_12}) }}
  {%- endif %}
{%- endset -%}
{{ og_include('blocks/section-frame.html.j2', {'p': {'id': v_id, 'title': v_title, 'tone': v_tone, 'landmarkLabel': v_landmarkLabel}, 'children': og_markup(c_13)}) }}

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.

A long read: sections with headings, text and an optional pull quote, in one reading column or beside a table of contents that links to each section. Axes: layout (column, toc), quotes (show, hide), tone. Highlighting the section being read is a port contract.

Props of ArticleBody
PropTypeDefault Description
id (required)string-
title (required)string-
sections (required)Section[]-
empty string""the text of the empty state (no records), from the dictionary
tocTitle (required)string-
layout "column" | "toc""column"
quotes "show" | "hide""show"
tone "default" | "muted""default"
landmarkLabel string-accessible name of the landmark of this component when the page shows it more than once (a variant); replaces the heading name of the root landmark, follows the name of a nested one