Skip to content

Commit

Permalink
Add limitation on title and on subtitle texts
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovic35 committed Jan 30, 2024
1 parent aa5111c commit 9dddad7
Showing 1 changed file with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,18 @@ public struct ODSListItem: View {
case checkmark(Bool)
}

public enum SubtitleNumberOfLines: Int {
case one = 1
case two = 2
}

// =======================
// MARK: Stored Properties
// =======================

private let title: Text
private let subtitle: Text?
private let subtitleNumberOfLines: SubtitleNumberOfLines?
private let leading: Leading?
private let trailing: TrailingElement?
private let height = ODSListItemModifier.defaultHeight
Expand All @@ -156,68 +162,80 @@ public struct ODSListItem: View {
/// - Parameters:
/// - title: The primary text of the list item
/// - subtitle: The secondary text of the list item (optional)
/// - subtitleNumberOfLines: If `subtitle` is provided, it is possible to limit the text
/// to 1 line or 2 lines. If set to nil, no restriction is applied (be carefull: this is not design compliant).
/// - leading: The leading icon of the list item (optional)
///
public init(
title: Text,
subtitle: Text? = nil,
subtitleNumberOfLines: SubtitleNumberOfLines? = .one,
leading: Leading? = nil)
{
self.init(title: title, subtitle: subtitle, leading: leading, trailing: nil)
self.init(title: title, subtitle: subtitle, subtitleNumberOfLines: subtitleNumberOfLines, leading: leading, trailing: nil)
}

/// Describe the Item content with trailing text.
///
/// - Parameters:
/// - title: The primary text of the list item
/// - subtitle: The secondary text of the list item (optional)
/// - subtitleNumberOfLines: If `subtitle` is provided, it is possible to limit the text
/// to 1 line or 2 lines.
/// - leading: The leading icon of the list item (optional)
/// - trailingText The text on trailing
///
public init(
title: Text,
subtitle: Text? = nil,
subtitleNumberOfLines: SubtitleNumberOfLines? = .one,
leading: Leading? = nil,
trailingText: Text)
{
self.init(title: title, subtitle: subtitle, leading: leading, trailing: .textOnly(trailingText))
self.init(title: title, subtitle: subtitle, subtitleNumberOfLines: subtitleNumberOfLines, leading: leading, trailing: .textOnly(trailingText))
}

/// Describe the Item content with trailing text and iButton.
///
/// - Parameters:
/// - title: The primary text of the list item
/// - subtitle: The secondary text of the list item (optional)
/// - subtitleNumberOfLines: If `subtitle` is provided, it is possible to limit the text
/// to 1 line or 2 lines. If set to nil, no restriction is applied (be carefull: this is not design compliant).
/// - leading: The leading icon of the list item (optional)
/// - trailingText The text on trailing
/// - trailingIButtonAction: The action the i button on trailing
///
public init(
title: Text,
subtitle: Text? = nil,
subtitleNumberOfLines: SubtitleNumberOfLines? = .one,
leading: Leading? = nil,
trailingText: Text? = nil,
trailingIButtonAction: @escaping () -> Void)
{
self.init(title: title, subtitle: subtitle, leading: leading, trailing: .iButton(trailingIButtonAction, trailingText))
self.init(title: title, subtitle: subtitle, subtitleNumberOfLines: subtitleNumberOfLines, leading: leading, trailing: .iButton(trailingIButtonAction, trailingText))
}

/// Describe the Item content with trailing toggle.
///
/// - Parameters:
/// - title: The primary text of the list item
/// - subtitle: The secondary text of the list item (optional)
/// - subtitleNumberOfLines: If `subtitle` is provided, it is possible to limit the text
/// to 1 line or 2 lines. If set to nil, no restriction is applied (be carefull: this is not design compliant).
/// - leading: The leading icon of the list item (optional)
/// - trailingText The text on trailing
/// - trailingToggleIsOn: The binding to a property that determines whether the toggle is on or off.
///
public init(
title: Text,
subtitle: Text? = nil,
subtitleNumberOfLines: SubtitleNumberOfLines? = .one,
leading: Leading? = nil,
trailingToggleIsOn: Binding<Bool>)
{
self.init(title: title, subtitle: subtitle, leading: leading, trailing:
self.init(title: title, subtitle: subtitle, subtitleNumberOfLines: subtitleNumberOfLines, leading: leading, trailing:
.toggle(trailingToggleIsOn))
}

Expand All @@ -226,35 +244,42 @@ public struct ODSListItem: View {
/// - Parameters:
/// - title: The primary text of the list item
/// - subtitle: The secondary text of the list item (optional)
/// - subtitleNumberOfLines: If `subtitle` is provided, it is possible to limit the text
/// to 1 line or 2 lines. If set to nil, no restriction is applied (be carefull: this is not design compliant).
/// - leading: The leading icon of the list item (optional)
/// - trailingText The text on trailing
/// - trailingCheckmarkIsSelected: The flag to indicate if checkmark is visbile or not.
///
public init(
title: Text,
subtitle: Text? = nil,
subtitleNumberOfLines: SubtitleNumberOfLines? = .one,
leading: Leading? = nil,
trailingCheckmarkIsSelected: Bool)
{
self.init(title: title, subtitle: subtitle, leading: leading, trailing: .checkmark(trailingCheckmarkIsSelected))
self.init(title: title, subtitle: subtitle, subtitleNumberOfLines: subtitleNumberOfLines, leading: leading, trailing: .checkmark(trailingCheckmarkIsSelected))
}

/// Describe the Item content with trailing element.
///
/// - Parameters:
/// - title: The primary text of the list item
/// - subtitle: The secondary text of the list item (optional)
/// - subtitleNumberOfLines: If `subtitle` is provided, it is possible to limit the text
/// to 1 line or 2 lines. If set to nil, no restriction is applied (be carefull: this is not design compliant).
/// - leading: The leading icon of the list item (optional)
/// - trailing: The trailing element
///
init(
title: Text,
subtitle: Text? = nil,
subtitleNumberOfLines: SubtitleNumberOfLines? = .one,
leading: Leading? = nil,
trailing: TrailingElement? = nil)
{
self.title = title
self.subtitle = subtitle
self.subtitleNumberOfLines = subtitleNumberOfLines
self.leading = leading
self.trailing = trailing
}
Expand All @@ -272,12 +297,16 @@ public struct ODSListItem: View {

VStack(alignment: .leading, spacing: ODSSpacing.none) {
title
.lineLimit(1)
.truncationMode(.tail)
.odsFont(.bodyLRegular)
.foregroundColor(.primary)
.frame(maxWidth: .infinity, alignment: .leading)
.multilineTextAlignment(.leading)

subtitle?
.lineLimit(subtitleNumberOfLines?.rawValue)
.truncationMode(.tail)
.odsFont(.labelL)
.foregroundColor(.primary)
.multilineTextAlignment(.leading)
Expand Down

0 comments on commit 9dddad7

Please sign in to comment.