-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #482 from ensan-hcl/feat/sf_symbols_picker
feat: SF Symbolsの選択が簡単になるPickerを追加
- Loading branch information
Showing
3 changed files
with
117 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// | ||
// SystemIconPicker.swift | ||
// azooKey | ||
// | ||
// Created by miwa on 2024/10/07. | ||
// Copyright © 2024 DevEn3. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SystemIconPicker: View { | ||
init( | ||
icon: Binding<String>, | ||
recommendation: [String] = [ | ||
"doc.on.doc", | ||
"doc.on.doc.fill", | ||
"doc.on.clipboard", | ||
"doc.on.clipboard.fill", | ||
"scissors", | ||
"delete.left", | ||
"delete.left.fill", | ||
"delete.right", | ||
"delete.right.fill", | ||
"heart", | ||
"clear", | ||
"clear.fill", | ||
"arrowtriangle.left.and.line.vertical.and.arrowtriangle.right", | ||
"arrowtriangle.left.and.line.vertical.and.arrowtriangle.right.fill", | ||
"xmark", | ||
"shift", | ||
"shift.fill", | ||
"capslock", | ||
"capslock.fill", | ||
"globe", | ||
"keyboard.chevron.compact.down", | ||
"keyboard.chevron.compact.down.fill", | ||
"space", | ||
"return", | ||
"command", | ||
] | ||
) { | ||
self._icon = icon | ||
self.recommendation = recommendation | ||
} | ||
|
||
private var recommendation: [String] | ||
|
||
@Binding var icon: String | ||
|
||
var body: some View { | ||
LazyVGrid(columns: Array(repeating: GridItem(), count: 5)) { // カラム数の指定 | ||
ForEach(recommendation.indices, id: \.self) { index in | ||
Button { | ||
self.icon = self.recommendation[index] | ||
} label: { | ||
if self.icon == self.recommendation[index] { | ||
Image(systemName: self.recommendation[index]) | ||
.frame(width: 45, height: 45) | ||
.foregroundStyle(.white) | ||
.background(.tint) | ||
.cornerRadius(10) | ||
} else { | ||
Image(systemName: self.recommendation[index]) | ||
.frame(width: 45, height: 45) | ||
} | ||
} | ||
.buttonStyle(.plain) | ||
} | ||
} | ||
HStack { | ||
TextField("ID", text: $icon, prompt: Text("SF SymbolsのIDを指定")) | ||
.textFieldStyle(.roundedBorder) | ||
.monospaced() | ||
.keyboardType(.asciiCapable) | ||
.submitLabel(.done) | ||
Image(systemName: self.icon) | ||
.frame(width: 45, height: 45) | ||
.foregroundStyle(.white) | ||
.background(.tint) | ||
.cornerRadius(10) | ||
} | ||
.padding(.horizontal) | ||
} | ||
} | ||
|
||
@available(iOS 17, *) | ||
#Preview { | ||
@Previewable @State var icon = "star" | ||
return SystemIconPicker(icon: $icon) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters