-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 💡 [HCPSDKFIORIUIKIT-2879] KeyValueItem Refactor (#984)
* refactor: 💡 [HCPSDKFIORIUIKIT-2879] KeyValueItem Refactor * Update KeyValueItemStyle.fiori.swift Add the default Style (font and foregroundColor) * Update KeyValueItemExample.swift * refactor: 💡 [HCPSDKFIORIUIKIT-2879] KeyValueItem Refactor * refactor: 💡 [HCPSDKFIORIUIKIT-2879] KeyValueItem Refactor * refactor: 💡 [HCPSDKFIORIUIKIT-2879] KeyValueItem Refactor --------- Co-authored-by: xiaoqinggrace <[email protected]>
- Loading branch information
1 parent
6ee6bbe
commit 019e773
Showing
26 changed files
with
802 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,49 +2,87 @@ import FioriSwiftUICore | |
import SwiftUI | ||
|
||
struct KeyValueItemExample: View { | ||
@State var axis: Axis = .horizontal | ||
|
||
struct CustomKeyValueItemStyle: KeyValueItemStyle { | ||
func makeBody(_ configuration: KeyValueItemConfiguration) -> some View { | ||
KeyValueItem(configuration) | ||
.keyStyle { c in | ||
c.key | ||
.lineLimit(2) | ||
.font(.fiori(forTextStyle: .callout)) | ||
.foregroundStyle(Color.preferredColor(.green7)) | ||
} | ||
.valueStyle { c in | ||
c.value | ||
.lineLimit(2) | ||
.font(.fiori(forTextStyle: .title3)) | ||
.foregroundStyle(Color.preferredColor(.indigo7)) | ||
.background(Color.preferredColor(.red3)) | ||
} | ||
} | ||
} | ||
|
||
var body: some View { | ||
Text("KeyValueItemExample") | ||
List { | ||
Text("Default Horizontal") | ||
KeyValueItem { | ||
Text("Key 1") | ||
|
||
} value: { | ||
Text("Value 1") | ||
Section { | ||
Picker("Axis", selection: self.$axis) { | ||
Text("Horizontal").tag(Axis.horizontal) | ||
Text("Vertical").tag(Axis.vertical) | ||
} | ||
} | ||
|
||
Text("Vertical") | ||
KeyValueItem(key: { | ||
Text("Vertical Axis") | ||
}, value: { | ||
Text("Value 2") | ||
}, axis: .vertical) | ||
|
||
Text("Custom Color and Font") | ||
KeyValueItem { | ||
Text("Custom Color") | ||
.foregroundStyle(.red) | ||
.font(.fiori(forTextStyle: .title1)) | ||
} value: { | ||
Text("Value 3") | ||
.foregroundStyle(.brown) | ||
.font(.fiori(forTextStyle: .footnote)) | ||
Section { | ||
Text("Key Value Item (Default Style)") | ||
KeyValueItem( | ||
key: { Text("Key 1") }, | ||
value: { Text("Value 1") }, | ||
axis: self.axis | ||
) | ||
|
||
Divider().background(Color.gray) | ||
Text("Key Value Item (Long String)") | ||
KeyValueItem( | ||
key: { Text("Long long long long long long long long long long long long long long long long long long Key") }, | ||
value: { self.MultipleValues() }, | ||
axis: self.axis | ||
) | ||
|
||
Divider().background(Color.gray) | ||
Text("Key Value Item 2 lines (Custom Style)") | ||
KeyValueItem( | ||
key: { Text("Long long long long long long long long long long long long long long long long long long long long long Key") }, | ||
value: { Text("Long long long long long long long long long Value") }, | ||
axis: self.axis | ||
).keyValueItemStyle(CustomKeyValueItemStyle()) | ||
} | ||
|
||
Text("Verticle Custom Color and Font") | ||
KeyValueItem(key: { | ||
Text("Custom Color and Font Vertical Axis") | ||
.foregroundStyle(.red) | ||
.font(.fiori(forTextStyle: .title1)) | ||
}, value: { | ||
Text("Value 4") | ||
.foregroundStyle(.brown) | ||
.font(.fiori(forTextStyle: .footnote)) | ||
}, axis: .vertical) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
KeyValueItemExample() | ||
|
||
func MultipleValues() -> any View { | ||
switch self.axis { | ||
case .horizontal: | ||
return HStack(spacing: 0) { | ||
Text("Long long long long long long long long long Value") | ||
Spacer() | ||
Link("650-000-0000", destination: URL(string: "tel:650-000-0000")!).foregroundColor(.blue) | ||
Spacer() | ||
Text("[email protected]") | ||
Spacer() | ||
Text("www.google.com") | ||
} | ||
case .vertical: | ||
return VStack(alignment: .leading) { | ||
Text("Long long long long long long long long long Value") | ||
Link("650-000-0000", destination: URL(string: "tel:650-000-0000")!).foregroundColor(.blue) | ||
Text("[email protected]") | ||
Text("https://www.google.com") | ||
} | ||
} | ||
} | ||
|
||
struct KeyValueItemExample_Previews: PreviewProvider { | ||
static var previews: some View { | ||
KeyValueItemExample() | ||
} | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
Apps/Examples/Examples/FioriSwiftUICore/Views/_KeyValueItemExample.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,50 @@ | ||
import FioriSwiftUICore | ||
import SwiftUI | ||
|
||
struct _KeyValueItemExample: View { | ||
var body: some View { | ||
Text("_KeyValueItemExample") | ||
List { | ||
Text("Default Horizontal") | ||
_KeyValueItem { | ||
Text("Key 1") | ||
|
||
} value: { | ||
Text("Value 1") | ||
} | ||
|
||
Text("Vertical") | ||
_KeyValueItem(key: { | ||
Text("Vertical Axis") | ||
}, value: { | ||
Text("Value 2") | ||
}, axis: .vertical) | ||
|
||
Text("Custom Color and Font") | ||
_KeyValueItem { | ||
Text("Custom Color") | ||
.foregroundStyle(.red) | ||
.font(.fiori(forTextStyle: .title1)) | ||
} value: { | ||
Text("Value 3") | ||
.foregroundStyle(.brown) | ||
.font(.fiori(forTextStyle: .footnote)) | ||
} | ||
|
||
Text("Verticle Custom Color and Font") | ||
_KeyValueItem(key: { | ||
Text("Custom Color and Font Vertical Axis") | ||
.foregroundStyle(.red) | ||
.font(.fiori(forTextStyle: .title1)) | ||
}, value: { | ||
Text("Value 4") | ||
.foregroundStyle(.brown) | ||
.font(.fiori(forTextStyle: .footnote)) | ||
}, axis: .vertical) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
_KeyValueItemExample() | ||
} |
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
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/KeyStyle.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 KeyBaseStyle: KeyStyle { | ||
@ViewBuilder | ||
public func makeBody(_ configuration: KeyConfiguration) -> some View { | ||
configuration.key | ||
} | ||
} | ||
|
||
// Default fiori styles | ||
public struct KeyFioriStyle: KeyStyle { | ||
@ViewBuilder | ||
public func makeBody(_ configuration: KeyConfiguration) -> some View { | ||
Key(configuration) | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
Sources/FioriSwiftUICore/_FioriStyles/KeyValueItemStyle.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,61 @@ | ||
import FioriThemeManager | ||
import Foundation | ||
import SwiftUI | ||
|
||
// Base Layout style | ||
public struct KeyValueItemBaseStyle: KeyValueItemStyle { | ||
public func makeBody(_ configuration: KeyValueItemConfiguration) -> some View { | ||
CompactVStack(alignment: .leading) { | ||
switch configuration.axis { | ||
case .horizontal: | ||
HStack(spacing: 0) { | ||
configuration.key | ||
Spacer() | ||
configuration.value | ||
} | ||
.frame(maxWidth: .infinity) | ||
case .vertical: | ||
configuration.key | ||
configuration.value | ||
} | ||
}.accessibilityElement(children: .combine) | ||
.buttonStyle(.borderless) | ||
} | ||
} | ||
|
||
// Default fiori styles | ||
extension KeyValueItemFioriStyle { | ||
struct ContentFioriStyle: KeyValueItemStyle { | ||
func makeBody(_ configuration: KeyValueItemConfiguration) -> some View { | ||
KeyValueItem(configuration) | ||
} | ||
} | ||
|
||
public struct KeyFioriStyle: KeyStyle { | ||
let keyValueItemConfiguration: KeyValueItemConfiguration | ||
|
||
public func makeBody(_ configuration: KeyConfiguration) -> some View { | ||
Key(configuration) | ||
.font(.fiori(forTextStyle: .subheadline, weight: .semibold)) | ||
.foregroundColor(.preferredColor(.primaryLabel)) | ||
} | ||
} | ||
|
||
struct ValueFioriStyle: ValueStyle { | ||
let keyValueItemConfiguration: KeyValueItemConfiguration | ||
|
||
func makeBody(_ configuration: ValueConfiguration) -> some View { | ||
Value(configuration) | ||
.font(.fiori(forTextStyle: .body)) | ||
.foregroundColor(.preferredColor(.primaryLabel)) | ||
} | ||
} | ||
|
||
struct FormViewFioriStyle: FormViewStyle { | ||
let keyValueItemConfiguration: KeyValueItemConfiguration | ||
|
||
func makeBody(_ configuration: FormViewConfiguration) -> some View { | ||
FormView(configuration) | ||
} | ||
} | ||
} |
Oops, something went wrong.