Skip to content

Commit 68d60f9

Browse files
committed
fix: improve the way rounding is written
1 parent 6ffda3e commit 68d60f9

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

Sources/WebUI/Styles/Appearance/Border.swift

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ extension Element {
9292
public func border(
9393
width: Int? = nil,
9494
edges: Edge...,
95-
radius: (side: RadiusSide?, size: RadiusSize)? = nil,
9695
style: BorderStyle? = nil,
9796
color: Color? = nil,
9897
on modifiers: Modifier...
@@ -104,7 +103,8 @@ extension Element {
104103
if let width = width {
105104
if style == .divide {
106105
for edge in effectiveEdges {
107-
let edgePrefix = edge == .horizontal ? "x" : edge == .vertical ? "y" : ""
106+
let edgePrefix =
107+
edge == .horizontal ? "x" : edge == .vertical ? "y" : ""
108108
if !edgePrefix.isEmpty {
109109
baseClasses.append("divide-\(edgePrefix)-\(width)")
110110
}
@@ -114,7 +114,8 @@ extension Element {
114114
contentsOf: effectiveEdges.map { edge in
115115
let edgePrefix = edge.rawValue.isEmpty ? "" : "-\(edge.rawValue)"
116116
return "border\(edgePrefix)\(width != 0 ? "-\(width)" : "")"
117-
})
117+
}
118+
)
118119
}
119120
}
120121

@@ -124,14 +125,8 @@ extension Element {
124125
contentsOf: effectiveEdges.map { edge in
125126
let edgePrefix = edge.rawValue.isEmpty ? "" : "-\(edge.rawValue)"
126127
return "border\(edgePrefix)"
127-
})
128-
}
129-
130-
// Handle radius
131-
if let (side, size) = radius {
132-
let sidePrefix = side?.rawValue ?? ""
133-
let sideClass = sidePrefix.isEmpty ? "" : "-\(sidePrefix)"
134-
baseClasses.append("rounded\(sideClass)-\(size.rawValue)")
128+
}
129+
)
135130
}
136131

137132
// Handle style
@@ -140,7 +135,8 @@ extension Element {
140135
contentsOf: effectiveEdges.map { edge in
141136
let edgePrefix = edge.rawValue.isEmpty ? "" : "-\(edge.rawValue)"
142137
return "border\(edgePrefix)-\(styleValue.rawValue)"
143-
})
138+
}
139+
)
144140
}
145141

146142
// Handle color
@@ -162,6 +158,27 @@ extension Element {
162158
)
163159
}
164160

161+
public func rounded(
162+
_ size: RadiusSize,
163+
_ edge: RadiusSide = .all,
164+
on modifiers: Modifier...
165+
) -> Element {
166+
let sidePrefix = edge.rawValue.isEmpty ? "" : "-\(edge.rawValue)"
167+
let baseClasses = ["rounded\(sidePrefix)-\(size.rawValue)"]
168+
let newClasses = combineClasses(baseClasses, withModifiers: modifiers)
169+
170+
return Element(
171+
tag: self.tag,
172+
id: self.id,
173+
classes: (self.classes ?? []) + newClasses,
174+
role: self.role,
175+
label: self.label,
176+
isSelfClosing: self.isSelfClosing,
177+
customAttributes: self.customAttributes,
178+
content: self.contentBuilder
179+
)
180+
}
181+
165182
public func outline(
166183
width: Int? = nil,
167184
style: BorderStyle? = nil,

Tests/WebUITests/Styles/AppearanceTests.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,17 @@ import Testing
6767

6868
@Test("Border with radius")
6969
func testBorderWithRadius() async throws {
70-
let element = Element(tag: "div").border(radius: (.all, .md))
70+
let element = Element(tag: "div").rounded(.md)
7171
let rendered = element.render()
7272
#expect(rendered.contains("class=\"rounded-md\""))
7373
}
74+
75+
@Test("Border with radius on just one side")
76+
func testBorderWithOneSidedRadius() async throws {
77+
let element = Element(tag: "div").rounded(.full, .topLeft)
78+
let rendered = element.render()
79+
#expect(rendered.contains("class=\"rounded-tl-full\""))
80+
}
7481

7582
@Test("Border with specific edge and color")
7683
func testBorderWithEdgeAndColor() async throws {

0 commit comments

Comments
 (0)