# KeyUI Components The KeyUI components provide the user interface for the Keys for All system, including the main panel, activation views, and visual indicators. ## Main Components ### KeysForAllPanel ```swift struct KeysForAllPanel: View { @StateObject private var keyManager = KeyManager.shared @State private var showActivation = false @State private var showPurchase = false @State private var selectedTab = 0 var body: some View { VStack(spacing: 0) { // Header KeysHeaderView(currentLevel: keyManager.currentLicenseLevel) // Tab Selection Picker("View", selection: $selectedTab) { Text("Status").tag(0) Text("Purchase").tag(1) Text("Share").tag(2) } .pickerStyle(SegmentedPickerStyle()) .padding() // Content ScrollView { switch selectedTab { case 0: LicenseStatusView() case 1: PurchaseOptionsView() case 2: KeySharingView() default: EmptyView() } } } .navigationTitle("Keys for All") .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button("Have a Key?") { showActivation = true } } } .sheet(isPresented: $showActivation) { KeyActivationView() } } } ``` ### KeysHeaderView ```swift struct KeysHeaderView: View { let currentLevel: LicenseLevel var body: some View { HStack { VStack(alignment: .leading, spacing: 4) { Text("Current License") .font(.caption) .foregroundColor(.secondary) HStack { Text(currentLevel.displayName) .font(.title2) .fontWeight(.semibold) ForEach(0.. String { // Remove all non-alphanumeric characters let cleaned = input.uppercased().filter { $0.isLetter || $0.isNumber } // Add dashes at appropriate positions var formatted = "" for (index, char) in cleaned.enumerated() { if index > 0 && index % 4 == 0 && index < 16 { formatted += "-" } formatted.append(char) } // Limit length return String(formatted.prefix(19)) } } ``` ### KeyBadge ```swift struct KeyBadge: View { let keysRequired: Int let isCompact: Bool init(keysRequired: Int, compact: Bool = false) { self.keysRequired = keysRequired self.isCompact = compact } var body: some View { if keysRequired > 0 { HStack(spacing: isCompact ? 2 : 4) { ForEach(0.. some View { configuration.label .frame(maxWidth: .infinity) .padding() .background(isEnabled ? Color.accentColor : Color.gray) .foregroundColor(.white) .cornerRadius(10) .scaleEffect(configuration.isPressed ? 0.95 : 1) .animation(.easeInOut(duration: 0.1), value: configuration.isPressed) } } ``` ## Design Principles 1. **Clear Visual Hierarchy** - Current status prominently displayed - Clear separation between unlocked/locked - Visual indicators (keys, locks, checkmarks) 2. **Progressive Disclosure** - Show relevant information based on license level - Hide complex features until needed - Clear upgrade paths 3. **Feedback and Validation** - Real-time key formatting - Clear error messages - Success animations - Haptic feedback 4. **Accessibility** - VoiceOver labels - Dynamic type support - Color-blind friendly indicators - Clear contrast ratios