SPB Git

Repository Public MIT

example-glass-segmented-control.txt 1.7 KB 44 lines text

1import SwiftUI2import SPGlassKit34public struct GlassSegmentedControlExample: GlassExample {5    public static let componentID = "glass-segmented-control"67    enum Mode: String, CaseIterable, Hashable {8        case list, grid, map910        var title: String { rawValue.capitalized }11    }1213    @State private var mode = Mode.list14    @State private var period = "Week"15    @State private var long = "Everything that happened"16    @State private var weekday = "Mon"1718    public init() {}1920    public var body: some View {21        ScrollView {22            VStack(alignment: .leading, spacing: 24) {23                GlassSegmentedControl("View", selection: $mode, options: Mode.allCases, title: \.title)24                Text("Showing: \(mode.title)").font(.callout).foregroundStyle(.secondary)2526                GlassSegmentedControl("Period", selection: $period, options: ["Day", "Week", "Month", "Year"]) { $0 }2728                Text("Titles too long for the width fall back to a menu").font(.headline)29                GlassSegmentedControl("Scope", selection: $long, options: ["Everything that happened", "Only what I was mentioned in", "Nothing at all, thank you"]) { $0 }3031                Text("More than five options: a menu").font(.headline)32                GlassSegmentedControl("Day", selection: $weekday, options: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]) { $0 }3334                GlassSegmentedControl("Locked", selection: .constant("On"), options: ["Off", "On"]) { $0 }35                    .disabled(true)36            }37            .frame(maxWidth: .infinity, alignment: .leading)38            .padding()39        }40    }41}4243#Preview("GlassSegmentedControl") { GlassSegmentedControlExample() }44
Files main
Menu

Theme