Skip to content

Commit 8c44179

Browse files
add docs for shared types
1 parent 7b38711 commit 8c44179

File tree

4 files changed

+69
-40
lines changed

4 files changed

+69
-40
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ struct ButtonPreview: View {
3232
Text("Bordered with small border").tag(ButtonVM.Style.bordered(.small))
3333
Text("Bordered with medium border").tag(ButtonVM.Style.bordered(.medium))
3434
Text("Bordered with large border").tag(ButtonVM.Style.bordered(.large))
35-
Text("Bordered with custom border: 6px").tag(ButtonVM.Style.bordered(.custom(6)))
3635
}
3736
}
3837
}
Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
11
import Foundation
22

3-
public struct AnimationScale: Hashable {
4-
var value: CGFloat
5-
6-
init(_ value: CGFloat) {
7-
self.value = value
8-
}
3+
/// An enumeration that defines how much a component shrinks or expands during animations.
4+
public enum AnimationScale: Hashable {
5+
/// No scaling is applied, meaning the component remains at its original size.
6+
case none
7+
/// A small scaling effect is applied, using a predefined value from the configuration.
8+
case small
9+
/// A medium scaling effect is applied, using a predefined value from the configuration.
10+
case medium
11+
/// A large scaling effect is applied, using a predefined value from the configuration.
12+
case large
13+
/// A custom scaling value.
14+
///
15+
/// - Parameter value: The custom scale value (0.0–1.0).
16+
case custom(_ value: CGFloat)
917
}
1018

1119
extension AnimationScale {
12-
public static var none: Self {
13-
return Self(1.0)
14-
}
15-
public static var small: Self {
16-
return Self(ComponentsKitConfig.shared.layout.animationScale.small)
17-
}
18-
public static var medium: Self {
19-
return Self(ComponentsKitConfig.shared.layout.animationScale.medium)
20-
}
21-
public static var large: Self {
22-
return Self(ComponentsKitConfig.shared.layout.animationScale.large)
23-
}
24-
public static func custom(_ value: CGFloat) -> Self {
25-
guard value >= 0 && value <= 1.0 else {
26-
fatalError("Animation scale value should be between 0 and 1")
20+
/// The scaling value represented as a `CGFloat`.
21+
///
22+
/// - Returns:
23+
/// - `1.0` for `.none` (no scaling).
24+
/// - Predefined values from `ComponentsKitConfig` for `.small`, `.medium`, and `.large`.
25+
/// - The custom value provided for `.custom`, constrained between `0.0` and `1.0`.
26+
/// - Note: If the custom value is outside the range `0.0–1.0`, an assertion failure occurs,
27+
/// and a default value of `1.0` is returned.
28+
public var value: CGFloat {
29+
switch self {
30+
case .none:
31+
return 1.0
32+
case .small:
33+
return ComponentsKitConfig.shared.layout.animationScale.small
34+
case .medium:
35+
return ComponentsKitConfig.shared.layout.animationScale.medium
36+
case .large:
37+
return ComponentsKitConfig.shared.layout.animationScale.large
38+
case .custom(let value):
39+
guard value >= 0 && value <= 1.0 else {
40+
assertionFailure("Animation scale value should be between 0 and 1")
41+
return 1.0
42+
}
43+
return value
2744
}
28-
return Self(value)
2945
}
3046
}
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import Foundation
22

3-
public struct BorderWidth: Hashable {
4-
var value: CGFloat
5-
6-
init(_ value: CGFloat) {
7-
self.value = value
8-
}
3+
/// An enumeration that defines border thickness for components.
4+
public enum BorderWidth: Hashable {
5+
/// A small border width.
6+
case small
7+
/// A medium border width.
8+
case medium
9+
/// A large border width.
10+
case large
911
}
1012

1113
extension BorderWidth {
12-
public static var small: Self {
13-
return Self(ComponentsKitConfig.shared.layout.borderWidth.small)
14-
}
15-
public static var medium: Self {
16-
return Self(ComponentsKitConfig.shared.layout.borderWidth.medium)
17-
}
18-
public static var large: Self {
19-
return Self(ComponentsKitConfig.shared.layout.borderWidth.large)
20-
}
21-
public static func custom(_ value: CGFloat) -> Self {
22-
return Self(value)
14+
/// The numeric value of the border width as a `CGFloat`.
15+
public var value: CGFloat {
16+
switch self {
17+
case .small:
18+
return ComponentsKitConfig.shared.layout.borderWidth.small
19+
case .medium:
20+
return ComponentsKitConfig.shared.layout.borderWidth.medium
21+
case .large:
22+
return ComponentsKitConfig.shared.layout.borderWidth.large
23+
}
2324
}
2425
}

Sources/ComponentsKit/Shared/Types/ComponentRadius.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
import Foundation
22
import SwiftUI
33

4+
/// An enumeration that defines the corner radius options for components.
45
public enum ComponentRadius: Hashable {
6+
/// No corner radius, resulting in sharp edges.
57
case none
8+
/// A small corner radius.
69
case small
10+
/// A medium corner radius.
711
case medium
12+
/// A large corner radius.
813
case large
14+
/// A fully rounded corner radius, where the radius is half of the component's height.
915
case full
16+
/// A custom corner radius with a specific value.
17+
///
18+
/// - Parameter value: The radius value as a `CGFloat`.
1019
case custom(CGFloat)
1120
}
1221

1322
extension ComponentRadius {
23+
/// Returns the numeric value of the corner radius, ensuring it does not exceed half the component's height.
24+
///
25+
/// - Parameter height: The height of the component. Defaults to a large number (10,000) for unrestricted calculations.
26+
/// - Returns: The calculated corner radius as a `CGFloat`, capped at half of the height for `full` rounding or custom values.
1427
func value(for height: CGFloat = 10_000) -> CGFloat {
1528
let maxValue = height / 2
1629
let value = switch self {

0 commit comments

Comments
 (0)