Skip to content

Commit b11a5c4

Browse files
authored
Merge pull request #5 from pommdau/feature/change-the-title-to-localizedstring
feat: change the title to optional LocalizedString
2 parents 204f302 + 8891d1b commit b11a5c4

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Sources/FontPicker/FontPicker.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,23 @@ class FontPickerDelegate {
2222
}
2323

2424
public struct FontPicker: View {
25-
let labelString: String
25+
let label: LocalizedStringKey?
2626

2727
@Binding var font: NSFont
28-
@State var fontPickerDelegate: FontPickerDelegate? = nil
28+
@State var fontPickerDelegate: FontPickerDelegate?
2929

30-
public init(_ label: String, selection: Binding<NSFont>) {
31-
self.labelString = label
30+
public init(_ titlekey: LocalizedStringKey? = nil, selection: Binding<NSFont>) {
31+
self.label = titlekey
3232
self._font = selection
3333
}
3434

3535
public var body: some View {
3636
HStack {
37-
Text(labelString)
37+
if let label {
38+
Text(label)
39+
} else {
40+
EmptyView()
41+
}
3842

3943
Button {
4044
if NSFontPanel.shared.isVisible {
@@ -65,6 +69,9 @@ public struct FontPicker: View {
6569

6670
struct FontPicker_Previews: PreviewProvider {
6771
static var previews: some View {
68-
FontPicker("font", selection: .constant(NSFont.systemFont(ofSize: 24)))
72+
Group {
73+
FontPicker("font", selection: .constant(NSFont.systemFont(ofSize: 24)))
74+
FontPicker(selection: .constant(NSFont.systemFont(ofSize: 24)))
75+
}
6976
}
7077
}

0 commit comments

Comments
 (0)