import SwiftUI import BucksleyKit /// A dollar figure in the theme's figure face, with tabular digits. public struct MoneyText: View { @Environment(\.palette) private var palette let value: Decimal let size: CGFloat var cents = true var signed = false var colored = false var weight: Font.Weight = .semibold public init(_ value: Decimal, size: CGFloat = 13, cents: Bool = true, signed: Bool = false, colored: Bool = false, weight: Font.Weight = .semibold) { self.value = value; self.size = size; self.cents = cents; self.signed = signed; self.colored = colored; self.weight = weight } public var body: some View { Text(Money.format(value, cents: cents, signed: signed)) .font(palette.figure(size, weight: weight)) .tracking(palette.figureTracking) .monospacedDigit() .foregroundStyle(colored ? (value > 0 ? palette.gain : value < 0 ? palette.loss : palette.text) : (value > 0 && signed ? palette.gain : palette.text)) .lineLimit(1) .fixedSize(horizontal: true, vertical: false) } } /// The big net worth number: "$184,046" with smaller cents, like the Afterhours hero. public struct HeroMoney: View { @Environment(\.palette) private var palette let value: Decimal let size: CGFloat public init(_ value: Decimal, size: CGFloat = 40) { self.value = value; self.size = size } public var body: some View { let text = Money.format(value) let parts = text.split(separator: ".", maxSplits: 1) HStack(alignment: .firstTextBaseline, spacing: 0) { Text(parts.first.map(String.init) ?? text).font(palette.figure(size, weight: .semibold)).tracking(palette.theme == .afterhours ? -2 : -0.5) if parts.count == 2 { Text("." + parts[1]).font(palette.figure(size * 0.5, weight: .medium)).foregroundStyle(palette.muted) } } .monospacedDigit() .lineLimit(1) .minimumScaleFactor(0.5) .accessibilityLabel(text) } } public struct SectionHeader: View { @Environment(\.palette) private var palette let title: String let trailing: Trailing public init(_ title: String, @ViewBuilder trailing: () -> Trailing = { EmptyView() }) { self.title = title; self.trailing = trailing() } public var body: some View { HStack(alignment: .firstTextBaseline) { Group { if palette.theme == .afterhours { Text(title.uppercased()).tracking(1.1).foregroundStyle(palette.muted) } else { Text(title).foregroundStyle(palette.theme == .almanac ? palette.text : palette.text) } } .font(palette.sectionFont) .accessibilityAddTraits(.isHeader) Spacer(minLength: 8) trailing } .padding(.bottom, palette.ruled ? 6 : 2) .overlay(alignment: .bottom) { if palette.ruled { Rectangle().fill(palette.text).frame(height: 1) } } } } /// A themed surface: filled rounded card (Afterhours, Evergreen) or a ruled block (Almanac). public struct Panel: View { @Environment(\.palette) private var palette let padding: CGFloat let content: Content public init(padding: CGFloat = 16, @ViewBuilder content: () -> Content) { self.padding = padding; self.content = content() } public var body: some View { content .padding(palette.ruled ? EdgeInsets(top: padding * 0.75, leading: 0, bottom: padding * 0.75, trailing: 0) : EdgeInsets(top: padding, leading: padding, bottom: padding, trailing: padding)) .frame(maxWidth: .infinity, alignment: .leading) .background { if palette.ruled { VStack { Rectangle().fill(palette.text).frame(height: 2); Spacer() } } else { RoundedRectangle(cornerRadius: palette.cardRadius, style: .continuous).fill(palette.card) } } } } /// Initials in a colored circle (rounded square in Afterhours), as in the design's transaction rows. public struct MerchantBadge: View { @Environment(\.palette) private var palette let name: String let colorIndex: Int var size: CGFloat = 30 var brand: Color? public init(name: String, colorIndex: Int, size: CGFloat = 30, brand: Color? = nil) { self.name = name; self.colorIndex = colorIndex; self.size = size; self.brand = brand } public var body: some View { let words = name.split(separator: " ").filter { $0.first?.isLetter == true } let initials = (words.count >= 2 ? String(words[0].prefix(1) + words[1].prefix(1)) : String(name.filter(\.isLetter).prefix(1))).uppercased() let tint = brand ?? palette.color(colorIndex) Text(initials.isEmpty ? "$" : initials) .font(.system(size: size * 0.38, weight: .bold)) .foregroundStyle(palette.dark ? tint : tint.opacity(0.95)) .frame(width: size, height: size) .background(tint.opacity(palette.dark ? 0.2 : 0.14), in: RoundedRectangle(cornerRadius: palette.theme == .evergreen ? size / 2 : size * 0.28, style: .continuous)) .accessibilityHidden(true) } } /// A category as a small colored pill. public struct CategoryTag: View { @Environment(\.palette) private var palette let category: BucksleyKit.Category? public init(_ category: BucksleyKit.Category?) { self.category = category } public var body: some View { let tint = palette.color(category?.colorIndex ?? 5) HStack(spacing: 4) { Text(category?.icon ?? "❔").font(.system(size: 10.5)).italic(false) Text(category?.name ?? "Uncategorized") } .font(.system(size: 11, weight: palette.theme == .almanac ? .regular : .bold, design: palette.theme == .almanac ? .serif : .default)) .italic(palette.theme == .almanac) .padding(.horizontal, palette.theme == .almanac ? 0 : 9).padding(.vertical, palette.theme == .almanac ? 0 : 4) .foregroundStyle(palette.theme == .almanac ? palette.muted : tint) .background(palette.theme == .almanac ? Color.clear : tint.opacity(palette.dark ? 0.2 : 0.14), in: Capsule()) .lineLimit(1) } } /// One transaction line: date, badge, name with category and account, amount. public struct TransactionRow: View { @Environment(\.palette) private var palette let entry: LedgerEntry let workspace: Workspace var showDate = true var showAccount = false public init(_ entry: LedgerEntry, workspace: Workspace, showDate: Bool = true, showAccount: Bool = false) { self.entry = entry; self.workspace = workspace; self.showDate = showDate; self.showAccount = showAccount } public var body: some View { let category = workspace.category(entry.categoryID) HStack(spacing: 12) { if showDate { Text(Self.shortDay(entry.day)).font(palette.theme == .afterhours ? palette.figure(11, weight: .regular) : .system(size: 11)) .foregroundStyle(palette.muted).frame(width: 44, alignment: .leading) } MerchantBadge(name: entry.name, colorIndex: category?.colorIndex ?? 5) VStack(alignment: .leading, spacing: 6) { HStack(spacing: 6) { Text(entry.name).font(.system(size: 13, weight: .semibold)).lineLimit(1) if entry.transaction.pending { Text("Pending").font(.system(size: 10, weight: .semibold)).foregroundStyle(palette.muted) } if !entry.reviewed { Circle().fill(palette.accent).frame(width: 6, height: 6).accessibilityLabel("Not reviewed") } } HStack(spacing: 8) { CategoryTag(category) if showAccount, let account = workspace.account(entry.accountID) { Text(account.displayName).font(.system(size: 11)).foregroundStyle(palette.muted).lineLimit(1) } if entry.note != nil { Image(systemName: "text.bubble").font(.system(size: 10)).foregroundStyle(palette.muted) } if !entry.splits.isEmpty { Image(systemName: "arrow.triangle.branch").font(.system(size: 10)).foregroundStyle(palette.muted) } } } Spacer(minLength: 8) MoneyText(entry.amount, size: 13, signed: true) .strikethrough(entry.excluded) } .padding(.vertical, 10) .contentShape(Rectangle()) } public static func shortDay(_ day: String) -> String { guard let d = DayKey.date(day) else { return day } return d.formatted(.dateTime.month(.abbreviated).day()) } } /// A small swatch of a theme for the Settings rows, the same idea as Inkspring's theme previews. public struct ThemeSwatch: View { let theme: BucksleyTheme let dark: Bool public init(theme: BucksleyTheme, dark: Bool) { self.theme = theme; self.dark = dark } public var body: some View { let p = BucksleyPalette(theme: theme, dark: dark) VStack(alignment: .leading, spacing: 3) { Capsule().fill(p.accent).frame(width: 18, height: 3) HStack(alignment: .bottom, spacing: 2) { ForEach(0..<4, id: \.self) { i in RoundedRectangle(cornerRadius: 1).fill(p.color(i)).frame(width: 4, height: CGFloat(6 + i * 3)) } } RoundedRectangle(cornerRadius: 2).fill(p.card).frame(width: 30, height: 6) .overlay { RoundedRectangle(cornerRadius: 2).strokeBorder(p.line) } } .padding(6) .frame(width: 46, height: 38, alignment: .topLeading) .background(p.canvas, in: .rect(cornerRadius: 6)) .overlay { RoundedRectangle(cornerRadius: 6).strokeBorder(p.line) } .accessibilityHidden(true) } } /// The primary-colored button used for main actions. public struct PrimaryButtonStyle: ButtonStyle { @Environment(\.palette) private var palette public init() {} public func makeBody(configuration: Configuration) -> some View { configuration.label .font(.system(size: 13, weight: .semibold)) .padding(.horizontal, 14).padding(.vertical, 7) .foregroundStyle(palette.theme == .almanac ? palette.canvas : palette.accentText) .background(palette.theme == .almanac ? palette.text : palette.accent, in: Capsule()) .opacity(configuration.isPressed ? 0.8 : 1) } } public struct SecondaryButtonStyle: ButtonStyle { @Environment(\.palette) private var palette public init() {} public func makeBody(configuration: Configuration) -> some View { configuration.label .font(.system(size: 13, weight: .semibold)) .padding(.horizontal, 14).padding(.vertical, 7) .foregroundStyle(palette.text) .background(palette.card, in: Capsule()) .overlay { Capsule().strokeBorder(palette.line) } .opacity(configuration.isPressed ? 0.8 : 1) } } /// Pill segmented control in the theme's style (range pickers, tabs). public struct PillPicker: View { @Environment(\.palette) private var palette let options: [(Value, String)] @Binding var selection: Value public init(_ options: [(Value, String)], selection: Binding) { self.options = options; _selection = selection } public var body: some View { HStack(spacing: 2) { ForEach(options.indices, id: \.self) { i in let (value, label) = options[i] let on = value == selection Button { selection = value } label: { Text(label).font(.system(size: 11, weight: .bold)) .padding(.horizontal, 10).padding(.vertical, 4) .foregroundStyle(on ? (palette.theme == .almanac ? palette.canvas : palette.accentText) : palette.muted) .background(on ? (palette.theme == .almanac ? palette.text : palette.accent) : .clear, in: Capsule()) .contentShape(Capsule()) } .buttonStyle(.plain) .accessibilityAddTraits(on ? .isSelected : []) } } .padding(2) .background(palette.card, in: Capsule()) } } /// The shared "A Project ATOM app" brand pill, copied from Inkspring and Jotley: black capsule, /// 22 pt logo, white semibold label, the same in every theme and appearance. public struct ProtomotaProductPill: View { public init() {} public var body: some View { Link(destination: URL(string: "https://jobley.ai/volunteer/")!) { HStack(spacing: 10) { Image("ProjectAtomLogo") .renderingMode(.original) .resizable() .scaledToFit() .frame(width: 22, height: 22) .clipShape(.rect(cornerRadius: 6)) .accessibilityHidden(true) Text("A Project ATOM app") .font(.system(size: 13.5, weight: .semibold)) .lineLimit(1) Image(systemName: "arrow.up.right") .font(.caption.weight(.medium)) .accessibilityHidden(true) } .fixedSize() .padding(.leading, 10) .padding(.trailing, 16) .padding(.vertical, 9) .foregroundStyle(.white) .background(Color(hex: 0x0B0E16), in: Capsule()) .overlay { Capsule().strokeBorder(Color(hex: 0x1D2230)) } .contentShape(Capsule()) } .buttonStyle(.plain) .accessibilityIdentifier("settings.protomotaProduct") #if os(macOS) .help("Explore Project ATOM volunteer work") #endif } }