SPB Git

Repository Public

Buttons.swift 6.5 KB 161 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Claude Remote / Codex Remote9// File             : Packages/ClaudeRemoteKit/Sources/ClaudeRemoteDesign/Buttons.swift10// Module           : ClaudeRemoteDesign11// Repository       : https://git.spboucher.ai/claude-remote-apple12// Project Website  : https://claude.spboucher.ai13// Created          : 2026-11-2914// Last Modified    : 2026-11-2915//16// =============================================================================17// AUTHOR & PROFESSIONAL AFFILIATION18// =============================================================================19//20// Author           : Simon-Pierre Boucher21// Position         : Professor of Finance22// Institution      : Université du Québec en Outaouais (UQO)23// Department       : Département des sciences administratives24// Organization     : SP Boucher25//26// Website          : https://spboucher.ai27// Git              : https://git.spboucher.ai28//29// =============================================================================30// OFFICIAL CONTACT DIRECTORY31// =============================================================================32//33// General          : info@spboucher.ai34// Professional     : contact@spboucher.ai35// Direct           : simon@spboucher.ai36// Research         : research@spboucher.ai37// Development      : dev@spboucher.ai38// Support          : support@spboucher.ai39// Security/Admin   : admin@spboucher.ai40// Notifications    : notifications@spboucher.ai41//42// Preferred Contact: support@spboucher.ai43//44// =============================================================================45// COPYRIGHT & INTELLECTUAL PROPERTY46// =============================================================================47//48// Copyright (c) 202649// Simon-Pierre Boucher50//51// All rights reserved where applicable.52//53// This file is governed by the applicable project license,54// copyright notices, institutional agreements and relevant law.55//56// Unless expressly authorized by the applicable license or57// rights holder, copying, redistribution, sublicensing,58// publication and commercial exploitation are not permitted.59//60// Existing third-party rights and notices remain unaffected.61//62// =============================================================================63// CONFIDENTIALITY & SECURITY64// =============================================================================65//66// Classification   : Public67// Distribution     : Public repository; use is governed by the project license68// Security Contact : admin@spboucher.ai69//70// Access to this source does not independently grant permission71// to redistribute or disclose confidential materials.72//73// Do not embed credentials, private keys, access tokens,74// certificates or confidential personal information.75//76// =============================================================================77// LICENSE & MAINTENANCE78// =============================================================================79//80// License          : None specified (no license file in this repository)81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import SwiftUI8990/// Minimum hit target: 44 pt on iOS / iPadOS, compact on macOS.91public enum CRControlSize {92    #if os(iOS)93    public static let minHeight: CGFloat = 4494    #else95    public static let minHeight: CGFloat = 2896    #endif97}9899private struct CRButtonBody: View {100    @Environment(\.isEnabled) private var isEnabled101    @Environment(\.accessibilityReduceMotion) private var reduceMotion102    let configuration: ButtonStyleConfiguration103    let foreground: Color104    let background: AnyShapeStyle105    let border: Color?106107    var body: some View {108        let shape = RoundedRectangle(cornerRadius: CRRadius.sm, style: .continuous)109        configuration.label110            .font(.callout.weight(.semibold))111            .foregroundStyle(foreground)112            .padding(.horizontal, CRSpacing.lg)113            .padding(.vertical, CRSpacing.xs)114            .frame(minHeight: CRControlSize.minHeight)115            .background(background, in: shape)116            .overlay(border.map { shape.strokeBorder($0, lineWidth: 1) })117            .opacity(isEnabled ? (configuration.isPressed ? 0.82 : 1) : 0.45)118            .scaleEffect(configuration.isPressed && !reduceMotion ? 0.98 : 1)119            .animation(CRMotion.animation(.quick, reduceMotion: reduceMotion), value: configuration.isPressed)120            .contentShape(shape)121    }122}123124/// Filled accent button (one per screen: the main action).125public struct CRPrimaryButtonStyle: ButtonStyle {126    @Environment(\.crTheme) private var theme127    public init() {}128    public func makeBody(configuration: Configuration) -> some View {129        CRButtonBody(configuration: configuration, foreground: theme.onAccent.color,130                     background: AnyShapeStyle(theme.accent.color), border: nil)131    }132}133134/// Quiet bordered button.135public struct CRSecondaryButtonStyle: ButtonStyle {136    public init() {}137    public func makeBody(configuration: Configuration) -> some View {138        CRButtonBody(configuration: configuration, foreground: CRPalette.text.color,139                     background: AnyShapeStyle(CRPalette.surface2.color), border: CRPalette.line2.color)140    }141}142143/// Destructive action (terminate, delete, revoke). Pair it with a confirmation or `reauthenticate`.144public struct CRDestructiveButtonStyle: ButtonStyle {145    public init() {}146    public func makeBody(configuration: Configuration) -> some View {147        CRButtonBody(configuration: configuration, foreground: CRPalette.error.color,148                     background: AnyShapeStyle(CRPalette.errorVivid.color.opacity(0.12)), border: CRPalette.errorVivid.color.opacity(0.35))149    }150}151152extension ButtonStyle where Self == CRPrimaryButtonStyle {153    public static var crPrimary: CRPrimaryButtonStyle { .init() }154}155extension ButtonStyle where Self == CRSecondaryButtonStyle {156    public static var crSecondary: CRSecondaryButtonStyle { .init() }157}158extension ButtonStyle where Self == CRDestructiveButtonStyle {159    public static var crDestructive: CRDestructiveButtonStyle { .init() }160}161
Files main
Menu

Theme