Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions Sources/Ignite/Elements/NavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public struct NavigationBar: HTML {

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

/// An array of items to show in this navigation bar.
let items: [any NavigationItem]
Expand All @@ -76,7 +76,7 @@ public struct NavigationBar: HTML {
public init(
logo: (any InlineElement)? = nil
) {
self.logo = logo
self.logo = logo ?? EmptyHTML()
self.items = []
}

Expand All @@ -90,7 +90,7 @@ public struct NavigationBar: HTML {
logo: (any InlineElement)? = nil,
@ElementBuilder<NavigationItem> items: () -> [any NavigationItem]
) {
self.logo = logo
self.logo = logo ?? EmptyHTML()
self.items = items()
}

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

/// Adjusts the style of this navigation bar.
Expand Down Expand Up @@ -156,10 +156,10 @@ public struct NavigationBar: HTML {
Tag("header") {
Tag("nav") {
Section {
if let logo {
if logo.isEmpty == false {
renderLogo(logo)
}
if !items.isEmpty {
if items.isEmpty == false {
renderToggleButton()
renderNavItems()
}
Expand Down Expand Up @@ -235,8 +235,15 @@ public struct NavigationBar: HTML {
}

private func renderLogo(_ logo: any InlineElement) -> some InlineElement {
Link(logo, target: "/")
let logo: Link = if let link = logo.as(Link.self) {
link
} else {
Link(logo, target: "/")
}

return logo
.trimmingMargin()
.class("d-inline-flex align-items-center")
.class("navbar-brand")
}
}
Expand Down
Loading