Skip to content

Commit

Permalink
Merge pull request #50 from markstamer/main
Browse files Browse the repository at this point in the history
Add NavigationBar width modifier
  • Loading branch information
twostraws authored May 22, 2024
2 parents 8024374 + 2d35318 commit 6089a95
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Sources/Ignite/Elements/NavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ public struct NavigationBar: BlockElement {
return copy
}

/// Adjusts the number of columns assigned to the items in the navigation bar. It does not have an effect on the navigation bar itself.
/// - Parameter width: The new number of columns to use.
/// - Returns: A new `NavigationBar` instance with the adjusted column width.
public func width(_ width: Int) -> Self {
var copy = self
copy.columnWidth = .count(width)
return copy
}

/// Adjusts the item alignment for this navigation bar.
/// - Parameter alignment: The new alignment.
/// - Returns: A new `NavigationBar` instance with the updated item alignment.
Expand Down Expand Up @@ -153,7 +162,7 @@ public struct NavigationBar: BlockElement {
.class("collapse", "navbar-collapse")
.id("navbarCollapse")
}
.class("container-fluid")
.class("container-fluid", columnWidth.className)
}
.attributes(attributes)
.class("navbar", "navbar-expand-md")
Expand Down
27 changes: 27 additions & 0 deletions Tests/IgniteTests/Elements/NavigationBar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// NavigationBar.swift
// Ignite
// https://www.github.com/twostraws/Ignite
// See LICENSE for license information.
//

import XCTest
@testable import Ignite

/// Tests for the `NavigationBar` element.
final class NavigationBarTests: ElementTest {

func test_defaultColumnWidth() {
let element = NavigationBar()
let output = element.render(context: publishingContext)

XCTAssertTrue(output.contains("container-fluid col"))
}

func test_columnWidthValueSet() {
let element = NavigationBar().width(10)
let output = element.render(context: publishingContext)

XCTAssertTrue(output.contains("container-fluid col-md-10"))
}
}

0 comments on commit 6089a95

Please sign in to comment.