Documentation
Switch
Slot-like track with a 20×20 raised thumb.
import { useState } from "react";
import { Switch } from "./index";
/**
* Switch 预览用例
*/
export function SwitchDemo() {
const [on, setOn] = useState(false);
return (
<div className="flex flex-col gap-8">
<label className="flex items-center gap-4">
<Switch
checked={on}
onCheckedChange={(next) => {
setOn(next);
}}
/>
<span className="font-mc mc-text">
难度锁定:
{on ? "开" : "关"}
</span>
</label>
<Switch aria-label="默认开" defaultChecked />
<Switch aria-label="禁用" disabled />
</div>
);
}
Install
CLI copy
$npx shadcn add @tennantite/switchnpm install
$pnpm add @tennantite/uinpm installs the compiled package; use the CLI copy above to adapt the source.
Usage
npm import
import { Switch } from "@tennantite/ui";CLI copy import
import { Switch } from "@/components/tennantite/switch";import { useState } from "react";
import { Switch } from "./index";
/**
* Switch 预览用例
*/
export function SwitchDemo() {
const [on, setOn] = useState(false);
return (
<div className="flex flex-col gap-8">
<label className="flex items-center gap-4">
<Switch
checked={on}
onCheckedChange={(next) => {
setOn(next);
}}
/>
<span className="font-mc mc-text">
难度锁定:
{on ? "开" : "关"}
</span>
</label>
<Switch aria-label="默认开" defaultChecked />
<Switch aria-label="禁用" disabled />
</div>
);
}API Reference
No public props.
Source
packages/ui/src/primitives/switch/index.tsxThe npm package keeps the source tree, so you can copy and adapt it directly.