Skip to content

Commit 113407a

Browse files
committed
Improve SwiftUI previews
1 parent 2d69bfb commit 113407a

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

CotEditor/Sources/InsetTextField.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99
// ---------------------------------------------------------------------------
1010
//
11-
// © 2022-2023 1024jp
11+
// © 2022-2024 1024jp
1212
//
1313
// Licensed under the Apache License, Version 2.0 (the "License");
1414
// you may not use this file except in compliance with the License.
@@ -190,7 +190,9 @@ final class PaddingTextField: NSTextField {
190190
// MARK: - Preview
191191

192192
#Preview {
193-
InsetTextField(text: .constant(""), prompt: "Prompt")
193+
@State var text = ""
194+
195+
return InsetTextField(text: $text, prompt: "Prompt")
194196
.inset(.leading, 20)
195197
.frame(width: 160)
196198
}

CotEditor/Sources/RegexTextField.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99
// ---------------------------------------------------------------------------
1010
//
11-
// © 2023 1024jp
11+
// © 2023-2024 1024jp
1212
//
1313
// Licensed under the Apache License, Version 2.0 (the "License");
1414
// you may not use this file except in compliance with the License.
@@ -122,6 +122,8 @@ struct RegexTextField: NSViewRepresentable {
122122
// MARK: - Preview
123123

124124
#Preview {
125-
RegexTextField(text: .constant("[^abc]def"))
125+
@State var text = "[^abc]def"
126+
127+
return RegexTextField(text: $text)
126128
.leadingInset(20)
127129
}

CotEditor/Sources/StepperNumberField.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ private extension Binding where Value == Int {
115115

116116
// MARK: - Preview
117117

118-
struct StepperNumberField_Previews: PreviewProvider {
118+
#Preview {
119+
@State var value = 4
119120

120-
static var previews: some View {
121-
122-
StepperNumberField(value: .constant(4), in: 0...10)
123-
}
121+
return StepperNumberField(value: $value, in: 0...10)
124122
}

CotEditor/Sources/ThemeEditorView.swift

+10-6
Original file line numberDiff line numberDiff line change
@@ -311,20 +311,24 @@ private extension Theme.Metadata {
311311

312312
// MARK: - Preview
313313

314-
#Preview {
314+
@available(macOS 14, *)
315+
#Preview(traits: .fixedLayout(width: 360, height: 280)) {
315316
ThemeEditorView(ThemeManager.shared.setting(name: "Anura")!, isBundled: false) { _ in }
316-
.frame(width: 360, height: 280)
317317
}
318318

319319
#Preview("Metadata (editable)") {
320-
ThemeMetadataView(metadata: .constant(.init(
320+
@State var metadata = Theme.Metadata(
321321
author: "Clarus",
322322
distributionURL: "https://coteditor.com"
323-
)), isEditable: true)
323+
)
324+
325+
return ThemeMetadataView(metadata: $metadata, isEditable: true)
324326
}
325327

326328
#Preview("Metadata (fixed)") {
327-
ThemeMetadataView(metadata: .constant(.init(
329+
@State var metadata = Theme.Metadata(
328330
author: "Claus"
329-
)), isEditable: false)
331+
)
332+
333+
return ThemeMetadataView(metadata: $metadata, isEditable: false)
330334
}

0 commit comments

Comments
 (0)