From 1c438dece91512f58a2e7f617e1373700148ac16 Mon Sep 17 00:00:00 2001 From: Ludovic PINEL Date: Wed, 31 Jan 2024 10:08:50 +0100 Subject: [PATCH] Add configuration for subtitle --- .../project.pbxproj | 4 ++ .../Resources/Base.lproj/Localizable.strings | 4 ++ .../Resources/en.lproj/Localizable.strings | 5 +++ .../Resources/fr.lproj/Localizable.strings | 4 ++ .../ListItemSelectionVariant.swift | 18 ++++++-- .../ListItemSelectionVariantModel.swift | 4 +- .../ListItemSelectionVariantOptions.swift | 10 ++--- .../ListItemStandardVariant.swift | 19 ++++++-- .../ListItemStandardVariantModel.swift | 4 +- .../ListItemStandardVariantOptions.swift | 11 ++--- .../ListItemVariant/SubtitleOption.swift | 44 +++++++++++++++++++ 11 files changed, 105 insertions(+), 22 deletions(-) create mode 100644 OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SubtitleOption.swift diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo.xcodeproj/project.pbxproj b/OrangeDesignSystemDemo/OrangeDesignSystemDemo.xcodeproj/project.pbxproj index c8084720..28d0bafc 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo.xcodeproj/project.pbxproj +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo.xcodeproj/project.pbxproj @@ -113,6 +113,7 @@ 07C3C7FE2AE7E56100833957 /* ListModuleOptionsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07C3C7FD2AE7E56100833957 /* ListModuleOptionsModel.swift */; }; 07E4C85C2AE7BC2D00FB4DAC /* ListModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07E4C85B2AE7BC2D00FB4DAC /* ListModule.swift */; }; 07E4C8692AE7BC8E00FB4DAC /* ListModuleOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07E4C8662AE7BC8E00FB4DAC /* ListModuleOptions.swift */; }; + 07F580152B69290300C8A00A /* SubtitleOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07F580142B69290300C8A00A /* SubtitleOption.swift */; }; 5107F55E2AE11BDD00D4D01F /* AppNews.json in Resources */ = {isa = PBXBuildFile; fileRef = 5107F5602AE11BDD00D4D01F /* AppNews.json */; }; 5107F5622AE1209A00D4D01F /* PrivacyNotice.html in Resources */ = {isa = PBXBuildFile; fileRef = 5107F5642AE1209A00D4D01F /* PrivacyNotice.html */; }; 5107F56A2AE1220900D4D01F /* CGU.html in Resources */ = {isa = PBXBuildFile; fileRef = 5107F56C2AE1220900D4D01F /* CGU.html */; }; @@ -267,6 +268,7 @@ 07C3C7FD2AE7E56100833957 /* ListModuleOptionsModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListModuleOptionsModel.swift; sourceTree = ""; }; 07E4C85B2AE7BC2D00FB4DAC /* ListModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListModule.swift; sourceTree = ""; }; 07E4C8662AE7BC8E00FB4DAC /* ListModuleOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListModuleOptions.swift; sourceTree = ""; }; + 07F580142B69290300C8A00A /* SubtitleOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubtitleOption.swift; sourceTree = ""; }; 2ACFE972C59B1460F410852D /* Pods-OrangeDesignSystemDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OrangeDesignSystemDemo.debug.xcconfig"; path = "Target Support Files/Pods-OrangeDesignSystemDemo/Pods-OrangeDesignSystemDemo.debug.xcconfig"; sourceTree = ""; }; 513876912ADD62A000AE53DF /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = OrangeDesignSystemDemo/Resources/fr.lproj/Localizable.strings; sourceTree = ""; }; 513C99F42B5812300043DAAE /* AppsPlus.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; name = AppsPlus.json; path = OrangeDesignSystemDemo/Resources/AppsPlus.json; sourceTree = ""; }; @@ -762,6 +764,7 @@ 07B94E072AD9891E00AAD1A5 /* SelectionVariant */, 07B94E062AD9890900AAD1A5 /* StandardVariant */, 077B673B2AE1500F0008C32B /* LeadingOption.swift */, + 07F580142B69290300C8A00A /* SubtitleOption.swift */, ); path = ListItemVariant; sourceTree = ""; @@ -1299,6 +1302,7 @@ 077C38512A9DDC79003D6B51 /* CapitalizedTextInputsVariant.swift in Sources */, 07B1A09C2B1E191F00ABF0A1 /* InputChipsVariant.swift in Sources */, 077C38632A9DDC79003D6B51 /* CardHorizontalVariant.swift in Sources */, + 07F580152B69290300C8A00A /* SubtitleOption.swift in Sources */, 077C38882A9DDC79003D6B51 /* CardViewDemo.swift in Sources */, 077C387F2A9DDC79003D6B51 /* TypographyGuideline.swift in Sources */, 077C389C2A9DEEDC003D6B51 /* RecipesLoader.swift in Sources */, diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Resources/Base.lproj/Localizable.strings b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Resources/Base.lproj/Localizable.strings index c6711140..0da3f514 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Resources/Base.lproj/Localizable.strings +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Resources/Base.lproj/Localizable.strings @@ -248,6 +248,10 @@ "screens.components.lists.alert" = "Information icon tapped! Bon appétit"; "screens.components.lists.options.description.info_button" = "Info button"; "screens.components.list.details" = "Details"; +"screens.components.lists.subtitle_option.title" = "Sous titre"; +"screens.components.lists.subtitle_option.none" = "Sans"; +"screens.components.lists.subtitle_option.one_line" = "Une ligne"; +"screens.components.lists.subtitle_option.two_lines" = "Deux ligne"; // ================================================== // MARK: - Screens - Components - Progress indicators diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Resources/en.lproj/Localizable.strings b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Resources/en.lproj/Localizable.strings index d5a38a0b..819627c1 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Resources/en.lproj/Localizable.strings +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Resources/en.lproj/Localizable.strings @@ -249,6 +249,11 @@ "screens.components.lists.alert" = "Information icon tapped! Bon appétit"; "screens.components.lists.options.description.info_button" = "Info button"; "screens.components.list.details" = "Details"; +"screens.components.lists.subtitle_option.title" = "Subtitle"; +"screens.components.lists.subtitle_option.none" = "None"; +"screens.components.lists.subtitle_option.one_line" = "One line"; +"screens.components.lists.subtitle_option.two_lines" = "Two lines"; + // ================================================== // MARK: - Screens - Components - Progress indicators diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Resources/fr.lproj/Localizable.strings b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Resources/fr.lproj/Localizable.strings index d80ecad7..65cc55fe 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Resources/fr.lproj/Localizable.strings +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Resources/fr.lproj/Localizable.strings @@ -248,6 +248,10 @@ "screens.components.lists.alert" = "Icône d'information tappée ! Bon appétit"; "screens.components.lists.options.description.info_button" = "Bouton d'information"; "screens.components.list.details" = "Détails"; +"screens.components.lists.subtitle_option.title" = "Subtitle"; +"screens.components.lists.subtitle_option.none" = "None"; +"screens.components.lists.subtitle_option.one_line" = "One line"; +"screens.components.lists.subtitle_option.two_lines" = "Two lines"; // ================================================== // MARK: - Screens - Components - Progress indicators diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SelectionVariant/ListItemSelectionVariant.swift b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SelectionVariant/ListItemSelectionVariant.swift index cf82c6de..214fed06 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SelectionVariant/ListItemSelectionVariant.swift +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SelectionVariant/ListItemSelectionVariant.swift @@ -74,6 +74,7 @@ private struct ListItemSelectionVariantInner: View { ODSListItem( title: title, subtitle: subtitle, + subtitleNumberOfLines: subtitleNumberOfLines, leading: leading, trailingToggleIsOn: $isSelected) @@ -81,6 +82,7 @@ private struct ListItemSelectionVariantInner: View { ODSListItem( title: title, subtitle: subtitle, + subtitleNumberOfLines: subtitleNumberOfLines, leading: leading, trailingCheckmarkIsSelected: isSelected) } @@ -91,13 +93,21 @@ private struct ListItemSelectionVariantInner: View { } private var subtitle: Text? { - if model.showSubtitle { - return Text(recipe.subtitle) - } else { - return nil + switch model.subtitleOption { + case .none: return nil + case .oneLine, .twoLines: return Text(recipe.description) } } + var subtitleNumberOfLines: ODSListItem.SubtitleNumberOfLines? { + switch model.subtitleOption { + case .none: return nil + case .oneLine: return .one + case .twoLines: return .two + } + } + + private var leading: ODSListItem.Leading? { let emptyImage = Image("ods_empty", bundle: Bundle.ods) switch model.leadingOption { diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SelectionVariant/ListItemSelectionVariantModel.swift b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SelectionVariant/ListItemSelectionVariantModel.swift index 2181f392..b68ecc02 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SelectionVariant/ListItemSelectionVariantModel.swift +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SelectionVariant/ListItemSelectionVariantModel.swift @@ -42,7 +42,7 @@ final class ListItemSelectionVariantModel: ObservableObject { // MARK: Stored properties // ======================= - @Published var showSubtitle: Bool + @Published var subtitleOption: SubtitleOption @Published var leadingOption: LeadingOption @Published var trailingOption: SelectionTrailingOption @@ -50,7 +50,7 @@ final class ListItemSelectionVariantModel: ObservableObject { // MARK: Initializers // ================== init() { - showSubtitle = true + subtitleOption = .twoLines leadingOption = .circle trailingOption = .toggle } diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SelectionVariant/ListItemSelectionVariantOptions.swift b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SelectionVariant/ListItemSelectionVariantOptions.swift index fb6f5ffb..8bd590d2 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SelectionVariant/ListItemSelectionVariantOptions.swift +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SelectionVariant/ListItemSelectionVariantOptions.swift @@ -28,11 +28,11 @@ struct ListItemSelectionVariantOptions: View { var body: some View { VStack(spacing: ODSSpacing.none) { - Toggle(isOn: $model.showSubtitle) { - Text("shared.subtitle").odsFont(.bodyLBold) - } - .padding(.horizontal, ODSSpacing.m) - .padding(.vertical, ODSSpacing.s) + ODSChoiceChipPicker( + title: Text("screens.components.lists.subtitle_option.title"), + chips: SubtitleOption.chips, + selection: $model.subtitleOption) + .padding(.vertical, ODSSpacing.s) ODSChoiceChipPicker( title: Text("shared.leading"), diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/StandardVariant/ListItemStandardVariant.swift b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/StandardVariant/ListItemStandardVariant.swift index b2ffe7fe..a2fe5e1a 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/StandardVariant/ListItemStandardVariant.swift +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/StandardVariant/ListItemStandardVariant.swift @@ -84,6 +84,7 @@ private struct ListItemStandardVariantInner: View { ODSListItem( title: title, subtitle: subtitle, + subtitleNumberOfLines: subtitleNumberOfLines, leading: leading, trailingText: Text("screens.components.list.details")) { @@ -93,6 +94,7 @@ private struct ListItemStandardVariantInner: View { ODSListItem( title: title, subtitle: subtitle, + subtitleNumberOfLines: subtitleNumberOfLines, leading: leading, trailingText: Text("screens.components.list.details")) @@ -100,6 +102,7 @@ private struct ListItemStandardVariantInner: View { ODSListItem( title: title, subtitle: subtitle, + subtitleNumberOfLines: subtitleNumberOfLines, leading: leading) { iButtonAction() @@ -109,6 +112,7 @@ private struct ListItemStandardVariantInner: View { ODSListItem( title: title, subtitle: subtitle, + subtitleNumberOfLines: subtitleNumberOfLines, leading: leading) } } @@ -118,10 +122,17 @@ private struct ListItemStandardVariantInner: View { } private var subtitle: Text? { - if model.showSubtitle { - return Text(recipe.subtitle) - } else { - return nil + switch model.subtitleOption { + case .none: return nil + case .oneLine, .twoLines: return Text(recipe.subtitle) + } + } + + var subtitleNumberOfLines: ODSListItem.SubtitleNumberOfLines? { + switch model.subtitleOption { + case .none: return nil + case .oneLine: return .one + case .twoLines: return .two } } diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/StandardVariant/ListItemStandardVariantModel.swift b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/StandardVariant/ListItemStandardVariantModel.swift index d4dff576..9fb98ebf 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/StandardVariant/ListItemStandardVariantModel.swift +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/StandardVariant/ListItemStandardVariantModel.swift @@ -46,7 +46,7 @@ class ListItemStandardVariantModel: ObservableObject { // MARK: Stored properties // ======================= - @Published var showSubtitle: Bool + @Published var subtitleOption: SubtitleOption @Published var leadingOption: LeadingOption @Published var trailingOptions: [StandardTrailingOption] @Published var navigate: Bool @@ -55,7 +55,7 @@ class ListItemStandardVariantModel: ObservableObject { // MARK: Initializers // ================== init() { - showSubtitle = true + subtitleOption = .twoLines leadingOption = .circle trailingOptions = [] navigate = true diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/StandardVariant/ListItemStandardVariantOptions.swift b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/StandardVariant/ListItemStandardVariantOptions.swift index f0f7ac9d..5f1273b7 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/StandardVariant/ListItemStandardVariantOptions.swift +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/StandardVariant/ListItemStandardVariantOptions.swift @@ -28,11 +28,12 @@ struct ListItemStandardVariantOptions: View { var body: some View { VStack(spacing: ODSSpacing.none) { - Toggle(isOn: $model.showSubtitle) { - Text("shared.subtitle").odsFont(.bodyLBold) - } - .padding(.horizontal, ODSSpacing.m) - .padding(.vertical, ODSSpacing.s) + + ODSChoiceChipPicker( + title: Text("screens.components.lists.subtitle_option.title"), + chips: SubtitleOption.chips, + selection: $model.subtitleOption) + .padding(.vertical, ODSSpacing.s) ODSChoiceChipPicker( title: Text("shared.leading"), diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SubtitleOption.swift b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SubtitleOption.swift new file mode 100644 index 00000000..ca8bdc2d --- /dev/null +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Lists/ListItemVariant/SubtitleOption.swift @@ -0,0 +1,44 @@ +// +// Software Name: Orange Design System +// SPDX-FileCopyrightText: Copyright (c) Orange SA +// SPDX-License-Identifier: MIT +// +// This software is distributed under the MIT licence, +// the text of which is available at https://opensource.org/license/MIT/ +// or see the "LICENSE" file for more details. +// +// Authors: See CONTRIBUTORS.txt +// Software description: A SwiftUI components library with code examples for Orange Design System +// + +import OrangeDesignSystem +import SwiftUI + +// ============= +// MARK: Options +// ============= + +enum SubtitleOption: Int, CaseIterable { + case none + case oneLine + case twoLines + + var description: LocalizedStringKey { + switch self { + case .none: + return "screens.components.lists.subtitle_option.none" + case .oneLine: + return "screens.components.lists.subtitle_option.one_line" + case .twoLines: + return "screens.components.lists.subtitle_option.two_lines" + } + } + + var chip: ODSChoiceChip { + .init(text: Text(description), value: self) + } + + static var chips: [ODSChoiceChip] { + Self.allCases.map { $0.chip } + } +}