Badge
Badge primitive
Install
npx ui8kit add badgePulls in: kit-text, recipes, 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 badgecompose/Badge.svelte
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Badge: Text <span> + recipe badge. -->
<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 { "size": v_size, "variant": v_variant, class: className, children, ...rest }: Omit<ComponentProps<typeof Prim>, "tag"> & { "size"?: string | number; "variant"?: string | number; class?: string; children?: Snippet } = $props();
const cls = $derived(cn(rc("badge", { "size": v_size, "variant": v_variant }), className));
</script>
<Prim tag={"span" as never} class={cls} data-slot="badge" {...rest}>{@render children?.()}</Prim>
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 badgecompose/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 BadgeProps = Omit<ComponentProps<typeof Prim>, "tag" | "size" | "variant"> & { "size"?: string | number; "variant"?: string | number; className?: string };
/** Badge: Text <span> + recipe badge. */
export function Badge({ "size": v_size, "variant": v_variant, className, ...rest }: BadgeProps) {
return <Prim tag={"span" as never} className={cn(rc("badge", { "size": v_size, "variant": v_variant }), className)} data-slot="badge" {...rest} />;
}
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 badgecompose/Badge.vue
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Badge: Text <span> + recipe badge. -->
<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: "Badge", inheritAttrs: false });
const props = defineProps<{ "size"?: string | number; "variant"?: string | number }>();
const attrs = useAttrs();
const rest = computed(() => {
const { class: _class, ...r } = attrs;
return r;
});
const cls = computed(() => cn(rc("badge", { "size": props["size"], "variant": props["variant"] }), attrs.class as string | undefined));
const tagValue = computed(() => "span");
</script>
<template>
<Prim :tag="tagValue as never" :class="cls" data-slot="badge" v-bind="rest"><slot /></Prim>
</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 badgecompose/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 BadgeProps = Omit<ComponentProps<typeof Prim>, "tag" | "class" | "className" | "size" | "variant"> & { "size"?: string | number; "variant"?: string | number; class?: string; className?: string };
/** Badge: Text <span> + recipe badge. */
export function Badge(props: BadgeProps) {
const [local, rest] = splitProps(props, ["size", "variant", "class", "className"]);
return <Prim tag={"span" as never} class={cn(rc("badge", { "size": local["size"], "variant": local["variant"] }), local.class ?? local.className)} data-slot="badge" {...rest} />;
}
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 badgecompose/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"
// BadgeProps: Badge: Text <span> + recipe badge.
type BadgeProps struct {
Size string
Variant string
text.TextProps
}
func badgeInner(p BadgeProps) text.TextProps {
in := p.TextProps
in.Class = Join(Rc("badge", map[string]string{"size": p.Size, "variant": p.Variant}), p.TextProps.Class)
in.Tag = "span"
in.Attrs = WithAttrs(in.Attrs, map[string]string{"data-slot": "badge"})
return in
}
// Badge renders Text with the composition classes.
templ Badge(p BadgeProps) {
@text.Text(badgeInner(p)) {
{ children... }
}
}
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 badgecompose/Badge.html.twig
{# Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. #}
{# Badge: Text <span> + recipe badge. Params: size, variant, class, attrs + the params of Text. #}
{% include 'ui/text/Text.html.twig' with compose_props('Badge', _context) only %}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 badgecompose/Badge.latte
{* Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. *}
{* Badge: Text <span> + recipe badge. *}
{parameters
string $class = '',
string $tag = '',
array $attrs = [],
string $children = '',
$size = null,
$variant = null,
}
{include '../ui/text/Text.latte', ...\CodegenX\Compose\Latte\Compose::props('Badge', ['class' => $class, 'tag' => $tag, 'attrs' => $attrs, 'children' => $children, 'size' => $size, 'variant' => $variant])}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 badgecompose/badge.html.j2
{#- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
Badge: Text <span> + recipe badge. Props (p): Size, Variant, Class, Attrs + the props of Text. -#}
{%- with p = compose_props('Badge', p) %}{% include 'ui/text/text.html.j2' %}{% endwith %}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.