Files
RedLintu16andClaude Opus 5.5 64ec524ba0 CrossSound for Apple platforms
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-10-14 13:28:34 -07:00

133 lines
4.1 KiB
Swift
Executable File

// Outlined — CrossSound's stand-ins for the library pieces that FILL
// themselves: text fields, pills, alerts and the app's own toasts / banners.
//
// The rule they share with BareButtons.swift: no coloured background. Each is
// primary text on the page colour, told apart by an outline — 2pt hair for a
// field (the artwork edge), 2pt primary for a notice (the now-playing edge),
// 1pt primary for a badge, which is too small to carry 2.
//
// CrossSound only; RedWhiteUI's RwPill / RwAlert / RwTextFieldStyle are
// untouched for every other app.
import RedWhiteUI
import SwiftUI
// MARK: - Text fields
/// No well and no fill: a 2pt hair outline that turns primary while focused.
/// The library field's padding and type, so swapping it moves nothing. The
/// default for every TextField (CrossSoundLook); `.bare` names it where a
/// call site used to say `.rw`.
struct BareFieldStyle: TextFieldStyle {
@Environment(\.rw) private var p
@Environment(\.rwFontFamily) private var family
@FocusState private var focused: Bool
func _body(configuration: TextField<Self._Label>) -> some View {
configuration
.textFieldStyle(.plain)
.focused($focused)
.font(RwTextRole.labelLarge.font(family: family))
.foregroundStyle(p.text.color)
.padding(EdgeInsets(top: 13, leading: 16, bottom: 13, trailing: 16))
.outlined(focused ? p.red : p.hair)
.animation(.easeOut(duration: 0.12), value: focused)
}
}
extension TextFieldStyle where Self == BareFieldStyle {
static var bare: BareFieldStyle { BareFieldStyle() }
}
extension View {
/// A square outline of [color], drawn inside the frame — what the fields
/// and wells here wear instead of a fill. 2pt unless said otherwise.
func outlined(_ color: RwColor, width: CGFloat = 2) -> some View {
overlay(Rectangle().strokeBorder(color.color, lineWidth: width).allowsHitTesting(false))
}
}
// MARK: - Badges
/// Stands in for `RwPill`: the same small uppercase label, primary on the
/// page colour with a 1pt primary edge instead of a fill.
struct OutlinedBadge: View {
@Environment(\.rw) private var p
@Environment(\.rwFontFamily) private var family
let label: String
var systemImage: String? = nil
init(_ label: String, systemImage: String? = nil) {
self.label = label
self.systemImage = systemImage
}
var body: some View {
HStack(spacing: 4) {
if let systemImage {
Image(systemName: systemImage)
.font(.system(size: 10, weight: .bold))
}
Text(label.uppercased())
.rw(.labelSmall, color: p.red.color)
}
.foregroundStyle(p.red.color)
.padding(.horizontal, 10)
.padding(.vertical, 4)
.outlined(p.red, width: 1)
}
}
// MARK: - Notices
/// Stands in for `RwAlert`: an icon and a message, primary on the page colour
/// inside a 2pt primary edge — one look for errors and successes alike, since
/// the status colours are red here anyway (BareButtons.swift).
struct OutlinedNotice: View {
@Environment(\.rw) private var p
let message: String
var systemImage = "info.circle"
init(_ message: String, systemImage: String = "info.circle") {
self.message = message
self.systemImage = systemImage
}
var body: some View {
HStack(alignment: .top, spacing: 10) {
Image(systemName: systemImage)
.font(.system(size: 15, weight: .semibold))
Text(message)
.rw(.bodySmall)
.lineSpacing(3)
.frame(maxWidth: .infinity, alignment: .leading)
}
.foregroundStyle(p.red.color)
.padding(.horizontal, 14)
.padding(.vertical, 12)
.noticeChrome()
}
}
extension View {
/// The notice look for a toast or banner built in place: the page colour
/// behind it (it floats over content, so it must stay opaque) and a 2pt
/// primary edge. Colour the content itself primary — `.rw()` text already
/// is.
func noticeChrome() -> some View {
modifier(NoticeChrome())
}
}
private struct NoticeChrome: ViewModifier {
@Environment(\.rw) private var p
func body(content: Content) -> some View {
content
.background(p.bg.color)
.outlined(p.red)
}
}