Skip to content
ui8kit

primitive / primitives

Icon Badge

Icon Badge primitive

Install

npx ui8kit add icon-badge

Pulls in: kit-text, recipes, utils

Preview

variant: default
variant: primary
variant: accent
variant: secondary
variant: outline
variant: destructive
size: xs
size: sm
size: default
size: lg
size: xl

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 icon-badge
compose/IconBadge.svelte
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- IconBadge: Text <span> + recipe iconbadge. -->
<script lang="ts">
  import type { ComponentProps, Snippet } from "svelte";
  import Prim from "../kit/ui/text/Text.svelte";
  import { cn } from "../kit/utils";
  import { rc } from "./recipes";

  let { "variant": v_variant, "size": v_size, class: className, children, ...rest }: Omit<ComponentProps<typeof Prim>, "tag"> & { "variant"?: string | number; "size"?: string | number; class?: string; children?: Snippet } = $props();
  const cls = $derived(cn(rc("iconbadge", { "variant": v_variant, "size": v_size }), className));
</script>

<Prim tag={"span" as never} class={cls} {...rest}>{@render children?.()}</Prim>

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 icon-badge
compose/icon-badge.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import type { ComponentProps } from "react";
import { Text as Prim } from "../kit/ui/text/text";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

export type IconBadgeProps = Omit<ComponentProps<typeof Prim>, "tag" | "variant" | "size"> & { "variant"?: string | number; "size"?: string | number; className?: string };

/** IconBadge: Text <span> + recipe iconbadge. */
export function IconBadge({ "variant": v_variant, "size": v_size, className, ...rest }: IconBadgeProps) {
  return <Prim tag={"span" as never} className={cn(rc("iconbadge", { "variant": v_variant, "size": v_size }), className)} {...rest} />;
}

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 icon-badge
compose/IconBadge.vue
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- IconBadge: Text <span> + recipe iconbadge. -->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import Prim from "../kit/ui/text/Text.vue";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

defineOptions({ name: "IconBadge", inheritAttrs: false });
const props = defineProps<{ "variant"?: string | number; "size"?: string | number }>();
const attrs = useAttrs();
const rest = computed(() => {
  const { class: _class, ...r } = attrs;
  return r;
});
const cls = computed(() => cn(rc("iconbadge", { "variant": props["variant"], "size": props["size"] }), attrs.class as string | undefined));
const tagValue = computed(() => "span");
</script>

<template>
  <Prim :tag="tagValue as never" :class="cls" v-bind="rest"><slot /></Prim>
</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 icon-badge
compose/icon-badge.solid.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import { splitProps, type ComponentProps } from "solid-js";
import { Text as Prim } from "../kit/ui/text/text.solid";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

export type IconBadgeProps = Omit<ComponentProps<typeof Prim>, "tag" | "class" | "className" | "variant" | "size"> & { "variant"?: string | number; "size"?: string | number; class?: string; className?: string };

/** IconBadge: Text <span> + recipe iconbadge. */
export function IconBadge(props: IconBadgeProps) {
  const [local, rest] = splitProps(props, ["variant", "size", "class", "className"]);
  return <Prim tag={"span" as never} class={cn(rc("iconbadge", { "variant": local["variant"], "size": local["size"] }), local.class ?? local.className)} {...rest} />;
}

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 icon-badge
compose/icon-badge.templ
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.

package compose

import "github.com/ui8kit/codegen/generated/templ/ui/text"

// IconBadgeProps: IconBadge: Text <span> + recipe iconbadge.
type IconBadgeProps struct {
	Variant string
	Size string
	text.TextProps
}

func iconBadgeInner(p IconBadgeProps) text.TextProps {
	in := p.TextProps
	in.Class = Join(Rc("iconbadge", map[string]string{"variant": p.Variant, "size": p.Size}), p.TextProps.Class)
	in.Tag = "span"
	return in
}

// IconBadge renders Text with the composition classes.
templ IconBadge(p IconBadgeProps) {
	@text.Text(iconBadgeInner(p)) {
		{ 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 icon-badge
compose/IconBadge.html.twig
{# Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. #}
{# IconBadge: Text <span> + recipe iconbadge. Params: variant, size, class, attrs + the params of Text. #}
{% include 'ui/text/Text.html.twig' with compose_props('IconBadge', _context) only %}

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 icon-badge
compose/IconBadge.latte
{* Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. *}
{* IconBadge: Text <span> + recipe iconbadge. *}
{parameters
  string $class = '',
  string $tag = '',
  array $attrs = [],
  string $children = '',
  $variant = null,
  $size = null,
}
{include '../ui/text/Text.latte', ...\CodegenX\Compose\Latte\Compose::props('IconBadge', ['class' => $class, 'tag' => $tag, 'attrs' => $attrs, 'children' => $children, 'variant' => $variant, 'size' => $size])}

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 icon-badge
compose/icon-badge.html.j2
{#- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
    IconBadge: Text <span> + recipe iconbadge. Props (p): Variant, Size, Class, Attrs + the props of Text. -#}
{%- with p = compose_props('IconBadge', p) %}{% include 'ui/text/text.html.j2' %}{% endwith %}

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.

No props.