diff --git a/Sources/Views/SettingToggle.swift b/Sources/Views/SettingToggle.swift index 39fc909..28e7240 100644 --- a/Sources/Views/SettingToggle.swift +++ b/Sources/Views/SettingToggle.swift @@ -13,6 +13,8 @@ import SwiftUI */ public struct SettingToggle: View, Setting { public var id: AnyHashable? + public var icon: SettingIcon? + public var title: String @Binding public var isOn: Bool public var horizontalSpacing = CGFloat(12) @@ -21,6 +23,8 @@ public struct SettingToggle: View, Setting { public init( id: AnyHashable? = nil, + icon: SettingIcon? = nil, + title: String, isOn: Binding, horizontalSpacing: CGFloat = CGFloat(12), @@ -28,6 +32,7 @@ public struct SettingToggle: View, Setting { horizontalPadding: CGFloat? = nil ) { self.id = id + self.icon = icon self.title = title self._isOn = isOn self.horizontalSpacing = horizontalSpacing @@ -37,6 +42,7 @@ public struct SettingToggle: View, Setting { public var body: some View { SettingToggleView( + icon: icon, title: title, isOn: $isOn, horizontalSpacing: horizontalSpacing, @@ -48,7 +54,7 @@ public struct SettingToggle: View, Setting { struct SettingToggleView: View { @Environment(\.edgePadding) var edgePadding - + var icon: SettingIcon? let title: String @Binding var isOn: Bool @@ -58,6 +64,9 @@ struct SettingToggleView: View { var body: some View { HStack(spacing: horizontalSpacing) { + if let icon { + SettingIconView(icon: icon) + } Text(title) .fixedSize(horizontal: false, vertical: true) .frame(maxWidth: .infinity, alignment: .leading) @@ -70,3 +79,25 @@ struct SettingToggleView: View { .accessibilityElement(children: .combine) } } + +public extension SettingToggle { + func icon(_ icon: String, color: Color = .blue) -> SettingToggle { + var toggle = self + toggle.icon = .system(icon: icon, backgroundColor: color) + return toggle + } + + func icon(_ icon: String, foregroundColor: Color = .white, backgroundColor: Color = .blue) -> SettingToggle { + var toggle = self + toggle.icon = .system(icon: icon, foregroundColor: foregroundColor, backgroundColor: backgroundColor) + return toggle + } + + func icon(icon: SettingIcon) -> SettingToggle { + var toggle = self + toggle.icon = icon + return toggle + } + + +}