1+ /*
2+ Abstract:
3+ The file contains everything related to buttons.
4+ */
5+
16import HTMLKit
27import Foundation
38
49public 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
7995public 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
131154public 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