Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [JIRA: HCPSDKFIORIUIKIT-2488] SwiftUI InformationView (Validati…
…onView) (#636) * feat: [JIRA: HCPSDKFIORIUIKIT-2488] SwiftUI InformationView (ValidationView) * feat: [JIRA: HCPSDKFIORIUIKIT-2488] SwiftUI InformationView (ValidationView) * feat: [JIRA: HCPSDKFIORIUIKIT-2488] SwiftUI InformationView (ValidationView) * feat: [JIRA: HCPSDKFIORIUIKIT-2488] SwiftUI InformationView (ValidationView) * feat: 🎸 [JIRA: HCPSDKFIORIUIKIT-2488] SwiftUI InformationView SwiftUI InformationView (ValidationView) ✅ Closes: JIRA: HCPSDKFIORIUIKIT-2488 * feat: 🎸 [JIRA: HCPSDKFIORIUIKIT-2488] SwiftUI InformationView feat: [JIRA: HCPSDKFIORIUIKIT-2488] SwiftUI InformationView (ValidationView) ✅ Closes: JIRA: HCPSDKFIORIUIKIT-2488 --------- Co-authored-by: I824136 <xiaoqing.he@sap.com> Co-authored-by: Bill Zhou <bill.zhou01@sap.com>
- Loading branch information
1 parent
32651ab
commit 96b6220
Showing
17 changed files
with
689 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
Apps/Examples/Examples/FioriSwiftUICore/FormCells/InformationViewExample.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import FioriSwiftUICore | ||
import SwiftUI | ||
|
||
struct InformationViewExample: View { | ||
var body: some View { | ||
VStack(alignment: .leading) { | ||
Text("Default Fiori style, no icon") | ||
.informationView(description: AttributedString("test message")) | ||
|
||
Text("Error style") | ||
.informationView(description: AttributedString("test message")) | ||
.informationViewStyle(.error) | ||
|
||
Text("Warning style") | ||
.informationView(description: AttributedString("test message")) | ||
.informationViewStyle(.warning) | ||
|
||
Text("Informational style") | ||
.informationView(description: AttributedString("test message")) | ||
.informationViewStyle(.informational) | ||
|
||
Text("Success style") | ||
.informationView(description: AttributedString("test message")) | ||
.informationViewStyle(.success) | ||
|
||
Text("Customized icon") | ||
.informationView(icon: Image(systemName: "heart"), description: AttributedString("test message")) | ||
|
||
Text("Customized font and color") | ||
.informationView(icon: Image(systemName: "diamond"), description: AttributedString("test message")) | ||
.informationViewStyle(.fiori) | ||
.iconStyle(content: { iconConfiguration in | ||
iconConfiguration.icon | ||
.foregroundStyle(Color.preferredColor(.tintColor)) | ||
}) | ||
.descriptionStyle(content: { descriptionConfiguration in | ||
descriptionConfiguration.description | ||
.foregroundStyle(Color.preferredColor(.criticalLabel)) | ||
.font(.fiori(forTextStyle: .title2)) | ||
}) | ||
|
||
Spacer() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Sources/FioriSwiftUICore/_FioriStyles/IconStyle.fiori.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import FioriThemeManager | ||
import Foundation | ||
import SwiftUI | ||
|
||
// Base Layout style | ||
public struct IconBaseStyle: IconStyle { | ||
@ViewBuilder | ||
public func makeBody(_ configuration: IconConfiguration) -> some View { | ||
configuration.icon | ||
} | ||
} | ||
|
||
// Default fiori styles | ||
public struct IconFioriStyle: IconStyle { | ||
@ViewBuilder | ||
public func makeBody(_ configuration: IconConfiguration) -> some View { | ||
Icon(configuration) | ||
} | ||
} |
158 changes: 158 additions & 0 deletions
158
Sources/FioriSwiftUICore/_FioriStyles/InformationViewStyle.fiori.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import FioriThemeManager | ||
import Foundation | ||
import SwiftUI | ||
|
||
// Base Layout style | ||
public struct InformationViewBaseStyle: InformationViewStyle { | ||
public func makeBody(_ configuration: InformationViewConfiguration) -> some View { | ||
VStack { | ||
configuration.content | ||
HStack(alignment: .center, spacing: 8) { | ||
configuration.icon | ||
configuration.description | ||
Spacer() | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Default fiori styles | ||
extension InformationViewFioriStyle { | ||
struct ContentFioriStyle: InformationViewStyle { | ||
func makeBody(_ configuration: InformationViewConfiguration) -> some View { | ||
InformationView(configuration) | ||
.foregroundColor(.preferredColor(.primaryLabel)) | ||
.padding(.leading, 16) | ||
.padding(.trailing, 16) | ||
.padding(.top, 4) | ||
.padding(.bottom, 11) | ||
} | ||
} | ||
|
||
struct IconFioriStyle: IconStyle { | ||
func makeBody(_ configuration: IconConfiguration) -> some View { | ||
Icon(configuration) | ||
.foregroundStyle(Color.preferredColor(.primaryLabel)) | ||
.font(.fiori(forTextStyle: .footnote)) | ||
} | ||
} | ||
|
||
struct DescriptionFioriStyle: DescriptionStyle { | ||
func makeBody(_ configuration: DescriptionConfiguration) -> some View { | ||
Description(configuration) | ||
.foregroundStyle(Color.preferredColor(.primaryLabel)) | ||
.font(.fiori(forTextStyle: .footnote)) | ||
} | ||
} | ||
} | ||
|
||
public extension View { | ||
/// To show the InformationView at the bottom of the view. It includes an icon and text. It is used in error handling to show error / warning / informational / success confirmation message. | ||
func informationView(icon: Image? = nil, description: AttributedString) -> some View { | ||
InformationView(icon: icon, description: description, content: { self }) | ||
} | ||
} | ||
|
||
public struct InformationViewErrorStyle: InformationViewStyle { | ||
public func makeBody(_ configuration: InformationViewConfiguration) -> some View { | ||
InformationView(configuration) | ||
.iconStyle(content: { IconConfiguration in | ||
if IconConfiguration.icon.isEmpty { | ||
Image(systemName: "exclamationmark.circle") | ||
.foregroundStyle(Color.preferredColor(.negativeLabel)) | ||
} else { | ||
IconConfiguration.icon | ||
.foregroundStyle(Color.preferredColor(.negativeLabel)) | ||
} | ||
}) | ||
.descriptionStyle(content: { descriptionConfiguration in | ||
descriptionConfiguration.description | ||
.foregroundStyle(Color.preferredColor(.negativeLabel)) | ||
}) | ||
} | ||
} | ||
|
||
public struct InformationViewWarningStyle: InformationViewStyle { | ||
public func makeBody(_ configuration: InformationViewConfiguration) -> some View { | ||
InformationView(configuration) | ||
.iconStyle(content: { IconConfiguration in | ||
if IconConfiguration.icon.isEmpty { | ||
Image(systemName: "exclamationmark.triangle") | ||
.foregroundStyle(Color.preferredColor(.mango5)) | ||
} else { | ||
IconConfiguration.icon | ||
.foregroundStyle(Color.preferredColor(.mango5)) | ||
} | ||
}) | ||
.descriptionStyle(content: { descriptionConfiguration in | ||
descriptionConfiguration.description | ||
.foregroundStyle(Color.preferredColor(.mango5)) | ||
}) | ||
} | ||
} | ||
|
||
public struct InformationViewInformationalStyle: InformationViewStyle { | ||
public func makeBody(_ configuration: InformationViewConfiguration) -> some View { | ||
InformationView(configuration) | ||
.iconStyle(content: { IconConfiguration in | ||
if IconConfiguration.icon.isEmpty { | ||
Image(systemName: "info.circle") | ||
.foregroundStyle(Color.preferredColor(.primaryLabel)) | ||
} else { | ||
IconConfiguration.icon | ||
.foregroundStyle(Color.preferredColor(.primaryLabel)) | ||
} | ||
}) | ||
.descriptionStyle(content: { descriptionConfiguration in | ||
descriptionConfiguration.description | ||
.foregroundStyle(Color.preferredColor(.primaryLabel)) | ||
}) | ||
} | ||
} | ||
|
||
public struct InformationViewSuccessStyle: InformationViewStyle { | ||
public func makeBody(_ configuration: InformationViewConfiguration) -> some View { | ||
InformationView(configuration) | ||
.iconStyle(content: { IconConfiguration in | ||
if IconConfiguration.icon.isEmpty { | ||
Image(systemName: "checkmark.circle") | ||
.foregroundStyle(Color.preferredColor(.positiveLabel)) | ||
} else { | ||
IconConfiguration.icon | ||
.foregroundStyle(Color.preferredColor(.positiveLabel)) | ||
} | ||
}) | ||
.descriptionStyle(content: { descriptionConfiguration in | ||
descriptionConfiguration.description | ||
.foregroundStyle(Color.preferredColor(.positiveLabel)) | ||
}) | ||
} | ||
} | ||
|
||
/// Error style of the InformationView. It is used to show error message. | ||
public extension InformationViewStyle where Self == InformationViewErrorStyle { | ||
static var error: InformationViewErrorStyle { | ||
InformationViewErrorStyle() | ||
} | ||
} | ||
|
||
/// Warning style of the InformationView. It is used to show warning message. | ||
public extension InformationViewStyle where Self == InformationViewWarningStyle { | ||
static var warning: InformationViewWarningStyle { | ||
InformationViewWarningStyle() | ||
} | ||
} | ||
|
||
/// Informationalstyle of the InformationView. It is used to show informational message. | ||
public extension InformationViewStyle where Self == InformationViewInformationalStyle { | ||
static var informational: InformationViewInformationalStyle { | ||
InformationViewInformationalStyle() | ||
} | ||
} | ||
|
||
/// Success style of the InformationView. It is used to show success message. | ||
public extension InformationViewStyle where Self == InformationViewSuccessStyle { | ||
static var success: InformationViewSuccessStyle { | ||
InformationViewSuccessStyle() | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
Sources/FioriSwiftUICore/_generated/StyleableComponents/Icon/Icon.generated.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Generated using Sourcery 2.1.3 — https://github.com/krzysztofzablocki/Sourcery | ||
// DO NOT EDIT | ||
import Foundation | ||
import SwiftUI | ||
|
||
public struct Icon { | ||
let icon: any View | ||
|
||
@Environment(\.iconStyle) var style | ||
|
||
fileprivate var _shouldApplyDefaultStyle = true | ||
|
||
public init(@ViewBuilder icon: () -> any View = { EmptyView() }) { | ||
self.icon = icon() | ||
} | ||
} | ||
|
||
public extension Icon { | ||
init(icon: Image? = nil) { | ||
self.init(icon: { icon }) | ||
} | ||
} | ||
|
||
public extension Icon { | ||
init(_ configuration: IconConfiguration) { | ||
self.icon = configuration.icon | ||
self._shouldApplyDefaultStyle = false | ||
} | ||
} | ||
|
||
extension Icon: View { | ||
public var body: some View { | ||
if self._shouldApplyDefaultStyle { | ||
self.defaultStyle() | ||
} else { | ||
self.style.resolve(configuration: .init(icon: .init(self.icon))).typeErased | ||
.transformEnvironment(\.iconStyleStack) { stack in | ||
if !stack.isEmpty { | ||
stack.removeLast() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private extension Icon { | ||
func shouldApplyDefaultStyle(_ bool: Bool) -> some View { | ||
var s = self | ||
s._shouldApplyDefaultStyle = bool | ||
return s | ||
} | ||
|
||
func defaultStyle() -> some View { | ||
Icon(icon: { self.icon }) | ||
.shouldApplyDefaultStyle(false) | ||
.iconStyle(.fiori) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Sources/FioriSwiftUICore/_generated/StyleableComponents/Icon/IconStyle.generated.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Generated using Sourcery 2.1.3 — https://github.com/krzysztofzablocki/Sourcery | ||
// DO NOT EDIT | ||
import Foundation | ||
import SwiftUI | ||
|
||
public protocol IconStyle: DynamicProperty { | ||
associatedtype Body: View | ||
|
||
func makeBody(_ configuration: IconConfiguration) -> Body | ||
} | ||
|
||
struct AnyIconStyle: IconStyle { | ||
let content: (IconConfiguration) -> any View | ||
|
||
init(@ViewBuilder _ content: @escaping (IconConfiguration) -> any View) { | ||
self.content = content | ||
} | ||
|
||
public func makeBody(_ configuration: IconConfiguration) -> some View { | ||
self.content(configuration).typeErased | ||
} | ||
} | ||
|
||
public struct IconConfiguration { | ||
public let icon: Icon | ||
|
||
public typealias Icon = ConfigurationViewWrapper | ||
} |
Oops, something went wrong.