106 lines
3.3 KiB
Swift
106 lines
3.3 KiB
Swift
//
|
|
// LicensesView.swift
|
|
// Bedrock
|
|
//
|
|
// Created by Matt Bruce on 1/4/26.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
// MARK: - License Model
|
|
|
|
/// Represents an open source license for a third-party library
|
|
public struct License: Identifiable, Sendable {
|
|
public let id: String
|
|
public let name: String
|
|
public let url: String
|
|
public let licenseType: String
|
|
public let description: String
|
|
|
|
public init(
|
|
name: String,
|
|
url: String,
|
|
licenseType: String,
|
|
description: String
|
|
) {
|
|
self.id = name
|
|
self.name = name
|
|
self.url = url
|
|
self.licenseType = licenseType
|
|
self.description = description
|
|
}
|
|
}
|
|
|
|
// MARK: - Licenses View
|
|
|
|
/// A reusable view for displaying open source licenses
|
|
public struct LicensesView: View {
|
|
public let licenses: [License]
|
|
public let backgroundColor: Color
|
|
public let cardBackgroundColor: Color
|
|
public let cardBorderColor: Color
|
|
public let accentColor: Color
|
|
public let navigationTitle: String
|
|
|
|
public init(
|
|
licenses: [License],
|
|
backgroundColor: Color = .Surface.overlay,
|
|
cardBackgroundColor: Color = .Surface.card,
|
|
cardBorderColor: Color = .Border.subtle,
|
|
accentColor: Color = .Accent.primary,
|
|
navigationTitle: String = String(localized: "Open Source Licenses")
|
|
) {
|
|
self.licenses = licenses
|
|
self.backgroundColor = backgroundColor
|
|
self.cardBackgroundColor = cardBackgroundColor
|
|
self.cardBorderColor = cardBorderColor
|
|
self.accentColor = accentColor
|
|
self.navigationTitle = navigationTitle
|
|
}
|
|
|
|
public var body: some View {
|
|
ScrollView {
|
|
VStack(alignment: .leading, spacing: Design.Spacing.large) {
|
|
ForEach(licenses) { license in
|
|
licenseCard(license)
|
|
}
|
|
}
|
|
.padding(Design.Spacing.large)
|
|
}
|
|
.background(backgroundColor)
|
|
.navigationTitle(navigationTitle)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
}
|
|
|
|
private func licenseCard(_ license: License) -> some View {
|
|
SettingsCard(backgroundColor: cardBackgroundColor, borderColor: cardBorderColor) {
|
|
VStack(alignment: .leading, spacing: Design.Spacing.small) {
|
|
Text(license.name)
|
|
.font(Design.Typography.bodyBold)
|
|
.foregroundStyle(.white)
|
|
|
|
Text(license.description)
|
|
.font(Design.Typography.caption)
|
|
.foregroundStyle(.white.opacity(Design.Opacity.strong))
|
|
|
|
HStack {
|
|
Label(license.licenseType, systemImage: "doc.text")
|
|
.font(Design.Typography.captionSmall)
|
|
.foregroundStyle(accentColor)
|
|
|
|
Spacer()
|
|
|
|
if let linkURL = URL(string: license.url) {
|
|
Link(destination: linkURL) {
|
|
Label(String(localized: "View on GitHub"), systemImage: "arrow.up.right.square")
|
|
.font(Design.Typography.captionSmall)
|
|
.foregroundStyle(accentColor)
|
|
}
|
|
}
|
|
}
|
|
.padding(.top, Design.Spacing.xSmall)
|
|
}
|
|
}
|
|
}
|
|
}
|