Skip to content

Commit 841c74c

Browse files
add docs and update card preview
1 parent 088e587 commit 841c74c

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/CardPreview.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ struct CardPreview: View {
88
var body: some View {
99
VStack {
1010
PreviewWrapper(title: "UIKit") {
11-
UKCard(model: self.model, content: {
12-
let label = UILabel()
13-
label.text = "Hello World!"
14-
return label
15-
})
11+
UKCard(model: self.model, content: cardContent)
1612
.preview
1713
}
1814
Form {
1915
Picker("Background Color", selection: self.$model.backgroundColor) {
2016
Text("Default").tag(Optional<UniversalColor>.none)
17+
Text("Secondary Background").tag(UniversalColor.secondaryBackground)
2118
Text("Accent Background").tag(ComponentColor.accent.background)
2219
Text("Success Background").tag(ComponentColor.success.background)
2320
Text("Warning Background").tag(ComponentColor.warning.background)
@@ -46,3 +43,26 @@ struct CardPreview: View {
4643
#Preview {
4744
CardPreview()
4845
}
46+
47+
// MARK: - Helpers
48+
49+
private func cardContent() -> UIView {
50+
let titleLabel = UILabel()
51+
titleLabel.text = "Card"
52+
titleLabel.font = UniversalFont.mdHeadline.uiFont
53+
titleLabel.textColor = UniversalColor.foreground.uiColor
54+
titleLabel.numberOfLines = 0
55+
56+
let subtitleLabel = UILabel()
57+
subtitleLabel.text = "Card is a container for text, photos, and other content."
58+
subtitleLabel.font = UniversalFont.mdBody.uiFont
59+
subtitleLabel.textColor = UniversalColor.secondaryForeground.uiColor
60+
subtitleLabel.numberOfLines = 0
61+
62+
63+
let stackView = UIStackView(arrangedSubviews: [titleLabel, subtitleLabel])
64+
stackView.axis = .vertical
65+
stackView.spacing = 8
66+
67+
return stackView
68+
}

Sources/ComponentsKit/Components/Card/CardVM.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22

3+
/// A model that defines the appearance properties for a card component.
34
public struct CardVM: ComponentVM {
45
/// The background color of the card's content area.
56
public var backgroundColor: UniversalColor?
@@ -14,8 +15,12 @@ public struct CardVM: ComponentVM {
1415
/// Defaults to `.medium`.
1516
public var cornerRadius: ContainerRadius = .medium
1617

18+
/// The shadow of the card.
19+
///
20+
/// Defaults to `.medium`.
1721
public var shadow: Shadow = .medium
1822

23+
/// Initializes a new instance of `CardVM` with default values.
1924
public init() {}
2025
}
2126

Sources/ComponentsKit/Components/Card/UKCard.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
import AutoLayout
22
import UIKit
33

4+
/// A UIKit component that serves as a container for provided content.
5+
///
6+
/// - Example:
7+
/// ```swift
8+
/// let banner = UKCard(
9+
/// model: .init(),
10+
/// content: { _ in
11+
/// let label = UILabel()
12+
/// label.text = "This is the content of the card."
13+
/// label.numberOfLines = 0
14+
/// return label
15+
/// }
16+
/// )
417
open class UKCard: UIView, UKComponent {
518
// MARK: - Typealiases
619

20+
/// A closure that returns the content view to be displayed inside the card.
721
public typealias Content = () -> UIView
822

923
// MARK: - Subviews
1024

25+
/// The primary content of the card, provided as a custom view.
1126
public let content: UIView
27+
/// The container view that holds the card's content.
1228
public let contentView = UIView()
1329

1430
// MARK: - Properties
1531

1632
private var contentConstraints = LayoutConstraints()
1733

34+
/// A model that defines the appearance properties.
1835
public var model: CardVM {
1936
didSet {
2037
self.update(oldValue)
@@ -23,6 +40,11 @@ open class UKCard: UIView, UKComponent {
2340

2441
// MARK: - Initialization
2542

43+
/// Initializer.
44+
///
45+
/// - Parameters:
46+
/// - model: A model that defines the appearance properties.
47+
/// - content: The content that is displayed in the card.
2648
public init(model: CardVM, content: @escaping Content) {
2749
self.model = model
2850
self.content = content()
@@ -40,6 +62,7 @@ open class UKCard: UIView, UKComponent {
4062

4163
// MARK: - Setup
4264

65+
/// Sets up the card's subviews.
4366
open func setup() {
4467
self.addSubview(self.contentView)
4568
self.contentView.addSubview(self.content)
@@ -53,13 +76,15 @@ open class UKCard: UIView, UKComponent {
5376

5477
// MARK: - Style
5578

79+
/// Applies styling to the card's subviews.
5680
open func style() {
5781
Self.Style.mainView(self, model: self.model)
5882
Self.Style.contentView(self.contentView, model: self.model)
5983
}
6084

6185
// MARK: - Layout
6286

87+
/// Configures the layout.
6388
open func layout() {
6489
self.contentView.allEdges()
6590

0 commit comments

Comments
 (0)