73 lines
1.7 KiB
Swift
73 lines
1.7 KiB
Swift
//
|
|
// WorkoutIconSelector.swift
|
|
// WorkoutsPlus
|
|
//
|
|
// Created by Felix Förtsch on 26.08.24.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct WorkoutIconSelector: View {
|
|
|
|
@State private var selectedColor: Color = .black
|
|
@State private var selectedIcon: String?
|
|
|
|
@State private var searchText: String = ""
|
|
var filteredIcons: [String] {
|
|
if searchText.isEmpty {
|
|
return fitnessIcons
|
|
} else {
|
|
return fitnessIcons.filter { $0.contains(searchText.lowercased()) }
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
ScrollView {
|
|
LazyVGrid(columns: [GridItem(.adaptive(minimum: 50))]) {
|
|
ForEach(systemColors, id: \.self) { color in
|
|
Button(action: {
|
|
selectedColor = color
|
|
}) {
|
|
Circle()
|
|
.fill(color)
|
|
.frame(width: 40, height: 40)
|
|
.overlay(
|
|
Circle()
|
|
.stroke(Color.white, lineWidth: selectedColor == color ? 4 : 0)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
.padding()
|
|
LazyVGrid(columns: [GridItem(.adaptive(minimum: 50, maximum: 100))]) {
|
|
ForEach(filteredIcons, id: \.self) { iconName in
|
|
Button(action: {
|
|
selectedIcon = iconName
|
|
}) {
|
|
Image(systemName: iconName)
|
|
.foregroundStyle(selectedColor)
|
|
.padding()
|
|
.background()
|
|
.cornerRadius(8)
|
|
}
|
|
}
|
|
}
|
|
.padding()
|
|
.searchable(text: $searchText)
|
|
}
|
|
.overlay {
|
|
if filteredIcons.isEmpty {
|
|
ContentUnavailableView.search
|
|
}
|
|
}
|
|
|
|
.navigationTitle("Select a Workout Icon")
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
NavigationView() {
|
|
WorkoutIconSelector()
|
|
}
|
|
}
|