SPB Git

Repository Public MIT

doc-glass-toggle.md 2.2 KB 68 lines markdown

1# GlassToggle23| | |4|---|---|5| Identifier | `glass-toggle` |6| Module | `SPGlassForms` |7| Kind | `native-wrapper` — the system `Toggle`, tinted with the theme's `primary` colour |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Selection/GlassToggleExample.swift` |1011## Minimal usage1213```swift14@State private var notifications = true1516GlassToggle("Notifications", isOn: $notifications)17```1819## Variants2021| Variant | Use |22|---|---|23| `description:` | A secondary line under the title. |24| `systemImage:` | A decorative symbol before the title. |25| `appearance: .switch` | Always a switch. |26| `appearance: .checkbox` | A checkbox on macOS; a switch on iOS and iPadOS, which have no checkbox. |27| `appearance: .automatic` (default) | The platform's default. |2829## Parameters3031| Parameter | Type | Default | Meaning |32|---|---|---|---|33| `title` | `LocalizedStringKey` or `Text` | — | Title. |34| `description` | `LocalizedStringKey?` or `Text?` | `nil` | Description. |35| `systemImage` | `String?` | `nil` | SF Symbol. |36| `appearance` | `GlassToggleAppearance` | `.automatic` | Switch or checkbox. |37| `isOn` | `Binding<Bool>` | — | The value. |3839## States4041On, off, pressed and focused are drawn by the system. Disabled is the standard `.disabled(_:)` modifier.4243## Advanced example4445```swift46Form {47    Section("Privacy") {48        GlassToggle("Share diagnostics", description: "Crash reports without personal data.",49                    systemImage: "stethoscope", isOn: $settings.diagnostics)50        GlassToggle(title: Text(verbatim: account.name), description: Text("Sync this account"), isOn: $account.isSynced)51            .disabled(!settings.isOnline)52    }53}54```5556## Accessibility5758- Title and description form the label of the toggle, so VoiceOver reads both, then the state.59- The symbol is hidden from assistive technologies.60- Title and description wrap at large text sizes; nothing is truncated.61- The state is the position of the switch (and, with the system setting, its on/off labels), not the tint alone.6263## Limits6465- The switch itself, including its glass thumb, is drawn by the system and cannot be restyled.66- The checkbox appearance exists only on macOS.67- No built-in loading state; disable the toggle while a change is being saved.68
Files main
Menu

Theme