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

๐Ÿ”€ :: [#326] DesignSystem / SMSSegmentedControl #327

Merged
merged 2 commits into from
May 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import SwiftUI

public struct SMSSegmentedControl: View {
@State private var selectedIndex = 0
@Namespace private var segmentNamespace
private let options: [String]
private let onSelect: (String) -> Void

public init(
options: [String],
onSelect: @escaping (String) -> Void
) {
self.options = options
self.onSelect = onSelect
}

public var body: some View {
HStack(spacing: 0) {
ForEach(0..<options.count, id: \.self) { index in
let isSelected = selectedIndex == index
SMSText(options[index], font: .title2)
.frame(maxWidth: .infinity)
.padding(.vertical, 9.5)
.background {
if isSelected {
RoundedRectangle(cornerRadius: 8)
.fill(Color.sms(.primary(.p2)))
.matchedGeometryEffect(
id: "SEGMENTED_CONTROL",
in: segmentNamespace
)
}
}
.foregroundStyle(
self.selectedIndex == index ? Color.sms(.system(.white)) : Color.sms(.neutral(.n40))
)
.padding(4)
.buttonWrapper {
withAnimation(.interactiveSpring(duration: 0.5)) {
self.selectedIndex = index
}
}
}
}
.background {
RoundedRectangle(cornerRadius: 8)
.fill(Color.sms(.neutral(.n10)))
}
.padding()
baekteun marked this conversation as resolved.
Show resolved Hide resolved
}
}

Loading