Repository Public MIT
1import SwiftUI2import SPGlassKit34public struct GlassStepperExample: GlassExample {5 public static let componentID = "glass-stepper"6 @State private var guests = 27 @State private var dose = 0.58 @State private var zoom = 1.09 @State private var fixed = 31011 public init() {}1213 public var body: some View {14 ScrollView {15 VStack(alignment: .leading, spacing: 20) {16 GlassStepper("Guests", value: $guests, in: 1...12)1718 GlassStepper("Dose", value: $dose, in: 0...2.5, step: 0.25) { value in19 Measurement(value: value, unit: UnitMass.milligrams)20 .formatted(.measurement(width: .abbreviated, usage: .asProvided, numberFormatStyle: .number.precision(.fractionLength(2))))21 }2223 // The upper bound 4 is not on a step from 0.5 by 0.75: the last press stops at the bound.24 GlassStepper("Zoom", value: $zoom, in: 0.5...4, step: 0.75) { value in25 value.formatted(.percent.precision(.fractionLength(0)))26 }2728 GlassStepper("Seats (fixed by your plan)", value: $fixed, in: 1...5)29 .disabled(true)30 }31 .padding()32 }33 }34}3536#Preview("GlassStepper") { GlassStepperExample().glassTheme(.crystal) }37