Bottom Nav
An app-style tab bar for a phone: an icon over a name, the current tab marked.
Install
npx ui8kit add bottom-navPulls in: block, compose, inline, kit-box, kit-text, list, list-item, lucide-icon, menu-entry, nav-bar, utils
Preview
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 bottom-nav<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
An app-style tab bar for a phone: an icon over a label per tab, the current one marked. Axes: labels (show,
hide: icons only with the name hidden), position (static, sticky: stays at the bottom of the page), tone.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
import type { NavLink } from "./nav-bar.types";
export type BottomNavProps = {
label: string;
tabs: NavLink[];
current?: string;
labels?: "show" | "hide";
position?: "static" | "sticky";
tone?: "default" | "muted";
landmarkLabel?: string;
};
</script>
<script lang="ts">
import Block from "../compose/Block.svelte";
import Inline from "../compose/Inline.svelte";
import List from "../compose/List.svelte";
import ListItem from "../compose/ListItem.svelte";
import LucideIcon from "../icons/LucideIcon.svelte";
import MenuEntry from "../components/menu-entry.svelte";
import { cn } from "../utils";
let {
label,
tabs,
current = "",
labels = "show",
position = "static",
tone = "default",
landmarkLabel,
}: BottomNavProps = $props();
</script>
{#if ((tabs?.length ?? 0) > 0)}
<Block
tag="nav"
class={cn(
"mx-auto w-full max-w-md border-t border-border",
(((tone as string) === "muted") ? "bg-muted" : "bg-background"),
(((position as string) === "sticky") ? "sticky bottom-0 z-40" : "")
)}
aria-label={(landmarkLabel ?? label)}
data-position={position}
data-slot="bottom-nav"
>
<List class="m-0 grid list-none grid-flow-col auto-cols-fr p-0" data-slot="items">
{#each tabs as tab (tab.id)}
<ListItem data-slot="tabs-row">
<MenuEntry
href={tab.href}
class={cn(
"flex flex-col items-center gap-2 py-2 text-xs",
((tab.id === current) ? "font-semibold text-primary" : "text-muted-foreground")
)}
current={(tab.id === current)}
testid="item"
>
<LucideIcon name={tab.icon} size={20} />
<Inline class={(((labels as string) === "hide") ? "sr-only" : "")}>
{tab.name}
</Inline>
</MenuEntry>
</ListItem>
{/each}
</List>
</Block>
{/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 bottom-nav// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* An app-style tab bar for a phone: an icon over a label per tab, the current one marked. Axes: labels (show,
* hide: icons only with the name hidden), position (static, sticky: stays at the bottom of the page), tone.
*/
import { type ReactNode } from "react";
import { Block, Inline, List, ListItem } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { MenuEntry } from "../components/menu-entry";
import { cn } from "../utils";
import type { NavLink } from "./nav-bar.types";
export type BottomNavProps = {
label: string;
tabs: NavLink[];
current?: string;
labels?: "show" | "hide";
position?: "static" | "sticky";
tone?: "default" | "muted";
landmarkLabel?: string;
};
export function BottomNav({
label,
tabs,
current = "",
labels = "show",
position = "static",
tone = "default",
landmarkLabel,
}: BottomNavProps) {
return (
<>
{((tabs?.length ?? 0) > 0) ? (
<Block
tag="nav"
className={cn(
"mx-auto w-full max-w-md border-t border-border",
(((tone as string) === "muted") ? "bg-muted" : "bg-background"),
(((position as string) === "sticky") ? "sticky bottom-0 z-40" : "")
)}
aria-label={(landmarkLabel ?? label)}
data-position={position}
data-slot="bottom-nav"
>
<List className="m-0 grid list-none grid-flow-col auto-cols-fr p-0" data-slot="items">
{(tabs ?? []).map((tab) => (
<ListItem key={tab.id} data-slot="tabs-row">
<MenuEntry
href={tab.href}
className={cn(
"flex flex-col items-center gap-2 py-2 text-xs",
((tab.id === current) ? "font-semibold text-primary" : "text-muted-foreground")
)}
current={(tab.id === current)}
testid="item"
>
<LucideIcon name={tab.icon} size={20} />
<Inline className={(((labels as string) === "hide") ? "sr-only" : "")}>
{tab.name}
</Inline>
</MenuEntry>
</ListItem>
))}
</List>
</Block>
) : null}
</>
);
}
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 bottom-nav<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
An app-style tab bar for a phone: an icon over a label per tab, the current one marked. Axes: labels (show,
hide: icons only with the name hidden), position (static, sticky: stays at the bottom of the page), tone.
-->
<script lang="ts">
import type { NavLink } from "./nav-bar.types";
export type BottomNavProps = {
label: string;
tabs: NavLink[];
current?: string;
labels?: "show" | "hide";
position?: "static" | "sticky";
tone?: "default" | "muted";
landmarkLabel?: string;
};
</script>
<script setup lang="ts">
import Block from "../compose/Block.vue";
import Inline from "../compose/Inline.vue";
import List from "../compose/List.vue";
import ListItem from "../compose/ListItem.vue";
import LucideIcon from "../icons/LucideIcon.vue";
import MenuEntry from "../components/menu-entry.vue";
import { cn } from "../utils";
const {
label,
tabs,
current = "",
labels = "show",
position = "static",
tone = "default",
landmarkLabel,
} = defineProps<BottomNavProps>();
</script>
<template>
<Block v-if="((tabs?.length ?? 0) > 0)"
tag="nav"
:class="cn(
'mx-auto w-full max-w-md border-t border-border',
(((tone as string) === 'muted') ? 'bg-muted' : 'bg-background'),
(((position as string) === 'sticky') ? 'sticky bottom-0 z-40' : '')
)"
:aria-label="(landmarkLabel ?? label)"
:data-position="position"
data-slot="bottom-nav"
>
<List class="m-0 grid list-none grid-flow-col auto-cols-fr p-0" data-slot="items">
<ListItem v-for="tab in tabs" :key="tab.id" data-slot="tabs-row">
<MenuEntry
:href="tab.href"
:class="cn(
'flex flex-col items-center gap-2 py-2 text-xs',
((tab.id === current) ? 'font-semibold text-primary' : 'text-muted-foreground')
)"
:current="(tab.id === current)"
testid="item"
>
<LucideIcon :name="tab.icon" :size="20" />
<Inline :class="(((labels as string) === 'hide') ? 'sr-only' : '')">
{{ tab.name }}
</Inline>
</MenuEntry>
</ListItem>
</List>
</Block>
</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 bottom-nav// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* An app-style tab bar for a phone: an icon over a label per tab, the current one marked. Axes: labels (show,
* hide: icons only with the name hidden), position (static, sticky: stays at the bottom of the page), tone.
*/
import { For, type JSX } from "solid-js";
import { Block, Inline, List, ListItem } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { MenuEntry } from "../components/menu-entry";
import { cn } from "../utils";
import type { NavLink } from "./nav-bar.types";
export type BottomNavProps = {
label: string;
tabs: NavLink[];
current?: string;
labels?: "show" | "hide";
position?: "static" | "sticky";
tone?: "default" | "muted";
landmarkLabel?: string;
};
export function BottomNav({
label,
tabs,
current = "",
labels = "show",
position = "static",
tone = "default",
landmarkLabel,
}: BottomNavProps) {
return (
<>
{((tabs?.length ?? 0) > 0) ? (
<Block
tag="nav"
class={cn(
"mx-auto w-full max-w-md border-t border-border",
(((tone as string) === "muted") ? "bg-muted" : "bg-background"),
(((position as string) === "sticky") ? "sticky bottom-0 z-40" : "")
)}
aria-label={(landmarkLabel ?? label)}
data-position={position}
data-slot="bottom-nav"
>
<List class="m-0 grid list-none grid-flow-col auto-cols-fr p-0" data-slot="items">
<For each={tabs ?? []}>{(tab) => (
<ListItem data-slot="tabs-row">
<MenuEntry
href={tab.href}
class={cn(
"flex flex-col items-center gap-2 py-2 text-xs",
((tab.id === current) ? "font-semibold text-primary" : "text-muted-foreground")
)}
current={(tab.id === current)}
testid="item"
>
<LucideIcon name={tab.icon} size={20} />
<Inline class={(((labels as string) === "hide") ? "sr-only" : "")}>
{tab.name}
</Inline>
</MenuEntry>
</ListItem>
)}</For>
</List>
</Block>
) : null}
</>
);
}
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 bottom-nav// 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/bottom-nav.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/icons"
"github.com/ui8kit/codegen/generated/templ/ui/text"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// BottomNavProps are the props of BottomNav; the values are the JSON shapes of the TypeScript props.
type BottomNavProps struct {
Label any `json:"label"`
Tabs any `json:"tabs"`
Current any `json:"current"`
Labels any `json:"labels"`
Position any `json:"position"`
Tone any `json:"tone"`
LandmarkLabel any `json:"landmarkLabel"`
}
// An app-style tab bar for a phone: an icon over a label per tab, the current one marked. Axes: labels (show, hide: icons only with the name hidden), position (static, sticky: stays at the bottom of the page), tone.
templ BottomNav(p BottomNavProps) {
{{ vLabel := p.Label }}
{{ vTabs := p.Tabs }}
{{ vCurrent := uiutils.Def(p.Current, "") }}
{{ vLabels := uiutils.Def(p.Labels, "show") }}
{{ vPosition := uiutils.Def(p.Position, "static") }}
{{ vTone := uiutils.Def(p.Tone, "default") }}
{{ vLandmarkLabel := p.LandmarkLabel }}
if uiutils.Gt(uiutils.Len(vTabs), float64(0)) {
@compose.Block(compose.BlockProps{BoxProps: box.BoxProps{Tag: "nav", Class: uiutils.S(uiutils.Cnv("mx-auto w-full max-w-md border-t border-border", uiutils.Cond(uiutils.T(uiutils.Eq(vTone, "muted")), "bg-muted", "bg-background"), uiutils.Cond(uiutils.T(uiutils.Eq(vPosition, "sticky")), "sticky bottom-0 z-40", ""))), Attrs: uiutils.Attrs("aria-label", uiutils.Coalesce(vLandmarkLabel, vLabel), "data-position", vPosition, "data-slot", "bottom-nav")}}) {
@compose.List(compose.ListProps{BoxProps: box.BoxProps{Class: "m-0 grid list-none grid-flow-col auto-cols-fr p-0", Attrs: uiutils.Attrs("data-slot", "items")}}) {
for _, vTab := range uiutils.L(vTabs) {
@compose.ListItem(compose.ListItemProps{BoxProps: box.BoxProps{Attrs: uiutils.Attrs("data-slot", "tabs-row")}}) {
@MenuEntry(MenuEntryProps{Href: uiutils.Get(vTab, "href"), Class: uiutils.Cnv(uiutils.Cnv("flex flex-col items-center gap-2 py-2 text-xs", uiutils.Cond(uiutils.T(uiutils.Eq(uiutils.Get(vTab, "id"), vCurrent)), "font-semibold text-primary", "text-muted-foreground"))), Current: uiutils.Eq(uiutils.Get(vTab, "id"), vCurrent), Testid: "item"}) {
@icons.LucideIcon(icons.LucideIconProps{Name: uiutils.S(uiutils.Get(vTab, "icon")), Size: 20})
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: uiutils.S(uiutils.Cond(uiutils.T(uiutils.Eq(vLabels, "hide")), "sr-only", ""))}}) {
{ uiutils.Text(uiutils.Get(vTab, "name")) }
}
}
}
}
}
}
}
}
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 bottom-nav{#- 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/bottom-nav.json
An app-style tab bar for a phone: an icon over a label per tab, the current one marked. Axes: labels (show, hide: icons only with the name hidden), position (static, sticky: stays at the bottom of the page), tone.
Props (p): label, tabs, current, labels, position, tone, landmarkLabel. -#}
{%- set v_label = (p.label ?? null) -%}
{%- set v_tabs = (p.tabs ?? null) -%}
{%- set v_current = (p.current ?? '') -%}
{%- set v_labels = (p.labels ?? 'show') -%}
{%- set v_position = (p.position ?? 'static') -%}
{%- set v_tone = (p.tone ?? 'default') -%}
{%- set v_landmarkLabel = (p.landmarkLabel ?? null) -%}
{%- if og_t(og_gt(og_len(v_tabs), 0)) %}
{%- set c_5 -%}
{%- set c_4 -%}
{%- for v_tab in og_l(v_tabs) %}
{%- set c_3 -%}
{%- set c_2 -%}
{{ include('icons/LucideIcon.html.twig', {'name': og_s(og_get(v_tab, ['icon'])), 'size': 20}, with_context = false) }}
{%- set c_1 -%}
{{ og_text(og_get(v_tab, ['name'])) }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': og_s((og_t(og_eq(v_labels, 'hide')) ? 'sr-only' : '')), 'children': c_1}, with_context = false) }}
{%- endset -%}
{{ include('blocks/menu-entry.html.twig', {'p': {'href': og_get(v_tab, ['href']), 'className': og_cnv([og_cnv(['flex flex-col items-center gap-2 py-2 text-xs', (og_t(og_eq(og_get(v_tab, ['id']), v_current)) ? 'font-semibold text-primary' : 'text-muted-foreground')])]), 'current': og_eq(og_get(v_tab, ['id']), v_current), 'testid': 'item'}, 'children': og_markup(c_2)}, with_context = false) }}
{%- endset -%}
{{ include('compose/ListItem.html.twig', {'attrs': og_attrs(['data-slot', 'tabs-row']), 'children': c_3}, with_context = false) }}
{%- endfor %}
{%- endset -%}
{{ include('compose/List.html.twig', {'class': 'm-0 grid list-none grid-flow-col auto-cols-fr p-0', 'attrs': og_attrs(['data-slot', 'items']), 'children': c_4}, with_context = false) }}
{%- endset -%}
{{ include('compose/Block.html.twig', {'tag': 'nav', 'class': og_s(og_cnv(['mx-auto w-full max-w-md border-t border-border', (og_t(og_eq(v_tone, 'muted')) ? 'bg-muted' : 'bg-background'), (og_t(og_eq(v_position, 'sticky')) ? 'sticky bottom-0 z-40' : '')])), 'attrs': og_attrs(['aria-label', og_coalesce([v_landmarkLabel, v_label]), 'data-position', v_position, 'data-slot', 'bottom-nav']), 'children': c_5}, 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 bottom-nav{* 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/bottom-nav.json
An app-style tab bar for a phone: an icon over a label per tab, the current one marked. Axes: labels (show, hide: icons only with the name hidden), position (static, sticky: stays at the bottom of the page), tone.
Props (p): label, tabs, current, labels, position, tone, landmarkLabel. *}
{var $v_label = ($p['label'] ?? null)}
{var $v_tabs = ($p['tabs'] ?? null)}
{var $v_current = ($p['current'] ?? '')}
{var $v_labels = ($p['labels'] ?? 'show')}
{var $v_position = ($p['position'] ?? 'static')}
{var $v_tone = ($p['tone'] ?? 'default')}
{var $v_landmarkLabel = ($p['landmarkLabel'] ?? null)}
{if og_t(og_gt(og_len($v_tabs), 0))}
{capture $c_5}
{capture $c_4}
{foreach og_l($v_tabs) as $v_tab}
{capture $c_3}
{capture $c_2}
{=og_include('icons/LucideIcon.latte', ['name' => og_s(og_get($v_tab, ['icon'])), 'size' => 20])|noescape}
{capture $c_1}
{=og_text(og_get($v_tab, ['name']))}
{/capture}
{=og_include('compose/Inline.latte', ['class' => og_s((og_t(og_eq($v_labels, 'hide')) ? 'sr-only' : '')), 'children' => (string) $c_1])|noescape}
{/capture}
{=og_include('blocks/menu-entry.latte', ['p' => ['href' => og_get($v_tab, ['href']), 'className' => og_cnv([og_cnv(['flex flex-col items-center gap-2 py-2 text-xs', (og_t(og_eq(og_get($v_tab, ['id']), $v_current)) ? 'font-semibold text-primary' : 'text-muted-foreground')])]), 'current' => og_eq(og_get($v_tab, ['id']), $v_current), 'testid' => 'item'], 'children' => og_markup($c_2)])|noescape}
{/capture}
{=og_include('compose/ListItem.latte', ['attrs' => og_attrs(['data-slot', 'tabs-row']), 'children' => (string) $c_3])|noescape}
{/foreach}
{/capture}
{=og_include('compose/List.latte', ['class' => 'm-0 grid list-none grid-flow-col auto-cols-fr p-0', 'attrs' => og_attrs(['data-slot', 'items']), 'children' => (string) $c_4])|noescape}
{/capture}
{=og_include('compose/Block.latte', ['tag' => 'nav', 'class' => og_s(og_cnv(['mx-auto w-full max-w-md border-t border-border', (og_t(og_eq($v_tone, 'muted')) ? 'bg-muted' : 'bg-background'), (og_t(og_eq($v_position, 'sticky')) ? 'sticky bottom-0 z-40' : '')])), 'attrs' => og_attrs(['aria-label', og_coalesce([$v_landmarkLabel, $v_label]), 'data-position', $v_position, 'data-slot', 'bottom-nav']), 'children' => (string) $c_5])|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 bottom-nav{#- 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/bottom-nav.json
An app-style tab bar for a phone: an icon over a label per tab, the current one marked. Axes: labels (show, hide: icons only with the name hidden), position (static, sticky: stays at the bottom of the page), tone.
Props (p): label, tabs, current, labels, position, tone, landmarkLabel. -#}
{%- set v_label = og_def(p['label'], none) -%}
{%- set v_tabs = og_def(p['tabs'], none) -%}
{%- set v_current = og_def(p['current'], '') -%}
{%- set v_labels = og_def(p['labels'], 'show') -%}
{%- set v_position = og_def(p['position'], 'static') -%}
{%- set v_tone = og_def(p['tone'], 'default') -%}
{%- set v_landmarkLabel = og_def(p['landmarkLabel'], none) -%}
{%- if og_t(og_gt(og_len(v_tabs), 0)) %}
{%- set c_5 -%}
{%- set c_4 -%}
{%- for v_tab in og_l(v_tabs) %}
{%- set c_3 -%}
{%- set c_2 -%}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': og_s(og_get(v_tab, ['icon'])), 'Size': 20}}) }}
{%- set c_1 -%}
{{ og_text(og_get(v_tab, ['name'])) }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': og_s(('sr-only' if og_t(og_eq(v_labels, 'hide')) else ''))}, 'children': c_1}) }}
{%- endset -%}
{{ og_include('blocks/menu-entry.html.j2', {'p': {'href': og_get(v_tab, ['href']), 'className': og_cnv([og_cnv(['flex flex-col items-center gap-2 py-2 text-xs', ('font-semibold text-primary' if og_t(og_eq(og_get(v_tab, ['id']), v_current)) else 'text-muted-foreground')])]), 'current': og_eq(og_get(v_tab, ['id']), v_current), 'testid': 'item'}, 'children': og_markup(c_2)}) }}
{%- endset -%}
{{ og_include('compose/list-item.html.j2', {'p': {'Attrs': og_attrs(['data-slot', 'tabs-row'])}, 'children': c_3}) }}
{%- endfor %}
{%- endset -%}
{{ og_include('compose/list.html.j2', {'p': {'Class': 'm-0 grid list-none grid-flow-col auto-cols-fr p-0', 'Attrs': og_attrs(['data-slot', 'items'])}, 'children': c_4}) }}
{%- endset -%}
{{ og_include('compose/block.html.j2', {'p': {'Tag': 'nav', 'Class': og_s(og_cnv(['mx-auto w-full max-w-md border-t border-border', ('bg-muted' if og_t(og_eq(v_tone, 'muted')) else 'bg-background'), ('sticky bottom-0 z-40' if og_t(og_eq(v_position, 'sticky')) else '')])), 'Attrs': og_attrs(['aria-label', og_coalesce([v_landmarkLabel, v_label]), 'data-position', v_position, 'data-slot', 'bottom-nav'])}, 'children': c_5}) }}
{%- 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.
An app-style tab bar for a phone: an icon over a label per tab, the current one marked. Axes: labels (show, hide: icons only with the name hidden), position (static, sticky: stays at the bottom of the page), tone.
| Prop | Type | Default | Description |
|---|---|---|---|
| label (required) | string | - | |
| tabs (required) | NavLink[] | - | |
| current | string | "" | |
| labels | "show" | "hide" | "show" | |
| position | "static" | "sticky" | "static" | |
| 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 |