Skip to content
ui8kit

component / components

Menu Entry

Menu Entry component

Install

npx ui8kit add menu-entry

Pulls in: box, compose, inline, kit-box, kit-link, kit-text, link, utils

Preview

Settings

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 menu-entry
components/menu-entry.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. -->
<!--
  One entry of a menu: a link to its address, or, without one, its content as text in the same box (the magazine
  routes nothing, so it shows text). current marks the page the entry stands for (aria-current) either way.
-->
<script lang="ts" module>
  import type { Snippet } from "svelte";

  export type MenuEntryProps = {
    href?: string;
    current?: boolean;
    variant?: "default" | "muted" | "block";
    size?: "default" | "sm";
    testid?: string;
    block?: boolean;
    class?: string;
    children?: Snippet;
  };
</script>

<script lang="ts">
  import Box from "../compose/Box.svelte";
  import Inline from "../compose/Inline.svelte";
  import Link from "../compose/Link.svelte";
  import { urlOf } from "../utils";

  let {
    href,
    current = false,
    variant = "default",
    size = "default",
    testid,
    block = false,
    class: className,
    children,
  }: MenuEntryProps = $props();
</script>

{#if href}
  <Link
    href={urlOf(href)}
    variant={variant}
    size={size}
    aria-current={(current ? "page" : undefined)}
    class={className}
    data-slot={(testid ?? "menu-entry")}
  >
    {@render children?.()}
  </Link>
{:else if block}
  <Box class={className} aria-current={(current ? "page" : undefined)} data-slot={(testid ?? "menu-entry")}>
    {@render children?.()}
  </Box>
{:else}
  <Inline class={className} aria-current={(current ? "page" : undefined)} data-slot={(testid ?? "menu-entry")}>
    {@render children?.()}
  </Inline>
{/if}

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 menu-entry
components/menu-entry.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.
/**
 * One entry of a menu: a link to its address, or, without one, its content as text in the same box (the magazine
 * routes nothing, so it shows text). current marks the page the entry stands for (aria-current) either way.
 */
import { type ReactNode } from "react";
import { Box, Inline, Link } from "../compose";
import { urlOf } from "../utils";

export type MenuEntryProps = {
  href?: string;
  current?: boolean;
  variant?: "default" | "muted" | "block";
  size?: "default" | "sm";
  testid?: string;
  block?: boolean;
  className?: string;
  children?: ReactNode;
};

export function MenuEntry({
  href,
  current = false,
  variant = "default",
  size = "default",
  testid,
  block = false,
  className,
  children,
}: MenuEntryProps) {
  return (
    <>
      {href ? (
        <Link
          href={urlOf(href)}
          variant={variant}
          size={size}
          aria-current={(current ? "page" : undefined)}
          className={className}
          data-slot={(testid ?? "menu-entry")}
        >
          {children}
        </Link>
      ) : block ? (
        <Box className={className} aria-current={(current ? "page" : undefined)} data-slot={(testid ?? "menu-entry")}>
          {children}
        </Box>
      ) : (
        <Inline
          className={className}
          aria-current={(current ? "page" : undefined)}
          data-slot={(testid ?? "menu-entry")}
        >
          {children}
        </Inline>
      )}
    </>
  );
}

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 menu-entry
components/menu-entry.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. -->
<!--
  One entry of a menu: a link to its address, or, without one, its content as text in the same box (the magazine
  routes nothing, so it shows text). current marks the page the entry stands for (aria-current) either way.
-->
<script lang="ts">
export type MenuEntryProps = {
  href?: string;
  current?: boolean;
  variant?: "default" | "muted" | "block";
  size?: "default" | "sm";
  testid?: string;
  block?: boolean;
  class?: string;
};
</script>

<script setup lang="ts">
import Box from "../compose/Box.vue";
import Inline from "../compose/Inline.vue";
import Link from "../compose/Link.vue";
import { urlOf } from "../utils";

const {
  href,
  current = false,
  variant = "default",
  size = "default",
  testid,
  block = false,
  class: className,
} = defineProps<MenuEntryProps>();
defineSlots<{ default?(): unknown }>();
</script>

<template>
  <Link v-if="href"
    :href="urlOf(href)"
    :variant="variant"
    :size="size"
    :aria-current="(current ? 'page' : undefined)"
    :class="className"
    :data-slot="(testid ?? 'menu-entry')"
  >
    <slot />
  </Link>
  <Box
    v-else-if="block"
    :class="className"
    :aria-current="(current ? 'page' : undefined)"
    :data-slot="(testid ?? 'menu-entry')"
  >
    <slot />
  </Box>
  <Inline
    v-else
    :class="className"
    :aria-current="(current ? 'page' : undefined)"
    :data-slot="(testid ?? 'menu-entry')"
  >
    <slot />
  </Inline>
</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 menu-entry
components/menu-entry.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.
/**
 * One entry of a menu: a link to its address, or, without one, its content as text in the same box (the magazine
 * routes nothing, so it shows text). current marks the page the entry stands for (aria-current) either way.
 */
import { type JSX } from "solid-js";
import { Box, Inline, Link } from "../compose";
import { urlOf } from "../utils";

export type MenuEntryProps = {
  href?: string;
  current?: boolean;
  variant?: "default" | "muted" | "block";
  size?: "default" | "sm";
  testid?: string;
  block?: boolean;
  class?: string;
  children?: JSX.Element;
};

export function MenuEntry({
  href,
  current = false,
  variant = "default",
  size = "default",
  testid,
  block = false,
  class: className,
  children,
}: MenuEntryProps) {
  return (
    <>
      {href ? (
        <Link
          href={urlOf(href)}
          variant={variant}
          size={size}
          aria-current={(current ? "page" : undefined)}
          class={className}
          data-slot={(testid ?? "menu-entry")}
        >
          {children}
        </Link>
      ) : block ? (
        <Box class={className} aria-current={(current ? "page" : undefined)} data-slot={(testid ?? "menu-entry")}>
          {children}
        </Box>
      ) : (
        <Inline class={className} aria-current={(current ? "page" : undefined)} data-slot={(testid ?? "menu-entry")}>
          {children}
        </Inline>
      )}
    </>
  );
}

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 menu-entry
blocks/menu-entry.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/menu-entry.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"
)

// MenuEntryProps are the props of MenuEntry; the values are the JSON shapes of the TypeScript props.
type MenuEntryProps struct {
	Href any `json:"href"`
	Current any `json:"current"`
	Variant any `json:"variant"`
	Size any `json:"size"`
	Testid any `json:"testid"`
	Block any `json:"block"`
	Class string `json:"className"`
}

// One entry of a menu: a link to its address, or, without one, its content as text in the same box (the magazine routes nothing, so it shows text). current marks the page the entry stands for (aria-current) either way.
templ MenuEntry(p MenuEntryProps) {
	{{ vHref := p.Href }}
	{{ vCurrent := uiutils.Def(p.Current, false) }}
	{{ vVariant := uiutils.Def(p.Variant, "default") }}
	{{ vSize := uiutils.Def(p.Size, "default") }}
	{{ vTestid := p.Testid }}
	{{ vBlock := uiutils.Def(p.Block, false) }}
	if uiutils.T(vHref) {
		@compose.Link(compose.LinkProps{Variant: uiutils.S(vVariant), Size: uiutils.S(vSize), LinkProps: link.LinkProps{Href: uiutils.URL(vHref, false), AriaCurrent: uiutils.S(uiutils.Cond(uiutils.T(vCurrent), "page", nil)), Class: uiutils.S(p.Class), Attrs: uiutils.Attrs("data-slot", uiutils.Coalesce(vTestid, "menu-entry"))}}) {
			{ children... }
		}
	} else if uiutils.T(vBlock) {
		@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: uiutils.S(p.Class), Attrs: uiutils.Attrs("aria-current", uiutils.Cond(uiutils.T(vCurrent), "page", nil), "data-slot", uiutils.Coalesce(vTestid, "menu-entry"))}}) {
			{ children... }
		}
	} else {
		@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: uiutils.S(p.Class), Attrs: uiutils.Attrs("aria-current", uiutils.Cond(uiutils.T(vCurrent), "page", nil), "data-slot", uiutils.Coalesce(vTestid, "menu-entry"))}}) {
			{ 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 menu-entry
blocks/menu-entry.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/menu-entry.json
    One entry of a menu: a link to its address, or, without one, its content as text in the same box (the magazine routes nothing, so it shows text). current marks the page the entry stands for (aria-current) either way.
    Props (p): href, current, variant, size, testid, block, className; children: markup. -#}
{%- set v_href = (p.href ?? null) -%}
{%- set v_current = (p.current ?? false) -%}
{%- set v_variant = (p.variant ?? 'default') -%}
{%- set v_size = (p.size ?? 'default') -%}
{%- set v_testid = (p.testid ?? null) -%}
{%- set v_block = (p.block ?? false) -%}
{%- if og_t(v_href) %}
  {%- set c_1 -%}
    {{ og_slot((children ?? null))|raw }}
  {%- endset -%}
  {{ include('compose/Link.html.twig', {'href': og_url(og_s(v_href)), 'variant': og_s(v_variant), 'size': og_s(v_size), 'ariaCurrent': og_s((og_t(v_current) ? 'page' : null)), 'class': og_s((p.className ?? '')), 'attrs': og_attrs(['data-slot', og_coalesce([v_testid, 'menu-entry'])]), 'children': c_1}, with_context = false) }}
{%- elseif og_t(v_block) %}
  {%- set c_2 -%}
    {{ og_slot((children ?? null))|raw }}
  {%- endset -%}
  {{ include('compose/Box.html.twig', {'class': og_s((p.className ?? '')), 'attrs': og_attrs(['aria-current', (og_t(v_current) ? 'page' : null), 'data-slot', og_coalesce([v_testid, 'menu-entry'])]), 'children': c_2}, with_context = false) }}
{%- else %}
  {%- set c_3 -%}
    {{ og_slot((children ?? null))|raw }}
  {%- endset -%}
  {{ include('compose/Inline.html.twig', {'class': og_s((p.className ?? '')), 'attrs': og_attrs(['aria-current', (og_t(v_current) ? 'page' : null), 'data-slot', og_coalesce([v_testid, 'menu-entry'])]), 'children': c_3}, with_context = false) }}
{%- endif %}

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 menu-entry
blocks/menu-entry.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/menu-entry.json
    One entry of a menu: a link to its address, or, without one, its content as text in the same box (the magazine routes nothing, so it shows text). current marks the page the entry stands for (aria-current) either way.
    Props (p): href, current, variant, size, testid, block, className; children: markup. *}
{var $v_href = ($p['href'] ?? null)}
{var $v_current = ($p['current'] ?? false)}
{var $v_variant = ($p['variant'] ?? 'default')}
{var $v_size = ($p['size'] ?? 'default')}
{var $v_testid = ($p['testid'] ?? null)}
{var $v_block = ($p['block'] ?? false)}
{if og_t($v_href)}
  {capture $c_1}
    {=og_slot(($children ?? null))|noescape}
  {/capture}
  {=og_include('compose/Link.latte', ['href' => og_url(og_s($v_href)), 'variant' => og_s($v_variant), 'size' => og_s($v_size), 'ariaCurrent' => og_s((og_t($v_current) ? 'page' : null)), 'class' => og_s(($p['className'] ?? '')), 'attrs' => og_attrs(['data-slot', og_coalesce([$v_testid, 'menu-entry'])]), 'children' => (string) $c_1])|noescape}
{elseif og_t($v_block)}
  {capture $c_2}
    {=og_slot(($children ?? null))|noescape}
  {/capture}
  {=og_include('compose/Box.latte', ['class' => og_s(($p['className'] ?? '')), 'attrs' => og_attrs(['aria-current', (og_t($v_current) ? 'page' : null), 'data-slot', og_coalesce([$v_testid, 'menu-entry'])]), 'children' => (string) $c_2])|noescape}
{else}
  {capture $c_3}
    {=og_slot(($children ?? null))|noescape}
  {/capture}
  {=og_include('compose/Inline.latte', ['class' => og_s(($p['className'] ?? '')), 'attrs' => og_attrs(['aria-current', (og_t($v_current) ? 'page' : null), 'data-slot', og_coalesce([$v_testid, 'menu-entry'])]), 'children' => (string) $c_3])|noescape}
{/if}

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 menu-entry
blocks/menu-entry.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/menu-entry.json
    One entry of a menu: a link to its address, or, without one, its content as text in the same box (the magazine routes nothing, so it shows text). current marks the page the entry stands for (aria-current) either way.
    Props (p): href, current, variant, size, testid, block, className; children: markup. -#}
{%- set v_href = og_def(p['href'], none) -%}
{%- set v_current = og_def(p['current'], false) -%}
{%- set v_variant = og_def(p['variant'], 'default') -%}
{%- set v_size = og_def(p['size'], 'default') -%}
{%- set v_testid = og_def(p['testid'], none) -%}
{%- set v_block = og_def(p['block'], false) -%}
{%- if og_t(v_href) %}
  {%- set c_1 -%}
    {{ og_slot(og_def(children, none))|safe }}
  {%- endset -%}
  {{ og_include('compose/link.html.j2', {'p': {'Href': og_url(og_s(v_href)), 'Variant': og_s(v_variant), 'Size': og_s(v_size), 'AriaCurrent': og_s(('page' if og_t(v_current) else none)), 'Class': og_s(og_def(p['className'], '')), 'Attrs': og_attrs(['data-slot', og_coalesce([v_testid, 'menu-entry'])])}, 'children': c_1}) }}
{%- elif og_t(v_block) %}
  {%- set c_2 -%}
    {{ og_slot(og_def(children, none))|safe }}
  {%- endset -%}
  {{ og_include('compose/box.html.j2', {'p': {'Class': og_s(og_def(p['className'], '')), 'Attrs': og_attrs(['aria-current', ('page' if og_t(v_current) else none), 'data-slot', og_coalesce([v_testid, 'menu-entry'])])}, 'children': c_2}) }}
{%- else %}
  {%- set c_3 -%}
    {{ og_slot(og_def(children, none))|safe }}
  {%- endset -%}
  {{ og_include('compose/inline.html.j2', {'p': {'Class': og_s(og_def(p['className'], '')), 'Attrs': og_attrs(['aria-current', ('page' if og_t(v_current) else none), 'data-slot', og_coalesce([v_testid, 'menu-entry'])])}, 'children': c_3}) }}
{%- endif %}

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.

One entry of a menu: a link to its address, or, without one, its content as text in the same box (the magazine routes nothing, so it shows text). current marks the page the entry stands for (aria-current) either way.

Props of MenuEntry
PropTypeDefault Description
href string-the address; none: text, not a link
current booleanfalsethe entry of the current page
variant "default" | "muted" | "block""default"the look of the link
size "default" | "sm""default"
testid string-data-slot of the entry (default: the component name)
block booleanfalsethe content holds block elements: without an address it sits in a div, not a span

Used in