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

merge :: 디자인 시스템 - RadioButton #31

Merged
merged 10 commits into from
Oct 9, 2022
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import SwiftUI

public struct DMSRadioButton: View {

@Binding var isOn: Bool
@Binding var isDisabeld: Bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disabled를 binding으로 받는 특별한 이유가 있을까요?

Copy link
Member

@baekteun baekteun Oct 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Environment(.isEnabled)로 isEnabled상태를 받을 수 있으니 이거 쓰시는게 어떤가요


let id: String
let size: CGFloat
let callback: (String) -> Void
baekteun marked this conversation as resolved.
Show resolved Hide resolved

public init(
isOn: Binding<Bool> = .constant(false),
isDisabled: Binding<Bool> = .constant(false),
id: String,
size: CGFloat = 20,
callback: @escaping (String) -> Void
) {
self._isOn = isOn
self._isDisabeld = isDisabled
self.id = id
self.size = size
baekteun marked this conversation as resolved.
Show resolved Hide resolved
self.callback = callback
}

public var body: some View {
Button {
self.isOn.toggle()
self.callback(self.id)
} label: {
HStack(alignment: .center) {
if self.isDisabeld {
Image(systemName: self.isOn ? "largecircle.fill.circle" : "circle")
.clipShape(Circle())
.foregroundColor(self.isOn ? Color.PrimaryVariant.lighten1 : Color.GrayScale.gray3)
.disabled(isDisabeld)
baekteun marked this conversation as resolved.
Show resolved Hide resolved
} else {
Image(systemName: self.isOn ? "largecircle.fill.circle" : "circle")
.clipShape(Circle())
.foregroundColor(self.isOn ? Color.PrimaryVariant.primary : Color.GrayScale.gray5)
.disabled(isDisabeld)
baekteun marked this conversation as resolved.
Show resolved Hide resolved
}
baekteun marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}

struct DMSRadioButton_Previews: PreviewProvider {
static var previews: some View {
DMSRadioButton(
id: "asdf",
callback: { _ in }
)
}
}