66import HTMLKit
77import Foundation
88
9- /// A component that initiates an action.
9+ /// A view that represents a button.
10+ ///
11+ /// Use `Button` to trigger an action when tapped or clicked.
12+ ///
13+ /// ```swift
14+ /// Button(role: .button) {
15+ /// "Lorem ipsum"
16+ /// }
17+ /// ```
1018public struct Button : View , Modifiable , Actionable {
1119
20+ /// The identifier of the button.
1221 internal var id : String ?
1322
14- /// The role of the button
23+ /// The role of the button.
1524 internal var role : HTMLKit . Values . Button
1625
1726 /// The content of the button.
@@ -20,16 +29,33 @@ public struct Button: View, Modifiable, Actionable {
2029 /// The classes of the button.
2130 internal var classes : [ String ]
2231
32+ /// The events of the button.
2333 internal var events : [ String ] ?
2434
25- /// Creates a action button.
35+ /// Create a button.
36+ ///
37+ /// - Parameters:
38+ /// - role: The role of the button.
39+ /// - content: The button's content.
2640 public init ( role: HTMLKit . Values . Button , @ContentBuilder < Content > content: ( ) -> [ Content ] ) {
2741
2842 self . role = role
2943 self . content = content ( )
3044 self . classes = [ " button " ]
3145 }
3246
47+ /// Create a button.
48+ ///
49+ /// - Parameters:
50+ /// - localizedStringKey: The key of the localized string used as a label.
51+ /// - role: The role of the button.
52+ public init ( _ localizedStringKey: LocalizedStringKey , role: HTMLKit . Values . Button ) {
53+
54+ self . role = role
55+ self . content = [ LocalizedString ( key: localizedStringKey) ]
56+ self . classes = [ " button " ]
57+ }
58+
3359 public var body : Content {
3460 HTMLKit . Button {
3561 self . content
@@ -146,11 +172,21 @@ extension Button: ViewModifier {
146172 }
147173}
148174
149- /// A component that initiates an action.
175+ /// A view that represents a link button.
176+ ///
177+ /// Use `LinkButton`to navigate to a target.
178+ ///
179+ /// ```swift
180+ /// LinkButton(destination: "https://..") {
181+ /// "Lorem ipsum"
182+ /// }
183+ /// ```
150184public struct LinkButton : View , Modifiable , Identifiable {
151185
186+ /// The unique identifier of the button.
152187 internal var id : String ?
153188
189+ /// The target behaviour for the destination
154190 internal let target : HTMLKit . Values . Target
155191
156192 /// The url path of the target.
@@ -165,7 +201,12 @@ public struct LinkButton: View, Modifiable, Identifiable {
165201 /// The events of the button.
166202 internal var events : [ String ] ?
167203
168- /// Creates a action button.
204+ /// Create a link button.
205+ ///
206+ /// - Parameters:
207+ /// - destination: The url of the target to navigate to.
208+ /// - target: The behaviour that determines how to open the target.
209+ /// - content: The content displayed as the label.
169210 public init ( destination: String , target: HTMLKit . Values . Target = . current, @ContentBuilder < Content > content: ( ) -> [ Content ] ) {
170211
171212 self . destination = destination
@@ -174,7 +215,26 @@ public struct LinkButton: View, Modifiable, Identifiable {
174215 self . classes = [ " button " ]
175216 }
176217
177- /// Creates a action button.
218+ /// Create a link button.
219+ ///
220+ /// - Parameters:
221+ /// - localizedStringKey: The key of the localized string used as the label.
222+ /// - destination: The url of the target to navigate to.
223+ /// - target: The behaviour that determines how to open the target.
224+ public init ( _ localizedStringKey: LocalizedStringKey , destination: String , target: HTMLKit . Values . Target = . current) {
225+
226+ self . destination = destination
227+ self . target = target
228+ self . content = [ LocalizedString ( key: localizedStringKey) ]
229+ self . classes = [ " button " ]
230+ }
231+
232+ /// Create a link button.
233+ ///
234+ /// - Parameters:
235+ /// - destination: The url of the target to navigate to.
236+ /// - target: The behaviour that determines how to open the target.
237+ /// - content: The content displayed as the label.
178238 public init ( destination: URL , target: HTMLKit . Values . Target = . current, @ContentBuilder < Content > content: ( ) -> [ Content ] ) {
179239
180240 self . destination = destination. absoluteString
@@ -183,6 +243,20 @@ public struct LinkButton: View, Modifiable, Identifiable {
183243 self . classes = [ " button " ]
184244 }
185245
246+ /// Create a link button.
247+ ///
248+ /// - Parameters:
249+ /// - localizedStringKey: The key of the localized string used as the label.
250+ /// - destination: The url of the target to navigate to.
251+ /// - target: The behaviour that determines how to open the target.
252+ public init ( _ localizedStringKey: LocalizedStringKey , destination: URL , target: HTMLKit . Values . Target = . current) {
253+
254+ self . destination = destination. absoluteString
255+ self . target = target
256+ self . content = [ LocalizedString ( key: localizedStringKey) ]
257+ self . classes = [ " button " ]
258+ }
259+
186260 public var body : Content {
187261 Anchor {
188262 self . content
0 commit comments