@@ -28,50 +28,78 @@ public struct Grid: HTML, HorizontalAligning {
2828 /// The amount of space between elements.
2929 private var spacingAmount : SpacingType = . semantic( . none)
3030
31+ /// The alignment of the items within the grid.
32+ private var alignment : Alignment = . center
33+
3134 /// The items to display in this grid.
3235 private var items : HTMLCollection
3336
3437 /// Creates a new `Grid` object using a block element builder
3538 /// that returns an array of items to use in this grid.
3639 /// - Parameters:
40+ /// - alignment: The alignment of items in the grid. Defaults to `.center`.
3741 /// - spacing: The number of pixels between each element.
3842 /// - items: The items to use in this grid.
39- public init ( spacing: Int , @HTMLBuilder items: ( ) -> some HTML ) {
43+ public init (
44+ alignment: Alignment = . center,
45+ spacing: Int ,
46+ @HTMLBuilder items: ( ) -> some HTML
47+ ) {
4048 self . items = HTMLCollection ( items)
49+ self . alignment = alignment
4150 self . spacingAmount = . exact( spacing)
4251 }
4352
4453 /// Creates a new `Grid` object using a block element builder
4554 /// that returns an array of items to use in this grid.
4655 /// - Parameters:
56+ /// - alignment: The alignment of items in the grid. Defaults to `.center`.
4757 /// - spacing: The predefined size between each element. Defaults to `.none`.
4858 /// - items: The items to use in this grid.
49- public init ( spacing: SpacingAmount = . medium, @HTMLBuilder items: ( ) -> some HTML ) {
59+ public init (
60+ alignment: Alignment = . center,
61+ spacing: SpacingAmount = . medium,
62+ @HTMLBuilder items: ( ) -> some HTML
63+ ) {
5064 self . items = HTMLCollection ( items)
65+ self . alignment = alignment
5166 self . spacingAmount = . semantic( spacing)
5267 }
5368
5469 /// Creates a new grid from a collection of items, along with a function that converts
5570 /// a single object from the collection into one grid column.
5671 /// - Parameters:
5772 /// - items: A sequence of items you want to convert into columns.
73+ /// - alignment: The alignment of items in the grid. Defaults to `.center`.
5874 /// - spacing: The number of pixels between each element.
5975 /// - content: A function that accepts a single value from the sequence, and
6076 /// returns a some HTML representing that value in the grid.
61- public init < T> ( _ items: any Sequence < T > , spacing: Int , content: ( T ) -> some HTML ) {
77+ public init < T> (
78+ _ items: any Sequence < T > ,
79+ alignment: Alignment = . center,
80+ spacing: Int , content: ( T ) -> some HTML
81+ ) {
6282 self . items = HTMLCollection ( items. map ( content) )
83+ self . alignment = alignment
6384 self . spacingAmount = . exact( spacing)
6485 }
6586
6687 /// Creates a new grid from a collection of items, along with a function that converts
6788 /// a single object from the collection into one grid column.
6889 /// - Parameters:
6990 /// - items: A sequence of items you want to convert into columns.
91+ /// - alignment: The alignment of items in the grid. Defaults to `.center`.
7092 /// - spacing: The predefined size between each element. Defaults to `.none`
7193 /// - content: A function that accepts a single value from the sequence, and
7294 /// returns a some HTML representing that value in the grid.
73- public init < T> ( _ items: any Sequence < T > , spacing: SpacingAmount = . medium, content: ( T ) -> some HTML ) {
95+ public init < T> (
96+ _ items: any Sequence < T > ,
97+ alignment: Alignment = . center,
98+ spacing: SpacingAmount = . medium,
99+ content: ( T ) -> some HTML
100+ ) {
74101 self . items = HTMLCollection ( items. map ( content) )
102+ self . alignment = alignment
75103 self . spacingAmount = . semantic( spacing)
76104 }
77105
@@ -88,6 +116,7 @@ public struct Grid: HTML, HorizontalAligning {
88116 /// - Returns: The HTML for this element.
89117 public func render( ) -> String {
90118 var gridAttributes = attributes. appending ( classes: [ " row " ] )
119+ gridAttributes. append ( classes: alignment. horizontal. containerAlignmentClass)
91120
92121 // If a column count is set, we want to use that for all
93122 // page sizes that are medium and above. Below that we
@@ -138,6 +167,7 @@ public struct Grid: HTML, HorizontalAligning {
138167
139168 return Section ( item)
140169 . class ( name ?? " col " )
170+ . class ( alignment. vertical. itemAlignmentClass)
141171 }
142172
143173 /// Renders a group of HTML elements with consistent styling and attributes.
0 commit comments