Skip to content

Commit ca669b4

Browse files
authored
Merge pull request #802 from JPToroDev/label
Minor polishes to `NavigationBar`.
2 parents 676b1e8 + 49bcdb9 commit ca669b4

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Sources/Ignite/Elements/NavigationBar.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public struct NavigationBar: HTML {
5959

6060
/// The main logo for your site, such as an image or some text. This becomes
6161
/// clickable to let users navigate to your homepage.
62-
let logo: (any InlineElement)?
62+
let logo: any InlineElement
6363

6464
/// An array of items to show in this navigation bar.
6565
let items: [any NavigationItem]
@@ -76,7 +76,7 @@ public struct NavigationBar: HTML {
7676
public init(
7777
logo: (any InlineElement)? = nil
7878
) {
79-
self.logo = logo
79+
self.logo = logo ?? EmptyHTML()
8080
self.items = []
8181
}
8282

@@ -90,7 +90,7 @@ public struct NavigationBar: HTML {
9090
logo: (any InlineElement)? = nil,
9191
@ElementBuilder<NavigationItem> items: () -> [any NavigationItem]
9292
) {
93-
self.logo = logo
93+
self.logo = logo ?? EmptyHTML()
9494
self.items = items()
9595
}
9696

@@ -102,10 +102,10 @@ public struct NavigationBar: HTML {
102102
/// - logo: The logo to use in the top-left edge of your bar.
103103
public init(
104104
@ElementBuilder<NavigationItem> items: () -> [any NavigationItem],
105-
logo: (() -> (any InlineElement))? = nil
105+
@InlineElementBuilder logo: () -> any InlineElement = { EmptyHTML() }
106106
) {
107107
self.items = items()
108-
self.logo = logo?()
108+
self.logo = logo()
109109
}
110110

111111
/// Adjusts the style of this navigation bar.
@@ -156,10 +156,10 @@ public struct NavigationBar: HTML {
156156
Tag("header") {
157157
Tag("nav") {
158158
Section {
159-
if let logo {
159+
if logo.isEmpty == false {
160160
renderLogo(logo)
161161
}
162-
if !items.isEmpty {
162+
if items.isEmpty == false {
163163
renderToggleButton()
164164
renderNavItems()
165165
}
@@ -235,8 +235,15 @@ public struct NavigationBar: HTML {
235235
}
236236

237237
private func renderLogo(_ logo: any InlineElement) -> some InlineElement {
238-
Link(logo, target: "/")
238+
let logo: Link = if let link = logo.as(Link.self) {
239+
link
240+
} else {
241+
Link(logo, target: "/")
242+
}
243+
244+
return logo
239245
.trimmingMargin()
246+
.class("d-inline-flex align-items-center")
240247
.class("navbar-brand")
241248
}
242249
}

0 commit comments

Comments
 (0)