71 lines
2.1 KiB
Swift
71 lines
2.1 KiB
Swift
import SwiftUI
|
|
|
|
struct FollowAllButton: View {
|
|
let isCompleted: Bool
|
|
let isLoading: Bool
|
|
let action: () -> Void
|
|
|
|
init(
|
|
isCompleted: Bool,
|
|
isLoading: Bool = false,
|
|
action: @escaping () -> Void
|
|
) {
|
|
self.isCompleted = isCompleted
|
|
self.isLoading = isLoading
|
|
self.action = action
|
|
}
|
|
|
|
var body: some View {
|
|
Button {
|
|
if !isCompleted && !isLoading {
|
|
action()
|
|
}
|
|
} label: {
|
|
HStack(spacing: SodaSpacing.s6) {
|
|
if isCompleted {
|
|
Image("ic_new_following")
|
|
.resizable()
|
|
.renderingMode(.template)
|
|
.foregroundColor(.black)
|
|
.frame(width: 20, height: 20)
|
|
} else {
|
|
Image("ic_new_follow")
|
|
.resizable()
|
|
.renderingMode(.template)
|
|
.foregroundColor(.white)
|
|
.frame(width: 20, height: 20)
|
|
}
|
|
|
|
Text(isCompleted ? I18n.HomeRecommendation.followAllCompleted : I18n.HomeRecommendation.followAll)
|
|
.appFont(.body5)
|
|
.foregroundColor(isCompleted ? .black : .white)
|
|
}
|
|
.padding(SodaSpacing.s12)
|
|
.frame(maxWidth: .infinity)
|
|
.background(isCompleted ? Color.white : Color.clear)
|
|
.overlay {
|
|
if !isCompleted {
|
|
Capsule()
|
|
.stroke(Color.white.opacity(0.3), lineWidth: 1)
|
|
}
|
|
}
|
|
.clipShape(Capsule())
|
|
.opacity(isLoading ? 0.6 : 1)
|
|
}
|
|
.buttonStyle(.plain)
|
|
.disabled(isCompleted || isLoading)
|
|
}
|
|
}
|
|
|
|
struct FollowAllButton_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
VStack(spacing: SodaSpacing.s12) {
|
|
FollowAllButton(isCompleted: false) {}
|
|
FollowAllButton(isCompleted: true) {}
|
|
}
|
|
.padding(SodaSpacing.s20)
|
|
.background(Color.black)
|
|
.previewLayout(.sizeThatFits)
|
|
}
|
|
}
|