Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds SocialIcon to Framework, SocialFooter to Components #73

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
41 changes: 41 additions & 0 deletions Sources/Ignite/Components/SocialFooter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// SocialFooter.swift
// Ignite
// https://www.github.com/twostraws/Ignite
// See LICENSE for license information.
// Created by joshua kaunert on 6/14/24.
//

import Foundation

/// Displays "Social Footer", with each icon opening an external social site in a new browser tab.
public struct SocialFooter: Component {
/// the array of `Links` to use in the social footer, populated using an array of `SocialIcons` passed into initializer
var links: [Link] = []

/// Initializer constructs `Link`s from user provided array of `SocialIcon`s and appends each to `links` array
public init(_ icons: [SocialIcon]) {
for icon in icons {
links.append(
Link(icon.image, target: icon.targetURL)
.target(.blank)
.relationship(.noOpener, .noReferrer)
.margin(.trailing, 20)
.role(.secondary)
)
}
}

public func body(context: PublishingContext) -> [any PageElement] {

Text {
/// Iterates over `links` and adds each link to the `Text` element
for link in links {
link
}
}
.font(.title2)
.horizontalAlignment(.center)
.margin(.top, .extraLarge)
}
}
40 changes: 40 additions & 0 deletions Sources/Ignite/Framework/SocialIcon.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// SocialIcon.swift
// Ignite
// https://www.github.com/twostraws/Ignite
// See LICENSE for license information.
// Created by joshua kaunert on 6/14/24.
//

import Foundation

/// represents a single social icon
public struct SocialIcon {
/// name of built-in icon (Built-in icons must be enabled)
/// see https://icons.getbootstrap.com/?q=social for complete list
let iconName: String
/// the url target
let targetURL: String
/// location of image file if not using built-in
let customImageURL: String?

/// computed property, returns either built-in image, or custom image if passed a `customImageURL`
var image: Image {
if let imageURL = customImageURL {
Image(decorative: imageURL)
.frame(width: 32)
.resizable()
.opacity(0.74)
.foregroundStyle(.secondary)
} else {
Image(systemName: iconName)
.opacity(0.74)
}
}

public init(name: String, targetURL: String, customImageURL: String? = nil) {
self.iconName = name
self.targetURL = targetURL
self.customImageURL = customImageURL
}
}