Topic Chips
Topic Chips component
Install
npx ui8kit add topic-chipsPulls in: button, compose, group, kit-box, kit-button, lucide-icon, 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 topic-chips<!-- 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 centered row of topic pills: links where a topic has an address, else buttons. tone inverse: on a dark band
with an icon per topic; default: outlined.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
import type { Topic } from "./topic-chips.types";
export type TopicChipsProps = {
topics: Topic[];
tone?: "default" | "inverse";
};
</script>
<script lang="ts">
import Button from "../compose/Button.svelte";
import Group from "../compose/Group.svelte";
import LucideIcon from "../icons/LucideIcon.svelte";
import { urlOf } from "../utils";
let { topics, tone = "default" }: TopicChipsProps = $props();
</script>
<Group gap="2" align="center" justify="center" class="flex-wrap" data-slot="hero-topics">
{#each topics as topic (topic.id)}
{#if ((tone as string) === "inverse")}
<Button
href={urlOf(topic.href)}
variant="ghost"
size="sm"
class="gap-2 text-background inset-ring-background/30 hover:bg-background/10"
>
{#if topic.icon}
<LucideIcon name={topic.icon} size={16} />
{/if}
{topic.name}
</Button>
{:else}
<Button href={urlOf(topic.href)} variant="outline" size="sm">
{topic.name}
</Button>
{/if}
{/each}
</Group>
// 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 Topic = {
id: string;
name: string;
icon: string;
href?: string;
};
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 topic-chips// 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 centered row of topic pills: links where a topic has an address, else buttons. tone inverse: on a dark band
* with an icon per topic; default: outlined.
*/
import { Fragment, type ReactNode } from "react";
import { Button, Group } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { urlOf } from "../utils";
import type { Topic } from "./topic-chips.types";
export type TopicChipsProps = {
topics: Topic[];
tone?: "default" | "inverse";
};
export function TopicChips({ topics, tone = "default" }: TopicChipsProps) {
return (
<Group gap="2" align="center" justify="center" className="flex-wrap" data-slot="hero-topics">
{(topics ?? []).map((topic) => (
<Fragment key={topic.id}>
{((tone as string) === "inverse") ? (
<Button
href={urlOf(topic.href)}
variant="ghost"
size="sm"
className="gap-2 text-background inset-ring-background/30 hover:bg-background/10"
>
{topic.icon ? (
<LucideIcon name={topic.icon} size={16} />
) : null}
{topic.name}
</Button>
) : (
<Button href={urlOf(topic.href)} variant="outline" size="sm">
{topic.name}
</Button>
)}
</Fragment>
))}
</Group>
);
}
// 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 Topic = {
id: string;
name: string;
icon: string;
href?: string;
};
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 topic-chips// 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 Topic = {
id: string;
name: string;
icon: string;
href?: string;
};
<!-- 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 centered row of topic pills: links where a topic has an address, else buttons. tone inverse: on a dark band
with an icon per topic; default: outlined.
-->
<script lang="ts">
import type { Topic } from "./topic-chips.types";
export type TopicChipsProps = {
topics: Topic[];
tone?: "default" | "inverse";
};
</script>
<script setup lang="ts">
import Button from "../compose/Button.vue";
import Group from "../compose/Group.vue";
import LucideIcon from "../icons/LucideIcon.vue";
import { urlOf } from "../utils";
const { topics, tone = "default" } = defineProps<TopicChipsProps>();
</script>
<template>
<Group gap="2" align="center" justify="center" class="flex-wrap" data-slot="hero-topics">
<template v-for="topic in topics" :key="topic.id">
<Button v-if="((tone as string) === 'inverse')"
:href="urlOf(topic.href)"
variant="ghost"
size="sm"
class="gap-2 text-background inset-ring-background/30 hover:bg-background/10"
>
<LucideIcon v-if="topic.icon" :name="topic.icon" :size="16" />
{{ topic.name }}
</Button>
<Button v-else :href="urlOf(topic.href)" variant="outline" size="sm">
{{ topic.name }}
</Button>
</template>
</Group>
</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 topic-chips// 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 centered row of topic pills: links where a topic has an address, else buttons. tone inverse: on a dark band
* with an icon per topic; default: outlined.
*/
import { For, type JSX } from "solid-js";
import { Button, Group } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { urlOf } from "../utils";
import type { Topic } from "./topic-chips.types";
export type TopicChipsProps = {
topics: Topic[];
tone?: "default" | "inverse";
};
export function TopicChips({ topics, tone = "default" }: TopicChipsProps) {
return (
<Group gap="2" align="center" justify="center" class="flex-wrap" data-slot="hero-topics">
<For each={topics ?? []}>{(topic) => (
<>
{((tone as string) === "inverse") ? (
<Button
href={urlOf(topic.href)}
variant="ghost"
size="sm"
class="gap-2 text-background inset-ring-background/30 hover:bg-background/10"
>
{topic.icon ? (
<LucideIcon name={topic.icon} size={16} />
) : null}
{topic.name}
</Button>
) : (
<Button href={urlOf(topic.href)} variant="outline" size="sm">
{topic.name}
</Button>
)}
</>
)}</For>
</Group>
);
}
// 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 Topic = {
id: string;
name: string;
icon: string;
href?: string;
};
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 topic-chips// 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/topic-chips.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/icons"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// TopicChipsProps are the props of TopicChips; the values are the JSON shapes of the TypeScript props.
type TopicChipsProps struct {
Topics any `json:"topics"`
Tone any `json:"tone"`
}
// A centered row of topic pills: links where a topic has an address, else buttons. tone inverse: on a dark band with an icon per topic; default: outlined.
templ TopicChips(p TopicChipsProps) {
{{ vTopics := p.Topics }}
{{ vTone := uiutils.Def(p.Tone, "default") }}
@compose.Group(compose.GroupProps{Gap: "2", Align: "center", Justify: "center", BoxProps: box.BoxProps{Class: "flex-wrap", Attrs: uiutils.Attrs("data-slot", "hero-topics")}}) {
for _, vTopic := range uiutils.L(vTopics) {
if uiutils.Eq(vTone, "inverse") {
@compose.Button(compose.ButtonProps{Variant: "ghost", Size: "sm", ButtonProps: button.ButtonProps{Href: uiutils.URL(uiutils.Get(vTopic, "href"), false), Class: "gap-2 text-background inset-ring-background/30 hover:bg-background/10"}}) {
if uiutils.T(uiutils.Get(vTopic, "icon")) {
@icons.LucideIcon(icons.LucideIconProps{Name: uiutils.S(uiutils.Get(vTopic, "icon")), Size: 16})
}
{ uiutils.Text(uiutils.Get(vTopic, "name")) }
}
} else {
@compose.Button(compose.ButtonProps{Variant: "outline", Size: "sm", ButtonProps: button.ButtonProps{Href: uiutils.URL(uiutils.Get(vTopic, "href"), false)}}) {
{ uiutils.Text(uiutils.Get(vTopic, "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 topic-chips{#- 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/topic-chips.json
A centered row of topic pills: links where a topic has an address, else buttons. tone inverse: on a dark band with an icon per topic; default: outlined.
Props (p): topics, tone. -#}
{%- set v_topics = (p.topics ?? null) -%}
{%- set v_tone = (p.tone ?? 'default') -%}
{%- set c_3 -%}
{%- for v_topic in og_l(v_topics) %}
{%- if og_t(og_eq(v_tone, 'inverse')) %}
{%- set c_1 -%}
{%- if og_t(og_get(v_topic, ['icon'])) %}
{{ include('icons/LucideIcon.html.twig', {'name': og_s(og_get(v_topic, ['icon'])), 'size': 16}, with_context = false) }}
{%- endif %}
{{ og_text(og_get(v_topic, ['name'])) }}
{%- endset -%}
{{ include('compose/Button.html.twig', {'href': og_url(og_s(og_get(v_topic, ['href']))), 'variant': 'ghost', 'size': 'sm', 'class': 'gap-2 text-background inset-ring-background/30 hover:bg-background/10', 'children': c_1}, with_context = false) }}
{%- else %}
{%- set c_2 -%}
{{ og_text(og_get(v_topic, ['name'])) }}
{%- endset -%}
{{ include('compose/Button.html.twig', {'href': og_url(og_s(og_get(v_topic, ['href']))), 'variant': 'outline', 'size': 'sm', 'children': c_2}, with_context = false) }}
{%- endif %}
{%- endfor %}
{%- endset -%}
{{ include('compose/Group.html.twig', {'gap': '2', 'align': 'center', 'justify': 'center', 'class': 'flex-wrap', 'attrs': og_attrs(['data-slot', 'hero-topics']), 'children': c_3}, with_context = false) }}
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 topic-chips{* 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/topic-chips.json
A centered row of topic pills: links where a topic has an address, else buttons. tone inverse: on a dark band with an icon per topic; default: outlined.
Props (p): topics, tone. *}
{var $v_topics = ($p['topics'] ?? null)}
{var $v_tone = ($p['tone'] ?? 'default')}
{capture $c_3}
{foreach og_l($v_topics) as $v_topic}
{if og_t(og_eq($v_tone, 'inverse'))}
{capture $c_1}
{if og_t(og_get($v_topic, ['icon']))}
{=og_include('icons/LucideIcon.latte', ['name' => og_s(og_get($v_topic, ['icon'])), 'size' => 16])|noescape}
{/if}
{=og_text(og_get($v_topic, ['name']))}
{/capture}
{=og_include('compose/Button.latte', ['href' => og_url(og_s(og_get($v_topic, ['href']))), 'variant' => 'ghost', 'size' => 'sm', 'class' => 'gap-2 text-background inset-ring-background/30 hover:bg-background/10', 'children' => (string) $c_1])|noescape}
{else}
{capture $c_2}
{=og_text(og_get($v_topic, ['name']))}
{/capture}
{=og_include('compose/Button.latte', ['href' => og_url(og_s(og_get($v_topic, ['href']))), 'variant' => 'outline', 'size' => 'sm', 'children' => (string) $c_2])|noescape}
{/if}
{/foreach}
{/capture}
{=og_include('compose/Group.latte', ['gap' => '2', 'align' => 'center', 'justify' => 'center', 'class' => 'flex-wrap', 'attrs' => og_attrs(['data-slot', 'hero-topics']), 'children' => (string) $c_3])|noescape}
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 topic-chips{#- 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/topic-chips.json
A centered row of topic pills: links where a topic has an address, else buttons. tone inverse: on a dark band with an icon per topic; default: outlined.
Props (p): topics, tone. -#}
{%- set v_topics = og_def(p['topics'], none) -%}
{%- set v_tone = og_def(p['tone'], 'default') -%}
{%- set c_3 -%}
{%- for v_topic in og_l(v_topics) %}
{%- if og_t(og_eq(v_tone, 'inverse')) %}
{%- set c_1 -%}
{%- if og_t(og_get(v_topic, ['icon'])) %}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': og_s(og_get(v_topic, ['icon'])), 'Size': 16}}) }}
{%- endif %}
{{ og_text(og_get(v_topic, ['name'])) }}
{%- endset -%}
{{ og_include('compose/button.html.j2', {'p': {'Href': og_url(og_s(og_get(v_topic, ['href']))), 'Variant': 'ghost', 'Size': 'sm', 'Class': 'gap-2 text-background inset-ring-background/30 hover:bg-background/10'}, 'children': c_1}) }}
{%- else %}
{%- set c_2 -%}
{{ og_text(og_get(v_topic, ['name'])) }}
{%- endset -%}
{{ og_include('compose/button.html.j2', {'p': {'Href': og_url(og_s(og_get(v_topic, ['href']))), 'Variant': 'outline', 'Size': 'sm'}, 'children': c_2}) }}
{%- endif %}
{%- endfor %}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Gap': '2', 'Align': 'center', 'Justify': 'center', 'Class': 'flex-wrap', 'Attrs': og_attrs(['data-slot', 'hero-topics'])}, 'children': c_3}) }}
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 centered row of topic pills: links where a topic has an address, else buttons. tone inverse: on a dark band with an icon per topic; default: outlined.
| Prop | Type | Default | Description |
|---|---|---|---|
| topics (required) | Topic[] | - | |
| tone | "default" | "inverse" | "default" |