Skip to content

Commit

Permalink
Merge pull request #37 from GSM-MSG/36-selection-controls-design-system
Browse files Browse the repository at this point in the history
  • Loading branch information
kimsh153 authored May 22, 2023
2 parents a78526a + 97479aa commit e7daad0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 30 deletions.
40 changes: 10 additions & 30 deletions Projects/Core/DesignSystem/Demo/Sources/DemoView.swift
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
import DesignSystem
import SwiftUI

struct DemoView: View {
@State var isPresentedBottomSheet = false
var body: some View {
public struct DemoView: View {
@State var isSeleted = true
@State var selection: Int? = 0

public var body: some View {
VStack {
Group {
CTAButton(text: "CTA Default", style: .default) {
withAnimation {
isPresentedBottomSheet = true
ForEach(0..<4) { index in
HStack {
SMSSelectionControls(isSeleted: $isSeleted)
Text("asdfasdf")
}
}
}
}
.padding(8)

NavigationLink {
AView()
} label: {
Text("A")
}
}
.smsBottomSheet(isShowing: $isPresentedBottomSheet) {
RoundedRectangle(cornerRadius: 8)
.fill(Color.sms(.neutral(.n20)))
.frame(maxWidth: .infinity)
.frame(height: 500)
.padding(.horizontal)
}
}
}

struct AView: View {
@Environment(\.dismiss) var dismiss

var body: some View {
Text("A")
.smsBackButton(dismiss: dismiss)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import SwiftUI

public struct SMSSelectionControls: View {
@Binding var isSeleted: Bool

public init(isSeleted: Binding<Bool>) {
_isSeleted = isSeleted
}
public var body: some View {
Button {
self.isSeleted.toggle()
} label: {
ZStack {
Circle()
.stroke(isSeleted ? Color.sms(.primary(.p2)) : Color.sms(.neutral(.n20)), lineWidth: 2)
.frame(width: 20, height: 20)
Circle()
.fill(isSeleted ? Color.sms(.primary(.p2)) : .clear)
.frame(width: 12, height: 12)
}
}
.buttonStyle(PressedSelectionButtonStyle(isSeleted: isSeleted))
}
}

private struct PressedSelectionButtonStyle: ButtonStyle {
var isSeleted: Bool

init(isSeleted: Bool) {
self.isSeleted = isSeleted
}

@ViewBuilder
func makeBody(configuration: Configuration) -> some View {
Circle()
.fill(self.isSeleted && configuration.isPressed ? Color.sms(.neutral(.n20)) : Color.clear)
.overlay {
configuration.label
}
.frame(width: 32, height: 32)
}
}

0 comments on commit e7daad0

Please sign in to comment.