Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ContentUnavailableView #1484

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@ let package = Package(
),
dependencies: []
),

// Unfortunately, this tool cannot be a plugin due to limitations on network access.
// Once SwiftPM supports plugins with network access, this can become a plugin again.
.executableTarget(
name: "TutorialRepoGenerator",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "Markdown", package: "swift-markdown"),
]
),

.macro(
name: "LiveViewNativeMacros",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ struct _AnyGesture: ParseableModifierValue {
}
#endif

@MainActor
@ParseableExpression
struct LongPress {
static let name = "LongPressGesture"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import LiveViewNativeStylesheet

#if os(macOS) || os(visionOS)
@available(macOS 15, visionOS 2, *)
extension PointerStyle: @retroactive ParseableModifierValue {
extension PointerStyle: ParseableModifierValue {
public static func parser(in context: ParseableModifierContext) -> some Parser<Substring.UTF8View, Self> {
ImplicitStaticMember {
OneOf {
Expand Down Expand Up @@ -144,7 +144,7 @@ extension VerticalDirection.Set: ParseableModifierValue {

#if os(macOS)
@available(macOS 15.0, *)
extension FrameResizeDirection.Set: @retroactive ParseableModifierValue {
extension FrameResizeDirection.Set: ParseableModifierValue {
public static func parser(in context: ParseableModifierContext) -> some Parser<Substring.UTF8View, Self> {
OneOf {
Array<Self.Element>.parser(in: context).map({ Self.init($0) })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//
// ContentUnavailableView.swift
// LiveViewNative
//
// Created by Carson Katri on 11/12/24.
//

import SwiftUI

/// An interface that indicates content is missing or unavailable.
///
/// ```html
/// <ContentUnavailableView>
/// <Label systemImage="tray.fill">No Mail</Label>
///
/// <Text template="description">
/// New mails you receive will appear here.
/// </Text>
///
/// <Group template="actions">
/// <Button phx-click="refresh">Check Again</Button>
/// </Group>
/// </ContentUnavailableView>
/// ```
///
/// You can also create a default `search` view:
///
/// ```html
/// <ContentUnavailableView search />
/// ```
///
/// Optionally `search` to the search query string:
///
/// ```html
/// <ContentUnavailableView search={@query} />
/// ```
///
/// ## Attributes
/// * ``search``
/// * ``image``
/// * ``systemImage``
/// * ``description``
///
/// ## Children
/// * `label` - Describes the current value.
/// * `description` - Describes the current value.
/// * `actions` - Describes the current value.
@_documentation(visibility: public)
@LiveElement
struct ContentUnavailableView<Root: RootRegistry>: View {
/// The search query string.
@_documentation(visibility: public)
private var search: String?

/// An image to use for the label.
@_documentation(visibility: public)
private var image: String?

/// A system image to use for the label.
@_documentation(visibility: public)
private var systemImage: String?

/// A description of the unavailable content.
@_documentation(visibility: public)
private var description: String?

public var body: some View {
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) {
if let search {
if search.isEmpty {
SwiftUI.ContentUnavailableView.search
} else {
SwiftUI.ContentUnavailableView.search(text: search)
}
} else {
SwiftUI.ContentUnavailableView {
if let image {
SwiftUI.Label {
$liveElement.children(in: "label", default: true)
} icon: {
SwiftUI.Image(image)
}
} else if let systemImage {
SwiftUI.Label {
$liveElement.children(in: "label", default: true)
} icon: {
SwiftUI.Image(systemName: systemImage)
}
} else {
$liveElement.children(in: "label", default: true)
}
} description: {
if let description {
SwiftUI.Text(description)
} else {
$liveElement.children(in: "description")
}
} actions: {
$liveElement.children(in: "actions")
}
}
}
}
}
120 changes: 0 additions & 120 deletions Sources/TutorialRepoGenerator/Executable.swift

This file was deleted.

20 changes: 0 additions & 20 deletions Sources/TutorialRepoGenerator/Project.swift

This file was deleted.

Loading
Loading