diff --git a/Sources/MultiPicker/MultiPicker.swift b/Sources/MultiPicker/MultiPicker.swift index ee7d162..ea22e5e 100644 --- a/Sources/MultiPicker/MultiPicker.swift +++ b/Sources/MultiPicker/MultiPicker.swift @@ -323,158 +323,141 @@ fileprivate struct MultiPickerSelectionList = ["1"] + let choices = ["1", "2", "3"] - multiPickerNavigationLinkPreview() - .previewDisplayName("Navigation Link Style Plain Style Choice") - - multiPickerNavigationLinkRichChoicePreview() - .previewDisplayName("Navigation Link Style Rich Style Choice") + Form { + Section { + MultiPicker("Regular", selection: $multiSelection) { + ForEach(choices, id: \.self) { + Text("\($0)") + .mpTag($0) + } + } + } + Section { + MultiPickerSelectionList(selection: $multiSelection, indicatorPosition: .trailing) { + ForEach(choices, id: \.self) { + Text("\($0)") + .mpTag($0) + } + } + } + Section { + MultiPickerSelectionList(selection: $multiSelection) { + ForEach(choices, id: \.self) { + Text("\($0)") + .mpTag($0) + } + }.environment(\.layoutDirection, .rightToLeft) + } + Section { + MultiPickerSelectionList(selection: $multiSelection, indicatorPosition: .trailing) { + ForEach(choices, id: \.self) { + Text("\($0)") + .mpTag($0) + } + }.environment(\.layoutDirection, .rightToLeft) + } } +} - static func multiPickerListPreview() -> some View { - PreviewBindingHelper2(values: (["1", "2", "3"], Set(arrayLiteral: "1"))) { (choices: Binding<[String]>, multiSelection: Binding>) in - - Form { - Section { - MultiPicker("Regular", selection: multiSelection) { - ForEach(choices.wrappedValue, id: \.self) { - Text("\($0)") - .mpTag($0) - } +#Preview("Navigation Link Style Plain Style Choice") { + @Previewable @State var oneSelection: String = "1" + @Previewable @State var oneOrNoneSelection: String? = "1" + @Previewable @State var multiSelection: Set = ["1"] + let choices = ["1", "2", "3"] + + NavigationStack { + Form { + Section("SwiftUI") { + Picker("Only One", selection: $oneSelection) { + ForEach(choices, id: \.self) { + Text("\($0)") + .tag($0) } } - Section { - MultiPickerSelectionList(selection: multiSelection, indicatorPosition: .trailing) { - ForEach(choices.wrappedValue, id: \.self) { - Text("\($0)") - .mpTag($0) - } + } +#if !os(macOS) + // .pickerStyle(.navigationLink) +#endif + Section("MultiPicker") { + MultiPicker("Only One", selection: $oneSelection) { + ForEach(choices, id: \.self) { + Text("\($0)") + .mpTag($0) } } - Section { - MultiPickerSelectionList(selection: multiSelection) { - ForEach(choices.wrappedValue, id: \.self) { - Text("\($0)") - .mpTag($0) - } - }.environment(\.layoutDirection, .rightToLeft) + MultiPicker("Multi", selection: $multiSelection as Binding>) { + ForEach(choices, id: \.self) { + Text("\($0)") + .mpTag($0) + } } - Section { - MultiPickerSelectionList(selection: multiSelection, indicatorPosition: .trailing) { - ForEach(choices.wrappedValue, id: \.self) { - Text("\($0)") - .mpTag($0) - } - }.environment(\.layoutDirection, .rightToLeft) + MultiPicker("One or None", selection: $oneOrNoneSelection) { + ForEach(choices, id: \.self) { + Text("\($0)") + .mpTag($0) + } } } + .mpPickerStyle(.navigationLink) } } +} - static func multiPickerNavigationLinkPreview() -> some View { - NavigationStack { - PreviewBindingHelper4(values: (["1", "2", "3"], "1", Optional("1"), Set(arrayLiteral: "1") as Set)) { (choices: Binding<[String]>, oneSelection: Binding, oneOrNoneSelection: Binding, multiSelection: Binding>) in - Form { - Section("SwiftUI") { - Picker("Only One", selection: oneSelection) { - ForEach(choices.wrappedValue, id: \.self) { - Text("\($0)") - .tag($0) - } - } - } - #if !os(macOS) - // .pickerStyle(.navigationLink) - #endif - Section("MultiPicker") { - MultiPicker("Only One", selection: oneSelection) { - ForEach(choices.wrappedValue, id: \.self) { - Text("\($0)") - .mpTag($0) - } - } - MultiPicker("Multi", selection: multiSelection as Binding>) { - ForEach(choices.wrappedValue, id: \.self) { - Text("\($0)") - .mpTag($0) - } - } - MultiPicker("One or None", selection: oneOrNoneSelection) { - ForEach(choices.wrappedValue, id: \.self) { - Text("\($0)") - .mpTag($0) - } - } +#Preview("Navigation Link Style Rich Style Choice") { + @Previewable @State var oneSelection = Model(title: String(localized: "Red"), color: .red) + @Previewable @State var oneOrNoneSelection: Model? = Model(title: String(localized: "Red"), color: .red) + @Previewable @State var multiSelection: Set = [Model(title: String(localized: "Red"), color: .red)] + let choices = [ + Model(title: String(localized: "Red"), color: .red), + Model(title: String(localized: "Orange"), color: .orange), + Model(title: String(localized: "Yellow"), color: .yellow), + Model(title: String(localized: "Green"), color: .green), + Model(title: String(localized: "Blue"), color: .blue), + Model(title: String(localized: "Indigo"), color: .indigo), + Model(title: String(localized: "Violet"), color: .purple), + ] + + NavigationStack { + Form { + Section("SwiftUI") { + Picker("Only One", selection: $oneSelection) { + ForEach(choices, id: \.self) { + ModelCell(model: $0) + .tag($0) } - .mpPickerStyle(.navigationLink) } } - } - } - - static func multiPickerNavigationLinkRichChoicePreview() -> some View { - NavigationStack { - PreviewBindingHelper4( - values: ( - [ - Model(title: String(localized: "Red"), color: .red), - Model(title: String(localized: "Orange"), color: .orange), - Model(title: String(localized: "Yellow"), color: .yellow), - Model(title: String(localized: "Green"), color: .green), - Model(title: String(localized: "Blue"), color: .blue), - Model(title: String(localized: "Indigo"), color: .indigo), - Model(title: String(localized: "Violet"), color: .purple), - ], - Model(title: String(localized: "Red"), color: .red), - Optional(Model(title: String(localized: "Red"), color: .red)), - Set(arrayLiteral: Model(title: String(localized: "Red"), color: .red)) as Set - ) - ) { (choices: Binding<[Model]>, - oneSelection: Binding, - oneOrNoneSelection: Binding, - multiSelection: Binding>) in - Form { - Section("SwiftUI") { - Picker("Only One", selection: oneSelection) { - ForEach(choices.wrappedValue, id: \.self) { - ModelCell(model: $0) - .tag($0) - } - } + .pickerStyle(.navigationLink) +#if !os(macOS) + // .pickerStyle(.navigationLink) +#endif + Section("MultiPicker") { + MultiPicker("Only One", selection: $oneSelection) { + ForEach(choices, id: \.self) { + ModelCell(model: $0) + .mpTag($0) } - .pickerStyle(.navigationLink) - #if !os(macOS) - // .pickerStyle(.navigationLink) - #endif - Section("MultiPicker") { - MultiPicker("Only One", selection: oneSelection) { - ForEach(choices.wrappedValue, id: \.self) { - ModelCell(model: $0) - .mpTag($0) - } - } - MultiPicker("Multi", selection: multiSelection as Binding>) { - ForEach(choices.wrappedValue, id: \.self) { - ModelCell(model: $0) - .mpTag($0) - } - } - MultiPicker("One or None", selection: oneOrNoneSelection) { - ForEach(choices.wrappedValue, id: \.self) { - ModelCell(model: $0) - .mpTag($0) - } - } + } + MultiPicker("Multi", selection: $multiSelection as Binding>) { + ForEach(choices, id: \.self) { + ModelCell(model: $0) + .mpTag($0) + } + } + MultiPicker("One or None", selection: $oneOrNoneSelection) { + ForEach(choices, id: \.self) { + ModelCell(model: $0) + .mpTag($0) } - .mpPickerStyle(.navigationLink) - .choiceRepresentationStyle(.rich) } } + .mpPickerStyle(.navigationLink) + .choiceRepresentationStyle(.rich) } } }