Files
iOS/Sources/Shared/DesignSystem/Components/ModalReusableButton.swift
Bruno Pantaleão Gonçalves cbaac4acf9 Improve mac empty state UI (#4813)
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->
<img width="2542" height="1494" alt="CleanShot 2026-06-23 at 15 37
01@2x"
src="https://github.com/user-attachments/assets/02570900-d21f-4f56-9ad5-396e19f20c4f"
/>

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-06-23 16:35:51 +02:00

67 lines
1.7 KiB
Swift

#if !os(watchOS)
import SFSafeSymbols
import SwiftUI
public struct ModalReusableButton: View {
public enum Icon {
case sfSymbol(SFSymbol)
case mdi(MaterialDesignIcons)
}
private let action: () -> Void
private let tint: Color
private let icon: Icon
private let imageSize: CGSize = .init(width: 16, height: 16)
/// A reusable icon-only button intended for modal headers/toolbars (executes `action` when tapped).
public init(
tint: Color = Color.secondary,
icon: Icon,
action: @escaping (() -> Void)
) {
self.action = action
self.icon = icon
self.tint = tint
}
public var body: some View {
Button(action: {
action()
}, label: {
image
.modify { view in
if #available(iOS 26.0, *) {
view
.padding(DesignSystem.Spaces.oneAndHalf)
.glassEffect(.clear.interactive(), in: .circle)
} else {
view
}
}
})
.buttonStyle(.plain)
.foregroundStyle(tint)
}
private var image: some View {
Group {
switch icon {
case let .sfSymbol(sFSymbol):
Image(systemSymbol: sFSymbol)
.resizable()
.frame(width: imageSize.width, height: imageSize.height)
case let .mdi(materialDesignIcons):
Image(uiImage: materialDesignIcons.image(ofSize: imageSize, color: UIColor(tint)))
}
}
}
}
#Preview {
ModalReusableButton(icon: .sfSymbol(.heart), action: {
/* no-op */
})
}
#endif