Skip to content

Commit b87030e

Browse files
Merge pull request #40 from componentskit/ukcard
UKCard
2 parents 7f20f75 + 94e2c52 commit b87030e

File tree

21 files changed

+447
-23
lines changed

21 files changed

+447
-23
lines changed

Examples/DemosApp/DemosApp/ComponentsPreview/Helpers/ModalPreview+Helpers.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,8 @@ struct ModalPreviewHelpers {
8282
Text("16px").tag(Paddings(padding: 16))
8383
Text("20px").tag(Paddings(padding: 20))
8484
}
85-
Picker("Corner Radius", selection: self.$model.cornerRadius) {
86-
Text("None").tag(ModalRadius.none)
87-
Text("Small").tag(ModalRadius.small)
88-
Text("Medium").tag(ModalRadius.medium)
89-
Text("Large").tag(ModalRadius.large)
90-
Text("Custom 30px").tag(ModalRadius.custom(30))
85+
ContainerRadiusPicker(selection: self.$model.cornerRadius) {
86+
Text("Custom 30px").tag(ContainerRadius.custom(30))
9187
}
9288
Picker("Overlay Style", selection: self.$model.overlayStyle) {
9389
Text("Blurred").tag(ModalOverlayStyle.blurred)

Examples/DemosApp/DemosApp/ComponentsPreview/Helpers/PreviewPickers.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct ComponentOptionalColorPicker: View {
7575

7676
// MARK: - CornerRadiusPicker
7777

78-
struct CornerRadiusPicker<Custom: View>: View {
78+
struct ComponentRadiusPicker<Custom: View>: View {
7979
@Binding var selection: ComponentRadius
8080
@ViewBuilder var custom: () -> Custom
8181

@@ -91,6 +91,21 @@ struct CornerRadiusPicker<Custom: View>: View {
9191
}
9292
}
9393

94+
struct ContainerRadiusPicker<Custom: View>: View {
95+
@Binding var selection: ContainerRadius
96+
@ViewBuilder var custom: () -> Custom
97+
98+
var body: some View {
99+
Picker("Corner Radius", selection: self.$selection) {
100+
Text("None").tag(ContainerRadius.none)
101+
Text("Small").tag(ContainerRadius.small)
102+
Text("Medium").tag(ContainerRadius.medium)
103+
Text("Large").tag(ContainerRadius.large)
104+
self.custom()
105+
}
106+
}
107+
}
108+
94109
// MARK: - FontPickers
95110

96111
struct BodyFontPicker: View {

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/ButtonPreview.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct ButtonPreview: View {
1919
Form {
2020
AnimationScalePicker(selection: self.$model.animationScale)
2121
ComponentOptionalColorPicker(selection: self.$model.color)
22-
CornerRadiusPicker(selection: self.$model.cornerRadius) {
22+
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
2323
Text("Custom: 20px").tag(ComponentRadius.custom(20))
2424
}
2525
ButtonFontPicker(selection: self.$model.font)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import ComponentsKit
2+
import SwiftUI
3+
import UIKit
4+
5+
struct CardPreview: View {
6+
@State private var model = CardVM()
7+
8+
var body: some View {
9+
VStack {
10+
PreviewWrapper(title: "UIKit") {
11+
UKCard(model: self.model, content: cardContent)
12+
.preview
13+
}
14+
Form {
15+
Picker("Background Color", selection: self.$model.backgroundColor) {
16+
Text("Default").tag(Optional<UniversalColor>.none)
17+
Text("Secondary Background").tag(UniversalColor.secondaryBackground)
18+
Text("Accent Background").tag(ComponentColor.accent.background)
19+
Text("Success Background").tag(ComponentColor.success.background)
20+
Text("Warning Background").tag(ComponentColor.warning.background)
21+
Text("Danger Background").tag(ComponentColor.danger.background)
22+
}
23+
Picker("Content Paddings", selection: self.$model.contentPaddings) {
24+
Text("12px").tag(Paddings(padding: 12))
25+
Text("16px").tag(Paddings(padding: 16))
26+
Text("20px").tag(Paddings(padding: 20))
27+
}
28+
ContainerRadiusPicker(selection: self.$model.cornerRadius) {
29+
Text("Custom 4px").tag(ContainerRadius.custom(4))
30+
}
31+
Picker("Shadow", selection: self.$model.shadow) {
32+
Text("None").tag(Shadow.none)
33+
Text("Small").tag(Shadow.small)
34+
Text("Medium").tag(Shadow.medium)
35+
Text("Large").tag(Shadow.large)
36+
Text("Custom").tag(Shadow.custom(20.0, .zero, ComponentColor.accent.background))
37+
}
38+
}
39+
}
40+
}
41+
}
42+
43+
#Preview {
44+
CardPreview()
45+
}
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, images, and other content."
58+
subtitleLabel.font = UniversalFont.mdBody.uiFont
59+
subtitleLabel.textColor = UniversalColor.secondaryForeground.uiColor
60+
subtitleLabel.numberOfLines = 0
61+
62+
let stackView = UIStackView(arrangedSubviews: [titleLabel, subtitleLabel])
63+
stackView.axis = .vertical
64+
stackView.spacing = 8
65+
66+
return stackView
67+
}

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/CheckboxPreview.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct CheckboxPreview: View {
3131
Text("Long").tag("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
3232
}
3333
ComponentColorPicker(selection: self.$model.color)
34-
CornerRadiusPicker(selection: self.$model.cornerRadius) {
34+
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
3535
Text("Custom: 2px").tag(ComponentRadius.custom(2))
3636
}
3737
BodyFontPicker(selection: self.$model.font)

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/InputFieldPreview.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct InputFieldPreview: View {
3535
AutocapitalizationPicker(selection: self.$model.autocapitalization)
3636
Toggle("Autocorrection Enabled", isOn: self.$model.isAutocorrectionEnabled)
3737
ComponentOptionalColorPicker(selection: self.$model.color)
38-
CornerRadiusPicker(selection: self.$model.cornerRadius) {
38+
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
3939
Text("Custom: 20px").tag(ComponentRadius.custom(20))
4040
}
4141
Toggle("Enabled", isOn: self.$model.isEnabled)

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/SegmentedControlPreview.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct SegmentedControlPreview: View {
4242
}
4343
Form {
4444
ComponentOptionalColorPicker(selection: self.$model.color)
45-
CornerRadiusPicker(selection: self.$model.cornerRadius) {
45+
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
4646
Text("Custom: 4px").tag(ComponentRadius.custom(4))
4747
}
4848
Toggle("Enabled", isOn: self.$model.isEnabled)

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/TextInputPreview.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct TextInputPreviewPreview: View {
3535
AutocapitalizationPicker(selection: self.$model.autocapitalization)
3636
Toggle("Autocorrection Enabled", isOn: self.$model.isAutocorrectionEnabled)
3737
ComponentOptionalColorPicker(selection: self.$model.color)
38-
CornerRadiusPicker(selection: self.$model.cornerRadius) {
38+
ComponentRadiusPicker(selection: self.$model.cornerRadius) {
3939
Text("Custom: 20px").tag(ComponentRadius.custom(20))
4040
}
4141
Toggle("Enabled", isOn: self.$model.isEnabled)

Examples/DemosApp/DemosApp/Core/App.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ struct App: View {
99
NavigationLinkWithTitle("Button") {
1010
ButtonPreview()
1111
}
12+
NavigationLinkWithTitle("Card") {
13+
CardPreview()
14+
}
1215
NavigationLinkWithTitle("Checkbox") {
1316
CheckboxPreview()
1417
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import Foundation
2+
3+
/// A model that defines the appearance properties for a card component.
4+
public struct CardVM: ComponentVM {
5+
/// The background color of the card.
6+
public var backgroundColor: UniversalColor?
7+
8+
/// The padding applied to the card's content area.
9+
///
10+
/// Defaults to a padding value of `16` for all sides.
11+
public var contentPaddings: Paddings = .init(padding: 16)
12+
13+
/// The corner radius of the card.
14+
///
15+
/// Defaults to `.medium`.
16+
public var cornerRadius: ContainerRadius = .medium
17+
18+
/// The shadow of the card.
19+
///
20+
/// Defaults to `.medium`.
21+
public var shadow: Shadow = .medium
22+
23+
/// Initializes a new instance of `CardVM` with default values.
24+
public init() {}
25+
}
26+
27+
// MARK: - Helpers
28+
29+
extension CardVM {
30+
var preferredBackgroundColor: UniversalColor {
31+
return self.backgroundColor ?? .background
32+
}
33+
}

0 commit comments

Comments
 (0)