Skip to content

Commit 87beac0

Browse files
committed
pr fix
- BadgeFontPicker deleted - code style fix - paddings fix - deleted optional for font and backgroundColor
1 parent ae7b7ef commit 87beac0

File tree

4 files changed

+18
-51
lines changed

4 files changed

+18
-51
lines changed

Examples/DemosApp/DemosApp/ComponentsPreview/Helpers/PreviewPickers.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -123,26 +123,6 @@ struct ContainerRadiusPicker<Custom: View>: View {
123123

124124
// MARK: - FontPickers
125125

126-
struct BadgeFontPicker: View {
127-
let title: String
128-
@Binding var selection: UniversalFont?
129-
130-
init(title: String = "Font", selection: Binding<UniversalFont?>) {
131-
self.title = title
132-
self._selection = selection
133-
}
134-
135-
var body: some View {
136-
Picker(self.title, selection: self.$selection) {
137-
Text("Default").tag(Optional<UniversalFont>.none)
138-
Text("Small").tag(UniversalFont.smButton)
139-
Text("Medium").tag(UniversalFont.mdButton)
140-
Text("Large").tag(UniversalFont.lgButton)
141-
Text("Custom: system bold of size 16").tag(UniversalFont.system(size: 16, weight: .bold))
142-
}
143-
}
144-
}
145-
146126
struct BodyFontPicker: View {
147127
let title: String
148128
@Binding var selection: UniversalFont?

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/BadgePreview.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ struct BadgePreview: View {
1313
SUBadge(model: self.model)
1414
}
1515
Form {
16-
BadgeFontPicker(selection: self.$model.font)
16+
Picker("Font", selection: self.$model.font) {
17+
Text("Default").tag(Optional<UniversalFont>.none)
18+
Text("Small").tag(UniversalFont.smButton)
19+
Text("Medium").tag(UniversalFont.mdButton)
20+
Text("Large").tag(UniversalFont.lgButton)
21+
Text("Custom: system bold of size 16").tag(UniversalFont.system(size: 16, weight: .bold))
22+
}
1723
ComponentOptionalColorPicker(selection: self.$model.color)
1824
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
1925
Text("Custom: 20px").tag(ComponentRadius.custom(20))

Sources/ComponentsKit/Components/Badge/Models/BadgeVM.swift

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,21 @@ public struct BadgeVM: ComponentVM {
1010

1111
/// The visual style of the badge.
1212
///
13-
/// Can be either `.filled` or `.light`.
1413
/// Defaults to `.filled`.
1514
public var style: Style = .filled
1615

1716
/// The font used for the badge's text.
1817
///
1918
/// Defaults to `.smButton`.
20-
public var font: UniversalFont? = .smButton
19+
public var font: UniversalFont = .smButton
2120

2221
/// The corner radius of the badge.
2322
///
2423
/// Defaults to `.medium`.
2524
public var cornerRadius: ComponentRadius = .medium
2625

27-
/// Vertical padding for the badge.
28-
///
29-
/// Defaults to `8`.
30-
public var verticalPadding: CGFloat = 8
31-
32-
/// Horizontal padding for the badge.
33-
///
34-
/// Defaults to `10`.
35-
public var horizontalPadding: CGFloat = 10
26+
/// Paddings for the badge.
27+
public var paddings: Paddings = .init(horizontal: 10, vertical: 8)
3628

3729
/// Initializes a new instance of `BadgeVM` with default values.
3830
public init() {}
@@ -42,32 +34,22 @@ public struct BadgeVM: ComponentVM {
4234

4335
extension BadgeVM {
4436
/// Returns the background color of the badge based on its style.
45-
var backgroundColor: UniversalColor? {
37+
var backgroundColor: UniversalColor {
4638
switch self.style {
4739
case .filled:
48-
let color = self.color?.main ?? .content2
49-
return color.enabled(true) // Badges are always "enabled"
40+
return self.color?.main ?? .content2
5041
case .light:
51-
let color = self.color?.background ?? .content1
52-
return color.enabled(true)
42+
return self.color?.background ?? .content1
5343
}
5444
}
5545

5646
/// Returns the foreground color of the badge based on its style.
5747
var foregroundColor: UniversalColor {
5848
switch self.style {
5949
case .filled:
60-
return (self.color?.contrast ?? .foreground).enabled(true)
50+
return self.color?.contrast ?? .foreground
6151
case .light:
62-
return (self.color?.main ?? .foreground).enabled(true)
63-
}
64-
}
65-
66-
/// Returns the preferred font for the badge text.
67-
var preferredFont: UniversalFont {
68-
if let font {
69-
return font
52+
return self.color?.main ?? .foreground
7053
}
71-
return .smButton
7254
}
7355
}

Sources/ComponentsKit/Components/Badge/SUBadge.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ public struct SUBadge: View {
1919

2020
public var body: some View {
2121
Text(self.model.title)
22-
.font(self.model.preferredFont.font)
23-
.padding(.vertical, self.model.verticalPadding)
24-
.padding(.horizontal, self.model.horizontalPadding)
22+
.font(self.model.font.font)
23+
.padding(self.model.paddings.edgeInsets)
2524
.foregroundStyle(self.model.foregroundColor.color)
26-
.background(self.model.backgroundColor?.color ?? .clear)
25+
.background(self.model.backgroundColor.color)
2726
.clipShape(
2827
RoundedRectangle(cornerRadius: self.model.cornerRadius.value())
2928
)

0 commit comments

Comments
 (0)