JGuang / JGuang UI
Components组件Base UIBase UI 组件

Switch

A control that allows the user to toggle between checked and not checked.

Partially translated: Chinese navigation, titles, descriptions, and common headings. The technical body is currently in English.
Loading JGuang UI example…

Installation

Command

Manual

Use the JGuang UI Registry URL provided on /systems/jguang-ui#install.

Install the following dependencies:

npm install @base-ui/react

Copy and paste the following code into your project.

View complete source: components/ui/switch.tsx

Update the import paths to match your project setup.

Usage

import { Switch } from "@/components/ui/switch"
<Switch />

Description

Loading JGuang UI example…

Choice Card

Card-style selection where FieldLabel wraps the entire Field for a clickable card pattern.

Loading JGuang UI example…

Disabled

Add the disabled prop to the Switch component to disable the switch. Add the data-disabled prop to the Field component for styling.

Loading JGuang UI example…

Invalid

Add the aria-invalid prop to the Switch component to indicate an invalid state. Add the data-invalid prop to the Field component for styling.

Loading JGuang UI example…

Size

Use the size prop to change the size of the switch.

Loading JGuang UI example…

RTL

To enable RTL support in JGuang UI, see the RTL configuration guide.

Loading JGuang UI example…

API Reference

See the Base UI Switch documentation.

Source: components/base/switch.mdx

Technical documentation for JGuang UI.

On this page