Skip to content
ui8kit

primitive / primitives

Button

Button primitive

Install

npx ui8kit add button

Pulls in: kit-button, recipes, utils

Preview

variant: default
variant: outline
variant: ghost
variant: secondary
variant: destructive
variant: link
size: sm
size: default
size: lg

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

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

<Prim class={cls} data-slot="button" {...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 button
compose/button.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import type { ComponentProps } from "react";
import { Button as Prim } from "../kit/ui/button/button";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

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

/** Button: Button + recipe button. */
export function Button({ "variant": v_variant, "size": v_size, "layout": v_layout, className, ...rest }: ButtonProps) {
  return <Prim className={cn(rc("button", { "variant": v_variant, "size": v_size, "layout": v_layout }), className)} data-slot="button" {...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 button
compose/Button.vue
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Button: Button + recipe button. -->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import Prim from "../kit/ui/button/Button.vue";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

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

<template>
  <Prim :class="cls" data-slot="button" 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 button
compose/button.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 { Button as Prim } from "../kit/ui/button/button.solid";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

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

/** Button: Button + recipe button. */
export function Button(props: ButtonProps) {
  const [local, rest] = splitProps(props, ["variant", "size", "layout", "class", "className"]);
  return <Prim class={cn(rc("button", { "variant": local["variant"], "size": local["size"], "layout": local["layout"] }), local.class ?? local.className)} data-slot="button" {...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 button
compose/button.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/button"

// ButtonProps: Button: Button + recipe button.
type ButtonProps struct {
	Variant string
	Size string
	Layout string
	button.ButtonProps
}

func buttonInner(p ButtonProps) button.ButtonProps {
	in := p.ButtonProps
	in.Class = Join(Rc("button", map[string]string{"variant": p.Variant, "size": p.Size, "layout": p.Layout}), p.ButtonProps.Class)
	in.Attrs = WithAttrs(in.Attrs, map[string]string{"data-slot": "button"})
	return in
}

// Button renders Button with the composition classes.
templ Button(p ButtonProps) {
	@button.Button(buttonInner(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 button
compose/Button.html.twig
{# Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. #}
{# Button: Button + recipe button. Params: variant, size, layout, class, attrs + the params of Button. #}
{% include 'ui/button/Button.html.twig' with compose_props('Button', _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 button
compose/Button.latte
{* Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. *}
{* Button: Button + recipe button. *}
{parameters
  string $class = '',
  string $type = '',
  ?string $form = null,
  string $href = '',
  bool $disabled = false,
  ?bool $pressed = null,
  ?bool $expanded = null,
  ?string $ariaLabel = null,
  ?string $ariaPressed = null,
  ?string $ariaExpanded = null,
  ?string $ariaControls = null,
  array $attrs = [],
  string $children = '',
  $variant = null,
  $size = null,
  $layout = null,
}
{include '../ui/button/Button.latte', ...\CodegenX\Compose\Latte\Compose::props('Button', ['class' => $class, 'type' => $type, 'form' => $form, 'href' => $href, 'disabled' => $disabled, 'pressed' => $pressed, 'expanded' => $expanded, 'ariaLabel' => $ariaLabel, 'ariaPressed' => $ariaPressed, 'ariaExpanded' => $ariaExpanded, 'ariaControls' => $ariaControls, 'attrs' => $attrs, 'children' => $children, 'variant' => $variant, 'size' => $size, 'layout' => $layout])}

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

Button renders a button element, or an anchor when Href is set. Type/Form apply only in button mode; Disabled on anchors uses aria-disabled.

Props of Button
PropTypeDefault Description
type string-button type (default button)
href string-renders an anchor when set
disabled boolean-blocks interaction