Skip to content
ui8kit

primitive / kit

Kit Radio

UI8Kit 3 Radio primitive (unstyled), from @ui8kit/registry

Install

npx ui8kit add kit-radio

Pulls in: 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-cdn
npx ui8kit add kit-radio
kit/ui/radio/Radio.svelte
<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
  Radio renders input[type=radio].
-->
<script lang="ts" module>

  export type RadioProps = {
    checked?: boolean;
    required?: boolean;
    disabled?: boolean;
    class?: string;
    [key: string]: unknown;
  };
</script>

<script lang="ts">
  import { radioClasses } from "./radio.shared";
  import { safeRest } from "../../utils/expr";

  let {
    checked,
    required,
    disabled,
    class: className,
    ...rawRest
  }: RadioProps = $props();

  const rest = $derived(safeRest(rawRest, { blank: ["id", "name", "aria-invalid", "aria-describedby"] }));
  const cls = $derived(radioClasses({ className }));
</script>

<input type="radio" {...(cls ? { class: cls } : {})} checked={checked || undefined} required={required || undefined} disabled={disabled || undefined} {...rest} />
kit/ui/radio/radio.shared.ts
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.radio — shared TypeScript contract (types + classes helpers)

import { cn } from "../../utils";

/** Radio renders input[type=radio]. */
export type RadioBaseProps = {
  checked?: boolean;
  required?: boolean;
  disabled?: boolean;
};

export type RadioClassesInput = {
  className?: string;
};

/** Compose Radio classes without rendering — the cross-runtime `asChild` substitute. */
export function radioClasses(input: RadioClassesInput = {}): string {
  return cn(input.className);
}

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 kit-radio
kit/ui/radio/radio.shared.ts
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.radio — shared TypeScript contract (types + classes helpers)

import { cn } from "../../utils";

/** Radio renders input[type=radio]. */
export type RadioBaseProps = {
  checked?: boolean;
  required?: boolean;
  disabled?: boolean;
};

export type RadioClassesInput = {
  className?: string;
};

/** Compose Radio classes without rendering — the cross-runtime `asChild` substitute. */
export function radioClasses(input: RadioClassesInput = {}): string {
  return cn(input.className);
}
kit/ui/radio/radio.tsx
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
 * Radio is a native input[type=radio]; pair it with Label.
 */

import { forwardRef, type InputHTMLAttributes } from "react";
import { radioClasses } from "./radio.shared";
import { safeRest } from "../../utils/expr";

/**
 * Radio renders input[type=radio].
 */
export type RadioProps = Omit<InputHTMLAttributes<HTMLInputElement>, "className" | "children" | "checked" | "required" | "disabled"> & {
  checked?: boolean;
  required?: boolean;
  disabled?: boolean;
  className?: string;
};

export const Radio = forwardRef<HTMLInputElement, RadioProps>(function Radio(
  { checked, required, disabled, className, ...rawRest },
  ref
) {
  const rest = safeRest(rawRest, { blank: ["id", "name", "aria-invalid", "aria-describedby"] });
  const cls = radioClasses({ className });
  return (
    <input ref={ref} type="radio" className={cls || undefined} checked={checked} required={required} disabled={disabled} {...rest} />
  );
});
Radio.displayName = "Radio";

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 kit-radio
kit/ui/radio/Radio.vue
<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
  Radio renders input[type=radio].
-->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import { radioClasses } from "./radio.shared";
import { safeRest } from "../../utils/expr";

defineOptions({ name: "Radio", inheritAttrs: false });

const props = defineProps<{
  checked?: boolean;
  required?: boolean;
  disabled?: boolean;
}>();

const attrs = useAttrs();
const callerClass = computed(() => attrs.class as string | undefined);
const restAttrs = computed(() => {
  const { class: _class, ...restEntries } = attrs;
  return safeRest(restEntries, { blank: ["id", "name", "aria-invalid", "aria-describedby"] });
});
const cls = computed(() => radioClasses({ className: callerClass.value }));
</script>

<template>
  <input type="radio" :class="cls || undefined" :checked="props.checked || undefined" :required="props.required || undefined" :disabled="props.disabled || undefined" v-bind="restAttrs" />
</template>
kit/ui/radio/radio.shared.ts
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.radio — shared TypeScript contract (types + classes helpers)

import { cn } from "../../utils";

/** Radio renders input[type=radio]. */
export type RadioBaseProps = {
  checked?: boolean;
  required?: boolean;
  disabled?: boolean;
};

export type RadioClassesInput = {
  className?: string;
};

/** Compose Radio classes without rendering — the cross-runtime `asChild` substitute. */
export function radioClasses(input: RadioClassesInput = {}): string {
  return cn(input.className);
}

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 kit-radio
kit/ui/radio/radio.shared.ts
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.radio — shared TypeScript contract (types + classes helpers)

import { cn } from "../../utils";

/** Radio renders input[type=radio]. */
export type RadioBaseProps = {
  checked?: boolean;
  required?: boolean;
  disabled?: boolean;
};

export type RadioClassesInput = {
  className?: string;
};

/** Compose Radio classes without rendering — the cross-runtime `asChild` substitute. */
export function radioClasses(input: RadioClassesInput = {}): string {
  return cn(input.className);
}
kit/ui/radio/radio.solid.tsx
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
 * Radio is a native input[type=radio]; pair it with Label.
 */

import { splitProps, type JSX, type Component } from "solid-js";
import { radioClasses } from "./radio.shared";
import { safeRest } from "../../utils/expr";

/**
 * Radio renders input[type=radio].
 */
export type RadioProps = Omit<JSX.InputHTMLAttributes<HTMLInputElement>, "class" | "className" | "children" | "checked" | "required" | "disabled"> & {
  checked?: boolean;
  required?: boolean;
  disabled?: boolean;
  class?: string;
  className?: string;
};

export const Radio: Component<RadioProps> = (props) => {
  const [local, rest] = splitProps(props, ["checked", "required", "disabled", "class", "className"]);
  const cls = () => radioClasses({ className: local.class ?? local.className });
  return (
    <input type="radio" {...(cls() ? { class: cls() } : {})} checked={local.checked || undefined} required={local.required || undefined} disabled={local.disabled || undefined} {...safeRest(rest, { blank: ["id", "name", "aria-invalid", "aria-describedby"] })} />
  );
};

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 kit-radio
ui/radio/radio.templ
// Code generated by @ui8kit/codegen. DO NOT EDIT.

/*
Radio is a native input[type=radio]; pair it with Label.
*/

package radio

import (
	uiutils "github.com/ui8kit/codegen/generated/templ/utils"
)

// RadioProps configures Radio.
type RadioProps struct {
	// Class — token class names supplied by the consumer
	Class string
	ID string
	Name string
	Value *string
	Checked bool
	Required bool
	Disabled bool
	AriaInvalid string
	AriaDescribedBy string
	Attrs templ.Attributes
}

// RadioClasses composes Radio classes without rendering —
// the server-composition escape hatch for custom root elements (no asChild in templ).
func RadioClasses(p RadioProps) string {
	return uiutils.Cn(p.Class)
}

// Radio renders the Radio contract.
templ Radio(p RadioProps) {
	<input
		if !uiutils.HasAttr(p.Attrs, "type") {
			type="radio"
		}
		if RadioClasses(p) != "" {
			class={ RadioClasses(p) }
		}
		if !uiutils.HasAttr(p.Attrs, "id") {
			if uiutils.IsSetStr(p.ID) {
				id={ p.ID }
			}
		}
		if !uiutils.HasAttr(p.Attrs, "name") {
			if uiutils.IsSetStr(p.Name) {
				name={ p.Name }
			}
		}
		if !uiutils.HasAttr(p.Attrs, "value") {
			if p.Value != nil {
				value={ *p.Value }
			}
		}
		if !uiutils.HasAttr(p.Attrs, "checked") {
			checked?={ p.Checked }
		}
		if !uiutils.HasAttr(p.Attrs, "required") {
			required?={ p.Required }
		}
		if !uiutils.HasAttr(p.Attrs, "disabled") {
			disabled?={ p.Disabled }
		}
		if !uiutils.HasAttr(p.Attrs, "aria-invalid") {
			if uiutils.IsSetStr(p.AriaInvalid) {
				aria-invalid={ p.AriaInvalid }
			}
		}
		if !uiutils.HasAttr(p.Attrs, "aria-describedby") {
			if uiutils.IsSetStr(p.AriaDescribedBy) {
				aria-describedby={ p.AriaDescribedBy }
			}
		}
		{ uiutils.RestAttrs(p.Attrs, false, "id", "name", "aria-invalid", "aria-describedby")... }
	/>
}

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 kit-radio
ui/radio/Radio.html.twig
{# Code generated by @ui8kit/codegen. DO NOT EDIT. #}
{# Radio — Radio renders input[type=radio]. #}
{# @param class (string) #}
{# @param id (string) #}
{# @param name (string) #}
{# @param value (string) #}
{# @param checked (bool) #}
{# @param required (bool) #}
{# @param disabled (bool) #}
{# @param ariaInvalid (string) #}
{# @param ariaDescribedBy (string) #}
{# @param attrs (attrs) #}
{% set class = class|default('') %}
{% set id = id ?? null %}
{% set name = name ?? null %}
{% set value = value ?? null %}
{% set checked = checked|default(false) %}
{% set required = required|default(false) %}
{% set disabled = disabled|default(false) %}
{% set ariaInvalid = ariaInvalid ?? null %}
{% set ariaDescribedBy = ariaDescribedBy ?? null %}
{% set attrs = attrs|default([]) %}
<input{{ ui8kit_attrs({'type': 'radio', 'class': ui8kit_or_null(ui8kit_classes('radioClasses', {'class': class, 'id': id, 'name': name, 'value': value, 'checked': checked, 'required': required, 'disabled': disabled, 'ariaInvalid': ariaInvalid, 'ariaDescribedBy': ariaDescribedBy})), 'id': ui8kit_or_null(id), 'name': ui8kit_or_null(name), 'value': value, 'checked': checked, 'required': required, 'disabled': disabled, 'aria-invalid': ui8kit_or_null(ariaInvalid), 'aria-describedby': ui8kit_or_null(ariaDescribedBy)}, attrs, false, ['id', 'name', 'aria-invalid', 'aria-describedby']) }}>

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 kit-radio
ui/radio/Radio.latte
{* Code generated by @ui8kit/codegen. DO NOT EDIT. *}
{* Radio — Radio renders input[type=radio]. *}
{parameters
  string $class = '',
  ?string $id = null,
  ?string $name = null,
  ?string $value = null,
  bool $checked = false,
  bool $required = false,
  bool $disabled = false,
  ?string $ariaInvalid = null,
  ?string $ariaDescribedBy = null,
  array $attrs = [],
}
<input n:attr="[
  'type' => 'radio',
  'class' => \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Classes::radioClasses(['class' => $class, 'id' => $id, 'name' => $name, 'value' => $value, 'checked' => $checked, 'required' => $required, 'disabled' => $disabled, 'ariaInvalid' => $ariaInvalid, 'ariaDescribedBy' => $ariaDescribedBy])),
  'id' => \UI8Kit\Latte\Rt::orNull($id),
  'name' => \UI8Kit\Latte\Rt::orNull($name),
  'value' => $value,
  'checked' => $checked,
  'required' => $required,
  'disabled' => $disabled,
  'aria-invalid' => \UI8Kit\Latte\Rt::orNull($ariaInvalid),
  'aria-describedby' => \UI8Kit\Latte\Rt::orNull($ariaDescribedBy),
  ...\UI8Kit\Latte\Rt::restAttrs($attrs, false, ['id', 'name', 'aria-invalid', 'aria-describedby']),
]">

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 kit-radio
ui/radio/radio.html.j2
{#- Code generated by @ui8kit/codegen. DO NOT EDIT.
    Radio: Radio renders input[type=radio].
    Props (p): Class (string), ID (string), Name (string), Value (string), Checked (bool), Required (bool), Disabled (bool), AriaInvalid (string), AriaDescribedBy (string), Attrs (attrs).
    Classes without rendering: radio_classes(p) (no asChild in Jinja2). -#}
<input
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'type') %} type="radio"{%- endif %}
  {%- with cls = radio_classes(p) %}{%- if cls %} class="{{ cls }}"{%- endif %}{%- endwith %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'id') %}{%- if ui_is_set_str(p['ID']) %} id="{{ p['ID'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'name') %}{%- if ui_is_set_str(p['Name']) %} name="{{ p['Name'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'value') %}{%- if p['Value'] is defined and p['Value'] is not none %} value="{{ p['Value'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'checked') %}{%- if ui_def(p['Checked'], false) %} checked{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'required') %}{%- if ui_def(p['Required'], false) %} required{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'disabled') %}{%- if ui_def(p['Disabled'], false) %} disabled{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-invalid') %}{%- if ui_is_set_str(p['AriaInvalid']) %} aria-invalid="{{ p['AriaInvalid'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-describedby') %}{%- if ui_is_set_str(p['AriaDescribedBy']) %} aria-describedby="{{ p['AriaDescribedBy'] }}"{%- endif %}{%- endif %}
  {{ ui_attr_html(ui_def(p['Attrs'], {}), false, ['id', 'name', 'aria-invalid', 'aria-describedby']) }}
>

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 data for this item.