forked from CodeEditApp/CodeEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlurButtonStyle.swift
More file actions
69 lines (62 loc) · 2.11 KB
/
BlurButtonStyle.swift
File metadata and controls
69 lines (62 loc) · 2.11 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
69
//
// BlurButtonStyle.swift
// CodeEdit
//
// Created by Wouter Hennen on 21/01/2023.
//
import SwiftUI
extension ButtonStyle where Self == BlurButtonStyle {
static var blur: BlurButtonStyle { BlurButtonStyle() }
static var secondaryBlur: BlurButtonStyle { BlurButtonStyle(isSecondary: true) }
}
struct BlurButtonStyle: ButtonStyle {
var isSecondary: Bool = false
@Environment(\.controlSize)
var controlSize
@Environment(\.colorScheme)
var colorScheme
var height: CGFloat {
switch controlSize {
case .large:
return 28
default:
return 20
}
}
func makeBody(configuration: Configuration) -> some View {
configuration.label
.padding(.horizontal, 8)
.frame(height: height)
.background {
switch colorScheme {
case .dark:
ZStack {
Color.gray.opacity(0.001)
if isSecondary {
Rectangle()
.fill(.regularMaterial)
} else {
Rectangle()
.fill(.regularMaterial)
.blendMode(.plusLighter)
}
Color.gray.opacity(isSecondary ? 0.10 : 0.30)
Color.white.opacity(configuration.isPressed ? 0.10 : 0.00)
}
case .light:
ZStack {
Color.gray.opacity(0.001)
Rectangle()
.fill(.regularMaterial)
.blendMode(.darken)
Color.gray.opacity(isSecondary ? 0.05 : 0.15)
.blendMode(.plusDarker)
Color.gray.opacity(configuration.isPressed ? 0.10 : 0.00)
}
@unknown default:
Color.black
}
}
.clipShape(RoundedRectangle(cornerRadius: controlSize == .large ? 6 : 5))
}
}