Skip to content
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

feat: 🎸 [JIRA:HCPSDKFIORIUIKIT-2716]Step Progress Indicator #787

Merged
merged 11 commits into from
Sep 13, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct SPIExampleWithIcon: View {
}
}
}
.stepProgressIndicatorNodeType(.icon)
Spacer().padding(20)
Button {
self.completeStep()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ public protocol StepItem {
/// Node icon.
var icon: Image? { get }
}

/// Node of Step Progress Indicator display type, default is `mixture`.
public enum StepProgressIndicatorNodeType {
KevinZK marked this conversation as resolved.
Show resolved Hide resolved
/// Text and icon.
case mixture
KevinZK marked this conversation as resolved.
Show resolved Hide resolved
/// Only text.
case text
/// Only icon.
case icon
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ extension EnvironmentValues {
}
}

struct StepProgressIndicatorNodeTypeKey: EnvironmentKey {
static let defaultValue: StepProgressIndicatorNodeType = .mixture
}

extension EnvironmentValues {
var stepProgressIndicatorNodeType: StepProgressIndicatorNodeType {
get { self[StepProgressIndicatorNodeTypeKey.self] }
set { self[StepProgressIndicatorNodeTypeKey.self] = newValue }
}
}

public extension View {
/// The style of the node of `StepProgressIndicator`.
/// - Parameter type: `StepProgressIndicatorNodeType` enum values.
/// - Returns: A new `StepProgressIndicator` with specific node.
func stepProgressIndicatorNodeType(_ type: StepProgressIndicatorNodeType) -> some View {
self.environment(\.stepProgressIndicatorNodeType, type)
}
}

public extension View {
/// Step style for `StepProgressIndicator`.
/// - Parameter style: Style for `StepProgressIndicator`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct DefaultSingleStep: View {
@Environment(\.dynamicTypeSize) var dynamicTypeSize
@Environment(\.stepAxis) var stepAxis
@Environment(\.stepFrames) var stepFrames
@Environment(\.stepProgressIndicatorNodeType) var type

var stepItem: StepItem
@Binding var selection: String
Expand Down Expand Up @@ -98,11 +99,23 @@ struct DefaultSingleStep: View {
} node: {
ZStack {
self.node(by: self.stepItem.state, isSelected: isSelected)
if self.stepItem.icon.isEmpty {
switch self.type {
case .mixture:
if self.stepItem.icon.isEmpty {
Text("\(self.index + 1)")
.font(Font.fiori(forTextStyle: .footnote))
} else {
self.stepItem.icon
}
case .icon:
if self.stepItem.icon.isEmpty {
Image(systemName: "app.dashed")
} else {
self.stepItem.icon
}
case .text:
Text("\(self.index + 1)")
.font(Font.fiori(forTextStyle: .footnote))
} else {
self.stepItem.icon
}
}
.frame(width: self.sideLength, height: self.sideLength)
Expand Down
Loading