1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 14:50:32 +05:30
yattee/Shared/Views/AccentButton.swift

53 lines
1.6 KiB
Swift
Raw Normal View History

2022-11-11 23:20:13 +05:30
import SwiftUI
2022-12-16 14:03:06 +05:30
struct AccentButton: View {
2022-11-11 23:20:13 +05:30
var text: String?
var imageSystemName: String?
2023-06-17 17:39:51 +05:30
var maxWidth: CGFloat? = .infinity // swiftlint:disable:this no_cgfloat
2022-12-16 14:03:06 +05:30
var bold = true
2023-05-25 17:58:29 +05:30
var verticalPadding = 10.0
var horizontalPadding = 10.0
var minHeight = 45.0
2022-11-11 23:20:13 +05:30
var action: () -> Void = {}
var body: some View {
Button(action: action) {
2022-11-12 07:09:44 +05:30
HStack(spacing: 8) {
2022-11-11 23:20:13 +05:30
if let imageSystemName {
Image(systemName: imageSystemName)
}
if let text {
2022-11-19 04:36:13 +05:30
Text(text.localized())
2022-12-16 14:03:06 +05:30
.fontWeight(bold ? .bold : .regular)
2022-11-11 23:20:13 +05:30
}
}
2023-05-25 17:58:29 +05:30
.padding(.vertical, verticalPadding)
.padding(.horizontal, horizontalPadding)
.frame(minHeight: minHeight)
2022-12-16 14:03:06 +05:30
.frame(maxWidth: maxWidth)
2022-11-11 23:20:13 +05:30
.contentShape(Rectangle())
}
2023-05-27 03:36:39 +05:30
#if !os(tvOS)
2022-11-11 23:20:13 +05:30
.foregroundColor(.accentColor)
.buttonStyle(.plain)
.background(buttonBackground)
2023-05-27 03:36:39 +05:30
#endif
2022-11-11 23:20:13 +05:30
}
var buttonBackground: some View {
RoundedRectangle(cornerRadius: 4)
.foregroundColor(Color.accentColor.opacity(0.33))
}
}
struct OpenVideosButton_Previews: PreviewProvider {
static var previews: some View {
2023-05-27 03:36:39 +05:30
VStack {
AccentButton(text: "Open Videos", imageSystemName: "play.circle.fill")
.padding(.horizontal, 100)
AccentButton(text: "Open Videos", imageSystemName: "play.circle.fill")
.padding(.horizontal, 100)
}
2022-11-11 23:20:13 +05:30
}
}