-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormColorPicker.swift
More file actions
67 lines (57 loc) · 1.69 KB
/
FormColorPicker.swift
File metadata and controls
67 lines (57 loc) · 1.69 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
//
// FormColorPicker.swift
//
// Copyright 2022, 2023 OpenAlloc LLC
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
import SwiftUI
// Using .clear as a local non-optional proxy for nil, because ColorPicker won't
// work with optional.
// When saved, the color .clear should be assigned is nil.
public struct FormColorPicker: View {
// MARK: - Parameters
@Binding private var color: Color
public init(color: Binding<Color>) {
_color = color
}
// MARK: - Locals
// MARK: - Views
public var body: some View {
HStack {
#if os(watchOS)
WColorPicker(selection: $color) {
Text("Color")
}
#elseif os(iOS)
ColorPicker(selection: $color, supportsOpacity: false) {
Text("Color")
}
#endif
Divider()
Image(systemName: "xmark.circle.fill")
.symbolRenderingMode(.hierarchical)
.onTapGesture {
color = .clear
}
}
}
}
struct CategoryColorPicker_Previews: PreviewProvider {
struct TestHolder: View {
@State var color: Color = Color(cgColor: CGColor(red: 0.1, green: 0.4, blue: 0.8, alpha: 1.0))
var body: some View {
NavigationStack {
Form {
FormColorPicker(color: $color)
}
}
}
}
static var previews: some View {
TestHolder()
.accentColor(.orange)
}
}