Skip to content

Commit 96c8a70

Browse files
Merge pull request #36 from componentskit/refactor/config
Refactor
2 parents e7470b4 + 09a2729 commit 96c8a70

File tree

81 files changed

+1328
-888
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1328
-888
lines changed

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

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@ struct ComponentColorPicker: View {
4040
var body: some View {
4141
Picker("Color", selection: self.$selection) {
4242
Text("Primary").tag(ComponentColor.primary)
43-
Text("Secondary").tag(ComponentColor.secondary)
4443
Text("Accent").tag(ComponentColor.accent)
4544
Text("Success").tag(ComponentColor.success)
4645
Text("Warning").tag(ComponentColor.warning)
4746
Text("Danger").tag(ComponentColor.danger)
4847
Text("Custom").tag(ComponentColor(
4948
main: .universal(.uiColor(.systemPurple)),
50-
contrast: .universal(.uiColor(.systemYellow)))
51-
)
49+
contrast: .universal(.uiColor(.systemYellow))
50+
))
5251
}
5352
}
5453
}
@@ -62,15 +61,14 @@ struct ComponentOptionalColorPicker: View {
6261
Picker("Color", selection: self.$selection) {
6362
Text("Default").tag(Optional<ComponentColor>.none)
6463
Text("Primary").tag(ComponentColor.primary)
65-
Text("Secondary").tag(ComponentColor.secondary)
6664
Text("Accent").tag(ComponentColor.accent)
6765
Text("Success").tag(ComponentColor.success)
6866
Text("Warning").tag(ComponentColor.warning)
6967
Text("Danger").tag(ComponentColor.danger)
7068
Text("Custom").tag(ComponentColor(
7169
main: .universal(.uiColor(.systemPurple)),
72-
contrast: .universal(.uiColor(.systemYellow)))
73-
)
70+
contrast: .universal(.uiColor(.systemYellow))
71+
))
7472
}
7573
}
7674
}
@@ -93,18 +91,84 @@ struct CornerRadiusPicker<Custom: View>: View {
9391
}
9492
}
9593

96-
// MARK: - FontPicker
94+
// MARK: - FontPickers
9795

98-
struct FontPicker: View {
96+
struct BodyFontPicker: View {
97+
let title: String
98+
@Binding var selection: UniversalFont?
99+
100+
init(title: String = "Font", selection: Binding<UniversalFont?>) {
101+
self.title = title
102+
self._selection = selection
103+
}
104+
105+
var body: some View {
106+
Picker(self.title, selection: self.$selection) {
107+
Text("Default").tag(Optional<UniversalFont>.none)
108+
Text("Small").tag(UniversalFont.smBody)
109+
Text("Medium").tag(UniversalFont.mdBody)
110+
Text("Large").tag(UniversalFont.lgBody)
111+
Text("Custom: system semibold of size 16").tag(UniversalFont.system(size: 16, weight: .semibold))
112+
}
113+
}
114+
}
115+
116+
struct ButtonFontPicker: View {
117+
let title: String
118+
@Binding var selection: UniversalFont?
119+
120+
init(title: String = "Font", selection: Binding<UniversalFont?>) {
121+
self.title = title
122+
self._selection = selection
123+
}
124+
125+
var body: some View {
126+
Picker(self.title, selection: self.$selection) {
127+
Text("Default").tag(Optional<UniversalFont>.none)
128+
Text("Small").tag(UniversalFont.smButton)
129+
Text("Medium").tag(UniversalFont.mdButton)
130+
Text("Large").tag(UniversalFont.lgButton)
131+
Text("Custom: system bold of size 16").tag(UniversalFont.system(size: 16, weight: .bold))
132+
}
133+
}
134+
}
135+
136+
struct HeadlineFontPicker: View {
137+
let title: String
99138
@Binding var selection: UniversalFont?
139+
140+
init(title: String = "Font", selection: Binding<UniversalFont?>) {
141+
self.title = title
142+
self._selection = selection
143+
}
100144

101145
var body: some View {
102-
Picker("Font", selection: self.$selection) {
146+
Picker(self.title, selection: self.$selection) {
147+
Text("Default").tag(Optional<UniversalFont>.none)
148+
Text("Small").tag(UniversalFont.smHeadline)
149+
Text("Medium").tag(UniversalFont.mdHeadline)
150+
Text("Large").tag(UniversalFont.lgHeadline)
151+
Text("Custom: system bold of size 20").tag(UniversalFont.system(size: 20, weight: .bold))
152+
}
153+
}
154+
}
155+
156+
struct CaptionFontPicker: View {
157+
let title: String
158+
@Binding var selection: UniversalFont?
159+
160+
init(title: String = "Font", selection: Binding<UniversalFont?>) {
161+
self.title = title
162+
self._selection = selection
163+
}
164+
165+
var body: some View {
166+
Picker(self.title, selection: self.$selection) {
103167
Text("Default").tag(Optional<UniversalFont>.none)
104-
Text("Small").tag(UniversalFont.Component.small)
105-
Text("Medium").tag(UniversalFont.Component.medium)
106-
Text("Large").tag(UniversalFont.Component.large)
107-
Text("Custom: system bold of size 18").tag(UniversalFont.system(size: 18, weight: .bold))
168+
Text("Small").tag(UniversalFont.smCaption)
169+
Text("Medium").tag(UniversalFont.mdCaption)
170+
Text("Large").tag(UniversalFont.lgCaption)
171+
Text("Custom: system semibold of size 12").tag(UniversalFont.system(size: 12, weight: .semibold))
108172
}
109173
}
110174
}
@@ -173,7 +237,6 @@ struct UniversalColorPicker: View {
173237
var body: some View {
174238
Picker(self.title, selection: self.$selection) {
175239
Text("Primary").tag(UniversalColor.primary)
176-
Text("Secondary").tag(UniversalColor.secondary)
177240
Text("Accent").tag(UniversalColor.accent)
178241
Text("Success").tag(UniversalColor.success)
179242
Text("Warning").tag(UniversalColor.warning)

Examples/DemosApp/DemosApp/ComponentsPreview/Helpers/PreviewWrapper.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ struct PreviewWrapper<Content: View>: View {
2121
LinearGradient(
2222
gradient: Gradient(
2323
colors: [
24-
Palette.Brand.blue.color(for: self.colorScheme),
25-
Palette.Brand.purple.color(for: self.colorScheme)
24+
UniversalColor.blue.color(for: self.colorScheme),
25+
UniversalColor.purple.color(for: self.colorScheme),
2626
]
2727
),
2828
startPoint: .topLeading,
@@ -42,3 +42,16 @@ struct PreviewWrapper<Content: View>: View {
4242
.padding(.horizontal)
4343
}
4444
}
45+
46+
// MARK: - Colors
47+
48+
extension UniversalColor {
49+
fileprivate static let blue: Self = .themed(
50+
light: .hex("#3684F8"),
51+
dark: .hex("#0058DB")
52+
)
53+
fileprivate static let purple: Self = .themed(
54+
light: .hex("#A920FD"),
55+
dark: .hex("#7800C1")
56+
)
57+
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ struct ButtonPreview: View {
1818
}
1919
Form {
2020
AnimationScalePicker(selection: self.$model.animationScale)
21-
ComponentColorPicker(selection: self.$model.color)
21+
ComponentOptionalColorPicker(selection: self.$model.color)
2222
CornerRadiusPicker(selection: self.$model.cornerRadius) {
2323
Text("Custom: 20px").tag(ComponentRadius.custom(20))
2424
}
25-
FontPicker(selection: self.$model.font)
25+
ButtonFontPicker(selection: self.$model.font)
2626
Toggle("Enabled", isOn: self.$model.isEnabled)
2727
Toggle("Full Width", isOn: self.$model.isFullWidth)
2828
SizePicker(selection: self.$model.size)
@@ -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
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct CheckboxPreview: View {
3434
CornerRadiusPicker(selection: self.$model.cornerRadius) {
3535
Text("Custom: 2px").tag(ComponentRadius.custom(2))
3636
}
37-
FontPicker(selection: self.$model.font)
37+
BodyFontPicker(selection: self.$model.font)
3838
Toggle("Enabled", isOn: self.$model.isEnabled)
3939
SizePicker(selection: self.$model.size)
4040
}

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/CountdownPreview.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ struct CountdownPreview: View {
1616
}
1717
Form {
1818
ComponentOptionalColorPicker(selection: self.$model.color)
19-
FontPicker(selection: self.$model.font)
2019
Picker("Locale", selection: self.$model.locale) {
2120
Text("Current").tag(Locale.current)
2221
Text("EN").tag(Locale(identifier: "en"))
@@ -30,6 +29,8 @@ struct CountdownPreview: View {
3029
Text("HI").tag(Locale(identifier: "hi"))
3130
Text("PT").tag(Locale(identifier: "pt"))
3231
}
32+
HeadlineFontPicker(title: "Main Font", selection: self.$model.mainFont)
33+
CaptionFontPicker(title: "Secondary Font", selection: self.$model.secondaryFont)
3334
SizePicker(selection: self.$model.size)
3435
Picker("Style", selection: self.$model.style) {
3536
Text("Plain").tag(CountdownVM.Style.plain)

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/DividerPreview.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@ struct DividerPreview: View {
1515
SUDivider(model: self.model)
1616
}
1717
Form {
18+
Picker("Color", selection: self.$model.color) {
19+
Text("Default").tag(Optional<ComponentColor>.none)
20+
Text("Primary").tag(ComponentColor.primary)
21+
Text("Accent").tag(ComponentColor.accent)
22+
Text("Success").tag(ComponentColor.success)
23+
Text("Warning").tag(ComponentColor.warning)
24+
Text("Danger").tag(ComponentColor.danger)
25+
Text("Custom").tag(ComponentColor(
26+
main: .universal(.uiColor(.systemPurple)),
27+
contrast: .universal(.uiColor(.systemYellow))
28+
))
29+
}
1830
Picker("Orientation", selection: self.$model.orientation) {
1931
Text("Horizontal").tag(DividerVM.Orientation.horizontal)
2032
Text("Vertical").tag(DividerVM.Orientation.vertical)
2133
}
2234
SizePicker(selection: self.$model.size)
23-
Picker("Color", selection: self.$model.color) {
24-
Text("Default").tag(Palette.Base.divider)
25-
Text("Primary").tag(UniversalColor.primary)
26-
Text("Secondary").tag(UniversalColor.secondary)
27-
Text("Accent").tag(UniversalColor.accent)
28-
Text("Success").tag(UniversalColor.success)
29-
Text("Warning").tag(UniversalColor.warning)
30-
Text("Danger").tag(UniversalColor.danger)
31-
Text("Custom").tag(UniversalColor.universal(.uiColor(.systemPurple)))
32-
}
3335
}
3436
}
3537
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct InputFieldPreview: View {
1717
self.inputField
1818
.preview
1919
.onAppear {
20+
self.inputField.text = ""
2021
self.inputField.model = Self.initialModel
2122
}
2223
.onChange(of: self.model) { newValue in
@@ -38,7 +39,7 @@ struct InputFieldPreview: View {
3839
Text("Custom: 20px").tag(ComponentRadius.custom(20))
3940
}
4041
Toggle("Enabled", isOn: self.$model.isEnabled)
41-
FontPicker(selection: self.$model.font)
42+
BodyFontPicker(selection: self.$model.font)
4243
KeyboardTypePicker(selection: self.$model.keyboardType)
4344
Toggle("Placeholder", isOn: .init(
4445
get: {

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/RadioGroupPreview.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct RadioGroupPreview: View {
3333
AnimationScalePicker(selection: self.$model.animationScale)
3434
UniversalColorPicker(title: "Color", selection: self.$model.color)
3535
Toggle("Enabled", isOn: self.$model.isEnabled)
36-
FontPicker(selection: self.$model.font)
36+
BodyFontPicker(selection: self.$model.font)
3737
SizePicker(selection: self.$model.size)
3838
Picker("Spacing", selection: self.$model.spacing) {
3939
Text("8px").tag(CGFloat(8))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct SegmentedControlPreview: View {
4646
Text("Custom: 4px").tag(ComponentRadius.custom(4))
4747
}
4848
Toggle("Enabled", isOn: self.$model.isEnabled)
49-
FontPicker(selection: self.$model.font)
49+
BodyFontPicker(selection: self.$model.font)
5050
Toggle("Full Width", isOn: self.$model.isFullWidth)
5151
SizePicker(selection: self.$model.size)
5252
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct TextInputPreviewPreview: View {
1717
self.textInput
1818
.preview
1919
.onAppear {
20+
self.textInput.text = ""
2021
self.textInput.model = Self.initialModel
2122
}
2223
.onChange(of: self.model) { newValue in
@@ -38,7 +39,7 @@ struct TextInputPreviewPreview: View {
3839
Text("Custom: 20px").tag(ComponentRadius.custom(20))
3940
}
4041
Toggle("Enabled", isOn: self.$model.isEnabled)
41-
FontPicker(selection: self.$model.font)
42+
BodyFontPicker(selection: self.$model.font)
4243
KeyboardTypePicker(selection: self.$model.keyboardType)
4344
Picker("Max Rows", selection: self.$model.maxRows) {
4445
Text("2 Rows").tag(2)

0 commit comments

Comments
 (0)