forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHoverButtunStyle.swift
More file actions
28 lines (25 loc) · 843 Bytes
/
HoverButtunStyle.swift
File metadata and controls
28 lines (25 loc) · 843 Bytes
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
import SwiftUI
// This is a custom button style that changes its background color when hovered
public struct HoverButtonStyle: ButtonStyle {
@State private var isHovered: Bool
private var padding: CGFloat
public init(isHovered: Bool = false, padding: CGFloat = 4) {
self.isHovered = isHovered
self.padding = padding
}
public func makeBody(configuration: Configuration) -> some View {
configuration.label
.padding(padding)
.background(
configuration.isPressed
? Color.gray.opacity(0.2)
: isHovered
? Color.gray.opacity(0.1)
: Color.clear
)
.cornerRadius(4)
.onHover { hover in
isHovered = hover
}
}
}