This browser is not supported. The glass needs a Chromium browser or Electron. Why

Toggle

SwiftUI's Toggle, the iOS switch. Under a finger its thumb lifts into a glass droplet that can be dragged across or off the switch; the value changes when the finger lifts. Switch is the same component under its UIKit name.

import { Toggle } from "@adamexu/glass"; // or { Switch }

Basic

With no label, name it with aria-label.

<Toggle defaultOn aria-label="Wi-Fi" />
<Toggle aria-label="Bluetooth" />

Label, tint and state

Children are the label, drawn at the leading edge with the switch at the trailing one, as in a List row. labelsHidden keeps the label for screen readers only.

Wi-FiTintedDisabledisOn = true
const [wifi, setWifi] = useState(true);

<Toggle isOn={wifi} onChange={setWifi}>Wi-Fi</Toggle>
<Toggle defaultOn tint="#ff5a1f">Tinted</Toggle>
<Toggle disabled>Disabled</Toggle>

Props

PropTypeDefaultDescription
isOnboolean-SwiftUI isOn: a controlled value. Leave it out and the toggle keeps its own.
defaultOnbooleanfalseThe initial value when uncontrolled.
onChange(isOn: boolean) => void-Runs when the finger lifts, never during a drag.
tintstring-SwiftUI .tint(_:): any CSS colour, for the on state.
disabledbooleanfalseSwiftUI .disabled(_:): stops responding and dims.
childrenReactNode-The label, at the leading edge.
labelsHiddenbooleanfalseSwiftUI .labelsHidden(): the label is only spoken.
idiom"phone" | "pad" | "duo""phone"The device whose feel to match. The look is the same; on iPad a drag has a gate before the thumb moves.
id, aria-labelstring-Go on the role="switch" button.
className, stylestring, CSSProperties-On the outer box.

Behaviour

The toggle is a role="switch" button, so Space and Enter flip it. It is drawn for Chromium, where the lifted thumb refracts the track and whatever is behind it.

SwiftUI

SwiftUI@adamexu/glass
Toggle(isOn:)<Toggle isOn onChange>
Toggle("Wi-Fi", isOn:)<Toggle isOn onChange>Wi-Fi</Toggle>
.tint(.orange)tint="orange"
.labelsHidden()labelsHidden
.disabled(true)disabled