Skip to content

Commit

Permalink
Add configuration for subtitle
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovic35 committed Jan 31, 2024
1 parent 9dddad7 commit 1c438de
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -267,6 +268,7 @@
07C3C7FD2AE7E56100833957 /* ListModuleOptionsModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListModuleOptionsModel.swift; sourceTree = "<group>"; };
07E4C85B2AE7BC2D00FB4DAC /* ListModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListModule.swift; sourceTree = "<group>"; };
07E4C8662AE7BC8E00FB4DAC /* ListModuleOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListModuleOptions.swift; sourceTree = "<group>"; };
07F580142B69290300C8A00A /* SubtitleOption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubtitleOption.swift; sourceTree = "<group>"; };
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 = "<group>"; };
513876912ADD62A000AE53DF /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = OrangeDesignSystemDemo/Resources/fr.lproj/Localizable.strings; sourceTree = "<group>"; };
513C99F42B5812300043DAAE /* AppsPlus.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; name = AppsPlus.json; path = OrangeDesignSystemDemo/Resources/AppsPlus.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -762,6 +764,7 @@
07B94E072AD9891E00AAD1A5 /* SelectionVariant */,
07B94E062AD9890900AAD1A5 /* StandardVariant */,
077B673B2AE1500F0008C32B /* LeadingOption.swift */,
07F580142B69290300C8A00A /* SubtitleOption.swift */,
);
path = ListItemVariant;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ private struct ListItemSelectionVariantInner: View {
ODSListItem(
title: title,
subtitle: subtitle,
subtitleNumberOfLines: subtitleNumberOfLines,
leading: leading,
trailingToggleIsOn: $isSelected)

case .checkmark:
ODSListItem(
title: title,
subtitle: subtitle,
subtitleNumberOfLines: subtitleNumberOfLines,
leading: leading,
trailingCheckmarkIsSelected: isSelected)
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ final class ListItemSelectionVariantModel: ObservableObject {
// MARK: Stored properties
// =======================

@Published var showSubtitle: Bool
@Published var subtitleOption: SubtitleOption
@Published var leadingOption: LeadingOption
@Published var trailingOption: SelectionTrailingOption

// ==================
// MARK: Initializers
// ==================
init() {
showSubtitle = true
subtitleOption = .twoLines
leadingOption = .circle
trailingOption = .toggle
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private struct ListItemStandardVariantInner: View {
ODSListItem(
title: title,
subtitle: subtitle,
subtitleNumberOfLines: subtitleNumberOfLines,
leading: leading,
trailingText: Text("screens.components.list.details"))
{
Expand All @@ -93,13 +94,15 @@ private struct ListItemStandardVariantInner: View {
ODSListItem(
title: title,
subtitle: subtitle,
subtitleNumberOfLines: subtitleNumberOfLines,
leading: leading,
trailingText: Text("screens.components.list.details"))

case (false, true):
ODSListItem(
title: title,
subtitle: subtitle,
subtitleNumberOfLines: subtitleNumberOfLines,
leading: leading)
{
iButtonAction()
Expand All @@ -109,6 +112,7 @@ private struct ListItemStandardVariantInner: View {
ODSListItem(
title: title,
subtitle: subtitle,
subtitleNumberOfLines: subtitleNumberOfLines,
leading: leading)
}
}
Expand All @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,7 +55,7 @@ class ListItemStandardVariantModel: ObservableObject {
// MARK: Initializers
// ==================
init() {
showSubtitle = true
subtitleOption = .twoLines
leadingOption = .circle
trailingOptions = []
navigate = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Self> {
.init(text: Text(description), value: self)
}

static var chips: [ODSChoiceChip<Self>] {
Self.allCases.map { $0.chip }
}
}

0 comments on commit 1c438de

Please sign in to comment.