Section Head
Section Head component
Install
npx ui8kit add section-headPulls in: box, button-plain, compose, inline, kit-box, kit-button, kit-text, presets, 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 section-head<!-- 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 sidebar section heading with optional right actions. Set `expanded` and it becomes a disclosure button
(aria-expanded, the toggle event).
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
import { variants } from "../utils";
/** SectionHead: the classes of each value (shadcn/cva style). */
export const sectionHeadVariants = variants({
base: "flex items-center justify-between pr-4 pl-4",
variants: {
size: {
default: "h-8 py-2 text-xs font-semibold",
lg: "h-12 py-2 text-sm font-bold",
},
},
defaultVariants: { size: "default" },
});
export type SectionHeadProps = {
size?: "default" | "lg";
expanded?: boolean;
controls?: string;
class?: string;
children?: Snippet;
right?: Snippet;
ontoggle?: () => void;
};
</script>
<script lang="ts">
import Box from "../compose/Box.svelte";
import ButtonPlain from "../compose/ButtonPlain.svelte";
import Inline from "../compose/Inline.svelte";
import { cn } from "../utils";
let {
size = "default",
expanded,
controls,
class: className,
children,
right,
ontoggle,
}: SectionHeadProps = $props();
const cls = $derived(
cn(
sectionHeadVariants({ size: size }),
"rounded text-foreground in-data-[nav=collapsed]:hidden",
className,
)
);
</script>
{#if (expanded != null)}
<ButtonPlain
type="button"
class={cn(cls, "w-full text-left")}
aria-expanded={expanded}
aria-controls={controls}
data-slot="section-head"
data-expanded={expanded}
onclick={() => ontoggle?.()}
>
<Inline data-slot="section-head-title">
{@render children?.()}
</Inline>
{#if right}
<Inline class="flex items-center gap-2" data-slot="section-head-right">
{@render right?.()}
</Inline>
{/if}
</ButtonPlain>
{:else}
<Box class={cls} data-slot="section-head">
<Inline data-slot="section-head-title">
{@render children?.()}
</Inline>
{#if right}
<Inline class="flex items-center gap-2" data-slot="section-head-right">
{@render right?.()}
</Inline>
{/if}
</Box>
{/if}
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 section-head// 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 sidebar section heading with optional right actions. Set `expanded` and it becomes a disclosure button
* (aria-expanded, the toggle event).
*/
import { type ReactNode } from "react";
import { Box, ButtonPlain, Inline } from "../compose";
import { cn, variants } from "../utils";
/** SectionHead: the classes of each value (shadcn/cva style). */
export const sectionHeadVariants = variants({
base: "flex items-center justify-between pr-4 pl-4",
variants: {
size: {
default: "h-8 py-2 text-xs font-semibold",
lg: "h-12 py-2 text-sm font-bold",
},
},
defaultVariants: { size: "default" },
});
export type SectionHeadProps = {
size?: "default" | "lg";
expanded?: boolean;
controls?: string;
className?: string;
children?: ReactNode;
right?: ReactNode;
onToggle?: () => void;
};
export function SectionHead({
size = "default",
expanded,
controls,
className,
children,
right,
onToggle,
}: SectionHeadProps) {
const cls =
cn(
sectionHeadVariants({ size: size }),
"rounded text-foreground in-data-[nav=collapsed]:hidden",
className,
);
return (
<>
{(expanded != null) ? (
<ButtonPlain
type="button"
className={cn(cls, "w-full text-left")}
aria-expanded={expanded}
aria-controls={controls}
data-slot="section-head"
data-expanded={expanded}
onClick={() => onToggle?.()}
>
<Inline data-slot="section-head-title">
{children}
</Inline>
{right ? (
<Inline className="flex items-center gap-2" data-slot="section-head-right">
{right}
</Inline>
) : null}
</ButtonPlain>
) : (
<Box className={cls} data-slot="section-head">
<Inline data-slot="section-head-title">
{children}
</Inline>
{right ? (
<Inline className="flex items-center gap-2" data-slot="section-head-right">
{right}
</Inline>
) : null}
</Box>
)}
</>
);
}
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 section-head<!-- 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 sidebar section heading with optional right actions. Set `expanded` and it becomes a disclosure button
(aria-expanded, the toggle event).
-->
<script lang="ts">
import { variants } from "../utils";
/** SectionHead: the classes of each value (shadcn/cva style). */
export const sectionHeadVariants = variants({
base: "flex items-center justify-between pr-4 pl-4",
variants: {
size: {
default: "h-8 py-2 text-xs font-semibold",
lg: "h-12 py-2 text-sm font-bold",
},
},
defaultVariants: { size: "default" },
});
export type SectionHeadProps = {
size?: "default" | "lg";
expanded?: boolean;
controls?: string;
class?: string;
};
</script>
<script setup lang="ts">
import { computed } from "vue";
import Box from "../compose/Box.vue";
import ButtonPlain from "../compose/ButtonPlain.vue";
import Inline from "../compose/Inline.vue";
import { cn } from "../utils";
const { size = "default", expanded, controls, class: className } = defineProps<SectionHeadProps>();
const emit = defineEmits<{ toggle: [] }>();
defineSlots<{ default?(): unknown, right?(): unknown }>();
const cls = computed(() =>
cn(
sectionHeadVariants({ size: size }),
"rounded text-foreground in-data-[nav=collapsed]:hidden",
className,
)
);
</script>
<template>
<ButtonPlain v-if="(expanded != null)"
type="button"
:class="cn(cls, 'w-full text-left')"
:aria-expanded="expanded"
:aria-controls="controls"
data-slot="section-head"
:data-expanded="expanded"
@click="() => emit('toggle')"
>
<Inline data-slot="section-head-title">
<slot />
</Inline>
<Inline v-if="$slots.right" class="flex items-center gap-2" data-slot="section-head-right">
<slot name="right" />
</Inline>
</ButtonPlain>
<Box v-else :class="cls" data-slot="section-head">
<Inline data-slot="section-head-title">
<slot />
</Inline>
<Inline v-if="$slots.right" class="flex items-center gap-2" data-slot="section-head-right">
<slot name="right" />
</Inline>
</Box>
</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 section-head// 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 sidebar section heading with optional right actions. Set `expanded` and it becomes a disclosure button
* (aria-expanded, the toggle event).
*/
import { type JSX } from "solid-js";
import { Box, ButtonPlain, Inline } from "../compose";
import { cn, variants } from "../utils";
/** SectionHead: the classes of each value (shadcn/cva style). */
export const sectionHeadVariants = variants({
base: "flex items-center justify-between pr-4 pl-4",
variants: {
size: {
default: "h-8 py-2 text-xs font-semibold",
lg: "h-12 py-2 text-sm font-bold",
},
},
defaultVariants: { size: "default" },
});
export type SectionHeadProps = {
size?: "default" | "lg";
expanded?: boolean;
controls?: string;
class?: string;
children?: JSX.Element;
right?: JSX.Element;
onToggle?: () => void;
};
export function SectionHead({
size = "default",
expanded,
controls,
class: className,
children,
right,
onToggle,
}: SectionHeadProps) {
const cls =
cn(
sectionHeadVariants({ size: size }),
"rounded text-foreground in-data-[nav=collapsed]:hidden",
className,
);
return (
<>
{(expanded != null) ? (
<ButtonPlain
type="button"
class={cn(cls, "w-full text-left")}
aria-expanded={expanded}
aria-controls={controls}
data-slot="section-head"
data-expanded={expanded}
onClick={() => onToggle?.()}
>
<Inline data-slot="section-head-title">
{children}
</Inline>
{right ? (
<Inline class="flex items-center gap-2" data-slot="section-head-right">
{right}
</Inline>
) : null}
</ButtonPlain>
) : (
<Box class={cls} data-slot="section-head">
<Inline data-slot="section-head-title">
{children}
</Inline>
{right ? (
<Inline class="flex items-center gap-2" data-slot="section-head-right">
{right}
</Inline>
) : null}
</Box>
)}
</>
);
}
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 section-head// 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/patterns/section-head.json
package blocks
import (
"github.com/ui8kit/codegen/generated/templ/ui/box"
"github.com/ui8kit/codegen/generated/templ/ui/button"
"github.com/ui8kit/codegen/generated/templ/compose"
"github.com/ui8kit/codegen/generated/templ/ui/text"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// SectionHeadProps are the props of SectionHead; the values are the JSON shapes of the TypeScript props.
type SectionHeadProps struct {
Size any `json:"size"`
Expanded any `json:"expanded"`
Controls any `json:"controls"`
Class string `json:"className"`
Right templ.Component `json:"-"`
}
// A sidebar section heading with optional right actions. Set `expanded` and it becomes a disclosure button (aria-expanded, the toggle event).
templ SectionHead(p SectionHeadProps) {
{{ vSize := uiutils.Def(p.Size, "default") }}
{{ vExpanded := p.Expanded }}
{{ vControls := p.Controls }}
{{ vCls := any(uiutils.Cnv(recipeSectionHead.Of(map[string]any{"size": vSize}), "rounded text-foreground in-data-[nav=collapsed]:hidden", p.Class)) }}
if uiutils.Has(vExpanded) {
@compose.ButtonPlain(compose.ButtonPlainProps{ButtonProps: button.ButtonProps{Type: "button", Class: uiutils.S(uiutils.Cnv(vCls, "w-full text-left")), Attrs: uiutils.Attrs("aria-expanded", vExpanded, "aria-controls", vControls, "data-slot", "section-head", "data-expanded", vExpanded)}}) {
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Attrs: uiutils.Attrs("data-slot", "section-head-title")}}) {
{ children... }
}
if uiutils.T((p.Right != nil)) {
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "flex items-center gap-2", Attrs: uiutils.Attrs("data-slot", "section-head-right")}}) {
if p.Right != nil {
@p.Right
}
}
}
}
} else {
@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: uiutils.S(vCls), Attrs: uiutils.Attrs("data-slot", "section-head")}}) {
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Attrs: uiutils.Attrs("data-slot", "section-head-title")}}) {
{ children... }
}
if uiutils.T((p.Right != nil)) {
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "flex items-center gap-2", Attrs: uiutils.Attrs("data-slot", "section-head-right")}}) {
if p.Right != nil {
@p.Right
}
}
}
}
}
}
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 section-head{#- 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/patterns/section-head.json
A sidebar section heading with optional right actions. Set `expanded` and it becomes a disclosure button (aria-expanded, the toggle event).
Props (p): size, expanded, controls, className, right (slot); children: markup. -#}
{%- set v_size = (p.size ?? 'default') -%}
{%- set v_expanded = (p.expanded ?? null) -%}
{%- set v_controls = (p.controls ?? null) -%}
{%- set v_cls = og_cnv([og_recipe('blocks/recipes/section-head.variants.json', {'size': v_size}), 'rounded text-foreground in-data-[nav=collapsed]:hidden', (p.className ?? '')]) -%}
{%- if og_t(og_has(v_expanded)) %}
{%- set c_3 -%}
{%- set c_1 -%}
{{ og_slot((children ?? null))|raw }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'attrs': og_attrs(['data-slot', 'section-head-title']), 'children': c_1}, with_context = false) }}
{%- if og_t(((p.right ?? null) is not null)) %}
{%- set c_2 -%}
{{ og_slot((p.right ?? null))|raw }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': 'flex items-center gap-2', 'attrs': og_attrs(['data-slot', 'section-head-right']), 'children': c_2}, with_context = false) }}
{%- endif %}
{%- endset -%}
{{ include('compose/ButtonPlain.html.twig', {'type': 'button', 'class': og_s(og_cnv([v_cls, 'w-full text-left'])), 'attrs': og_attrs(['aria-expanded', v_expanded, 'aria-controls', v_controls, 'data-slot', 'section-head', 'data-expanded', v_expanded]), 'children': c_3}, with_context = false) }}
{%- else %}
{%- set c_6 -%}
{%- set c_4 -%}
{{ og_slot((children ?? null))|raw }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'attrs': og_attrs(['data-slot', 'section-head-title']), 'children': c_4}, with_context = false) }}
{%- if og_t(((p.right ?? null) is not null)) %}
{%- set c_5 -%}
{{ og_slot((p.right ?? null))|raw }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': 'flex items-center gap-2', 'attrs': og_attrs(['data-slot', 'section-head-right']), 'children': c_5}, with_context = false) }}
{%- endif %}
{%- endset -%}
{{ include('compose/Box.html.twig', {'class': og_s(v_cls), 'attrs': og_attrs(['data-slot', 'section-head']), 'children': c_6}, with_context = false) }}
{%- endif %}
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 section-head{* 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/patterns/section-head.json
A sidebar section heading with optional right actions. Set `expanded` and it becomes a disclosure button (aria-expanded, the toggle event).
Props (p): size, expanded, controls, className, right (slot); children: markup. *}
{var $v_size = ($p['size'] ?? 'default')}
{var $v_expanded = ($p['expanded'] ?? null)}
{var $v_controls = ($p['controls'] ?? null)}
{var $v_cls = og_cnv([og_recipe('blocks/recipes/section-head.variants.json', ['size' => $v_size]), 'rounded text-foreground in-data-[nav=collapsed]:hidden', ($p['className'] ?? '')])}
{if og_t(og_has($v_expanded))}
{capture $c_3}
{capture $c_1}
{=og_slot(($children ?? null))|noescape}
{/capture}
{=og_include('compose/Inline.latte', ['attrs' => og_attrs(['data-slot', 'section-head-title']), 'children' => (string) $c_1])|noescape}
{if og_t(((($p['right'] ?? null) !== null)))}
{capture $c_2}
{=og_slot(($p['right'] ?? null))|noescape}
{/capture}
{=og_include('compose/Inline.latte', ['class' => 'flex items-center gap-2', 'attrs' => og_attrs(['data-slot', 'section-head-right']), 'children' => (string) $c_2])|noescape}
{/if}
{/capture}
{=og_include('compose/ButtonPlain.latte', ['type' => 'button', 'class' => og_s(og_cnv([$v_cls, 'w-full text-left'])), 'attrs' => og_attrs(['aria-expanded', $v_expanded, 'aria-controls', $v_controls, 'data-slot', 'section-head', 'data-expanded', $v_expanded]), 'children' => (string) $c_3])|noescape}
{else}
{capture $c_6}
{capture $c_4}
{=og_slot(($children ?? null))|noescape}
{/capture}
{=og_include('compose/Inline.latte', ['attrs' => og_attrs(['data-slot', 'section-head-title']), 'children' => (string) $c_4])|noescape}
{if og_t(((($p['right'] ?? null) !== null)))}
{capture $c_5}
{=og_slot(($p['right'] ?? null))|noescape}
{/capture}
{=og_include('compose/Inline.latte', ['class' => 'flex items-center gap-2', 'attrs' => og_attrs(['data-slot', 'section-head-right']), 'children' => (string) $c_5])|noescape}
{/if}
{/capture}
{=og_include('compose/Box.latte', ['class' => og_s($v_cls), 'attrs' => og_attrs(['data-slot', 'section-head']), 'children' => (string) $c_6])|noescape}
{/if}
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 section-head{#- 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/patterns/section-head.json
A sidebar section heading with optional right actions. Set `expanded` and it becomes a disclosure button (aria-expanded, the toggle event).
Props (p): size, expanded, controls, className, right (slot); children: markup. -#}
{%- set v_size = og_def(p['size'], 'default') -%}
{%- set v_expanded = og_def(p['expanded'], none) -%}
{%- set v_controls = og_def(p['controls'], none) -%}
{%- set v_cls = og_cnv([og_recipe('blocks/recipes/section-head.variants.json', {'size': v_size}), 'rounded text-foreground in-data-[nav=collapsed]:hidden', og_def(p['className'], '')]) -%}
{%- if og_t(og_has(v_expanded)) %}
{%- set c_3 -%}
{%- set c_1 -%}
{{ og_slot(og_def(children, none))|safe }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Attrs': og_attrs(['data-slot', 'section-head-title'])}, 'children': c_1}) }}
{%- if og_t((og_def(p['right'], none) is not none)) %}
{%- set c_2 -%}
{{ og_slot(og_def(p['right'], none))|safe }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': 'flex items-center gap-2', 'Attrs': og_attrs(['data-slot', 'section-head-right'])}, 'children': c_2}) }}
{%- endif %}
{%- endset -%}
{{ og_include('compose/button-plain.html.j2', {'p': {'Type': 'button', 'Class': og_s(og_cnv([v_cls, 'w-full text-left'])), 'Attrs': og_attrs(['aria-expanded', v_expanded, 'aria-controls', v_controls, 'data-slot', 'section-head', 'data-expanded', v_expanded])}, 'children': c_3}) }}
{%- else %}
{%- set c_6 -%}
{%- set c_4 -%}
{{ og_slot(og_def(children, none))|safe }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Attrs': og_attrs(['data-slot', 'section-head-title'])}, 'children': c_4}) }}
{%- if og_t((og_def(p['right'], none) is not none)) %}
{%- set c_5 -%}
{{ og_slot(og_def(p['right'], none))|safe }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': 'flex items-center gap-2', 'Attrs': og_attrs(['data-slot', 'section-head-right'])}, 'children': c_5}) }}
{%- endif %}
{%- endset -%}
{{ og_include('compose/box.html.j2', {'p': {'Class': og_s(v_cls), 'Attrs': og_attrs(['data-slot', 'section-head'])}, 'children': c_6}) }}
{%- endif %}
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 sidebar section heading with optional right actions. Set `expanded` and it becomes a disclosure button (aria-expanded, the toggle event).
| Prop | Type | Default | Description |
|---|---|---|---|
| size | "default" | "lg" | "default" | row height |
| expanded | boolean | - | set: the head is a disclosure button |
| controls | string | - | id of the region the button opens |