-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: 💡 [HCPSDKFIORIUIKIT-2685] FilterFormView Refactor #981
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
38969db
refactor: 💡 [HCPSDKFIORIUIKIT-2685] FilterFormView Refactor
hengyi-zhang a1cb560
refactor: 💡 [HCPSDKFIORIUIKIT-2685] FilterFormView Refactor
hengyi-zhang d354095
refactor: 💡 [HCPSDKFIORIUIKIT-2685] FilterFormView Refactor
hengyi-zhang dd27141
Merge branch 'main' into refactor/FilterFormView
hengyi-zhang 3f8c78c
refactor: 💡 [HCPSDKFIORIUIKIT-2685] FilterFormView Refactor
hengyi-zhang 451ea4e
Merge branch 'main' into refactor/FilterFormView
hengyi-zhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
236 changes: 236 additions & 0 deletions
236
Apps/Examples/Examples/FioriSwiftUICore/FormViews/FilterFormViewExamples.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,236 @@ | ||
import FioriSwiftUICore | ||
import FioriThemeManager | ||
import SwiftUI | ||
|
||
struct FilterFormViewExamples: View { | ||
let valueOptions: [AttributedString] = ["itemShort", "itemLong", "item222222222222222222", "itemSuperLongLabelDescription", "itemShort2"] | ||
let sortValueOptions: [AttributedString] = ["Received", "Started", "Hold", "Transfer", "Completed", "Pending Review Pending Pending Pending Pending Pending", "Accepted Medium", "Pending", "Completed Medium"] | ||
|
||
let priorityOptions: [AttributedString] = ["High", "Medium", "Low"] | ||
let numberOptions: [AttributedString] = ["1", "2", "3", "4"] | ||
|
||
@State private var showMandatoryField = false | ||
@State private var customizedMandatoryIndicator = false | ||
@State private var isEnabled = true | ||
|
||
@State private var multiSelectionEmptySelectionValue: [Int] = [1, 2] | ||
@State private var multiSelectionNonEmptySelectionValue: [Int] = [1, 2] | ||
@State private var singleSelectionEmptySelectionValue: [Int] = [] | ||
@State private var singleSelectionNonEmptySelectionValue: [Int] = [] | ||
@State private var singleSelectionNonEmptySelectionDisabledValue: [Int] = [1] | ||
@State private var singleSelectionNonEmptySelectionCustomizedColorValue: [Int] = [] | ||
|
||
@State private var prioritySelectionValue: [Int] = [0] | ||
@State private var numberSelectionValue: [Int] = [0] | ||
@State private var trySixSelectionValue: [Int] = [0] | ||
@State private var trySevenSelectionValue: [Int] = [0] | ||
@State private var sortFilterSelectionValue: [Int] = [0] | ||
@State private var sortFilterFixedSelectionValue: [Int] = [0] | ||
@State private var sortFilterEmptyTitleSelectionValue: [Int] = [0] | ||
|
||
func mandatoryField() -> TextOrIcon? { | ||
if self.customizedMandatoryIndicator { | ||
return .text("#") | ||
} else { | ||
return .text("*") | ||
} | ||
} | ||
|
||
var body: some View { | ||
List { | ||
Toggle(isOn: self.$showMandatoryField) { | ||
Text("Mandatory Field") | ||
.font(.fiori(forTextStyle: .subheadline, weight: .semibold)) | ||
.foregroundStyle(Color.preferredColor(.primaryLabel)) | ||
} | ||
.tint(Color.preferredColor(.tintColor)) | ||
Toggle(isOn: self.$customizedMandatoryIndicator) { | ||
Text("Customized Mandatory Indicator") | ||
.font(.fiori(forTextStyle: .subheadline, weight: .semibold)) | ||
.foregroundStyle(Color.preferredColor(.primaryLabel)) | ||
} | ||
.tint(Color.preferredColor(.tintColor)) | ||
Toggle(isOn: self.$isEnabled) { | ||
Text("Enabled") | ||
.font(.fiori(forTextStyle: .subheadline, weight: .semibold)) | ||
.foregroundStyle(Color.preferredColor(.primaryLabel)) | ||
} | ||
.tint(Color.preferredColor(.tintColor)) | ||
|
||
FilterFormView(title: "MultiSelection, EmptySelection", mandatoryFieldIndicator: self.mandatoryField(), isRequired: self.showMandatoryField, options: self.valueOptions, errorMessage: "Validation Message", isEnabled: self.isEnabled, allowsMultipleSelection: true, allowsEmptySelection: true, value: self.$multiSelectionEmptySelectionValue, buttonSize: .fixed, onValueChange: { value in | ||
print("MultiSelection, EmptySelection value change: \(value)") | ||
}) | ||
.mandatoryFieldIndicatorStyle { conf in | ||
conf.mandatoryFieldIndicator | ||
.foregroundStyle(self.mandatoryFieldIndicatorColor()) | ||
} | ||
.informationViewStyle(.success) | ||
|
||
FilterFormView(title: "MultiSelection, Non-EmptySelection", mandatoryFieldIndicator: self.mandatoryField(), isRequired: self.showMandatoryField, options: self.valueOptions, errorMessage: "Validation Message", isEnabled: self.isEnabled, allowsMultipleSelection: true, allowsEmptySelection: false, value: self.$multiSelectionNonEmptySelectionValue, buttonSize: .fixed) | ||
.mandatoryFieldIndicatorStyle { conf in | ||
conf.mandatoryFieldIndicator | ||
.foregroundStyle(self.mandatoryFieldIndicatorColor()) | ||
} | ||
|
||
FilterFormView(title: "SingleSelection, EmptySelection", mandatoryFieldIndicator: self.mandatoryField(), isRequired: self.showMandatoryField, options: self.valueOptions, errorMessage: "Validation Message", isEnabled: self.isEnabled, allowsMultipleSelection: false, allowsEmptySelection: true, value: self.$singleSelectionEmptySelectionValue, buttonSize: .fixed) | ||
.mandatoryFieldIndicatorStyle { conf in | ||
conf.mandatoryFieldIndicator | ||
.foregroundStyle(self.mandatoryFieldIndicatorColor()) | ||
} | ||
|
||
FilterFormView(title: "SingleSelection, Non-EmptySelection", mandatoryFieldIndicator: self.mandatoryField(), isRequired: self.showMandatoryField, options: self.valueOptions, errorMessage: "Validation Message", isEnabled: self.isEnabled, allowsMultipleSelection: false, allowsEmptySelection: false, value: self.$singleSelectionNonEmptySelectionValue, buttonSize: .fixed) | ||
.mandatoryFieldIndicatorStyle { conf in | ||
conf.mandatoryFieldIndicator | ||
.foregroundStyle(self.mandatoryFieldIndicatorColor()) | ||
} | ||
|
||
FilterFormView(title: "SingleSelection, Non-EmptySelection, Disabled", mandatoryFieldIndicator: self.mandatoryField(), isRequired: self.showMandatoryField, options: self.valueOptions, errorMessage: "Validation Message", isEnabled: false, allowsMultipleSelection: false, allowsEmptySelection: false, value: self.$singleSelectionNonEmptySelectionDisabledValue, buttonSize: .fixed) | ||
.mandatoryFieldIndicatorStyle { conf in | ||
conf.mandatoryFieldIndicator | ||
.foregroundStyle(self.mandatoryFieldIndicatorColor()) | ||
} | ||
|
||
FilterFormView(title: { | ||
Text("SingleSelection, Non-EmptySelection, Customized Color, Font") | ||
.foregroundStyle(self.isEnabled ? Color.red : .yellow) | ||
}, mandatoryFieldIndicator: { | ||
TextOrIconView(self.mandatoryField()) | ||
.foregroundStyle(self.isEnabled ? Color.green : .preferredColor(.separator)) | ||
}, isRequired: self.showMandatoryField, options: self.valueOptions, errorMessage: nil, isEnabled: self.isEnabled, allowsMultipleSelection: false, allowsEmptySelection: false, value: self.$singleSelectionNonEmptySelectionCustomizedColorValue, buttonSize: .fixed) | ||
.mandatoryFieldIndicatorStyle { conf in | ||
conf.mandatoryFieldIndicator | ||
.foregroundStyle(self.mandatoryFieldIndicatorColor()) | ||
} | ||
.filterFormOptionAttributes([ | ||
.enabledUnselected: [ | ||
.foregroundColor: Color.green, | ||
.strokeColor: Color.yellow, | ||
.font: Font.fiori(forTextStyle: .caption1) | ||
], | ||
.enabledSelected: [ | ||
.foregroundColor: Color.red, | ||
.strokeColor: Color.orange, | ||
.font: Font.fiori(forTextStyle: .caption1) | ||
] | ||
]) | ||
|
||
FilterFormView(title: "Priority", mandatoryFieldIndicator: self.mandatoryField(), isRequired: self.showMandatoryField, options: self.priorityOptions, errorMessage: nil, isEnabled: self.isEnabled, allowsMultipleSelection: true, allowsEmptySelection: true, value: self.$prioritySelectionValue, buttonSize: .flexibleByMaxChip) | ||
.mandatoryFieldIndicatorStyle { conf in | ||
conf.mandatoryFieldIndicator | ||
.foregroundStyle(self.mandatoryFieldIndicatorColor()) | ||
} | ||
|
||
FilterFormView(title: "Number", mandatoryFieldIndicator: self.mandatoryField(), isRequired: self.showMandatoryField, options: self.numberOptions, errorMessage: nil, isEnabled: self.isEnabled, allowsMultipleSelection: true, allowsEmptySelection: true, value: self.$numberSelectionValue, buttonSize: .flexibleByMaxChip) | ||
.mandatoryFieldIndicatorStyle { conf in | ||
conf.mandatoryFieldIndicator | ||
.foregroundStyle(self.mandatoryFieldIndicatorColor()) | ||
} | ||
|
||
FilterFormView(title: "SingleSelection, Non-EmptySelection, flexible, same size", mandatoryFieldIndicator: self.mandatoryField(), isRequired: self.showMandatoryField, options: self.valueOptions, errorMessage: nil, isEnabled: self.isEnabled, allowsMultipleSelection: true, allowsEmptySelection: true, value: self.$trySixSelectionValue, buttonSize: .flexibleByMaxChip) | ||
.mandatoryFieldIndicatorStyle { conf in | ||
conf.mandatoryFieldIndicator | ||
.foregroundStyle(self.mandatoryFieldIndicatorColor()) | ||
} | ||
|
||
FilterFormView(title: "SingleSelection, Non-EmptySelection, flexible", mandatoryFieldIndicator: self.mandatoryField(), isRequired: self.showMandatoryField, options: self.valueOptions, errorMessage: nil, isEnabled: self.isEnabled, allowsMultipleSelection: true, allowsEmptySelection: true, value: self.$trySevenSelectionValue, buttonSize: .flexible) | ||
.mandatoryFieldIndicatorStyle { conf in | ||
conf.mandatoryFieldIndicator | ||
.foregroundStyle(self.mandatoryFieldIndicatorColor()) | ||
} | ||
|
||
FilterFormView(title: "Sort Filter, MultiSelection, EmptySelection, flexible, no mandatory", mandatoryFieldIndicator: self.mandatoryField(), isRequired: false, options: self.sortValueOptions, errorMessage: nil, isEnabled: self.isEnabled, allowsMultipleSelection: true, allowsEmptySelection: true, value: self.$sortFilterSelectionValue, buttonSize: .flexible) | ||
.mandatoryFieldIndicatorStyle { conf in | ||
conf.mandatoryFieldIndicator | ||
.foregroundStyle(self.mandatoryFieldIndicatorColor()) | ||
} | ||
.filterFormOptionMinTouchHeight(50) | ||
.filterFormOptionCornerRadius(16) | ||
.filterFormOptionTitleSpacing(4) | ||
.filterFormOptionPadding(EdgeInsets(top: 4, leading: 9, bottom: 4, trailing: 9)) | ||
.filterFormOptionAttributes([ | ||
.enabledUnselected: [ | ||
.strokeWidth: 1.0, | ||
.strokeColor: Color.preferredColor(.separator), | ||
.foregroundColor: Color.preferredColor(.tertiaryLabel), | ||
.backgroundColor: Color.preferredColor(.tertiaryFill), | ||
.font: Font.system(.body) | ||
], | ||
.enabledSelected: [ | ||
.strokeWidth: 1.0, | ||
.strokeColor: Color.preferredColor(.tintColor), | ||
.foregroundColor: Color.preferredColor(.tintColor), | ||
.backgroundColor: Color.preferredColor(.secondaryGroupedBackground), | ||
.font: Font.system(.body) | ||
] | ||
]) | ||
|
||
FilterFormView(title: "Sort Filter, MultiSelection, EmptySelection, fixed, no mandatory", mandatoryFieldIndicator: self.mandatoryField(), isRequired: false, options: self.sortValueOptions, errorMessage: nil, isEnabled: self.isEnabled, allowsMultipleSelection: true, allowsEmptySelection: true, value: self.$sortFilterFixedSelectionValue, buttonSize: .fixed) | ||
.mandatoryFieldIndicatorStyle { conf in | ||
conf.mandatoryFieldIndicator | ||
.foregroundStyle(self.mandatoryFieldIndicatorColor()) | ||
} | ||
.filterFormOptionMinTouchHeight(50) | ||
.filterFormOptionCornerRadius(16) | ||
.filterFormOptionTitleSpacing(4) | ||
.filterFormOptionPadding(EdgeInsets(top: 4, leading: 9, bottom: 4, trailing: 9)) | ||
.filterFormOptionsItemSpacing(16) | ||
.filterFormOptionsLineSpacing(10) | ||
.filterFormOptionAttributes([ | ||
.enabledUnselected: [ | ||
.strokeWidth: 1.0, | ||
.strokeColor: Color.preferredColor(.separator), | ||
.foregroundColor: Color.preferredColor(.tertiaryLabel), | ||
.backgroundColor: Color.preferredColor(.tertiaryFill), | ||
.font: Font.system(.body) | ||
], | ||
.enabledSelected: [ | ||
.strokeWidth: 1.0, | ||
.strokeColor: Color.preferredColor(.tintColor), | ||
.foregroundColor: Color.preferredColor(.tintColor), | ||
.backgroundColor: Color.preferredColor(.secondaryGroupedBackground), | ||
.font: Font.system(.body) | ||
] | ||
]) | ||
|
||
// Empty title and mandatory | ||
FilterFormView(title: { | ||
EmptyView() | ||
}, mandatoryFieldIndicator: { | ||
EmptyView() | ||
}, isRequired: false, options: self.sortValueOptions, isEnabled: self.isEnabled, allowsMultipleSelection: true, allowsEmptySelection: true, value: self.$sortFilterEmptyTitleSelectionValue, buttonSize: .flexible) | ||
.filterFormOptionMinTouchHeight(50) | ||
.filterFormOptionCornerRadius(16) | ||
.filterFormOptionTitleSpacing(4) | ||
.filterFormOptionPadding(EdgeInsets(top: 4, leading: 9, bottom: 4, trailing: 9)) | ||
.filterFormOptionAttributes([ | ||
.enabledUnselected: [ | ||
.strokeWidth: 1.0, | ||
.strokeColor: Color.preferredColor(.separator), | ||
.foregroundColor: Color.preferredColor(.tertiaryLabel), | ||
.backgroundColor: Color.preferredColor(.tertiaryFill), | ||
.font: Font.system(.body) | ||
], | ||
.enabledSelected: [ | ||
.strokeWidth: 1.0, | ||
.strokeColor: Color.preferredColor(.tintColor), | ||
.foregroundColor: Color.preferredColor(.tintColor), | ||
.backgroundColor: Color.preferredColor(.secondaryGroupedBackground), | ||
.font: Font.system(.body) | ||
] | ||
]) | ||
} | ||
.listStyle(.plain) | ||
} | ||
|
||
func mandatoryFieldIndicatorColor() -> Color { | ||
if !self.isEnabled { | ||
return .preferredColor(.separator) | ||
} else { | ||
return self.customizedMandatoryIndicator ? Color.red : Color.preferredColor(.primaryLabel) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
FilterFormViewExamples() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Foundation | ||
|
||
/// Size of `FUIFilterFormView` button | ||
public enum FilterButtonSize { | ||
/// Items will be displayed in two columns, each column's width will be 50% of available space. | ||
case fixed | ||
/// Items will be displayed in sequence, each item size will be decided by its own content. | ||
case flexible | ||
/// Items will be displayed in sequence, each item size will be the same as the chip size with largest content. | ||
case flexibleByMaxChip | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented codes to be deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed