Switch
Switch primitive
Install
npx ui8kit add switchPulls in: kit-switch, 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 switchcompose/Switch.svelte
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Switch: Switch + recipe switch. -->
<script lang="ts">
import type { ComponentProps, Snippet } from "svelte";
import Prim from "../kit/ui/switch/Switch.svelte";
import { cn } from "../kit/utils";
import { rc } from "./recipes";
let { "size": v_size, class: className, children, ...rest }: ComponentProps<typeof Prim> & { "size"?: string | number; class?: string; children?: Snippet } = $props();
const cls = $derived(cn(rc("switch", { "size": v_size }), className));
</script>
<Prim class={cls} {...rest} />
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 switchcompose/switch.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import type { ComponentProps } from "react";
import { Switch as Prim } from "../kit/ui/switch/switch";
import { cn } from "../kit/utils";
import { rc } from "./recipes";
export type SwitchProps = Omit<ComponentProps<typeof Prim>, "tag" | "size"> & { "size"?: string | number; className?: string };
/** Switch: Switch + recipe switch. */
export function Switch({ "size": v_size, className, ...rest }: SwitchProps) {
return <Prim className={cn(rc("switch", { "size": v_size }), 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 switchcompose/Switch.vue
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Switch: Switch + recipe switch. -->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import Prim from "../kit/ui/switch/Switch.vue";
import { cn } from "../kit/utils";
import { rc } from "./recipes";
defineOptions({ name: "Switch", inheritAttrs: false });
const props = defineProps<{ "size"?: string | number }>();
const attrs = useAttrs();
const rest = computed(() => {
const { class: _class, ...r } = attrs;
return r;
});
const cls = computed(() => cn(rc("switch", { "size": props["size"] }), attrs.class as string | undefined));
const tagValue = computed(() => "");
</script>
<template>
<Prim :class="cls" v-bind="rest" />
</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 switchcompose/switch.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 { Switch as Prim } from "../kit/ui/switch/switch.solid";
import { cn } from "../kit/utils";
import { rc } from "./recipes";
export type SwitchProps = Omit<ComponentProps<typeof Prim>, "tag" | "class" | "className" | "size"> & { "size"?: string | number; class?: string; className?: string };
/** Switch: Switch + recipe switch. */
export function Switch(props: SwitchProps) {
const [local, rest] = splitProps(props, ["size", "class", "className"]);
return <Prim class={cn(rc("switch", { "size": local["size"] }), 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 switchcompose/switch.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/switch"
// SwitchProps: Switch: Switch + recipe switch.
type SwitchProps struct {
Size string
formswitch.SwitchProps
}
func switchInner(p SwitchProps) formswitch.SwitchProps {
in := p.SwitchProps
in.Class = Join(Rc("switch", map[string]string{"size": p.Size}), p.SwitchProps.Class)
return in
}
// Switch renders Switch with the composition classes.
templ Switch(p SwitchProps) {
@formswitch.Switch(switchInner(p))
}
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 switchcompose/Switch.html.twig
{# Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. #}
{# Switch: Switch + recipe switch. Params: size, class, attrs + the params of Switch. #}
{% include 'ui/switch/Switch.html.twig' with compose_props('Switch', _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 switchcompose/Switch.latte
{* Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. *}
{* Switch: Switch + recipe switch. *}
{parameters
string $class = '',
bool $checked = false,
bool $disabled = false,
?string $id = null,
?string $name = null,
?string $value = null,
?string $ariaLabel = null,
?string $ariaLabelledBy = null,
array $attrs = [],
string $children = '',
$size = null,
}
{include '../ui/switch/Switch.latte', ...\CodegenX\Compose\Latte\Compose::props('Switch', ['class' => $class, 'checked' => $checked, 'disabled' => $disabled, 'id' => $id, 'name' => $name, 'value' => $value, 'ariaLabel' => $ariaLabel, 'ariaLabelledBy' => $ariaLabelledBy, 'attrs' => $attrs, 'children' => $children, 'size' => $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 switchcompose/switch.html.j2
{#- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
Switch: Switch + recipe switch. Props (p): Size, Class, Attrs + the props of Switch. -#}
{%- with p = compose_props('Switch', p) %}{% include 'ui/switch/switch.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.
Switch renders button[type=button][role=switch]; children render the thumb.
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | boolean | - | |
| disabled | boolean | - |