forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionButton.swift
More file actions
68 lines (62 loc) · 1.83 KB
/
ActionButton.swift
File metadata and controls
68 lines (62 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// ActionButton.swift
// LoopKitUI
//
// Created by Pete Schwamb on 2020-03-04.
// Copyright © 2020 LoopKit Authors. All rights reserved.
//
import SwiftUI
// TODO: Migrate use sites to ActionButtonStyle
public struct ActionButton: ViewModifier {
private let fontColor: Color
private let backgroundColor: Color
private let edgeColor: Color
private let cornerRadius: CGFloat = 10
public enum ButtonType {
case primary
case secondary
case destructive
case deactivated
case plain
}
init(_ style: ButtonType = .primary) {
switch style {
case .primary:
fontColor = .white
backgroundColor = .accentColor
edgeColor = .clear
case .destructive:
fontColor = .white
backgroundColor = .red
edgeColor = .clear
case .secondary:
fontColor = .accentColor
backgroundColor = .clear
edgeColor = .accentColor
case .deactivated:
fontColor = .white
backgroundColor = .gray
edgeColor = .clear
case .plain:
fontColor = .accentColor
backgroundColor = .clear
edgeColor = .clear
}
}
public func body(content: Content) -> some View {
content
.padding(.all)
.foregroundColor(fontColor)
.font(.headline)
.frame(maxWidth: .infinity)
.background(backgroundColor)
.cornerRadius(cornerRadius)
.overlay(RoundedRectangle(cornerRadius: cornerRadius)
.stroke(edgeColor))
}
}
public extension View {
func actionButtonStyle(_ style: ActionButton.ButtonType = .primary) -> some View {
ModifiedContent(content: self, modifier: ActionButton(style))
}
}