Files
wehub-resource-sync e9a2f726c9
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.13) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:29:51 +08:00

41 lines
1.0 KiB
Swift

// PR 3 — segmented control matching the JSX `Segmented`.
import SwiftUI
struct Segmented<Value: Hashable>: View {
@Binding var selection: Value
let titleKey: LocalizedStringKey = ""
let options: [(value: Value, label: String)]
@Environment(\.omlxTheme) private var theme
var body: some View {
Picker(titleKey, selection: $selection) {
ForEach(options, id: \.value) { opt in
Text(opt.label)
.tag(opt.value)
}
}
.pickerStyle(.segmented)
.labelsHidden()
}
}
#Preview("Segmented") {
@Previewable @State var mode = "local"
@Previewable @State var scope = "session"
return VStack(spacing: 14) {
Segmented(selection: $mode, options: [
("cloud", "Cloud"), ("local", "Local"),
])
.frame(width: 180)
Segmented(selection: $scope, options: [
("session", "Session"), ("alltime", "All Time"),
])
.frame(width: 180)
}
.padding(24)
.omlxThemed()
}