Files
TUIkit/Sources/TUIkitExample/Pages/TogglePage.swift
T
phranck 8eb8f26781 Refactor: Implement SwiftUI-compatible ToggleStyle API
- Add ToggleStyle protocol matching SwiftUI's pattern
- Add .automatic, .checkbox, .switch built-in styles
- Add .toggleStyle(_:) view modifier via Environment
- All styles render as [ ]/[x] in TUI (documented constraint)
- Remove old ToggleStyle enum (.toggle/.checkbox)
- Update example app and tests for new API
2026-02-13 16:18:13 +01:00

46 lines
1.4 KiB
Swift

// TUIKit - Terminal UI Kit for Swift
// TogglePage.swift
//
// Created by LAYERED.work
// License: MIT
import TUIkit
/// Toggle demo page.
struct TogglePage: View {
@State var notificationsEnabled: Bool = false
@State var darkModeEnabled: Bool = true
@State var showHiddenFiles: Bool = false
var body: some View {
VStack(alignment: .leading, spacing: 1) {
DemoSection("Toggles") {
VStack(alignment: .leading, spacing: 1) {
Toggle("Enable Notifications", isOn: $notificationsEnabled)
Toggle("Dark Mode", isOn: $darkModeEnabled)
Toggle("Show Hidden Files", isOn: $showHiddenFiles)
Toggle("Disabled (OFF)", isOn: .constant(false)).disabled()
Toggle("Disabled (ON)", isOn: .constant(true)).disabled()
}
}
DemoSection("Keyboard Controls") {
VStack(alignment: .leading) {
Text("[Tab] Move focus between toggles").dim()
Text("[Space] or [Enter] Toggle the focused item").dim()
}
}
Spacer()
}
.appHeader {
HStack {
Text("Toggle Demo").bold().foregroundStyle(.palette.accent)
Spacer()
Text("TUIkit v\(tuiKitVersion)").foregroundStyle(.palette.foregroundTertiary)
}
}
}
}