summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/View controllers/Tunnel/ConnectionView/HeaderView.swift
blob: 41eaeac39d9c85fd2e579f25dc46e586ea6b5946 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
//  HeaderView.swift
//  MullvadVPN
//
//  Created by Andrew Bulhak on 2025-01-03.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import SwiftUI

extension ConnectionView {
    internal struct HeaderView: View {
        @ObservedObject var viewModel: ConnectionViewViewModel
        @Binding var isExpanded: Bool

        var body: some View {
            Button {
                withAnimation {
                    isExpanded.toggle()
                }
            } label: {
                VStack(alignment: .leading, spacing: 0) {
                    HStack(alignment: .top) {
                        Text(viewModel.localizedTitleForSecureLabel)
                            .font(.title3.weight(.semibold))
                            .foregroundStyle(viewModel.textColorForSecureLabel.color)
                            .accessibilityIdentifier(viewModel.accessibilityIdForSecureLabel.asString)
                            .accessibilityLabel(viewModel.localizedAccessibilityLabelForSecureLabel)
                        Group {
                            Spacer()
                            Button {
                                withAnimation {
                                    isExpanded.toggle()
                                }
                            } label: {
                                Image(.iconChevronUp)
                                    .renderingMode(.template)
                                    .rotationEffect(isExpanded ? .degrees(-180) : .degrees(0))
                                    .foregroundStyle(.white)
                                    .accessibilityIdentifier(AccessibilityIdentifier.relayStatusCollapseButton.asString)
                            }
                        }
                        .showIf(viewModel.showsConnectionDetails)
                    }
                }
            }
            .disabled(!viewModel.showsConnectionDetails)
        }
    }
}

#Preview {
    ConnectionViewComponentPreview(showIndicators: true) { _, vm, isExpanded in
        ConnectionView.HeaderView(viewModel: vm, isExpanded: isExpanded)
    }
}