Skip to content

Commit e8440a1

Browse files
authored
feat: 🎸 [jira: 1975] status and substatus should support both icon and text (SAP#1023)
* feat: 🎸 status and substatus should support both icon and text jira: HCPSDKFIORIUIKIT-1975 * docs: ✏️ [jira: 1975] fix documentations
1 parent da602f2 commit e8440a1

File tree

9 files changed

+110
-8
lines changed

9 files changed

+110
-8
lines changed

Apps/Examples/Examples/FioriSwiftUICore/ObjectHeader/ObjectHeaderViewScenarios.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ struct ObjectHeaderViewScenarios: ListDataProtocol {
158158
footnote: "Due on 12/31/16",
159159
descriptionText: "Temperature sensor predicts overheating failure in 4 days Urgent and needs attention sensor predicts overheating failure in 4 days Urgent and need attention.",
160160
status: TextOrIcon.text("Very High Priority"),
161-
substatus: TextOrIcon.text("Scheduled"),
162-
detailContent: {})
161+
substatus: TextOrIcon.both("Time", Image(systemName: "clock")),
162+
detailContent: {}).environment(\.iconHorizontalAlignment, .trailing)
163+
.substatusStyle(.negativeLabel)
163164

164165
return AnyView(oh)
165166

Apps/Examples/Examples/FioriSwiftUICore/ObjectItem/ObjectCell_Spec_Jan2018.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ struct ObjectCell_Spec_Jan2018: ObjectItemListDataProtocol {
6464
oi = ObjectItem(title: "Lorem ipseum dolor",
6565
footnote: "Words\nSeparated\nNewLineChars and this is Just some really long text that is here dont worry about it too much",
6666
description: "Some description",
67-
status: TextOrIcon.text("Some status"),
67+
status: .both("Some status", Image(systemName: "paperplane")),
6868
substatus: TextOrIcon.text("some substatus"))
6969
.footnoteStyle {
7070
Footnote($0)
7171
.lineLimit(4)
7272
}
73+
.statusStyle(.positiveLabel)
7374
} else {
7475
oi = _ObjectItem(title: "Lorem ipseum dolor",
7576
footnote: "Words\nSeparated\nNewLineChars and this is Just some really long text that is here dont worry about it too much",

Apps/Examples/Examples/FioriSwiftUICore/Timeline/TimelineItemsExample.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ struct TimelineItemsExample: View {
2121
})
2222
}
2323
Section(header: Text("Timeline")) {
24-
Timeline(timestamp: "06/21/24", secondaryTimestamp: .icon(Image(systemName: "sun.max")), timelineNode: .complete, title: "Complete", subtitle: "abc", attribute: "attr", status: .text("Info"), substatus: .icon(Image(systemName: "exclamationmark.circle")), subAttribute: "subAttr", isPast: true)
24+
Timeline(timestamp: "06/21/24", secondaryTimestamp: .icon(Image(systemName: "sun.max")), timelineNode: .complete, title: "Complete", subtitle: "abc", attribute: "attr", status: .text("Info"), substatus: .both("substatus", Image(systemName: "exclamationmark.circle")), subAttribute: "subAttr", isPast: true)
2525
.modifier(CustomListRowModifier())
2626
.secondaryTimestampStyle(content: { config in
2727
config.secondaryTimestamp.foregroundColor(.yellow)
2828
})
29-
.substatusStyle(content: { config in
30-
config.substatus.foregroundColor(.yellow)
31-
})
29+
.substatusStyle(.positiveLabel)
3230
Timeline(timestamp: "06/21/24", secondaryTimestamp: .icon(Image(systemName: "sun.max")), timelineNode: .complete, title: "Complete(Disabled)", subtitle: "abc", attribute: "attr", status: .text("Info"), substatus: .icon(Image(systemName: "exclamationmark.circle")), subAttribute: "subAttr", isPast: true)
3331
.modifier(CustomListRowModifier())
3432
.disabled(/*@START_MENU_TOKEN@*/true/*@END_MENU_TOKEN@*/)

Sources/FioriSwiftUICore/Components/TextOrIcon.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import SwiftUI
33

44
/// It is either a String or Image
55
public enum TextOrIcon {
6-
case text(String)
6+
/// Contains a text only
7+
case text(AttributedString)
8+
/// Contains an icon only
79
case icon(Image)
10+
/// Contains both a text and an icon
11+
case both(AttributedString, Image)
812
}

Sources/FioriSwiftUICore/Views/CustomBuilder/FootnoteIconsBuilder.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ extension FootnoteIconStack: FootnoteIconList {
242242
Text(txt)
243243
case .icon(let icon):
244244
icon
245+
case .both(let txt, let icon):
246+
Text(txt)
245247
}
246248
}
247249
}

Sources/FioriSwiftUICore/Views/IconStack/IconStack+View.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ extension IconStack: ViewList {
2626
Text(txt)
2727
case .icon(let icon):
2828
icon
29+
case .both(let txt, let icon):
30+
Text(txt)
2931
}
3032
}
3133
}
@@ -41,6 +43,8 @@ extension IconStack: ViewList {
4143
return true
4244
case .icon:
4345
return false
46+
case .both:
47+
return true
4448
}
4549
}
4650

Sources/FioriSwiftUICore/Views/TextOrIconView.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
import SwiftUI
22

3+
struct IconHorizontalAlignment: EnvironmentKey {
4+
/// The default is `.leading`. `.center` and `.trailing` means `.trailing`.
5+
public static let defaultValue: HorizontalAlignment = .leading
6+
}
7+
8+
public extension EnvironmentValues {
9+
/// Determine the relative positioning of an icon within the `TextOrIcon` when both a text and an icon are present. . The default is `.leading`. `.center` and `.trailing` means `.trailing`.
10+
var iconHorizontalAlignment: HorizontalAlignment {
11+
get {
12+
self[IconHorizontalAlignment.self]
13+
} set {
14+
self[IconHorizontalAlignment.self] = newValue
15+
}
16+
}
17+
}
18+
319
/// TextOrIconView to display TextOrIcon
420
public struct TextOrIconView: View {
21+
@Environment(\.iconHorizontalAlignment) var iconHorizontalAlignment
522
var content: TextOrIcon?
623

724
/// init with TextOrIcon
@@ -30,6 +47,17 @@ public struct TextOrIconView: View {
3047

3148
case .icon(let icon):
3249
icon
50+
51+
case .both(let text, let icon):
52+
HStack(alignment: .center, spacing: 2) {
53+
if self.iconHorizontalAlignment == .leading {
54+
icon
55+
Text(text)
56+
} else {
57+
Text(text)
58+
icon
59+
}
60+
}
3361
}
3462
} else {
3563
EmptyView()

Sources/FioriSwiftUICore/_FioriStyles/StatusStyle.fiori.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,35 @@ public struct StatusFioriStyle: StatusStyle {
2626
.font(.fiori(forTextStyle: .subheadline))
2727
}
2828
}
29+
30+
/// A convenient `StatusStyle` to set a foreground color for `Status`
31+
public struct StatusColorStyleStyle: StatusStyle {
32+
let style: ColorStyle
33+
public func makeBody(_ configuration: StatusConfiguration) -> some View {
34+
Status(configuration)
35+
.foregroundStyle(Color.preferredColor(self.style))
36+
.font(.fiori(forTextStyle: .subheadline))
37+
}
38+
}
39+
40+
public extension StatusStyle where Self == StatusColorStyleStyle {
41+
/// `.negativeLabel` color style for `Status`
42+
static var negativeLabel: Self {
43+
StatusColorStyleStyle(style: .negativeLabel)
44+
}
45+
46+
/// `.positiveLabel` color style for `Status`
47+
static var positiveLabel: Self {
48+
StatusColorStyleStyle(style: .positiveLabel)
49+
}
50+
51+
/// `.criticalLabel` color style for `Status`
52+
static var criticalLabel: Self {
53+
StatusColorStyleStyle(style: .criticalLabel)
54+
}
55+
56+
/// `.informativeLabel` color style for `Status`
57+
static var informativeLabel: Self {
58+
StatusColorStyleStyle(style: .informativeLabel)
59+
}
60+
}

Sources/FioriSwiftUICore/_FioriStyles/SubstatusStyle.fiori.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,35 @@ public struct SubstatusFioriStyle: SubstatusStyle {
2626
.font(.fiori(forTextStyle: .subheadline))
2727
}
2828
}
29+
30+
/// A convenient `SubstatusStyle` to set a foreground color for `Substatus`
31+
public struct SubstatusColorStyle: SubstatusStyle {
32+
let style: ColorStyle
33+
public func makeBody(_ configuration: SubstatusConfiguration) -> some View {
34+
Substatus(configuration)
35+
.foregroundStyle(Color.preferredColor(self.style))
36+
.font(.fiori(forTextStyle: .subheadline))
37+
}
38+
}
39+
40+
public extension SubstatusStyle where Self == SubstatusColorStyle {
41+
/// `.negativeLabel` color style for `Substatus`
42+
static var negativeLabel: Self {
43+
SubstatusColorStyle(style: .negativeLabel)
44+
}
45+
46+
/// `.positiveLabel` color style for `Substatus`
47+
static var positiveLabel: Self {
48+
SubstatusColorStyle(style: .positiveLabel)
49+
}
50+
51+
/// `.criticalLabel` color style for `Substatus`
52+
static var criticalLabel: Self {
53+
SubstatusColorStyle(style: .criticalLabel)
54+
}
55+
56+
/// `.informativeLabel` color style for `Substatus`
57+
static var informativeLabel: Self {
58+
SubstatusColorStyle(style: .informativeLabel)
59+
}
60+
}

0 commit comments

Comments
 (0)