forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewExtension.swift
More file actions
59 lines (47 loc) · 2 KB
/
ViewExtension.swift
File metadata and controls
59 lines (47 loc) · 2 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
import SwiftUI
let BLUE_IN_LIGHT_THEME = Color(red: 98/255, green: 154/255, blue: 248/255)
let BLUE_IN_DARK_THEME = Color(red: 55/255, green: 108/255, blue: 194/255)
struct HoverBackgroundModifier: ViewModifier {
@Environment(\.colorScheme) var colorScheme
var isHovered: Bool
func body(content: Content) -> some View {
content
.background(isHovered ? (colorScheme == .dark ? BLUE_IN_DARK_THEME : BLUE_IN_LIGHT_THEME) : Color.clear)
}
}
struct HoverRadiusBackgroundModifier: ViewModifier {
@Environment(\.colorScheme) var colorScheme
var isHovered: Bool
var cornerRadius: CGFloat = 0
func body(content: Content) -> some View {
content.background(
RoundedRectangle(cornerRadius: cornerRadius)
.fill(isHovered ? (colorScheme == .dark ? BLUE_IN_DARK_THEME : BLUE_IN_LIGHT_THEME) : Color.clear)
)
}
}
struct HoverForegroundModifier: ViewModifier {
@Environment(\.colorScheme) var colorScheme
var isHovered: Bool
var defaultColor: Color
func body(content: Content) -> some View {
content.foregroundColor(isHovered ? Color.white : defaultColor)
}
}
extension View {
public func hoverBackground(isHovered: Bool) -> some View {
self.modifier(HoverBackgroundModifier(isHovered: isHovered))
}
public func hoverRadiusBackground(isHovered: Bool, cornerRadius: CGFloat) -> some View {
self.modifier(HoverRadiusBackgroundModifier(isHovered: isHovered, cornerRadius: cornerRadius))
}
public func hoverForeground(isHovered: Bool, defaultColor: Color) -> some View {
self.modifier(HoverForegroundModifier(isHovered: isHovered, defaultColor: defaultColor))
}
public func hoverPrimaryForeground(isHovered: Bool) -> some View {
self.hoverForeground(isHovered: isHovered, defaultColor: .primary)
}
public func hoverSecondaryForeground(isHovered: Bool) -> some View {
self.hoverForeground(isHovered: isHovered, defaultColor: .secondary)
}
}