Icon Tab
Icon Tab component
Install
npx ui8kit add icon-tabPulls in: button-plain, compose, kit-button, presets, utils
Preview
No static preview for this item: it needs content or a parent that this page cannot supply. The code is below.
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 icon-tab<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
One icon-only tab (28 by 28, a 16 px glyph in the children). `label` is its accessible name. Arrow-key
movement between tabs is the job of IconTabs (see roving).
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
import { variants } from "../utils";
/** IconTab: the classes of each value (shadcn/cva style). */
export const iconTabVariants = variants({
base:
"inline-flex size-8 shrink-0 items-center justify-center text-muted-foreground inset-ring " +
"inset-ring-transparent [&>svg]:size-4 rounded",
variants: {
state: {
default: "",
active: "bg-card text-foreground inset-ring-border",
},
},
defaultVariants: { state: "default" },
});
export type IconTabProps = {
active?: boolean;
label: string;
class?: string;
children?: Snippet;
onclick?: () => void;
};
</script>
<script lang="ts">
import ButtonPlain from "../compose/ButtonPlain.svelte";
import { cn } from "../utils";
let { active = false, label, class: className, children, onclick }: IconTabProps = $props();
</script>
<ButtonPlain
type="button"
role="tab"
aria-label={label}
class={cn(iconTabVariants({ state: (active ? "active" : "default") }), className)}
aria-selected={active}
tabindex={(active ? 0 : -1)}
data-slot="icon-tab"
data-state={(active ? "active" : "default")}
onclick={() => onclick?.()}
>
{@render children?.()}
</ButtonPlain>
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 icon-tab// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* One icon-only tab (28 by 28, a 16 px glyph in the children). `label` is its accessible name. Arrow-key
* movement between tabs is the job of IconTabs (see roving).
*/
import { type ReactNode } from "react";
import { ButtonPlain } from "../compose";
import { cn, variants } from "../utils";
/** IconTab: the classes of each value (shadcn/cva style). */
export const iconTabVariants = variants({
base:
"inline-flex size-8 shrink-0 items-center justify-center text-muted-foreground inset-ring " +
"inset-ring-transparent [&>svg]:size-4 rounded",
variants: {
state: {
default: "",
active: "bg-card text-foreground inset-ring-border",
},
},
defaultVariants: { state: "default" },
});
export type IconTabProps = {
active?: boolean;
label: string;
className?: string;
children?: ReactNode;
onClick?: () => void;
};
export function IconTab({ active = false, label, className, children, onClick }: IconTabProps) {
return (
<ButtonPlain
type="button"
role="tab"
aria-label={label}
className={cn(iconTabVariants({ state: (active ? "active" : "default") }), className)}
aria-selected={active}
tabIndex={(active ? 0 : -1)}
data-slot="icon-tab"
data-state={(active ? "active" : "default")}
onClick={() => onClick?.()}
>
{children}
</ButtonPlain>
);
}
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 icon-tab<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
One icon-only tab (28 by 28, a 16 px glyph in the children). `label` is its accessible name. Arrow-key
movement between tabs is the job of IconTabs (see roving).
-->
<script lang="ts">
import { variants } from "../utils";
/** IconTab: the classes of each value (shadcn/cva style). */
export const iconTabVariants = variants({
base:
"inline-flex size-8 shrink-0 items-center justify-center text-muted-foreground inset-ring " +
"inset-ring-transparent [&>svg]:size-4 rounded",
variants: {
state: {
default: "",
active: "bg-card text-foreground inset-ring-border",
},
},
defaultVariants: { state: "default" },
});
export type IconTabProps = {
active?: boolean;
label: string;
class?: string;
};
</script>
<script setup lang="ts">
import ButtonPlain from "../compose/ButtonPlain.vue";
import { cn } from "../utils";
const { active = false, label, class: className } = defineProps<IconTabProps>();
const emit = defineEmits<{ click: [] }>();
defineSlots<{ default?(): unknown }>();
</script>
<template>
<ButtonPlain
type="button"
role="tab"
:aria-label="label"
:class="cn(iconTabVariants({ state: (active ? 'active' : 'default') }), className)"
:aria-selected="active"
:tabindex="(active ? 0 : -1)"
data-slot="icon-tab"
:data-state="(active ? 'active' : 'default')"
@click="() => emit('click')"
>
<slot />
</ButtonPlain>
</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 icon-tab// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* One icon-only tab (28 by 28, a 16 px glyph in the children). `label` is its accessible name. Arrow-key
* movement between tabs is the job of IconTabs (see roving).
*/
import { type JSX } from "solid-js";
import { ButtonPlain } from "../compose";
import { cn, variants } from "../utils";
/** IconTab: the classes of each value (shadcn/cva style). */
export const iconTabVariants = variants({
base:
"inline-flex size-8 shrink-0 items-center justify-center text-muted-foreground inset-ring " +
"inset-ring-transparent [&>svg]:size-4 rounded",
variants: {
state: {
default: "",
active: "bg-card text-foreground inset-ring-border",
},
},
defaultVariants: { state: "default" },
});
export type IconTabProps = {
active?: boolean;
label: string;
class?: string;
children?: JSX.Element;
onClick?: () => void;
};
export function IconTab({ active = false, label, class: className, children, onClick }: IconTabProps) {
return (
<ButtonPlain
type="button"
role="tab"
aria-label={label}
class={cn(iconTabVariants({ state: (active ? "active" : "default") }), className)}
aria-selected={active}
tabindex={(active ? 0 : -1)}
data-slot="icon-tab"
data-state={(active ? "active" : "default")}
onClick={() => onClick?.()}
>
{children}
</ButtonPlain>
);
}
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 icon-tab// 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/patterns/icon-tab.json
package blocks
import (
"github.com/ui8kit/codegen/generated/templ/ui/button"
"github.com/ui8kit/codegen/generated/templ/compose"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// IconTabProps are the props of IconTab; the values are the JSON shapes of the TypeScript props.
type IconTabProps struct {
Active any `json:"active"`
Label any `json:"label"`
Class string `json:"className"`
}
// One icon-only tab (28 by 28, a 16 px glyph in the children). `label` is its accessible name. Arrow-key movement between tabs is the job of IconTabs (see roving).
templ IconTab(p IconTabProps) {
{{ vActive := uiutils.Def(p.Active, false) }}
{{ vLabel := p.Label }}
@compose.ButtonPlain(compose.ButtonPlainProps{ButtonProps: button.ButtonProps{Type: "button", AriaLabel: uiutils.S(vLabel), Class: uiutils.S(uiutils.Cnv(recipeIconTab.Of(map[string]any{"state": uiutils.Cond(uiutils.T(vActive), "active", "default")}), p.Class)), Attrs: uiutils.Attrs("role", "tab", "aria-selected", vActive, "tabindex", uiutils.Cond(uiutils.T(vActive), float64(0), float64(-1)), "data-slot", "icon-tab", "data-state", uiutils.Cond(uiutils.T(vActive), "active", "default"))}}) {
{ 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 icon-tab{#- 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/patterns/icon-tab.json
One icon-only tab (28 by 28, a 16 px glyph in the children). `label` is its accessible name. Arrow-key movement between tabs is the job of IconTabs (see roving).
Props (p): active, label, className; children: markup. -#}
{%- set v_active = (p.active ?? false) -%}
{%- set v_label = (p.label ?? null) -%}
{%- set c_1 -%}
{{ og_slot((children ?? null))|raw }}
{%- endset -%}
{{ include('compose/ButtonPlain.html.twig', {'type': 'button', 'ariaLabel': og_s(v_label), 'class': og_s(og_cnv([og_recipe('blocks/recipes/icon-tab.variants.json', {'state': (og_t(v_active) ? 'active' : 'default')}), (p.className ?? '')])), 'attrs': og_attrs(['role', 'tab', 'aria-selected', v_active, 'tabindex', (og_t(v_active) ? 0 : -1), 'data-slot', 'icon-tab', 'data-state', (og_t(v_active) ? 'active' : 'default')]), 'children': c_1}, 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 icon-tab{* 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/patterns/icon-tab.json
One icon-only tab (28 by 28, a 16 px glyph in the children). `label` is its accessible name. Arrow-key movement between tabs is the job of IconTabs (see roving).
Props (p): active, label, className; children: markup. *}
{var $v_active = ($p['active'] ?? false)}
{var $v_label = ($p['label'] ?? null)}
{capture $c_1}
{=og_slot(($children ?? null))|noescape}
{/capture}
{=og_include('compose/ButtonPlain.latte', ['type' => 'button', 'ariaLabel' => og_s($v_label), 'class' => og_s(og_cnv([og_recipe('blocks/recipes/icon-tab.variants.json', ['state' => (og_t($v_active) ? 'active' : 'default')]), ($p['className'] ?? '')])), 'attrs' => og_attrs(['role', 'tab', 'aria-selected', $v_active, 'tabindex', (og_t($v_active) ? 0 : -1), 'data-slot', 'icon-tab', 'data-state', (og_t($v_active) ? 'active' : 'default')]), 'children' => (string) $c_1])|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 icon-tab{#- 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/patterns/icon-tab.json
One icon-only tab (28 by 28, a 16 px glyph in the children). `label` is its accessible name. Arrow-key movement between tabs is the job of IconTabs (see roving).
Props (p): active, label, className; children: markup. -#}
{%- set v_active = og_def(p['active'], false) -%}
{%- set v_label = og_def(p['label'], none) -%}
{%- set c_1 -%}
{{ og_slot(og_def(children, none))|safe }}
{%- endset -%}
{{ og_include('compose/button-plain.html.j2', {'p': {'Type': 'button', 'AriaLabel': og_s(v_label), 'Class': og_s(og_cnv([og_recipe('blocks/recipes/icon-tab.variants.json', {'state': ('active' if og_t(v_active) else 'default')}), og_def(p['className'], '')])), 'Attrs': og_attrs(['role', 'tab', 'aria-selected', v_active, 'tabindex', (0 if og_t(v_active) else -1), 'data-slot', 'icon-tab', 'data-state', ('active' if og_t(v_active) else 'default')])}, 'children': c_1}) }}
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.
One icon-only tab (28 by 28, a 16 px glyph in the children). `label` is its accessible name. Arrow-key movement between tabs is the job of IconTabs (see roving).
| Prop | Type | Default | Description |
|---|---|---|---|
| active | boolean | false | the selected tab |
| label (required) | string | - | accessible name |