generated from StanfordBDHG/SwiftPackageTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Add InfoButton for list rows ## ♻️ Current situation & Problem This PR adds a new icon-only `InfoButton` that is useful in List views to provide additional context to a row element. ## ⚙️ Release Notes * Added new `InfoButton`. ## 📚 Documentation Added the new button to the documentation catalog. ## ✅ Testing Tested via UI tests. ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
- Loading branch information
Showing
16 changed files
with
267 additions
and
31 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
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
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,69 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import SwiftUI | ||
|
||
|
||
/// Icon-only info button. | ||
/// | ||
/// You can use this button, e.g., on the trailing side of a list row to provide additional information about an entity. | ||
public struct InfoButton: View { | ||
private let label: Text | ||
private let action: () -> Void | ||
|
||
public var body: some View { | ||
Button(action: action) { | ||
SwiftUI.Label { | ||
label | ||
} icon: { | ||
Image(systemName: "info.circle") // swiftlint:disable:this accessibility_label_for_image | ||
} | ||
} | ||
.labelStyle(.iconOnly) | ||
.font(.title3) | ||
.foregroundColor(.accentColor) | ||
.buttonStyle(.borderless) // ensure button is clickable next to the other button | ||
.accessibilityIdentifier("info-button") | ||
.accessibilityAction(named: label, action) | ||
} | ||
|
||
/// Create a new info button. | ||
/// - Parameters: | ||
/// - label: The text label. This is not shown but useful for accessibility. | ||
/// - action: The button action. | ||
public init(_ label: Text, action: @escaping () -> Void) { | ||
self.label = label | ||
self.action = action | ||
} | ||
|
||
/// Create a new info button. | ||
/// - Parameters: | ||
/// - resource: The localized button label. This is not shown but useful for accessibility. | ||
/// - action: The button action. | ||
public init(_ resource: LocalizedStringResource, action: @escaping () -> Void) { | ||
self.label = Text(resource) | ||
self.action = action | ||
} | ||
} | ||
|
||
|
||
#if DEBUG | ||
#Preview { | ||
List { | ||
Button { | ||
print("Primary") | ||
} label: { | ||
ListRow("Entry") { | ||
InfoButton("Entry Info") { | ||
print("Info") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
#endif |
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,105 @@ | ||
// | ||
// This source file is part of the Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import SwiftUI | ||
|
||
|
||
/// Header view for Lists or Forms. | ||
/// | ||
/// A header view that can be used in List or Form views. | ||
public struct ListHeader<Image: View, Title: View, Instructions: View>: View { | ||
private let image: Image | ||
private let title: Title | ||
private let instructions: Instructions | ||
|
||
|
||
public var body: some View { | ||
VStack { | ||
VStack { | ||
image | ||
.foregroundColor(.accentColor) | ||
.symbolRenderingMode(.multicolor) | ||
.font(.custom("XXL", size: 50, relativeTo: .title)) | ||
.accessibilityHidden(true) | ||
title | ||
.accessibilityAddTraits(.isHeader) | ||
.font(.title) | ||
.bold() | ||
.padding(.bottom, 4) | ||
} | ||
.accessibilityElement(children: .combine) | ||
instructions | ||
.padding([.leading, .trailing], 25) | ||
} | ||
.multilineTextAlignment(.center) | ||
.frame(maxWidth: .infinity) | ||
} | ||
|
||
/// Create a new list header. | ||
/// - Parameters: | ||
/// - image: The image view. | ||
/// - title: The title view. | ||
public init(@ViewBuilder image: () -> Image, @ViewBuilder title: () -> Title) where Instructions == EmptyView { | ||
self.init(image: image, title: title) { | ||
EmptyView() | ||
} | ||
} | ||
|
||
/// Create a new list header. | ||
/// - Parameters: | ||
/// - image: The image view. | ||
/// - title: The title view. | ||
/// - instructions: The instructions subheadline. | ||
public init(@ViewBuilder image: () -> Image, @ViewBuilder title: () -> Title, @ViewBuilder instructions: () -> Instructions) { | ||
self.image = image() | ||
self.title = title() | ||
self.instructions = instructions() | ||
} | ||
|
||
/// Create a new list header. | ||
/// - Parameters: | ||
/// - systemImage: The name of the system symbol image. | ||
/// - title: The title view. | ||
public init(systemImage: String, @ViewBuilder title: () -> Title) where Image == SwiftUI.Image, Instructions == EmptyView { | ||
// swiftlint:disable:next accessibility_label_for_image | ||
self.init(image: { SwiftUI.Image(systemName: systemImage) }, title: title) { | ||
EmptyView() | ||
} | ||
} | ||
|
||
/// Create a new list header. | ||
/// - Parameters: | ||
/// - systemImage: The name of the system symbol image. | ||
/// - title: The title view. | ||
/// - instructions: The instructions subheadline. | ||
public init(systemImage: String, @ViewBuilder title: () -> Title, @ViewBuilder instructions: () -> Instructions) where Image == SwiftUI.Image { | ||
// swiftlint:disable:next accessibility_label_for_image | ||
self.init(image: { SwiftUI.Image(systemName: systemImage) }, title: title, instructions: instructions) | ||
} | ||
} | ||
|
||
|
||
#if DEBUG | ||
#Preview { | ||
List { | ||
ListHeader(systemImage: "person.fill.badge.plus") { | ||
Text("Create a new Account", bundle: .module) | ||
} instructions: { | ||
Text("Please fill out the details below to create your new account.", bundle: .module) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
List { | ||
ListHeader(systemImage: "person.fill.badge.plus") { | ||
Text("Create a new Account", bundle: .module) | ||
} | ||
} | ||
} | ||
#endif |
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
Binary file added
BIN
+89.3 KB
...wsTests/__Snapshots__/SnapshotTests/testListHeader.list-header-instructions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+74.3 KB
Tests/SpeziViewsTests/__Snapshots__/SnapshotTests/testListHeader.list-header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -76,6 +76,12 @@ | |
}, | ||
"Enter your details" : { | ||
|
||
}, | ||
"Entity" : { | ||
|
||
}, | ||
"Entity Info" : { | ||
|
||
}, | ||
"Error Description" : { | ||
|
||
|
Oops, something went wrong.