Skip to content

Commit ceffdfa

Browse files
committed
Add example
1 parent 6043f55 commit ceffdfa

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

Example/SettingExample/PreferencesView.swift

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -225,45 +225,23 @@ struct PreferencesView: View {
225225
}
226226
.previewIcon(icon: .system(icon: "paintbrush.fill", backgroundColor: Color(hex: model.color)))
227227

228-
SettingPage(
229-
title: "Mode",
230-
selectedChoice: "Normal",
231-
previewConfiguration: .init(
232-
icon: .system(icon: "paintbrush.fill", backgroundColor: Color(hex: model.color))
233-
)
234-
) {
235-
SettingCustomView(id: "Color Picker Preview") {
236-
VStack {
237-
if #available(iOS 16.0, macOS 13.0, *) {
238-
Rectangle()
239-
.fill(Color(hex: model.color).gradient)
240-
} else {
241-
Rectangle()
242-
.fill(Color(hex: model.color))
243-
}
228+
SettingPage(title: "Extras", selectedChoice: "Hello, world!") {
229+
SettingGroup {
230+
SettingButton(title: "Hello, world!") {
231+
print("Hello world pressed!")
244232
}
245-
.frame(height: 100)
246-
.cornerRadius(12)
247-
.shadow(color: .black.opacity(0.25), radius: 12, x: 0, y: 6)
248-
.padding(.horizontal, 16)
233+
.icon(icon: .system(icon: "ellipsis", backgroundColor: Color.teal))
249234
}
250-
235+
251236
SettingGroup {
252-
SettingText(title: "Choose a Color")
253-
254-
SettingCustomView(id: "Color Picker") {
255-
let binding = Binding {
256-
Color(hex: model.color)
257-
} set: { newValue in
258-
model.color = Int(newValue.hex)
259-
}
260-
261-
ColorPicker("Color", selection: binding)
262-
.padding(.horizontal, 16)
263-
.padding(.vertical, 10)
237+
SettingButton(title: ":)") {
238+
print(":) pressed!")
264239
}
240+
.icon(icon: .system(icon: "sparkles", backgroundColor: Color.pink))
241+
.indicator("face.smiling")
265242
}
266243
}
244+
.previewIcon(icon: .system(icon: "ellipsis", backgroundColor: Color.teal))
267245
}
268246

269247
SettingGroup {

Sources/Views/SettingButton.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,29 @@ struct SettingButtonView: View {
8989
.buttonStyle(.row)
9090
}
9191
}
92+
93+
public extension SettingButton {
94+
func icon(_ icon: String, color: Color = .blue) -> SettingButton {
95+
var button = self
96+
button.icon = .system(icon: icon, backgroundColor: color)
97+
return button
98+
}
99+
100+
func icon(_ icon: String, foregroundColor: Color = .white, backgroundColor: Color = .blue) -> SettingButton {
101+
var button = self
102+
button.icon = .system(icon: icon, foregroundColor: foregroundColor, backgroundColor: backgroundColor)
103+
return button
104+
}
105+
106+
func icon(icon: SettingIcon) -> SettingButton {
107+
var button = self
108+
button.icon = icon
109+
return button
110+
}
111+
112+
func indicator(_ indicator: String) -> SettingButton {
113+
var button = self
114+
button.indicator = indicator
115+
return button
116+
}
117+
}

0 commit comments

Comments
 (0)