Repository Public License
1// ORIX Scan2// File: Packages/ORIXKit/Sources/ORIXDesign/Components.swift3// Description: Reusable ORIX components: cards, buttons, chips, section headers, empty states, banners, progress, the page frame.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import SwiftUI89// MARK: Surfaces1011public struct ORIXCard: ViewModifier {12 var padding: CGFloat13 public func body(content: Content) -> some View {14 content15 .padding(padding)16 .background(ORIX.Palette.surface, in: RoundedRectangle(cornerRadius: ORIX.Radius.card, style: .continuous))17 .overlay(RoundedRectangle(cornerRadius: ORIX.Radius.card, style: .continuous).strokeBorder(ORIX.Palette.hairline.opacity(0.7), lineWidth: 0.5))18 }19}2021public extension View {22 /// Standard ORIX card surface.23 func orixCard(padding: CGFloat = ORIX.Space.md) -> some View { modifier(ORIXCard(padding: padding)) }2425 /// The soft, low shadow used under document pages and floating controls. One elevation only: ORIX stays flat elsewhere.26 func orixLift(_ enabled: Bool = true) -> some View {27 shadow(color: .black.opacity(enabled ? 0.14 : 0), radius: 10, x: 0, y: 4)28 }29}3031// MARK: Buttons3233/// The primary call to action: accent gradient, large target.34public struct ORIXPrimaryButtonStyle: ButtonStyle {35 @Environment(\.orixAccent) private var accent36 @Environment(\.isEnabled) private var isEnabled37 public init() {}38 public func makeBody(configuration: Configuration) -> some View {39 configuration.label40 .font(.orixHeadline)41 .foregroundStyle(ORIX.Palette.onAccent)42 .frame(maxWidth: .infinity, minHeight: 52)43 .padding(.horizontal, ORIX.Space.md)44 .background(accent.gradient, in: RoundedRectangle(cornerRadius: ORIX.Radius.control, style: .continuous))45 .opacity(isEnabled ? (configuration.isPressed ? 0.85 : 1) : 0.45)46 .scaleEffect(configuration.isPressed ? 0.98 : 1)47 .animation(ORIX.Motion.quick, value: configuration.isPressed)48 }49}5051/// Secondary action: tinted fill.52public struct ORIXSecondaryButtonStyle: ButtonStyle {53 @Environment(\.orixAccent) private var accent54 @Environment(\.isEnabled) private var isEnabled55 public init() {}56 public func makeBody(configuration: Configuration) -> some View {57 configuration.label58 .font(.orixHeadline)59 .foregroundStyle(accent.primary)60 .frame(maxWidth: .infinity, minHeight: 48)61 .padding(.horizontal, ORIX.Space.md)62 .background(accent.primary.opacity(configuration.isPressed ? 0.2 : 0.12), in: RoundedRectangle(cornerRadius: ORIX.Radius.control, style: .continuous))63 .opacity(isEnabled ? 1 : 0.45)64 .animation(ORIX.Motion.quick, value: configuration.isPressed)65 }66}6768/// A square tile with a symbol and a label (home quick actions, tool grids).69public struct ORIXTileButtonStyle: ButtonStyle {70 public init() {}71 public func makeBody(configuration: Configuration) -> some View {72 configuration.label73 .frame(maxWidth: .infinity, minHeight: 84)74 .padding(ORIX.Space.sm)75 .background(ORIX.Palette.surface, in: RoundedRectangle(cornerRadius: ORIX.Radius.card, style: .continuous))76 .overlay(RoundedRectangle(cornerRadius: ORIX.Radius.card, style: .continuous).strokeBorder(ORIX.Palette.hairline.opacity(0.7), lineWidth: 0.5))77 .scaleEffect(configuration.isPressed ? 0.97 : 1)78 .animation(ORIX.Motion.quick, value: configuration.isPressed)79 }80}8182public extension ButtonStyle where Self == ORIXPrimaryButtonStyle { static var orixPrimary: ORIXPrimaryButtonStyle { .init() } }83public extension ButtonStyle where Self == ORIXSecondaryButtonStyle { static var orixSecondary: ORIXSecondaryButtonStyle { .init() } }84public extension ButtonStyle where Self == ORIXTileButtonStyle { static var orixTile: ORIXTileButtonStyle { .init() } }8586/// Symbol on a tinted rounded square: the standard ORIX leading glyph for rows and tiles.87public struct ORIXGlyph: View {88 @Environment(\.orixAccent) private var accent89 let systemName: String90 var tint: Color?91 var size: CGFloat92 public init(_ systemName: String, tint: Color? = nil, size: CGFloat = 36) {93 self.systemName = systemName94 self.tint = tint95 self.size = size96 }97 public var body: some View {98 let color = tint ?? accent.primary99 Image(systemName: systemName)100 .font(.system(size: size * 0.46, weight: .semibold))101 .foregroundStyle(color)102 .frame(width: size, height: size)103 .background(color.opacity(0.13), in: RoundedRectangle(cornerRadius: size * 0.3, style: .continuous))104 .accessibilityHidden(true)105 }106}107108// MARK: Labels109110public struct ORIXSectionHeader<Trailing: View>: View {111 let title: LocalizedStringKey112 let trailing: Trailing113 public init(_ title: LocalizedStringKey, @ViewBuilder trailing: () -> Trailing = { EmptyView() }) {114 self.title = title115 self.trailing = trailing()116 }117 public var body: some View {118 HStack(alignment: .firstTextBaseline) {119 Text(title).font(.orixTitle).foregroundStyle(ORIX.Palette.textPrimary).accessibilityAddTraits(.isHeader)120 Spacer(minLength: ORIX.Space.xs)121 trailing122 }123 }124}125126/// A compact status or metadata chip.127public struct ORIXChip: View {128 let text: Text129 var systemName: String?130 var tint: Color131 public init(_ text: Text, systemName: String? = nil, tint: Color = ORIX.Palette.textSecondary) {132 self.text = text133 self.systemName = systemName134 self.tint = tint135 }136 public var body: some View {137 HStack(spacing: 4) {138 if let systemName { Image(systemName: systemName).imageScale(.small).accessibilityHidden(true) }139 text140 }141 .font(.orixCaption)142 .foregroundStyle(tint)143 .padding(.horizontal, 8)144 .padding(.vertical, 4)145 .background(tint.opacity(0.12), in: Capsule())146 }147}148149// MARK: States150151public struct ORIXEmptyState<Actions: View>: View {152 @Environment(\.orixAccent) private var accent153 let systemName: String154 let title: LocalizedStringKey155 let message: LocalizedStringKey156 let actions: Actions157 public init(systemName: String, title: LocalizedStringKey, message: LocalizedStringKey, @ViewBuilder actions: () -> Actions = { EmptyView() }) {158 self.systemName = systemName159 self.title = title160 self.message = message161 self.actions = actions()162 }163 public var body: some View {164 VStack(spacing: ORIX.Space.md) {165 ZStack {166 Circle().fill(accent.primary.opacity(0.1)).frame(width: 96, height: 96)167 Image(systemName: systemName).font(.system(size: 38, weight: .medium)).foregroundStyle(accent.primary)168 }169 .accessibilityHidden(true)170 VStack(spacing: ORIX.Space.xs) {171 Text(title).font(.orixTitle).foregroundStyle(ORIX.Palette.textPrimary).multilineTextAlignment(.center)172 Text(message).font(.orixCallout).foregroundStyle(ORIX.Palette.textSecondary).multilineTextAlignment(.center)173 }174 actions175 }176 .frame(maxWidth: 420)177 .padding(ORIX.Space.xl)178 .frame(maxWidth: .infinity, maxHeight: .infinity)179 }180}181182public enum ORIXBannerKind: Sendable { case info, success, warning, error }183184/// Inline message with an icon; never colour alone (icon and text carry the meaning).185public struct ORIXBanner<Trailing: View>: View {186 @Environment(\.orixAccent) private var accent187 let kind: ORIXBannerKind188 let title: Text189 let message: Text?190 let trailing: Trailing191 public init(_ kind: ORIXBannerKind, title: Text, message: Text? = nil, @ViewBuilder trailing: () -> Trailing = { EmptyView() }) {192 self.kind = kind193 self.title = title194 self.message = message195 self.trailing = trailing()196 }197 private var tint: Color {198 switch kind { case .info: accent.primary; case .success: ORIX.Palette.success; case .warning: ORIX.Palette.warning; case .error: ORIX.Palette.danger }199 }200 private var symbol: String {201 switch kind {202 case .info: "info.circle.fill"; case .success: "checkmark.circle.fill"203 case .warning: "exclamationmark.triangle.fill"; case .error: "xmark.octagon.fill"204 }205 }206 public var body: some View {207 HStack(alignment: .top, spacing: ORIX.Space.sm) {208 Image(systemName: symbol).foregroundStyle(tint).font(.body.weight(.semibold)).accessibilityHidden(true)209 VStack(alignment: .leading, spacing: 2) {210 title.font(.orixHeadline).foregroundStyle(ORIX.Palette.textPrimary)211 if let message { message.font(.orixCallout).foregroundStyle(ORIX.Palette.textSecondary) }212 }213 Spacer(minLength: 0)214 trailing215 }216 .padding(ORIX.Space.sm)217 .background(tint.opacity(0.1), in: RoundedRectangle(cornerRadius: ORIX.Radius.control, style: .continuous))218 .accessibilityElement(children: .combine)219 }220}221222/// Determinate progress with a label and the ORIX beam colour.223public struct ORIXProgressBar: View {224 @Environment(\.orixAccent) private var accent225 let value: Double226 public init(value: Double) { self.value = value }227 public var body: some View {228 GeometryReader { proxy in229 ZStack(alignment: .leading) {230 Capsule().fill(ORIX.Palette.surfaceRaised)231 Capsule()232 .fill(LinearGradient(colors: [accent.primary, accent.secondary], startPoint: .leading, endPoint: .trailing))233 .frame(width: max(6, proxy.size.width * min(max(value, 0), 1)))234 }235 }236 .frame(height: 6)237 .animation(ORIX.Motion.standard, value: value)238 .accessibilityElement()239 .accessibilityValue(Text(value, format: .percent.precision(.fractionLength(0))))240 }241}242243// MARK: Documents244245/// Frames a page image as paper: near-square corners, hairline, soft lift.246public struct ORIXPageFrame: ViewModifier {247 var lifted: Bool248 public func body(content: Content) -> some View {249 content250 .clipShape(RoundedRectangle(cornerRadius: ORIX.Radius.page, style: .continuous))251 .overlay(RoundedRectangle(cornerRadius: ORIX.Radius.page, style: .continuous).strokeBorder(.black.opacity(0.08), lineWidth: 0.5))252 .orixLift(lifted)253 }254}255256public extension View {257 func orixPage(lifted: Bool = true) -> some View { modifier(ORIXPageFrame(lifted: lifted)) }258}259260/// The ORIX signature: a thin luminous beam sweeping over content while it is being processed.261public struct ORIXScanBeam: ViewModifier {262 @Environment(\.orixAccent) private var accent263 @Environment(\.accessibilityReduceMotion) private var reduceMotion264 let active: Bool265 @State private var phase: CGFloat = 0266 public func body(content: Content) -> some View {267 content.overlay {268 if active && !reduceMotion {269 GeometryReader { proxy in270 Rectangle()271 .fill(accent.beam)272 .frame(height: 3)273 .shadow(color: accent.secondary.opacity(0.8), radius: 8)274 .offset(y: phase * proxy.size.height)275 .onAppear {276 phase = 0277 withAnimation(.easeInOut(duration: 1.5).repeatForever(autoreverses: true)) { phase = 1 }278 }279 }280 .allowsHitTesting(false)281 .accessibilityHidden(true)282 }283 }284 }285}286287public extension View {288 func orixScanBeam(active: Bool) -> some View { modifier(ORIXScanBeam(active: active)) }289}290291/// The ORIX mark drawn in code: four viewfinder arcs forming the "O", crossed by the beam.292public struct ORIXMark: View {293 @Environment(\.orixAccent) private var accent294 var ring: Color?295 public init(ring: Color? = nil) { self.ring = ring }296 public var body: some View {297 Canvas { context, size in298 let side = min(size.width, size.height)299 let center = CGPoint(x: size.width / 2, y: size.height / 2)300 let radius = side * 0.34301 let width = side * 0.11302 for quadrant in 0..<4 {303 let start = Angle.degrees(Double(quadrant) * 90 + 16), end = Angle.degrees(Double(quadrant) * 90 + 74)304 var path = Path()305 path.addArc(center: center, radius: radius, startAngle: start, endAngle: end, clockwise: false)306 context.stroke(path, with: .color(ring ?? accent.primary), style: StrokeStyle(lineWidth: width, lineCap: .round))307 }308 var beam = Path()309 beam.move(to: CGPoint(x: center.x - side * 0.47, y: center.y))310 beam.addLine(to: CGPoint(x: center.x + side * 0.47, y: center.y))311 context.stroke(beam, with: .color(accent.secondary), style: StrokeStyle(lineWidth: side * 0.045, lineCap: .round))312 }313 .aspectRatio(1, contentMode: .fit)314 .accessibilityHidden(true)315 }316}317