-
Notifications
You must be signed in to change notification settings - Fork 0
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
π :: DesignSystem SMSSelectionControls μ μ #37
Changes from 15 commits
e70aa84
715d732
4fb864d
abab51c
6eef1cf
3d7d4ad
94053a1
e25c2a4
1a75279
6535fe1
80e8c8e
8c29c2a
1208295
fdc43eb
8a8091a
f326a31
97479aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import SwiftUI | ||
|
||
public struct RadioComponent<T: Hashable, Content: View>: View { | ||
private let value: RadioValue<T> | ||
private let content: () -> Content | ||
|
||
public init( | ||
selection: Binding<T?>, | ||
@ViewBuilder _ content: @escaping () -> Content, | ||
onTapReceive: ((T?) -> Void)? = nil | ||
) { | ||
self.value = RadioValue(selection: selection, onTapReceive: onTapReceive) | ||
self.content = content | ||
} | ||
|
||
public var body: some View { | ||
content() | ||
.environmentObject(value) | ||
} | ||
} | ||
|
||
final class RadioValue<T: Hashable>: ObservableObject { | ||
typealias TapReceiveAction = (T?) -> Void | ||
|
||
@Binding var selection: T? | ||
var onTapReceive: (TapReceiveAction)? | ||
|
||
init(selection: Binding<T?>, onTapReceive: (TapReceiveAction)? = nil) { | ||
_selection = selection | ||
self.onTapReceive = onTapReceive | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import SwiftUI | ||
|
||
public struct RadioTag<T: Hashable>: ViewModifier { | ||
@EnvironmentObject private var value: RadioValue<T> | ||
private var tag: T? | ||
|
||
init(_ tag: T?) { | ||
self.tag = tag | ||
} | ||
|
||
public func body(content: Content) -> some View { | ||
Button { | ||
value.selection = tag | ||
value.onTapReceive?(tag) | ||
} label: { | ||
content | ||
} | ||
.buttonStyle(CustomButtonStyle(isOn: tag == value.selection)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ΄κ±° RadioTagμ λ€λ건 μ’ λ¬Έμ κ° λ§μ§ μμμ? |
||
} | ||
} | ||
|
||
extension View { | ||
public func radioTag<T: Hashable>(_ tag: T?) -> some View { | ||
self.modifier(RadioTag(tag)) | ||
} | ||
} | ||
|
||
private struct CustomButtonStyle: ButtonStyle { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. κ·Έλμ μ΄ μΉκ΅¬ μ΄λ¦μ΄ μ΄λ»κ² λλμ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PressedButtonStyle μ΄λ€κ°μ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Selection μ μ©μ΄λ PressedSelectionButtonStyle μ΄λ€κ°μ. |
||
var isOn: Bool | ||
|
||
init(isOn: Bool) { | ||
self.isOn = isOn | ||
} | ||
|
||
@ViewBuilder | ||
func makeBody(configuration: Configuration) -> some View { | ||
Circle() | ||
.fill(self.isOn && configuration.isPressed ? Color.sms(.neutral(.n20)) : Color.clear) | ||
.overlay { | ||
configuration.label | ||
} | ||
.frame(width: 32, height: 32) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import SwiftUI | ||
|
||
public struct SMSSelectionControls<T: Hashable>: View { | ||
@EnvironmentObject private var value: RadioValue<T> | ||
private var tag: T? | ||
|
||
public init(tag: T?) { | ||
self.tag = tag | ||
} | ||
|
||
public var body: some View { | ||
ZStack { | ||
Circle() | ||
.stroke(tag == value.selection ? Color.sms(.primary(.p2)) : Color.sms(.neutral(.n20)), lineWidth: 2) | ||
.frame(width: 20, height: 20) | ||
|
||
Circle() | ||
.fill(tag == value.selection ? Color.sms(.primary(.p2)) : .clear) | ||
.frame(width: 12, height: 12) | ||
} | ||
} | ||
} |
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.
content μ΄ μΉκ΅¬ labelμ΄ μ _ μΈκ±°μ£ ?