Skip to content
This repository was archived by the owner on Sep 26, 2022. It is now read-only.

Commit 33c8798

Browse files
authored
Clean up and comment (#11)
* Add comments * Update the package description * Refactor code * Export the import of htmlkit * Fix issues * Update readme
1 parent dfa494e commit 33c8798

35 files changed

+1309
-480
lines changed

Dependencies/src/css/components/collection.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,12 @@
1212
}
1313

1414
.collection.style\:grid > .collection-item {
15-
1615
border-width: var(--collectionBorderWidth);
1716
border-style: solid;
1817
border-color: var(--collectionBorderColor);
1918
border-radius: var(--collectionBorderRadius);
2019
}
2120

22-
.collection.style\:carousel {
23-
24-
}
25-
2621
.collection.ratio\:50 {
2722
grid-template-columns: repeat(2, 1fr);
2823
}

Dependencies/src/css/components/form.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
}
1010

1111
.label {
12-
1312
display: inline-block;
1413
margin-top: 20px;
1514
margin-bottom: 10px;

Dependencies/src/css/components/link.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
.link {
6-
76
font-family: var(--textFontFamily);
87
font-size: var(--textFontSize);
98
font-weight: var(--textFontHeight);

Dependencies/src/css/components/text.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
font-weight: 400;
4141
}
4242

43-
.text.weight\:semibold {
43+
.text.weight\:medium {
4444
font-weight: 500;
4545
}
4646

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:5.4
22

33
import PackageDescription
44

55
let package = Package(
66
name: "HTMLKitComponents",
77
platforms: [
8-
.macOS(.v10_15)
8+
.macOS(.v10_14)
99
],
1010
products: [
1111
.library(
1212
name: "HTMLKitComponents",
1313
targets: ["HTMLKitComponents"]),
1414
],
1515
dependencies: [
16-
.package(url: "https://github.com/vapor-community/HTMLKit", .branch("main")),
16+
.package(url: "https://github.com/vapor-community/HTMLKit", from: "2.5.0")
1717
],
1818
targets: [
1919
.target(

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@ Add the packages to your dependecies and targets in your package file.
1515
dependencies: [
1616
...
1717
///1. Add the packages
18-
.package(name: "HTMLKit", url: "https://github.com/vapor-community/HTMLKit.git", from: "2.4.4"),
19-
.package(name: "HTMLKitComponents", url: "https://github.com/vapor-community/HTMLKit-Components.git", from: "0.1.0")
18+
.package(url: "https://github.com/vapor-community/HTMLKit-Components.git", from: "0.1.0")
2019
],
2120
targets: [
2221
.target(
2322
...
2423
dependencies: [
2524
...
2625
/// 2. Add the products
27-
.product(name: "HTMLKit", package: "HTMLKit"),
28-
.product(name: "HTMLKitComponents", package: "HTMLKitComponents")
26+
.product(name: "HTMLKitComponents", package: "HTMLKit-Components")
2927
]
3028
),
3129
...

Sources/HTMLKitComponents/Core/Actions.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
Abstract:
3+
The file contains the actions for the components.
4+
*/
5+
16
public enum Actions {
27

38
case show(_ target: String)
@@ -8,15 +13,12 @@ public enum Actions {
813

914
switch self {
1015
case .show(let target):
11-
1216
return show(target)
1317

1418
case .hide(let target):
15-
1619
return hide(target)
1720

1821
case .animate(let target):
19-
2022
return animate(target)
2123
}
2224
}
Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1+
/*
2+
Abstract:
3+
The file contains everything related to buttons.
4+
*/
5+
16
import HTMLKit
27
import Foundation
38

49
public struct ActionButton: Component {
510

11+
/// The url path of the target.
612
internal let destination: TemplateValue<String>
713

14+
/// The content of the button.
815
internal var content: [AnyContent]
916

17+
/// The classes of the button.
1018
internal var classes: [String]
1119

20+
/// The events of the button.
1221
internal var events: [String]?
1322

23+
/// Creates a action button.
1424
public init(destination: TemplateValue<String>, @ContentBuilder<AnyContent> content: () -> [AnyContent]) {
1525

1626
self.destination = destination
1727
self.content = content()
1828
self.classes = ["button"]
1929
}
2030

31+
/// Creates a action button.
2132
internal init(destination: TemplateValue<String>, content: [AnyContent], classes: [String], events: [String]?) {
2233

2334
self.destination = destination
@@ -28,60 +39,68 @@ public struct ActionButton: Component {
2839

2940
public var body: AnyContent {
3041
Anchor {
31-
content
42+
self.content
3243
}
33-
.reference(destination.rawValue)
34-
.class(classes.joined(separator: " "))
44+
.reference(self.destination.rawValue)
45+
.class(self.classes.joined(separator: " "))
3546
.role(.button)
3647
}
3748

49+
/// The behaviour of the button.
3850
public var scripts: AnyContent {
3951

4052
if let events = self.events {
41-
return [content.scripts, Script { events }]
53+
return [self.content.scripts, Script { events }]
4254
}
4355

44-
return [content.scripts]
56+
return [self.content.scripts]
4557
}
4658
}
4759

48-
extension ActionButton: ButtonComponent {
60+
extension ActionButton: ButtonModifier {
4961

50-
public func buttonSize(_ size: ButtonSize) -> ActionButton {
62+
public func buttonSize(_ size: Tokens.ButtonSize) -> ActionButton {
5163

5264
var newSelf = self
5365
newSelf.classes.append(size.rawValue)
66+
5467
return newSelf
5568
}
5669

57-
public func borderShape(_ shape: BorderShape) -> ActionButton {
70+
public func borderShape(_ shape: Tokens.BorderShape) -> ActionButton {
5871

5972
var newSelf = self
6073
newSelf.classes.append(shape.rawValue)
74+
6175
return newSelf
6276
}
6377

64-
public func buttonStyle(_ style: ButtonStyle) -> ActionButton {
78+
public func buttonStyle(_ style: Tokens.ButtonStyle) -> ActionButton {
6579

6680
var newSelf = self
6781
newSelf.classes.append(style.rawValue)
82+
6883
return newSelf
6984
}
7085

71-
public func backgroundColor(_ color: BackgroundColor) -> ActionButton {
86+
public func backgroundColor(_ color: Tokens.BackgroundColor) -> ActionButton {
7287

7388
var newSelf = self
7489
newSelf.classes.append(color.rawValue)
90+
7591
return newSelf
7692
}
7793
}
7894

7995
public struct SubmitButton: Component {
8096

97+
/// The content of the button.
8198
internal var content: [AnyContent]
8299

100+
/// The classes of the button.
83101
internal var classes: [String]
84102

103+
/// Creates a submit button.
85104
public init(@ContentBuilder<AnyContent> content: () -> [AnyContent]) {
86105

87106
self.content = content()
@@ -90,92 +109,110 @@ public struct SubmitButton: Component {
90109

91110
public var body: AnyContent {
92111
Button {
93-
content
112+
self.content
94113
}
95114
.type(.submit)
96-
.class(classes.joined(separator: " "))
115+
.class(self.classes.joined(separator: " "))
97116
}
98117
}
99118

100-
extension SubmitButton: ButtonComponent {
119+
extension SubmitButton: ButtonModifier {
101120

102-
public func buttonSize(_ size: ButtonSize) -> SubmitButton {
121+
public func buttonSize(_ size: Tokens.ButtonSize) -> SubmitButton {
103122

104123
var newSelf = self
105124
newSelf.classes.append(size.rawValue)
125+
106126
return newSelf
107127
}
108128

109-
public func borderShape(_ shape: BorderShape) -> SubmitButton {
129+
public func borderShape(_ shape: Tokens.BorderShape) -> SubmitButton {
110130

111131
var newSelf = self
112132
newSelf.classes.append(shape.rawValue)
133+
113134
return newSelf
114135
}
115136

116-
public func buttonStyle(_ style: ButtonStyle) -> SubmitButton {
137+
public func buttonStyle(_ style: Tokens.ButtonStyle) -> SubmitButton {
117138

118139
var newSelf = self
119140
newSelf.classes.append(style.rawValue)
141+
120142
return newSelf
121143
}
122144

123-
public func backgroundColor(_ color: BackgroundColor) -> SubmitButton {
145+
public func backgroundColor(_ color: Tokens.BackgroundColor) -> SubmitButton {
124146

125147
var newSelf = self
126148
newSelf.classes.append(color.rawValue)
149+
127150
return newSelf
128151
}
129152
}
130153

131154
public struct ResetButton: Component {
132155

156+
/// The content of the button.
133157
internal var content: [AnyContent]
134158

159+
/// The classes of the button.
135160
internal var classes: [String]
136161

162+
/// Creates a reset button.
137163
public init(@ContentBuilder<AnyContent> content: () -> [AnyContent]) {
138164

139165
self.content = content()
140166
self.classes = ["button"]
141167
}
142168

169+
/// Creates a sbumit button.
170+
internal init(content: [AnyContent], classes: [String]) {
171+
172+
self.content = content
173+
self.classes = classes
174+
}
175+
143176
public var body: AnyContent {
144177
Button {
145-
content
178+
self.content
146179
}
147180
.type(.reset)
148-
.class(classes.joined(separator: " "))
181+
.class(self.classes.joined(separator: " "))
149182
}
150183
}
151184

152-
extension ResetButton: ButtonComponent {
185+
extension ResetButton: ButtonModifier {
153186

154-
public func buttonSize(_ size: ButtonSize) -> ResetButton {
187+
public func buttonSize(_ size: Tokens.ButtonSize) -> ResetButton {
155188

156189
var newSelf = self
157190
newSelf.classes.append(size.rawValue)
191+
158192
return newSelf
159193
}
160194

161-
public func borderShape(_ shape: BorderShape) -> ResetButton {
195+
public func borderShape(_ shape: Tokens.BorderShape) -> ResetButton {
162196

163197
var newSelf = self
164198
newSelf.classes.append(shape.rawValue)
199+
165200
return newSelf
166201
}
167202

168-
public func buttonStyle(_ style: ButtonStyle) -> ResetButton {
203+
public func buttonStyle(_ style: Tokens.ButtonStyle) -> ResetButton {
169204

170205
var newSelf = self
171206
newSelf.classes.append(style.rawValue)
207+
172208
return newSelf
173209
}
174210

175-
public func backgroundColor(_ color: BackgroundColor) -> ResetButton {
211+
public func backgroundColor(_ color: Tokens.BackgroundColor) -> ResetButton {
176212

177213
var newSelf = self
178214
newSelf.classes.append(color.rawValue)
215+
179216
return newSelf
180217
}
181218
}

0 commit comments

Comments
 (0)