wake-ios/wake/Components/Buttons/ReturnButton.swift
2025-09-02 20:31:13 +08:00

124 lines
3.3 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.

//
// ReturnButton.swift
// wake
//
// Created by Junhui on 2025/8/19.
//
import SwiftUI
///
struct ReturnButton: View {
let action: () -> Void
var iconName: String = "chevron.left"
var iconSize: TypographyStyle = .title
var iconColor: Color = .primary
var body: some View {
Button(action: action) {
Image(systemName: iconName)
.font(Typography.font(for: iconSize))
.fontWeight(.medium)
.foregroundColor(iconColor)
.padding(10) //
.contentShape(Rectangle()) // 使
}
.buttonStyle(PlainButtonStyle())
}
}
///
struct ReturnButtonWithText: View {
let action: () -> Void
let text: String
var iconName: String = "chevron.left"
var spacing: CGFloat = 4
var textStyle: TypographyStyle = .body
var iconColor: Color = .primary
var textColor: Color = .primary
var body: some View {
Button(action: action) {
HStack(spacing: spacing) {
Image(systemName: iconName)
.font(Typography.font(for: textStyle, family: .quicksandRegular))
.fontWeight(.medium)
.foregroundColor(iconColor)
Text(text)
.font(Typography.font(for: textStyle, family: .quicksandRegular))
.foregroundColor(textColor)
}
}
.buttonStyle(PlainButtonStyle())
}
}
///
struct CircularReturnButton: View {
let action: () -> Void
var iconName: String = "chevron.left"
var size: CGFloat = 40
var backgroundColor: Color = Color(.systemBackground)
var iconColor: Color = .primary
var shadowRadius: CGFloat = 4
var body: some View {
Button(action: action) {
Image(systemName: iconName)
.font(Typography.font(for: .body, family: .quicksandRegular))
.foregroundColor(iconColor)
.frame(width: size, height: size)
.background(backgroundColor)
.clipShape(Circle())
.shadow(color: Color.black.opacity(0.1), radius: shadowRadius, x: 0, y: 2)
}
.buttonStyle(PlainButtonStyle())
}
}
#Preview("基础返回按钮") {
VStack(spacing: 20) {
HStack {
ReturnButton {
print("返回")
}
Spacer()
}
.padding()
Spacer()
}
.background(Color(.systemGroupedBackground))
}
#Preview("带文字返回按钮") {
VStack(spacing: 20) {
HStack {
ReturnButtonWithText(action: {
print("返回")
}, text: "Back")
Spacer()
}
.padding()
Spacer()
}
.background(Color(.systemGroupedBackground))
}
#Preview("圆形返回按钮") {
VStack(spacing: 20) {
HStack {
CircularReturnButton {
print("返回")
}
Spacer()
}
.padding()
Spacer()
}
.background(Color(.systemGroupedBackground))
}