Skip to content

Commit a0861dd

Browse files
added border width param to modals and alert
1 parent 63a84a8 commit a0861dd

File tree

10 files changed

+47
-3
lines changed

10 files changed

+47
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct ModalPreviewHelpers {
6565
Text("Warning Background").tag(ComponentColor.warning.background)
6666
Text("Danger Background").tag(ComponentColor.danger.background)
6767
}
68+
BorderWidthPicker(selection: self.$model.borderWidth)
6869
Toggle("Closes On Overlay Tap", isOn: self.$model.closesOnOverlayTap)
6970
.disabled(self.footer == nil)
7071
Picker("Outer Paddings", selection: self.$model.outerPaddings) {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ struct AutocapitalizationPicker: View {
3232
}
3333
}
3434

35+
// MARK: - BorderWidthPicker
36+
37+
struct BorderWidthPicker: View {
38+
@Binding var selection: BorderWidth
39+
40+
var body: some View {
41+
Picker("Border Width", selection: self.$selection) {
42+
Text("None").tag(BorderWidth.none)
43+
Text("Small").tag(BorderWidth.small)
44+
Text("Medium").tag(BorderWidth.medium)
45+
Text("Large").tag(BorderWidth.large)
46+
}
47+
}
48+
}
49+
3550
// MARK: - ComponentColorPicker
3651

3752
struct ComponentColorPicker: View {

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/AlertPreview.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct AlertPreview: View {
8989
Text("Warning Background").tag(ComponentColor.warning.background)
9090
Text("Danger Background").tag(ComponentColor.danger.background)
9191
}
92+
BorderWidthPicker(selection: self.$model.borderWidth)
9293
Toggle("Closes On Overlay Tap", isOn: self.$model.closesOnOverlayTap)
9394
Picker("Content Paddings", selection: self.$model.contentPaddings) {
9495
Text("12px").tag(Paddings(padding: 12))

Sources/ComponentsKit/Components/Alert/Models/AlertVM.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public struct AlertVM: ComponentVM {
2121
/// The background color of the modal.
2222
public var backgroundColor: UniversalColor?
2323

24+
/// The border thickness of the alert.
25+
///
26+
/// Defaults to `.small`.
27+
public var borderWidth: BorderWidth = .small
28+
2429
/// A Boolean value indicating whether the modal should close when tapping on the overlay.
2530
///
2631
/// Defaults to `false`.
@@ -56,6 +61,7 @@ extension AlertVM {
5661
var modalVM: CenterModalVM {
5762
return CenterModalVM {
5863
$0.backgroundColor = self.backgroundColor
64+
$0.borderWidth = self.borderWidth
5965
$0.closesOnOverlayTap = self.closesOnOverlayTap
6066
$0.contentPaddings = self.contentPaddings
6167
$0.cornerRadius = self.cornerRadius

Sources/ComponentsKit/Components/Modal/Models/BottomModalVM.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ public struct BottomModalVM: ModalVM {
55
/// The background color of the modal.
66
public var backgroundColor: UniversalColor?
77

8+
/// The border thickness of the modal.
9+
///
10+
/// Defaults to `.small`.
11+
public var borderWidth: BorderWidth = .small
12+
813
/// A Boolean value indicating whether the modal should close when tapping on the overlay.
914
///
1015
/// Defaults to `true`.

Sources/ComponentsKit/Components/Modal/Models/CenterModalVM.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ public struct CenterModalVM: ModalVM {
55
/// The background color of the modal.
66
public var backgroundColor: UniversalColor?
77

8+
/// The border thickness of the modal.
9+
///
10+
/// Defaults to `.small`.
11+
public var borderWidth: BorderWidth = .small
12+
813
/// A Boolean value indicating whether the modal should close when tapping on the overlay.
914
///
1015
/// Defaults to `true`.

Sources/ComponentsKit/Components/Modal/Models/ModalVM.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ public protocol ModalVM: ComponentVM {
55
/// The background color of the modal.
66
var backgroundColor: UniversalColor? { get set }
77

8+
/// The border thickness of the modal.
9+
var borderWidth: BorderWidth { get set }
10+
811
/// A Boolean value indicating whether the modal should close when tapping on the overlay.
912
var closesOnOverlayTap: Bool { get set }
1013

Sources/ComponentsKit/Components/Modal/SwiftUI/ModalContent.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ struct ModalContent<VM: ModalVM, Header: View, Body: View, Footer: View>: View {
6060
.frame(maxWidth: self.model.size.maxWidth, alignment: .leading)
6161
.background(self.model.preferredBackgroundColor.color)
6262
.background(UniversalColor.background.color)
63-
.clipShape(RoundedRectangle(
64-
cornerRadius: self.model.cornerRadius.value
65-
))
63+
.clipShape(RoundedRectangle(cornerRadius: self.model.cornerRadius.value))
64+
.overlay(
65+
RoundedRectangle(cornerRadius: self.model.cornerRadius.value)
66+
.stroke(UniversalColor.divider.color, lineWidth: self.model.borderWidth.value)
67+
)
6668
.padding(self.model.outerPaddings.edgeInsets)
6769
}
6870

Sources/ComponentsKit/Components/Modal/UIKit/UKModalController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ extension UKModalController {
212212
view.backgroundColor = model.preferredBackgroundColor.uiColor
213213
view.layer.cornerRadius = model.cornerRadius.value
214214
view.clipsToBounds = true
215+
view.layer.borderColor = UniversalColor.divider.cgColor
216+
view.layer.borderWidth = model.borderWidth.value
215217
}
216218
static func bodyWrapper(_ scrollView: UIScrollView) {
217219
scrollView.delaysContentTouches = false

Sources/ComponentsKit/Shared/Types/BorderWidth.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import Foundation
22

33
/// An enumeration that defines border thickness for components.
44
public enum BorderWidth: Hashable {
5+
/// No border.
6+
case none
57
/// A small border width.
68
case small
79
/// A medium border width.
@@ -14,6 +16,8 @@ extension BorderWidth {
1416
/// The numeric value of the border width as a `CGFloat`.
1517
public var value: CGFloat {
1618
switch self {
19+
case .none:
20+
return 0.0
1721
case .small:
1822
return ComponentsKitConfig.shared.layout.borderWidth.small
1923
case .medium:

0 commit comments

Comments
 (0)