Skip to content

Commit b68f23b

Browse files
add minimal button style
1 parent 4653a34 commit b68f23b

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/ButtonPreview.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct ButtonPreview: View {
5151
Text("Filled").tag(ButtonStyle.filled)
5252
Text("Plain").tag(ButtonStyle.plain)
5353
Text("Light").tag(ButtonStyle.light)
54+
Text("Minimal").tag(ButtonStyle.minimal)
5455
Text("Bordered with small border").tag(ButtonStyle.bordered(.small))
5556
Text("Bordered with medium border").tag(ButtonStyle.bordered(.medium))
5657
Text("Bordered with large border").tag(ButtonStyle.bordered(.large))

Sources/ComponentsKit/Components/Button/Models/ButtonVM.swift

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,30 +93,30 @@ extension ButtonVM {
9393
case .light:
9494
let color = self.color?.background ?? .content1
9595
return color.enabled(self.isInteractive)
96-
case .plain, .bordered:
96+
case .plain, .bordered, .minimal:
9797
return nil
9898
}
9999
}
100100
var foregroundColor: UniversalColor {
101101
let color = switch self.style {
102102
case .filled:
103103
self.color?.contrast ?? .foreground
104-
case .plain, .light, .bordered:
104+
case .plain, .light, .bordered, .minimal:
105105
self.color?.main ?? .foreground
106106
}
107107
return color.enabled(self.isInteractive)
108108
}
109109
var borderWidth: CGFloat {
110110
switch self.style {
111-
case .filled, .plain, .light:
111+
case .filled, .plain, .light, .minimal:
112112
return 0.0
113113
case .bordered(let borderWidth):
114114
return borderWidth.value
115115
}
116116
}
117117
var borderColor: UniversalColor? {
118118
switch self.style {
119-
case .filled, .plain, .light:
119+
case .filled, .plain, .light, .minimal:
120120
return nil
121121
case .bordered:
122122
if let color {
@@ -140,11 +140,16 @@ extension ButtonVM {
140140
return .lgButton
141141
}
142142
}
143-
var height: CGFloat {
144-
return switch self.size {
145-
case .small: 36
146-
case .medium: 44
147-
case .large: 52
143+
var height: CGFloat? {
144+
switch self.style {
145+
case .minimal:
146+
return nil
147+
case .light, .filled, .bordered, .plain:
148+
return switch self.size {
149+
case .small: 36
150+
case .medium: 44
151+
case .large: 52
152+
}
148153
}
149154
}
150155
var imageSide: CGFloat {
@@ -155,10 +160,15 @@ extension ButtonVM {
155160
}
156161
}
157162
var horizontalPadding: CGFloat {
158-
return switch self.size {
159-
case .small: 16
160-
case .medium: 20
161-
case .large: 24
163+
switch self.style {
164+
case .minimal:
165+
return 0
166+
case .light, .filled, .bordered, .plain:
167+
return switch self.size {
168+
case .small: 16
169+
case .medium: 20
170+
case .large: 24
171+
}
162172
}
163173
}
164174
}
@@ -196,7 +206,7 @@ extension ButtonVM {
196206
width = contentSize.width + 2 * self.horizontalPadding
197207
}
198208

199-
return .init(width: width, height: self.height)
209+
return .init(width: width, height: self.height ?? contentSize.height)
200210
}
201211
func shouldUpdateImagePosition(_ oldModel: Self?) -> Bool {
202212
guard let oldModel else { return true }

Sources/ComponentsKit/Shared/Types/ButtonStyle.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ public enum ButtonStyle: Hashable {
1010
case light
1111
/// A button with a transparent background and a border.
1212
case bordered(BorderWidth)
13+
/// A button with no background or padding, sized strictly to fit its content.
14+
case minimal
1315
}

0 commit comments

Comments
 (0)