Skip to content

Commit 92b24c6

Browse files
committed
Various Changes
- Make `RadixSegmentedPicker` Respect `RadixAutoColor` - Added Divider between `RadixSegmentedPicker` Options - Mark `RadixAutoColor` as `Equatable` - Fix Foreground Color for B&W Buttons
1 parent fb7a3aa commit 92b24c6

File tree

6 files changed

+82
-71
lines changed

6 files changed

+82
-71
lines changed

Sources/RadixUI/DemoViews/PickerDemoView.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ struct PickerDemoView: View {
1212

1313
init() {
1414
RadixSegmentedPicker(
15-
backgroundColor: RadixAutoColor.tomato.component1,
16-
selectedColor: RadixAutoColor.tomato.solid2,
17-
foregroundColor: RadixAutoColor.tomato.background2,
18-
selectedFont: .systemFont(ofSize: 15),
19-
unselectedFont: .systemFont(ofSize: 15)
15+
color: .grass,
16+
selectedFont: .systemFont(ofSize: 15, weight: .semibold),
17+
notSelectedFont: .systemFont(ofSize: 15, weight: .light)
2018
)
2119
}
2220

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// Toggle+Extensions.swift
3+
// RadixUI
4+
//
5+
// Created by Amir Mohammadi on 11/20/1403 AP.
6+
//
7+
8+
import SwiftUI
9+
10+
extension ToggleStyle where Self == RadixToggleStyle {
11+
12+
public static func radixCheckbox(
13+
bgColor: RadixAutoColor? = nil,
14+
iconColor: RadixAutoColor? = nil,
15+
boxSize: CGFloat? = nil
16+
) -> Self {
17+
.init(
18+
variant: .checkbox,
19+
backgroundColor: bgColor,
20+
foregroundColor: iconColor,
21+
size: boxSize
22+
)
23+
}
24+
25+
public static func radixSwitch(
26+
onColor: RadixAutoColor? = nil,
27+
thumbColor: RadixAutoColor? = nil
28+
) -> Self {
29+
.init(
30+
variant: .switch,
31+
backgroundColor: onColor,
32+
foregroundColor: thumbColor,
33+
size: nil
34+
)
35+
}
36+
37+
public static func radixToggle(
38+
bgColor: RadixAutoColor? = nil,
39+
iconColor: RadixAutoColor? = nil,
40+
boxSize: CGFloat? = nil
41+
) -> Self {
42+
.init(
43+
variant: .toggle,
44+
backgroundColor: bgColor,
45+
foregroundColor: iconColor,
46+
size: boxSize
47+
)
48+
}
49+
50+
}

Sources/RadixUI/RadixColors/RadixAutoColor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99
import SwiftUI
1010

11-
public enum RadixAutoColor {
11+
public enum RadixAutoColor: Equatable {
1212

1313
case amber
1414
case blackA

Sources/RadixUI/RadixPrimitives/Toggle/RadixToggleStyle.swift

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -99,45 +99,3 @@ public struct RadixToggleStyle: ToggleStyle {
9999
}
100100
}
101101
}
102-
103-
extension ToggleStyle where Self == RadixToggleStyle {
104-
105-
public static func radixCheckbox(
106-
bgColor: RadixAutoColor? = nil,
107-
iconColor: RadixAutoColor? = nil,
108-
boxSize: CGFloat? = nil
109-
) -> Self {
110-
.init(
111-
variant: .checkbox,
112-
backgroundColor: bgColor,
113-
foregroundColor: iconColor,
114-
size: boxSize
115-
)
116-
}
117-
118-
public static func radixSwitch(
119-
onColor: RadixAutoColor? = nil,
120-
thumbColor: RadixAutoColor? = nil
121-
) -> Self {
122-
.init(
123-
variant: .switch,
124-
backgroundColor: onColor,
125-
foregroundColor: thumbColor,
126-
size: nil
127-
)
128-
}
129-
130-
public static func radixToggle(
131-
bgColor: RadixAutoColor? = nil,
132-
iconColor: RadixAutoColor? = nil,
133-
boxSize: CGFloat? = nil
134-
) -> Self {
135-
.init(
136-
variant: .toggle,
137-
backgroundColor: bgColor,
138-
foregroundColor: iconColor,
139-
size: boxSize
140-
)
141-
}
142-
143-
}

Sources/RadixUI/RadixThemes/Button/RadixButtonLabelStyle.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ public struct RadixButtonLabelStyle: LabelStyle {
4545
return 0.6
4646
}
4747

48+
private var fgColor: Color {
49+
guard color != .blackA else { return .whiteA11 }
50+
guard color != .whiteA else { return .blackA11 }
51+
guard variant != .solid else {
52+
return colorScheme == .light ? color.background2 : color.text2
53+
}
54+
return color.text1
55+
}
56+
4857
public func makeBody(configuration: Configuration) -> some View {
4958
HStack(spacing: 8) {
5059
switch layout {
@@ -60,11 +69,7 @@ public struct RadixButtonLabelStyle: LabelStyle {
6069
icon(configuration.icon)
6170
}
6271
}
63-
.foregroundStyle(
64-
variant == .solid
65-
? (colorScheme == .light ? color.background2 : color.text2)
66-
: color.text1
67-
)
72+
.foregroundStyle(fgColor)
6873
.padding(.horizontal, 12)
6974
.padding(.vertical, 8)
7075
.background(shape())

Sources/RadixUI/RadixThemes/Picker/RadixSegmentedPicker.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,44 @@ import SwiftUI
99

1010
#if canImport(UIKit)
1111
public struct RadixSegmentedPicker {
12-
let backgroundColor: Color
13-
let selectedColor: Color
14-
let foregroundColor: Color
12+
let color: RadixAutoColor
1513
let selectedFont: UIFont
16-
let unselectedFont: UIFont
14+
let notSelectedFont: UIFont
1715

1816
@discardableResult public init(
19-
backgroundColor: Color,
20-
selectedColor: Color,
21-
foregroundColor: Color,
17+
color: RadixAutoColor,
2218
selectedFont: UIFont,
23-
unselectedFont: UIFont
19+
notSelectedFont: UIFont
2420
) {
25-
self.backgroundColor = backgroundColor
26-
self.selectedColor = selectedColor
27-
self.foregroundColor = foregroundColor
21+
self.color = color
2822
self.selectedFont = selectedFont
29-
self.unselectedFont = unselectedFont
23+
self.notSelectedFont = notSelectedFont
24+
25+
var fgColor: Color {
26+
guard color != .blackA else { return .whiteA12 }
27+
guard color != .whiteA else { return .blackA12 }
28+
return color.background2
29+
}
3030

3131
let appeareance = UISegmentedControl.appearance()
3232

33-
appeareance.backgroundColor = UIColor(backgroundColor)
33+
appeareance.backgroundColor = UIColor(color.component1)
3434
appeareance.setDividerImage(
35-
UIImage(),
35+
UIImage(named: "divider-vertical", in: .module, compatibleWith: nil),
3636
forLeftSegmentState: .normal,
3737
rightSegmentState: .normal,
38-
barMetrics: .default
38+
barMetrics: .compact
3939
)
40-
appeareance.selectedSegmentTintColor = UIColor(selectedColor)
40+
appeareance.selectedSegmentTintColor = UIColor(color.solid2)
4141
appeareance.setTitleTextAttributes(
4242
[
43-
.foregroundColor: UIColor(foregroundColor),
43+
.foregroundColor: UIColor(fgColor),
4444
.font: selectedFont
4545
],
4646
for: .selected
4747
)
4848
appeareance.setTitleTextAttributes(
49-
[.font: unselectedFont],
49+
[.font: notSelectedFont],
5050
for: .normal
5151
)
5252

0 commit comments

Comments
 (0)