yattee/Shared/Views/AccentButton.swift

46 lines
1.3 KiB
Swift
Raw Normal View History

2022-11-11 17:50:13 +00:00
import SwiftUI
2022-12-16 08:33:06 +00:00
struct AccentButton: View {
2022-11-11 17:50:13 +00:00
var text: String?
var imageSystemName: String?
2022-12-16 08:33:06 +00:00
var maxWidth: CGFloat? = .infinity
var bold = true
2023-05-25 12:28:29 +00:00
var verticalPadding = 10.0
var horizontalPadding = 10.0
var minHeight = 45.0
2022-11-11 17:50:13 +00:00
var action: () -> Void = {}
var body: some View {
Button(action: action) {
2022-11-12 01:39:44 +00:00
HStack(spacing: 8) {
2022-11-11 17:50:13 +00:00
if let imageSystemName {
Image(systemName: imageSystemName)
}
if let text {
2022-11-18 23:06:13 +00:00
Text(text.localized())
2022-12-16 08:33:06 +00:00
.fontWeight(bold ? .bold : .regular)
2022-11-11 17:50:13 +00:00
}
}
2023-05-25 12:28:29 +00:00
.padding(.vertical, verticalPadding)
.padding(.horizontal, horizontalPadding)
.frame(minHeight: minHeight)
2022-12-16 08:33:06 +00:00
.frame(maxWidth: maxWidth)
2022-11-11 17:50:13 +00:00
.contentShape(Rectangle())
}
.foregroundColor(.accentColor)
.buttonStyle(.plain)
.background(buttonBackground)
}
var buttonBackground: some View {
RoundedRectangle(cornerRadius: 4)
.foregroundColor(Color.accentColor.opacity(0.33))
}
}
struct OpenVideosButton_Previews: PreviewProvider {
static var previews: some View {
2022-12-16 08:33:06 +00:00
AccentButton(text: "Open Videos", imageSystemName: "play.circle.fill")
2022-11-11 17:50:13 +00:00
}
}