Files
AlloVoisinsSwiftUI/AlloVoisinsSwiftUI/Core/Views/Sequoia/Components/SQToast.swift
Victor Bodinaud 6e711be25d 🏗️ Reorganize files
2024-11-14 10:07:56 +01:00

82 lines
2.5 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// SQToast.swift
//
//
// Created by Victor on 18/07/2024.
//
import SwiftUI
struct SQToast: View {
var title: String
var content: String
var style: SQToastStyle = .info
var hasClose: Bool = false
func backgroundColor() -> Color {
switch style {
case .danger:
.red
case .warning:
.orange
case .info:
.blue
case .success:
.green
}
}
init(_ title: String = "", content: String, style: SQToastStyle = .success, hasClose: Bool = false) {
self.title = title
self.content = content
self.style = style
self.hasClose = hasClose
}
var body: some View {
VStack {
HStack(spacing: 16) {
VStack(alignment: .leading) {
if !title.isEmpty {
SQText(title, font: .bold)
}
SQText(content, size: 14, font: .demiBold)
}
Spacer()
if hasClose {
Button {
} label: {
SQIcon(.xmark, size: .s, color: .sqNeutral(10))
}
}
}
.frame(maxWidth: .infinity)
.foregroundStyle(.white)
.padding(16)
.background(backgroundColor())
.cornerRadius(8)
}.padding(.horizontal)
}
}
enum SQToastStyle {
case danger
case warning
case info
case success
}
#Preview {
VStack(spacing: 16) {
SQToast("Restriction géolocalisation", content: "Nous navons pas réussi à vous géolocaliser.", style: .warning, hasClose: true)
SQToast("Restriction géolocalisation", content: "Nous navons pas réussi à vous géolocaliser.")
SQToast("Restriction géolocalisation", content: "Nous navons pas réussi à vous géolocaliser.", style: .danger, hasClose: true)
SQToast("Restriction géolocalisation", content: "Nous navons pas réussi à vous géolocaliser.", style: .info)
SQToast(content: "Nous navons pas réussi à vous géolocaliser.", style: .warning)
SQToast(content: "Nous navons pas réussi à vous géolocaliser.", hasClose: true)
SQToast(content: "Nous navons pas réussi à vous géolocaliser.", style: .danger)
SQToast(content: "Nous navons pas réussi à vous géolocaliser.", style: .info, hasClose: true)
}
}