Skip to content
ui8kit

component / components

Post Tags

Post Tags component

Install

npx ui8kit add post-tags

Pulls in: badge, compose, group, kit-box, kit-text, nav-bar, utils

Preview

PerformanceStatic sitesCachingOffline

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 post-tags
components/post-tags.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. -->
<!-- The tags of a post as small badges in a wrapping row. -->
<script lang="ts" module>
  import type { Snippet } from "svelte";
  import type { NavLink } from "../blocks/nav-bar.types";

  export type PostTagsProps = {
    tags: NavLink[];
    align?: "start" | "center";
  };
</script>

<script lang="ts">
  import Badge from "../compose/Badge.svelte";
  import Group from "../compose/Group.svelte";

  let { tags, align = "start" }: PostTagsProps = $props();
</script>

<Group gap="2" justify={align} class="flex-wrap" data-slot="post-tags">
  {#each tags as tag (tag.id)}
    <Badge variant="secondary" size="sm">
      {tag.name}
    </Badge>
  {/each}
</Group>

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 post-tags
components/post-tags.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.
/** The tags of a post as small badges in a wrapping row. */
import { type ReactNode } from "react";
import { Badge, Group } from "../compose";
import type { NavLink } from "../blocks/nav-bar.types";

export type PostTagsProps = {
  tags: NavLink[];
  align?: "start" | "center";
};

export function PostTags({ tags, align = "start" }: PostTagsProps) {
  return (
    <Group gap="2" justify={align} className="flex-wrap" data-slot="post-tags">
      {(tags ?? []).map((tag) => (
        <Badge key={tag.id} variant="secondary" size="sm">
          {tag.name}
        </Badge>
      ))}
    </Group>
  );
}

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 post-tags
components/post-tags.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. -->
<!-- The tags of a post as small badges in a wrapping row. -->
<script lang="ts">
import type { NavLink } from "../blocks/nav-bar.types";

export type PostTagsProps = {
  tags: NavLink[];
  align?: "start" | "center";
};
</script>

<script setup lang="ts">
import Badge from "../compose/Badge.vue";
import Group from "../compose/Group.vue";

const { tags, align = "start" } = defineProps<PostTagsProps>();
</script>

<template>
  <Group gap="2" :justify="align" class="flex-wrap" data-slot="post-tags">
    <Badge v-for="tag in tags" :key="tag.id" variant="secondary" size="sm">
      {{ tag.name }}
    </Badge>
  </Group>
</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 post-tags
components/post-tags.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.
/** The tags of a post as small badges in a wrapping row. */
import { For, type JSX } from "solid-js";
import { Badge, Group } from "../compose";
import type { NavLink } from "../blocks/nav-bar.types";

export type PostTagsProps = {
  tags: NavLink[];
  align?: "start" | "center";
};

export function PostTags({ tags, align = "start" }: PostTagsProps) {
  return (
    <Group gap="2" justify={align} class="flex-wrap" data-slot="post-tags">
      <For each={tags ?? []}>{(tag) => (
        <Badge variant="secondary" size="sm">
          {tag.name}
        </Badge>
      )}</For>
    </Group>
  );
}

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 post-tags
blocks/post-tags.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/post-tags.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/text"
	uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)

// PostTagsProps are the props of PostTags; the values are the JSON shapes of the TypeScript props.
type PostTagsProps struct {
	Tags any `json:"tags"`
	Align any `json:"align"`
}

// The tags of a post as small badges in a wrapping row.
templ PostTags(p PostTagsProps) {
	{{ vTags := p.Tags }}
	{{ vAlign := uiutils.Def(p.Align, "start") }}
	@compose.Group(compose.GroupProps{Gap: "2", Justify: uiutils.S(vAlign), BoxProps: box.BoxProps{Class: "flex-wrap", Attrs: uiutils.Attrs("data-slot", "post-tags")}}) {
		for _, vTag := range uiutils.L(vTags) {
			@compose.Badge(compose.BadgeProps{Variant: "secondary", Size: "sm", TextProps: text.TextProps{}}) {
				{ uiutils.Text(uiutils.Get(vTag, "name")) }
			}
		}
	}
}

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 post-tags
blocks/post-tags.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/post-tags.json
    The tags of a post as small badges in a wrapping row.
    Props (p): tags, align. -#}
{%- set v_tags = (p.tags ?? null) -%}
{%- set v_align = (p.align ?? 'start') -%}
{%- set c_2 -%}
  {%- for v_tag in og_l(v_tags) %}
    {%- set c_1 -%}
      {{ og_text(og_get(v_tag, ['name'])) }}
    {%- endset -%}
    {{ include('compose/Badge.html.twig', {'variant': 'secondary', 'size': 'sm', 'children': c_1}, with_context = false) }}
  {%- endfor %}
{%- endset -%}
{{ include('compose/Group.html.twig', {'gap': '2', 'justify': og_s(v_align), 'class': 'flex-wrap', 'attrs': og_attrs(['data-slot', 'post-tags']), 'children': c_2}, 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 post-tags
blocks/post-tags.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/post-tags.json
    The tags of a post as small badges in a wrapping row.
    Props (p): tags, align. *}
{var $v_tags = ($p['tags'] ?? null)}
{var $v_align = ($p['align'] ?? 'start')}
{capture $c_2}
  {foreach og_l($v_tags) as $v_tag}
    {capture $c_1}
      {=og_text(og_get($v_tag, ['name']))}
    {/capture}
    {=og_include('compose/Badge.latte', ['variant' => 'secondary', 'size' => 'sm', 'children' => (string) $c_1])|noescape}
  {/foreach}
{/capture}
{=og_include('compose/Group.latte', ['gap' => '2', 'justify' => og_s($v_align), 'class' => 'flex-wrap', 'attrs' => og_attrs(['data-slot', 'post-tags']), 'children' => (string) $c_2])|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 post-tags
blocks/post-tags.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/post-tags.json
    The tags of a post as small badges in a wrapping row.
    Props (p): tags, align. -#}
{%- set v_tags = og_def(p['tags'], none) -%}
{%- set v_align = og_def(p['align'], 'start') -%}
{%- set c_2 -%}
  {%- for v_tag in og_l(v_tags) %}
    {%- set c_1 -%}
      {{ og_text(og_get(v_tag, ['name'])) }}
    {%- endset -%}
    {{ og_include('compose/badge.html.j2', {'p': {'Variant': 'secondary', 'Size': 'sm'}, 'children': c_1}) }}
  {%- endfor %}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Gap': '2', 'Justify': og_s(v_align), 'Class': 'flex-wrap', 'Attrs': og_attrs(['data-slot', 'post-tags'])}, 'children': c_2}) }}

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.

The tags of a post as small badges in a wrapping row.

Props of PostTags
PropTypeDefault Description
tags (required)NavLink[]-
align "start" | "center""start"

Used in