Add support for cards
This commit is contained in:
parent
faffc6da0f
commit
6794e6922e
56
Sources/Core/View/Card.swift
Normal file
56
Sources/Core/View/Card.swift
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
//
|
||||||
|
// Card.swift
|
||||||
|
// MacBackend
|
||||||
|
//
|
||||||
|
// Created by david-swift on 05.01.2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
/// The card wrapper.
|
||||||
|
public struct Card: SwiftUIWidget {
|
||||||
|
|
||||||
|
/// The wrapped view.
|
||||||
|
var content: Body
|
||||||
|
|
||||||
|
/// The wrapped views.
|
||||||
|
public var wrappedViews: [String: Meta.AnyView] {
|
||||||
|
[.mainContent: content]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initialize a card view.
|
||||||
|
/// - Parameter content: The card's content.
|
||||||
|
public init(@Meta.ViewBuilder content: () -> Body) {
|
||||||
|
self.content = content()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the SwiftUI view.
|
||||||
|
/// - Parameter properties: The widget data.
|
||||||
|
/// - Returns: The SwiftUI view.
|
||||||
|
public static func view(properties: Self) -> some SwiftUI.View {
|
||||||
|
CardView()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The card view in SwiftUI.
|
||||||
|
struct CardView: SwiftUI.View {
|
||||||
|
|
||||||
|
/// The color scheme.
|
||||||
|
@SwiftUI.Environment(\.colorScheme)
|
||||||
|
var colorScheme
|
||||||
|
|
||||||
|
/// The view's body.
|
||||||
|
var body: some SwiftUI.View {
|
||||||
|
MacBackendView(.mainContent)
|
||||||
|
.padding(20)
|
||||||
|
.background(
|
||||||
|
Color(
|
||||||
|
colorScheme == .dark ? NSColor.darkGray : NSColor.white
|
||||||
|
),
|
||||||
|
in: .rect(cornerRadius: 10)
|
||||||
|
)
|
||||||
|
.shadow(color: .black.opacity(0.2), radius: 25)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -104,4 +104,10 @@ extension AnyView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Make the view a card.
|
||||||
|
/// - Returns: The view.
|
||||||
|
public func card() -> AnyView {
|
||||||
|
Card { self }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user