Newer Older
80 lines | 1.966kb
Bogdan Timofte authored 2 months ago
1
//
Bogdan Timofte authored 2 months ago
2
//  ChevronView.swift
Bogdan Timofte authored 2 months ago
3
//  USB Meter
4
//
5
//  Created by Bogdan Timofte on 02/05/2020.
6
//  Copyright © 2020 Bogdan Timofte. All rights reserved.
7
//
8

            
9
import SwiftUI
10

            
11
struct ChevronView: View {
12

            
13
    @Binding var rotate: Bool
14

            
15
    var body: some View {
16
        Button(action: {
17
            self.rotate.toggle()
18
        }) {
19
            Image(systemName: "chevron.right.circle")
20
                .imageScale(.large)
21
                .rotationEffect(.degrees(rotate ? 270 : 90))
Bogdan Timofte authored 2 months ago
22
                .animation(.easeInOut, value: rotate)
Bogdan Timofte authored 2 months ago
23
                .padding(.vertical)
24
        }
25
    }
26
}
Bogdan Timofte authored a month ago
27

            
28
struct ContextInfoButton: View {
29
    let title: String
30
    let message: String
31
    let popoverWidth: CGFloat
32

            
33
    @State private var showsPopover = false
34

            
35
    init(
36
        title: String,
37
        message: String,
38
        popoverWidth: CGFloat = 280
39
    ) {
40
        self.title = title
41
        self.message = message
42
        self.popoverWidth = popoverWidth
43
    }
44

            
45
    var body: some View {
46
        Button {
47
            showsPopover.toggle()
48
        } label: {
49
            Image(systemName: "info.circle")
50
                .font(.body.weight(.semibold))
51
                .foregroundColor(.secondary)
52
        }
53
        .buttonStyle(.plain)
54
        .accessibilityLabel("\(title) info")
55
        .popover(isPresented: $showsPopover, arrowEdge: .top) {
56
            VStack(alignment: .leading, spacing: 10) {
57
                Text(title)
58
                    .font(.headline)
59
                Text(message)
60
                    .font(.body)
61
                    .fixedSize(horizontal: false, vertical: true)
62
            }
63
            .padding(16)
64
            .frame(width: popoverWidth, alignment: .leading)
65
        }
66
    }
67
}
68

            
69
struct ContextInfoHeader: View {
70
    let title: String
71
    let message: String
72

            
73
    var body: some View {
74
        HStack(spacing: 8) {
75
            Text(title)
76
            Spacer(minLength: 0)
77
            ContextInfoButton(title: title, message: message)
78
        }
79
    }
80
}