Icon
Icon primitive
Install
npx ui8kit add iconPulls in: kit-icon, 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 iconcompose/Icon.svelte
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Icon: Icon + recipe icon. -->
<script lang="ts">
import type { ComponentProps, Snippet } from "svelte";
import Prim from "../kit/ui/icon/Icon.svelte";
import { cn } from "../kit/utils";
import { rc } from "./recipes";
let { "size": v_size, "type": v_type, class: className, children, ...rest }: ComponentProps<typeof Prim> & { "size"?: string | number; "type"?: string | number; class?: string; children?: Snippet } = $props();
const cls = $derived(cn(rc("icon", { "size": v_size, "type": v_type }), className));
</script>
<Prim class={cls} {...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 iconcompose/icon.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import type { ComponentProps } from "react";
import { Icon as Prim } from "../kit/ui/icon/icon";
import { cn } from "../kit/utils";
import { rc } from "./recipes";
export type IconProps = Omit<ComponentProps<typeof Prim>, "tag" | "size" | "type"> & { "size"?: string | number; "type"?: string | number; className?: string };
/** Icon: Icon + recipe icon. */
export function Icon({ "size": v_size, "type": v_type, className, ...rest }: IconProps) {
return <Prim className={cn(rc("icon", { "size": v_size, "type": v_type }), className)} {...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 iconcompose/Icon.vue
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Icon: Icon + recipe icon. -->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import Prim from "../kit/ui/icon/Icon.vue";
import { cn } from "../kit/utils";
import { rc } from "./recipes";
defineOptions({ name: "Icon", inheritAttrs: false });
const props = defineProps<{ "size"?: string | number; "type"?: string | number }>();
const attrs = useAttrs();
const rest = computed(() => {
const { class: _class, ...r } = attrs;
return r;
});
const cls = computed(() => cn(rc("icon", { "size": props["size"], "type": props["type"] }), attrs.class as string | undefined));
const tagValue = computed(() => "");
</script>
<template>
<Prim :class="cls" 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 iconcompose/icon.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 { Icon as Prim } from "../kit/ui/icon/icon.solid";
import { cn } from "../kit/utils";
import { rc } from "./recipes";
export type IconProps = Omit<ComponentProps<typeof Prim>, "tag" | "class" | "className" | "size" | "type"> & { "size"?: string | number; "type"?: string | number; class?: string; className?: string };
/** Icon: Icon + recipe icon. */
export function Icon(props: IconProps) {
const [local, rest] = splitProps(props, ["size", "type", "class", "className"]);
return <Prim class={cn(rc("icon", { "size": local["size"], "type": local["type"] }), local.class ?? local.className)} {...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 iconcompose/icon.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/icon"
// IconProps: Icon: Icon + recipe icon.
type IconProps struct {
Size string
Type string
icon.IconProps
}
func iconInner(p IconProps) icon.IconProps {
in := p.IconProps
in.Class = Join(Rc("icon", map[string]string{"size": p.Size, "type": p.Type}), p.IconProps.Class)
return in
}
// Icon renders Icon with the composition classes.
templ Icon(p IconProps) {
@icon.Icon(iconInner(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 iconcompose/Icon.html.twig
{# Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. #}
{# Icon: Icon + recipe icon. Params: size, type, class, attrs + the params of Icon. #}
{% include 'ui/icon/Icon.html.twig' with compose_props('Icon', _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 iconcompose/Icon.latte
{* Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. *}
{* Icon: Icon + recipe icon. *}
{parameters
string $class = '',
string $label = '',
array $attrs = [],
string $children = '',
$size = null,
$type = null,
}
{include '../ui/icon/Icon.latte', ...[...\CodegenX\Compose\Latte\Compose::props('Icon', ['class' => $class, 'label' => $label, 'attrs' => $attrs, 'children' => $children, 'size' => $size, 'type' => $type]), 'size' => '']}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 iconcompose/icon.html.j2
{#- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
Icon: Icon + recipe icon. Props (p): Size, Type, Class, Attrs + the props of Icon. -#}
{%- with p = compose_props('Icon', p) %}{% include 'ui/icon/icon.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.
Icon renders span[data-slot=icon]; Label switches to role=img + aria-label.
| Prop | Type | Default | Description |
|---|---|---|---|
| size | string | "sm" | size token: xs, sm, md, lg, xl (default sm) |
| label | string | - | accessible name; omitted = decorative (aria-hidden) |