|
1 | 1 | /// Possible values for HX-Reswap header
|
2 | 2 | ///
|
3 | 3 | /// [https://htmx.org/attributes/hx-swap/](https://htmx.org/attributes/hx-swap/)
|
4 |
| -public enum HxSwap: RawRepresentable, Equatable, CustomStringConvertible { |
5 |
| - public typealias RawValue = String |
| 4 | +public struct HxSwap: Equatable, CustomStringConvertible, ExpressibleByStringLiteral { |
| 5 | + public let description: String |
6 | 6 |
|
| 7 | + public init(_ description: String) { |
| 8 | + self.description = description |
| 9 | + } |
| 10 | + |
| 11 | + public init(stringLiteral value: StringLiteralType) { |
| 12 | + self.description = value |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +extension HxSwap { |
7 | 17 | /// Replace the inner html of the target element
|
8 |
| - case innerHTML |
| 18 | + public static let innerHTML = HxSwap("innerHTML") |
9 | 19 |
|
10 | 20 | /// Replace the entire target element with the response
|
11 |
| - case outerHTML |
| 21 | + public static let outerHTML = HxSwap("outerHTML") |
12 | 22 |
|
13 | 23 | /// Insert the response before the target element
|
14 |
| - case beforebegin |
| 24 | + public static let beforebegin = HxSwap("beforebegin") |
15 | 25 |
|
16 | 26 | /// Insert the response before the first child of the target element
|
17 |
| - case afterbegin |
| 27 | + public static let afterbegin = HxSwap("afterbegin") |
18 | 28 |
|
19 | 29 | /// Insert the response after the last child of the target element
|
20 |
| - case beforeend |
| 30 | + public static let beforeend = HxSwap("beforeend") |
21 | 31 |
|
22 | 32 | /// Insert the response after the target element
|
23 |
| - case afterend |
| 33 | + public static let afterend = HxSwap("afterend") |
24 | 34 |
|
25 | 35 | /// Deletes the target element regardless of the response
|
26 |
| - case delete |
| 36 | + public static let delete = HxSwap("delete") |
27 | 37 |
|
28 | 38 | /// Does not append content from response (out of band items will still be processed).
|
29 |
| - case none |
30 |
| - |
31 |
| - /// Fallback if you need a value other than the ones avaiable |
32 |
| - case raw(String) |
33 |
| - |
34 |
| - public var rawValue: String { |
35 |
| - switch self { |
36 |
| - case .innerHTML: return "innerHTML" |
37 |
| - case .outerHTML: return "outerHTML" |
38 |
| - case .beforebegin: return "beforebegin" |
39 |
| - case .afterbegin: return "afterbegin" |
40 |
| - case .beforeend: return "beforeend" |
41 |
| - case .afterend: return "afterend" |
42 |
| - case .delete: return "delete" |
43 |
| - case .none: return "none" |
44 |
| - case .raw(let string): return string |
45 |
| - } |
46 |
| - } |
47 |
| - |
48 |
| - public var description: String { rawValue } |
49 |
| - |
50 |
| - public init(rawValue: String) { |
51 |
| - switch rawValue { |
52 |
| - case "innerHTML": self = .innerHTML |
53 |
| - case "outerHTML": self = .outerHTML |
54 |
| - case "beforebegin": self = .beforebegin |
55 |
| - case "afterbegin": self = .afterbegin |
56 |
| - case "beforeend": self = .beforeend |
57 |
| - case "afterend": self = .afterend |
58 |
| - case "delete": self = .delete |
59 |
| - case "none": self = .none |
60 |
| - default: self = .raw(rawValue) |
61 |
| - } |
62 |
| - } |
| 39 | + public static let none = HxSwap("none") |
63 | 40 | }
|
0 commit comments