Skip to content

Commit afb5d6f

Browse files
committed
🔎 Conditional color modifier
1 parent 0d46ba4 commit afb5d6f

File tree

1 file changed

+23
-0
lines changed
  • Sources/ShinySwiftUI/Extensions/SwiftUI/Color

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// Color.swift
3+
//
4+
//
5+
// Created by Ben Myers on 3/16/22.
6+
//
7+
8+
import SwiftUI
9+
10+
@available(macOS 11.0, iOS 13.0, *)
11+
public extension Color {
12+
13+
// MARK: - Public Methods
14+
15+
/**
16+
Returns the color if the given condition is true, returns `.clear` otherwise.
17+
18+
- parameter condition: The condition to show the color.
19+
*/
20+
func `if`(_ condition: Binding<Bool>) -> Color {
21+
return condition.wrappedValue ? self : .clear
22+
}
23+
}

0 commit comments

Comments
 (0)