Let TitleAndIcon take an attributed subtitle

Add an AttributedString subtitle initialiser to Compound's TitleAndIcon,
with the existing String initialiser forwarding to it so current call
sites are unchanged. Add a preview state with a bold run and re-record
the titleAndIcon snapshots.

This lets screens with partially bold copy, such as the multi-account
announcement, use TitleAndIcon instead of rebuilding its layout.
This commit is contained in:
Mauro Romito
2026-10-05 14:34:39 +02:00
committed by Mauro
parent 8a6e297cba
commit 1b06ca0dcd
3 changed files with 30 additions and 5 deletions
@@ -16,7 +16,7 @@ import SwiftUI
/// than it is to add/subtract additional padding to some arbitrary defaults.
public struct TitleAndIcon: View {
private let title: String
private let subtitle: String?
private let subtitle: AttributedString?
private let icon: KeyPath<CompoundIcons, Image>
private let iconStyle: BigIcon.Style
private let button: ButtonDetails?
@@ -26,6 +26,18 @@ public struct TitleAndIcon: View {
icon: KeyPath<CompoundIcons, Image>,
iconStyle: BigIcon.Style,
button: ButtonDetails? = nil) {
self.init(title: title,
subtitle: subtitle.map { AttributedString($0) },
icon: icon,
iconStyle: iconStyle,
button: button)
}
public init(title: String,
subtitle: AttributedString?,
icon: KeyPath<CompoundIcons, Image>,
iconStyle: BigIcon.Style,
button: ButtonDetails? = nil) {
self.title = title
self.subtitle = subtitle
self.icon = icon
@@ -95,8 +107,21 @@ public struct TitleAndIcon_Previews: PreviewProvider, TestablePreview {
icon: \.circle,
iconStyle: .defaultSolid,
button: .init(title: "Learn more") { })
TitleAndIcon(title: "Headline",
subtitle: attributedSubtitle,
icon: \.circle,
iconStyle: .defaultSolid)
}
.padding(24)
.padding(.bottom, 16)
}
private static var attributedSubtitle: AttributedString {
var subtitle = AttributedString("Description with ")
var boldText = AttributedString("bold text")
boldText.inlinePresentationIntent = .stronglyEmphasized
subtitle.append(boldText)
return subtitle
}
}