Skip to content

Commit b3f020e

Browse files
committed
Tidy up a bit
1 parent 88b10a4 commit b3f020e

File tree

5 files changed

+33
-17
lines changed

5 files changed

+33
-17
lines changed

Sources/HTMLKit/Abstraction/Attributes/BasicAttributes.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,6 +3205,7 @@ public protocol ShapeAttribute: Attribute {
32053205
/// ```
32063206
///
32073207
/// - Parameter value: The shape used to interpret the coordinates.
3208+
/// - Parameter coordinates: The coordinates on which to base the shape.
32083209
///
32093210
/// - Returns: The element
32103211
func shape(_ value: Values.Shape, coordinates: String) -> Self
@@ -4338,14 +4339,14 @@ public protocol PopoverTargetAttribute: Attribute {
43384339
/// Button {
43394340
/// "Lorem ipsum"
43404341
/// }
4341-
/// .popoverTarget("id", as: .hide)
4342+
/// .popoverTarget("id", action: .hide)
43424343
/// ```
43434344
///
43444345
/// - Parameter id: The identifier of the target to bind the popover to.
43454346
/// - Parameter action: The action to perform when triggered.
43464347
///
43474348
/// - Returns: The element
4348-
func popoverTarget(_ id: String, as action: Values.Popover.Action) -> Self
4349+
func popoverTarget(_ id: String, action: Values.Popover.Action?) -> Self
43494350
}
43504351

43514352
extension PopoverTargetAttribute where Self: ContentNode {
@@ -4354,8 +4355,13 @@ extension PopoverTargetAttribute where Self: ContentNode {
43544355
return self.mutate(key: "popovertarget", value: value)
43554356
}
43564357

4357-
internal func mutate(popovertargetaction value: String) -> Self {
4358-
return self.mutate(key: "popovertargetaction", value: value)
4358+
internal func mutate(popovertargetaction value: String?) -> Self {
4359+
4360+
if let value = value {
4361+
return self.mutate(key: "popovertargetaction", value: value)
4362+
}
4363+
4364+
return self
43594365
}
43604366
}
43614367

@@ -4365,8 +4371,13 @@ extension PopoverTargetAttribute where Self: EmptyNode {
43654371
return self.mutate(key: "popovertarget", value: value)
43664372
}
43674373

4368-
internal func mutate(popovertargetaction value: String) -> Self {
4369-
return self.mutate(key: "popovertargetaction", value: value)
4374+
internal func mutate(popovertargetaction value: String?) -> Self {
4375+
4376+
if let value = value {
4377+
return self.mutate(key: "popovertargetaction", value: value)
4378+
}
4379+
4380+
return self
43704381
}
43714382
}
43724383

Sources/HTMLKit/Abstraction/Elements/FormElements.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,11 @@ extension Input: GlobalAttributes, GlobalEventAttributes, AcceptAttribute, Alter
403403
return mutate(popover: value.rawValue)
404404
}
405405

406-
public func popoverTarget(_ value: String, as action: Values.Popover.Action = .toggle) -> Input {
407-
return mutate(popovertarget: value).mutate(popovertargetaction: action.rawValue)
406+
public func popoverTarget(_ value: String, action: Values.Popover.Action? = nil) -> Input {
407+
return mutate(popovertarget: value).mutate(popovertargetaction: action?.rawValue)
408408
}
409409

410-
@available(*, deprecated, message: "Use the popoverTarget(_:as:) modifier instead.")
410+
@available(*, deprecated, message: "Use the popoverTarget(_:action:) modifier instead.")
411411
public func popoverAction(_ value: Values.Popover.Action) -> Input {
412412
return mutate(popoveraction: value.rawValue)
413413
}
@@ -1767,11 +1767,11 @@ extension Button: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes,
17671767
return mutate(popover: value.rawValue)
17681768
}
17691769

1770-
public func popoverTarget(_ value: String, as action: Values.Popover.Action = .toggle) -> Button {
1771-
return mutate(popovertarget: value).mutate(popovertargetaction: action.rawValue)
1770+
public func popoverTarget(_ value: String, action: Values.Popover.Action? = nil) -> Button {
1771+
return mutate(popovertarget: value).mutate(popovertargetaction: action?.rawValue)
17721772
}
17731773

1774-
@available(*, deprecated, message: "Use the popoverTarget(_:as:) modifier instead.")
1774+
@available(*, deprecated, message: "Use the popoverTarget(_:action:) modifier instead.")
17751775
public func popoverAction(_ value: Values.Popover.Action) -> Button {
17761776
return mutate(popoveraction: value.rawValue)
17771777
}

Sources/HTMLKit/Abstraction/Elements/MapElements.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ extension Area: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, A
242242
return mutate(coords: value)
243243
}
244244

245+
@available(*, deprecated, message: "Use the shape(_:coordinates:) modifier instead.")
246+
public func shape(_ value: Values.Shape) -> Area {
247+
return mutate(shape: value.rawValue)
248+
}
249+
245250
public func shape() -> Area {
246251
return mutate(shape: "default")
247252
}

Sources/HTMLKit/Abstraction/Tokens/ValueTokens.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,7 @@ public enum Values {
19431943
/// Button {
19441944
/// "Lorem ipsum"
19451945
/// }
1946-
/// .popoverTarget("id", as: .hide)
1946+
/// .popoverTarget("id", action: .hide)
19471947
/// ```
19481948
public enum Action: String {
19491949

Tests/HTMLKitTests/AttributesTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,8 @@ final class AttributesTests: XCTestCase {
750750
return self.mutate(popover: value.rawValue)
751751
}
752752

753-
func popoverTarget(_ id: String, as action: Values.Popover.Action = .toggle) -> Tag {
754-
return self.mutate(popovertarget: id).mutate(popovertargetaction: action.rawValue)
753+
func popoverTarget(_ id: String, action: Values.Popover.Action? = nil) -> Tag {
754+
return self.mutate(popovertarget: id).mutate(popovertargetaction: action?.rawValue)
755755
}
756756

757757
func popoverAction(_ value: Values.Popover.Action) -> Tag {
@@ -2420,12 +2420,12 @@ final class AttributesTests: XCTestCase {
24202420

24212421
let view = TestView {
24222422
Tag {}.popoverTarget("id")
2423-
Tag {}.popoverTarget("id", as: .hide)
2423+
Tag {}.popoverTarget("id", action: .hide)
24242424
}
24252425

24262426
XCTAssertEqual(try renderer.render(view: view),
24272427
"""
2428-
<tag popovertarget="id" popovertargetaction="toggle"></tag>\
2428+
<tag popovertarget="id"></tag>\
24292429
<tag popovertarget="id" popovertargetaction="hide"></tag>
24302430
"""
24312431
)

0 commit comments

Comments
 (0)