Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct ModalPreviewHelpers {
Text("Warning Background").tag(ComponentColor.warning.background)
Text("Danger Background").tag(ComponentColor.danger.background)
}
BorderWidthPicker(selection: self.$model.borderWidth)
Toggle("Closes On Overlay Tap", isOn: self.$model.closesOnOverlayTap)
.disabled(self.footer == nil)
Picker("Outer Paddings", selection: self.$model.outerPaddings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ struct AutocapitalizationPicker: View {
}
}

// MARK: - BorderWidthPicker

struct BorderWidthPicker: View {
@Binding var selection: BorderWidth

var body: some View {
Picker("Border Width", selection: self.$selection) {
Text("None").tag(BorderWidth.none)
Text("Small").tag(BorderWidth.small)
Text("Medium").tag(BorderWidth.medium)
Text("Large").tag(BorderWidth.large)
}
}
}

// MARK: - ComponentColorPicker

struct ComponentColorPicker: View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct AlertPreview: View {
Text("Warning Background").tag(ComponentColor.warning.background)
Text("Danger Background").tag(ComponentColor.danger.background)
}
BorderWidthPicker(selection: self.$model.borderWidth)
Toggle("Closes On Overlay Tap", isOn: self.$model.closesOnOverlayTap)
Picker("Content Paddings", selection: self.$model.contentPaddings) {
Text("12px").tag(Paddings(padding: 12))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct CardPreview: View {
Text("Warning Background").tag(ComponentColor.warning.background)
Text("Danger Background").tag(ComponentColor.danger.background)
}
BorderWidthPicker(selection: self.$model.borderWidth)
Picker("Content Paddings", selection: self.$model.contentPaddings) {
Text("12px").tag(Paddings(padding: 12))
Text("16px").tag(Paddings(padding: 16))
Expand Down
6 changes: 6 additions & 0 deletions Sources/ComponentsKit/Components/Alert/Models/AlertVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public struct AlertVM: ComponentVM {
/// The background color of the modal.
public var backgroundColor: UniversalColor?

/// The border thickness of the alert.
///
/// Defaults to `.small`.
public var borderWidth: BorderWidth = .small

/// A Boolean value indicating whether the modal should close when tapping on the overlay.
///
/// Defaults to `false`.
Expand Down Expand Up @@ -56,6 +61,7 @@ extension AlertVM {
var modalVM: CenterModalVM {
return CenterModalVM {
$0.backgroundColor = self.backgroundColor
$0.borderWidth = self.borderWidth
$0.closesOnOverlayTap = self.closesOnOverlayTap
$0.contentPaddings = self.contentPaddings
$0.cornerRadius = self.cornerRadius
Expand Down
5 changes: 5 additions & 0 deletions Sources/ComponentsKit/Components/Card/Models/CardVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ public struct CardVM: ComponentVM {
/// The background color of the card.
public var backgroundColor: UniversalColor?

/// The border thickness of the card.
///
/// Defaults to `.medium`.
public var borderWidth: BorderWidth = .medium

/// The padding applied to the card's content area.
///
/// Defaults to a padding value of `16` for all sides.
Expand Down
2 changes: 1 addition & 1 deletion Sources/ComponentsKit/Components/Card/SUCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public struct SUCard<Content: View>: View {
.cornerRadius(self.model.cornerRadius.value)
.overlay(
RoundedRectangle(cornerRadius: self.model.cornerRadius.value)
.stroke(UniversalColor.divider.color, lineWidth: 1.0)
.stroke(UniversalColor.divider.color, lineWidth: self.model.borderWidth.value)
)
.shadow(self.model.shadow)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ComponentsKit/Components/Card/UKCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ extension UKCard {
static func mainView(_ view: UIView, model: Model) {
view.backgroundColor = UniversalColor.background.uiColor
view.layer.cornerRadius = model.cornerRadius.value
view.layer.borderWidth = 1
view.layer.borderWidth = model.borderWidth.value
view.layer.borderColor = UniversalColor.divider.cgColor
view.layer.shadowRadius = model.shadow.radius
view.layer.shadowOffset = model.shadow.offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ public struct BottomModalVM: ModalVM {
/// The background color of the modal.
public var backgroundColor: UniversalColor?

/// The border thickness of the modal.
///
/// Defaults to `.small`.
public var borderWidth: BorderWidth = .small

/// A Boolean value indicating whether the modal should close when tapping on the overlay.
///
/// Defaults to `true`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ public struct CenterModalVM: ModalVM {
/// The background color of the modal.
public var backgroundColor: UniversalColor?

/// The border thickness of the modal.
///
/// Defaults to `.small`.
public var borderWidth: BorderWidth = .small

/// A Boolean value indicating whether the modal should close when tapping on the overlay.
///
/// Defaults to `true`.
Expand Down
3 changes: 3 additions & 0 deletions Sources/ComponentsKit/Components/Modal/Models/ModalVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public protocol ModalVM: ComponentVM {
/// The background color of the modal.
var backgroundColor: UniversalColor? { get set }

/// The border thickness of the modal.
var borderWidth: BorderWidth { get set }

/// A Boolean value indicating whether the modal should close when tapping on the overlay.
var closesOnOverlayTap: Bool { get set }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ struct ModalContent<VM: ModalVM, Header: View, Body: View, Footer: View>: View {
.frame(maxWidth: self.model.size.maxWidth, alignment: .leading)
.background(self.model.preferredBackgroundColor.color)
.background(UniversalColor.background.color)
.clipShape(RoundedRectangle(
cornerRadius: self.model.cornerRadius.value
))
.clipShape(RoundedRectangle(cornerRadius: self.model.cornerRadius.value))
.overlay(
RoundedRectangle(cornerRadius: self.model.cornerRadius.value)
.stroke(UniversalColor.divider.color, lineWidth: self.model.borderWidth.value)
)
.padding(self.model.outerPaddings.edgeInsets)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ open class UKModalController<VM: ModalVM>: UIViewController {
target: self,
action: #selector(self.handleOverlayTap)
))

if #available(iOS 17.0, *) {
self.registerForTraitChanges([UITraitUserInterfaceStyle.self]) { (controller: Self, _: UITraitCollection) in
controller.handleTraitChanges()
}
}
}

@objc func handleOverlayTap() {
Expand Down Expand Up @@ -188,6 +194,21 @@ open class UKModalController<VM: ModalVM>: UIViewController {
}
self.containerWidthConstraint?.isActive = true
}

// MARK: - UIViewController Methods

open override func traitCollectionDidChange(
_ previousTraitCollection: UITraitCollection?
) {
super.traitCollectionDidChange(previousTraitCollection)
self.handleTraitChanges()
}

// MARK: - Helpers

@objc private func handleTraitChanges() {
Self.Style.content(self.content, model: self.model)
}
}

// MARK: - Style Helpers
Expand All @@ -211,7 +232,8 @@ extension UKModalController {
static func content(_ view: UIView, model: VM) {
view.backgroundColor = model.preferredBackgroundColor.uiColor
view.layer.cornerRadius = model.cornerRadius.value
view.clipsToBounds = true
view.layer.borderColor = UniversalColor.divider.cgColor
view.layer.borderWidth = model.borderWidth.value
}
static func bodyWrapper(_ scrollView: UIScrollView) {
scrollView.delaysContentTouches = false
Expand Down
6 changes: 3 additions & 3 deletions Sources/ComponentsKit/Configuration/Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ extension ComponentsKitConfig {

/// The border width configuration for components.
public var borderWidth: BorderWidth = .init(
small: 1.0,
medium: 2.0,
large: 3.0
small: 0.5,
medium: 1.0,
large: 2.0
)

/// The animation scale configuration for components.
Expand Down
4 changes: 4 additions & 0 deletions Sources/ComponentsKit/Shared/Types/BorderWidth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Foundation

/// An enumeration that defines border thickness for components.
public enum BorderWidth: Hashable {
/// No border.
case none
/// A small border width.
case small
/// A medium border width.
Expand All @@ -14,6 +16,8 @@ extension BorderWidth {
/// The numeric value of the border width as a `CGFloat`.
public var value: CGFloat {
switch self {
case .none:
return 0.0
case .small:
return ComponentsKitConfig.shared.layout.borderWidth.small
case .medium:
Expand Down
Loading