Skip to content

Commit 3394c1d

Browse files
put Layout and Palette inside Config
1 parent 8c44179 commit 3394c1d

File tree

2 files changed

+279
-275
lines changed

2 files changed

+279
-275
lines changed
Lines changed: 172 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -1,191 +1,193 @@
11
import Foundation
22

3-
/// A structure that defines the layout-related configurations for components in the framework.
4-
public struct Layout: Initializable, Updatable {
5-
// MARK: - Radius
6-
7-
/// A structure representing radius values for components.
8-
public struct Radius {
9-
/// The small radius size.
10-
public var small: CGFloat
11-
/// The medium radius size.
12-
public var medium: CGFloat
13-
/// The large radius size.
14-
public var large: CGFloat
15-
16-
/// Initializes a new `Radius` instance.
17-
///
18-
/// - Parameters:
19-
/// - small: The small radius size.
20-
/// - medium: The medium radius size.
21-
/// - large: The large radius size.
22-
public init(small: CGFloat, medium: CGFloat, large: CGFloat) {
23-
self.small = small
24-
self.medium = medium
25-
self.large = large
3+
extension ComponentsKitConfig {
4+
/// A structure that defines the layout-related configurations for components in the framework.
5+
public struct Layout: Initializable, Updatable {
6+
// MARK: - Radius
7+
8+
/// A structure representing radius values for components.
9+
public struct Radius {
10+
/// The small radius size.
11+
public var small: CGFloat
12+
/// The medium radius size.
13+
public var medium: CGFloat
14+
/// The large radius size.
15+
public var large: CGFloat
16+
17+
/// Initializes a new `Radius` instance.
18+
///
19+
/// - Parameters:
20+
/// - small: The small radius size.
21+
/// - medium: The medium radius size.
22+
/// - large: The large radius size.
23+
public init(small: CGFloat, medium: CGFloat, large: CGFloat) {
24+
self.small = small
25+
self.medium = medium
26+
self.large = large
27+
}
2628
}
27-
}
2829

29-
// MARK: - BorderWidth
30+
// MARK: - BorderWidth
31+
32+
/// A structure representing border width values for components.
33+
public struct BorderWidth {
34+
/// The small border width.
35+
public var small: CGFloat
36+
/// The medium border width.
37+
public var medium: CGFloat
38+
/// The large border width.
39+
public var large: CGFloat
40+
41+
/// Initializes a new `BorderWidth` instance.
42+
///
43+
/// - Parameters:
44+
/// - small: The small border width.
45+
/// - medium: The medium border width.
46+
/// - large: The large border width.
47+
public init(small: CGFloat, medium: CGFloat, large: CGFloat) {
48+
self.small = small
49+
self.medium = medium
50+
self.large = large
51+
}
52+
}
3053

31-
/// A structure representing border width values for components.
32-
public struct BorderWidth {
33-
/// The small border width.
34-
public var small: CGFloat
35-
/// The medium border width.
36-
public var medium: CGFloat
37-
/// The large border width.
38-
public var large: CGFloat
54+
// MARK: - AnimationScale
3955

40-
/// Initializes a new `BorderWidth` instance.
56+
/// A structure representing animation scale values for components.
4157
///
42-
/// - Parameters:
43-
/// - small: The small border width.
44-
/// - medium: The medium border width.
45-
/// - large: The large border width.
46-
public init(small: CGFloat, medium: CGFloat, large: CGFloat) {
47-
self.small = small
48-
self.medium = medium
49-
self.large = large
58+
/// The values must be between `0.0` and `1.0`.
59+
public struct AnimationScale {
60+
/// The small animation scale.
61+
public var small: CGFloat
62+
/// The medium animation scale.
63+
public var medium: CGFloat
64+
/// The large animation scale.
65+
public var large: CGFloat
66+
67+
/// Initializes a new `AnimationScale` instance.
68+
///
69+
/// - Parameters:
70+
/// - small: The small animation scale (0.0–1.0).
71+
/// - medium: The medium animation scale (0.0–1.0).
72+
/// - large: The large animation scale (0.0–1.0).
73+
/// - Warning: This initializer will crash if the values are outside the range of `0.0` to `1.0`.
74+
public init(small: CGFloat, medium: CGFloat, large: CGFloat) {
75+
guard small >= 0 && small <= 1.0,
76+
medium >= 0 && medium <= 1.0,
77+
large >= 0 && large <= 1.0
78+
else {
79+
fatalError("Animation scale values should be between 0 and 1")
80+
}
81+
82+
self.small = small
83+
self.medium = medium
84+
self.large = large
85+
}
5086
}
51-
}
52-
53-
// MARK: - AnimationScale
54-
55-
/// A structure representing animation scale values for components.
56-
///
57-
/// The values must be between `0.0` and `1.0`.
58-
public struct AnimationScale {
59-
/// The small animation scale.
60-
public var small: CGFloat
61-
/// The medium animation scale.
62-
public var medium: CGFloat
63-
/// The large animation scale.
64-
public var large: CGFloat
6587

66-
/// Initializes a new `AnimationScale` instance.
67-
///
68-
/// - Parameters:
69-
/// - small: The small animation scale (0.0–1.0).
70-
/// - medium: The medium animation scale (0.0–1.0).
71-
/// - large: The large animation scale (0.0–1.0).
72-
/// - Warning: This initializer will crash if the values are outside the range of `0.0` to `1.0`.
73-
public init(small: CGFloat, medium: CGFloat, large: CGFloat) {
74-
guard small >= 0 && small <= 1.0,
75-
medium >= 0 && medium <= 1.0,
76-
large >= 0 && large <= 1.0
77-
else {
78-
fatalError("Animation scale values should be between 0 and 1")
88+
// MARK: - Typography
89+
90+
/// A structure representing a set of fonts for different component sizes.
91+
public struct FontSet {
92+
/// The small font.
93+
public var small: UniversalFont
94+
/// The medium font.
95+
public var medium: UniversalFont
96+
/// The large font.
97+
public var large: UniversalFont
98+
99+
/// Initializes a new `FontSet` instance.
100+
///
101+
/// - Parameters:
102+
/// - small: The small font.
103+
/// - medium: The medium font.
104+
/// - large: The large font.
105+
public init(small: UniversalFont, medium: UniversalFont, large: UniversalFont) {
106+
self.small = small
107+
self.medium = medium
108+
self.large = large
79109
}
110+
}
80111

81-
self.small = small
82-
self.medium = medium
83-
self.large = large
112+
/// A structure representing typography settings for various components.
113+
public struct Typography {
114+
/// The font set for headlines.
115+
public var headline: FontSet
116+
/// The font set for body text.
117+
public var body: FontSet
118+
/// The font set for buttons.
119+
public var button: FontSet
120+
/// The font set for captions.
121+
public var caption: FontSet
122+
123+
/// Initializes a new `Typography` instance.
124+
///
125+
/// - Parameters:
126+
/// - headline: The font set for headlines.
127+
/// - body: The font set for body text.
128+
/// - button: The font set for buttons.
129+
/// - caption: The font set for captions.
130+
public init(headline: FontSet, body: FontSet, button: FontSet, caption: FontSet) {
131+
self.headline = headline
132+
self.body = body
133+
self.button = button
134+
self.caption = caption
135+
}
84136
}
85-
}
86137

87-
// MARK: - Typography
138+
// MARK: - Properties
88139

89-
/// A structure representing a set of fonts for different component sizes.
90-
public struct FontSet {
91-
/// The small font.
92-
public var small: UniversalFont
93-
/// The medium font.
94-
public var medium: UniversalFont
95-
/// The large font.
96-
public var large: UniversalFont
140+
/// The opacity level for disabled components.
141+
public var disabledOpacity: CGFloat = 0.5
97142

98-
/// Initializes a new `FontSet` instance.
99-
///
100-
/// - Parameters:
101-
/// - small: The small font.
102-
/// - medium: The medium font.
103-
/// - large: The large font.
104-
public init(small: UniversalFont, medium: UniversalFont, large: UniversalFont) {
105-
self.small = small
106-
self.medium = medium
107-
self.large = large
108-
}
109-
}
143+
/// The radius configuration for components.
144+
public var componentRadius: Radius = .init(
145+
small: 10.0,
146+
medium: 12.0,
147+
large: 16.0
148+
)
110149

111-
/// A structure representing typography settings for various components.
112-
public struct Typography {
113-
/// The font set for headlines.
114-
public var headline: FontSet
115-
/// The font set for body text.
116-
public var body: FontSet
117-
/// The font set for buttons.
118-
public var button: FontSet
119-
/// The font set for captions.
120-
public var caption: FontSet
121-
122-
/// Initializes a new `Typography` instance.
123-
///
124-
/// - Parameters:
125-
/// - headline: The font set for headlines.
126-
/// - body: The font set for body text.
127-
/// - button: The font set for buttons.
128-
/// - caption: The font set for captions.
129-
public init(headline: FontSet, body: FontSet, button: FontSet, caption: FontSet) {
130-
self.headline = headline
131-
self.body = body
132-
self.button = button
133-
self.caption = caption
134-
}
135-
}
150+
/// The border width configuration for components.
151+
public var borderWidth: BorderWidth = .init(
152+
small: 1.0,
153+
medium: 2.0,
154+
large: 3.0
155+
)
136156

137-
// MARK: - Properties
138-
139-
/// The opacity level for disabled components.
140-
public var disabledOpacity: CGFloat = 0.5
141-
142-
/// The radius configuration for components.
143-
public var componentRadius: Radius = .init(
144-
small: 10.0,
145-
medium: 12.0,
146-
large: 16.0
147-
)
148-
149-
/// The border width configuration for components.
150-
public var borderWidth: BorderWidth = .init(
151-
small: 1.0,
152-
medium: 2.0,
153-
large: 3.0
154-
)
155-
156-
/// The animation scale configuration for components.
157-
public var animationScale: AnimationScale = .init(
158-
small: 0.99,
159-
medium: 0.98,
160-
large: 0.95
161-
)
162-
163-
/// The typography configuration for components.
164-
public var typography: Typography = .init(
165-
headline: .init(
166-
small: .system(size: 14, weight: .semibold),
167-
medium: .system(size: 20, weight: .semibold),
168-
large: .system(size: 28, weight: .semibold)
169-
),
170-
body: .init(
171-
small: .system(size: 14, weight: .regular),
172-
medium: .system(size: 16, weight: .regular),
173-
large: .system(size: 18, weight: .regular)
174-
),
175-
button: .init(
176-
small: .system(size: 14, weight: .medium),
177-
medium: .system(size: 16, weight: .medium),
178-
large: .system(size: 20, weight: .medium)
179-
),
180-
caption: .init(
181-
small: .system(size: 10, weight: .regular),
182-
medium: .system(size: 12, weight: .regular),
183-
large: .system(size: 14, weight: .regular)
157+
/// The animation scale configuration for components.
158+
public var animationScale: AnimationScale = .init(
159+
small: 0.99,
160+
medium: 0.98,
161+
large: 0.95
184162
)
185-
)
186163

187-
// MARK: - Initialization
164+
/// The typography configuration for components.
165+
public var typography: Typography = .init(
166+
headline: .init(
167+
small: .system(size: 14, weight: .semibold),
168+
medium: .system(size: 20, weight: .semibold),
169+
large: .system(size: 28, weight: .semibold)
170+
),
171+
body: .init(
172+
small: .system(size: 14, weight: .regular),
173+
medium: .system(size: 16, weight: .regular),
174+
large: .system(size: 18, weight: .regular)
175+
),
176+
button: .init(
177+
small: .system(size: 14, weight: .medium),
178+
medium: .system(size: 16, weight: .medium),
179+
large: .system(size: 20, weight: .medium)
180+
),
181+
caption: .init(
182+
small: .system(size: 10, weight: .regular),
183+
medium: .system(size: 12, weight: .regular),
184+
large: .system(size: 14, weight: .regular)
185+
)
186+
)
187+
188+
// MARK: - Initialization
188189

189-
/// Initializes a new `Layout` instance with default values.
190-
public init() {}
190+
/// Initializes a new `Layout` instance with default values.
191+
public init() {}
192+
}
191193
}

0 commit comments

Comments
 (0)