|
| 1 | +// The MIT License (MIT) |
| 2 | +// Copyright © 2020 Ivan Vorobei ( [email protected]) |
| 3 | +// |
| 4 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +// of this software and associated documentation files (the "Software"), to deal |
| 6 | +// in the Software without restriction, including without limitation the rights |
| 7 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +// copies of the Software, and to permit persons to whom the Software is |
| 9 | +// furnished to do so, subject to the following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included in all |
| 12 | +// copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | +// SOFTWARE. |
| 21 | + |
| 22 | +#if canImport(UIKit) && (os(iOS) || os(tvOS)) |
| 23 | +import UIKit |
| 24 | + |
| 25 | +extension SPDimmedButton { |
| 26 | + |
| 27 | + /** |
| 28 | + SparrowKit: Represent colors for state of button for elements. |
| 29 | + */ |
| 30 | + public struct Colorise { |
| 31 | + |
| 32 | + public var title: Mode |
| 33 | + public var icon: Mode |
| 34 | + public var background: Mode |
| 35 | + |
| 36 | + /** |
| 37 | + SparrowKit: This init allow create colorise with automatically tint oberving. |
| 38 | + |
| 39 | + - parameter content: Colorise mode for `title` & `icon`. |
| 40 | + - parameter background: Colorise mode for background. |
| 41 | + */ |
| 42 | + public init(content: Mode, background: Mode) { |
| 43 | + self.title = content |
| 44 | + self.icon = content |
| 45 | + self.background = background |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + - parameter content: Color for `title` & `icon`. |
| 50 | + - parameter background: Color for background. |
| 51 | + */ |
| 52 | + public init(content: UIColor, background: UIColor) { |
| 53 | + self.title = .custom(content) |
| 54 | + self.icon = .custom(content) |
| 55 | + self.background = .custom(background) |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + - parameter content: Color for `title` & `icon`. |
| 60 | + - parameter background: Color for image. |
| 61 | + - parameter background: Color for background. |
| 62 | + */ |
| 63 | + public init(content: UIColor, icon: UIColor, background: UIColor) { |
| 64 | + self.title = .custom(content) |
| 65 | + self.icon = .custom(icon) |
| 66 | + self.background = .custom(background) |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + SparrowKit: Represent of rendering colors in button. |
| 71 | + |
| 72 | + It need for have dynamic tint color and fixed custom. |
| 73 | + */ |
| 74 | + public enum Mode { |
| 75 | + |
| 76 | + /** |
| 77 | + SparrowKit: Always specific color. |
| 78 | + */ |
| 79 | + case custom(UIColor) |
| 80 | + |
| 81 | + /** |
| 82 | + SparrowKit: Observe and apply tint color of button. |
| 83 | + */ |
| 84 | + case tint |
| 85 | + |
| 86 | + /** |
| 87 | + SparrowKit: Observe and apply secondary tint color of button. |
| 88 | + */ |
| 89 | + case secondaryTint |
| 90 | + } |
| 91 | + |
| 92 | + // MARK: - Ready Use |
| 93 | + |
| 94 | + public static var tintedContent: Colorise { |
| 95 | + return .init(content: .tint, background: .custom(.clear)) |
| 96 | + } |
| 97 | + |
| 98 | + public static var tintedColorful: Colorise { |
| 99 | + return .init(content: .custom(.white), background: .tint) |
| 100 | + } |
| 101 | + |
| 102 | + public static var tinted: Colorise { |
| 103 | + return .init(content: .tint, background: .secondaryTint) |
| 104 | + } |
| 105 | + } |
| 106 | +} |
| 107 | +#endif |
0 commit comments