Skip to content

Commit 43b9c74

Browse files
committed
Some Code Cleanup
1 parent 64dcda0 commit 43b9c74

File tree

5 files changed

+103
-85
lines changed

5 files changed

+103
-85
lines changed

Sources/RadixUI/Helpers/ComponentViews/ResizableBundledImage.swift renamed to Sources/RadixUI/Helpers/Component/ResizableBundledImage.swift

File renamed without changes.

Sources/RadixUI/RadixPrimitives/Toggle/RadixToggleStyle.swift

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,6 @@ public struct RadixToggleStyle: ToggleStyle {
2828
self.size = size
2929
}
3030

31-
private var newBackgroundColor: RadixAutoColor {
32-
guard let backgroundColor else {
33-
return colorScheme == .light ? .blackA : .whiteA
34-
}
35-
return backgroundColor
36-
}
37-
38-
private var newForegroundColor: RadixAutoColor {
39-
guard let foregroundColor else {
40-
return colorScheme == .light ? .whiteA : .blackA
41-
}
42-
return foregroundColor
43-
}
44-
45-
private var newSize: CGFloat {
46-
guard let size else { return 27.5 }
47-
return size
48-
}
49-
5031
public func makeBody(configuration: Configuration) -> some View {
5132
switch variant {
5233
case .checkbox:
@@ -98,4 +79,28 @@ public struct RadixToggleStyle: ToggleStyle {
9879
}
9980
}
10081
}
82+
83+
}
84+
85+
extension RadixToggleStyle {
86+
87+
private var newBackgroundColor: RadixAutoColor {
88+
guard let backgroundColor else {
89+
return colorScheme == .light ? .blackA : .whiteA
90+
}
91+
return backgroundColor
92+
}
93+
94+
private var newForegroundColor: RadixAutoColor {
95+
guard let foregroundColor else {
96+
return colorScheme == .light ? .whiteA : .blackA
97+
}
98+
return foregroundColor
99+
}
100+
101+
private var newSize: CGFloat {
102+
guard let size else { return 27.5 }
103+
return size
104+
}
105+
101106
}

Sources/RadixUI/RadixThemes/Button/RadixButtonLabelStyle.swift

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,6 @@ public struct RadixButtonLabelStyle: LabelStyle {
3838
self.color = color
3939
}
4040

41-
private var opacityValue: Double {
42-
guard !isEnabled || isLoading.wrappedValue else {
43-
return 1.0
44-
}
45-
return 0.6
46-
}
47-
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-
5741
public func makeBody(configuration: Configuration) -> some View {
5842
HStack(spacing: 8) {
5943
switch layout {
@@ -102,41 +86,61 @@ public struct RadixButtonLabelStyle: LabelStyle {
10286
switch radius {
10387
case .none:
10488
Rectangle()
105-
.fill(buttonColor().first!)
89+
.fill(buttonColor.first!)
10690
.overlay {
10791
Rectangle()
10892
.stroke(
109-
buttonColor().last!,
93+
buttonColor.last!,
11094
lineWidth: 1
11195
)
11296
.background(.clear)
11397
}
11498
case .large:
11599
RoundedRectangle(cornerRadius: 8)
116-
.fill(buttonColor().first!)
100+
.fill(buttonColor.first!)
117101
.overlay {
118102
RoundedRectangle(cornerRadius: 8)
119103
.stroke(
120-
buttonColor().last!,
104+
buttonColor.last!,
121105
lineWidth: 1
122106
)
123107
.background(.clear)
124108
}
125109
case .full:
126110
Capsule()
127-
.fill(buttonColor().first!)
111+
.fill(buttonColor.first!)
128112
.overlay {
129113
Capsule()
130114
.stroke(
131-
buttonColor().last!,
115+
buttonColor.last!,
132116
lineWidth: 1
133117
)
134118
.background(.clear)
135119
}
136120
}
137121
}
138122

139-
private func buttonColor() -> [Color] {
123+
}
124+
125+
extension RadixButtonLabelStyle {
126+
127+
private var opacityValue: Double {
128+
guard !isEnabled || isLoading.wrappedValue else {
129+
return 1.0
130+
}
131+
return 0.6
132+
}
133+
134+
private var fgColor: Color {
135+
guard color != .blackA else { return .whiteA11 }
136+
guard color != .whiteA else { return .blackA11 }
137+
guard variant != .solid else {
138+
return colorScheme == .light ? color.background2 : color.text2
139+
}
140+
return color.text1
141+
}
142+
143+
private var buttonColor: [Color] {
140144
switch variant {
141145
// 1st Entry is Fill and 2nd is Stroke Colors
142146
case .ghost:

Sources/RadixUI/RadixThemes/Slider/RadixSliderStyle.swift

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,18 @@ public struct RadixSliderStyle: RxSliderStyle {
2626
self.color = color
2727
}
2828

29-
private var newColor: RadixAutoColor {
30-
guard let color else { return .blue }
31-
return color
32-
}
33-
34-
private var newSize: RadixSliderSize {
35-
guard let size else { return .medium }
36-
return size
37-
}
38-
3929
public func makeThumb(configuration: Configuration) -> some View {
4030
ZStack {
41-
thumbBorder(size: thumbSize())
31+
thumbBorder(size: thumbSize)
4232
if configuration.isActive {
4333
thumbActive(
4434
size: .init(
45-
width: thumbSize().width + 10,
46-
height: thumbSize().height + 10
35+
width: thumbSize.width + 10,
36+
height: thumbSize.height + 10
4737
)
4838
)
4939
}
50-
thumb(size: thumbSize())
40+
thumb(size: thumbSize)
5141
}
5242
}
5343

@@ -56,54 +46,69 @@ public struct RadixSliderStyle: RxSliderStyle {
5646
switch variant {
5747
case .soft:
5848
trackBase(
59-
size: trackSize(),
49+
size: trackSize,
6050
color: RadixAutoColor.gray.component3
6151
)
6252
trackFill(
6353
percentage: configuration.filledPercentage,
64-
size: trackSize(),
54+
size: trackSize,
6555
color: newColor.border2
6656
)
6757
case .surface:
6858
trackBase(
69-
size: trackSize(),
59+
size: trackSize,
7060
color: RadixAutoColor.gray.component2
7161
)
72-
trackBorder(size: trackSize())
62+
trackBorder(size: trackSize)
7363
trackFill(
7464
percentage: configuration.filledPercentage,
75-
size: trackSize(),
65+
size: trackSize,
7666
color: newColor.solid2
7767
)
7868
}
7969
}
8070
.opacity(configuration.isDisabled ? 0.6 : 1.0)
8171
}
8272

83-
private func trackSize() -> CGFloat {
73+
}
74+
75+
// MARK: - Computed Variables
76+
extension RadixSliderStyle {
77+
78+
private var newColor: RadixAutoColor {
79+
guard let color else { return .blue }
80+
return color
81+
}
82+
83+
private var newSize: RadixSliderSize {
84+
guard let size else { return .medium }
85+
return size
86+
}
87+
88+
private var trackSize: CGFloat {
8489
switch newSize {
8590
case .small: 6
8691
case .medium: 8
8792
case .large: 10
8893
}
8994
}
9095

91-
private func roundedRectangleRadius() -> CGFloat {
96+
private var roundedRectangleRadius: CGFloat {
9297
switch newSize {
9398
case .small: 1
9499
case .medium: 2
95100
case .large: 3
96101
}
97102
}
98-
private func thumbSize() -> CGSize {
103+
private var thumbSize: CGSize {
99104
switch newSize {
100105
case .small: .init(width: 12, height: 12)
101106
case .medium: .init(width: 16, height: 16)
102107
case .large: .init(width: 20, height: 20)
103108
}
104109
}
105-
}
106110

111+
}
107112
// MARK: - Thumb ViewBuilders
108113
extension RadixSliderStyle {
109114

@@ -114,7 +119,7 @@ extension RadixSliderStyle {
114119
Rectangle()
115120
.thumbShapeModifier(size: size)
116121
case .large:
117-
RoundedRectangle(cornerRadius: roundedRectangleRadius())
122+
RoundedRectangle(cornerRadius: roundedRectangleRadius)
118123
.thumbShapeModifier(size: size)
119124
case .full:
120125
Circle()
@@ -134,7 +139,7 @@ extension RadixSliderStyle {
134139
Rectangle()
135140
.thumbBorderShapeModifier(size: size)
136141
case .large:
137-
RoundedRectangle(cornerRadius: roundedRectangleRadius())
142+
RoundedRectangle(cornerRadius: roundedRectangleRadius)
138143
.thumbBorderShapeModifier(size: size)
139144
case .full:
140145
Circle()
@@ -154,7 +159,7 @@ extension RadixSliderStyle {
154159
Rectangle()
155160
.thumbActiveShapeModifier(size: size)
156161
case .large:
157-
RoundedRectangle(cornerRadius: roundedRectangleRadius())
162+
RoundedRectangle(cornerRadius: roundedRectangleRadius)
158163
.thumbActiveShapeModifier(size: size)
159164
case .full:
160165
Circle()
@@ -179,7 +184,7 @@ extension RadixSliderStyle {
179184
Rectangle()
180185
.trackShapeBaseModifier(size: size, color: color)
181186
case .large:
182-
RoundedRectangle(cornerRadius: roundedRectangleRadius())
187+
RoundedRectangle(cornerRadius: roundedRectangleRadius)
183188
.trackShapeBaseModifier(size: size, color: color)
184189
case .full:
185190
Capsule()
@@ -194,7 +199,7 @@ extension RadixSliderStyle {
194199
Rectangle()
195200
.trackShapeBorderModifier(size: size)
196201
case .large:
197-
RoundedRectangle(cornerRadius: roundedRectangleRadius())
202+
RoundedRectangle(cornerRadius: roundedRectangleRadius)
198203
.trackShapeBorderModifier(size: size)
199204
case .full:
200205
Capsule()
@@ -209,7 +214,7 @@ extension RadixSliderStyle {
209214
Rectangle()
210215
.trackShapeFillModifier(color, percentage, size)
211216
case .large:
212-
RoundedRectangle(cornerRadius: roundedRectangleRadius())
217+
RoundedRectangle(cornerRadius: roundedRectangleRadius)
213218
.trackShapeFillModifier(color, percentage, size)
214219
case .full:
215220
Capsule()

0 commit comments

Comments
 (0)