Skip to content

Commit bb38330

Browse files
update: build FeedbackView inspired by github ui
1 parent 982efbb commit bb38330

File tree

4 files changed

+167
-7
lines changed

4 files changed

+167
-7
lines changed

FeedbackKitPlayground/FeedbackKitPlayground/ContentView.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import FeedbackKit
1111
struct ContentView: View {
1212
var body: some View {
1313
VStack {
14-
Image(systemName: "globe")
15-
.imageScale(.large)
16-
.foregroundStyle(.tint)
17-
Text("Hello, world!")
14+
FeedbackView()
15+
Spacer()
16+
.background(Color.yellow)
1817
}
1918
.padding()
2019
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// NSTableView+Extension.swift
3+
//
4+
//
5+
// Created by Ahmed Shendy on 26/04/2024.
6+
//
7+
8+
#if os(macOS)
9+
import AppKit
10+
11+
extension NSTableView {
12+
open override func viewDidMoveToWindow() {
13+
super.viewDidMoveToWindow()
14+
15+
backgroundColor = NSColor.clear
16+
enclosingScrollView!.drawsBackground = false
17+
}
18+
}
19+
#endif

Sources/FeedbackKit/Feedback.swift

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
1-
struct Feedback {
1+
struct Feedback: Identifiable, Hashable {
2+
var id: String { title }
3+
24
let type: FeedbackType
35
let title: String
46
let description: String
7+
let state: FeedbackState
8+
}
9+
10+
extension Feedback {
11+
static var samples: [Feedback] {
12+
[
13+
.init(
14+
type: .bug,
15+
title: "We need an alternative when failed to create SQLite database using GRDB",
16+
description: "",
17+
state: .open
18+
),
19+
.init(
20+
type: .feature,
21+
title: "[FEATURE]: Hook up search screen and favoriting functionality",
22+
description: "",
23+
state: .closed
24+
),
25+
.init(
26+
type: .feature,
27+
title: "[FEATURE]: Sort search locations by distance from a location",
28+
description: "",
29+
state: .open
30+
),
31+
.init(
32+
type: .feature,
33+
title: "[FEATURE]: Enhance weather information for detail view of a location",
34+
description: "",
35+
state: .open
36+
),
37+
]
38+
}
39+
}
40+
41+
enum FeedbackState {
42+
case open
43+
case closed
544
}
Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,110 @@
11
import SwiftUI
22

3-
struct FeedbackView: View {
3+
public struct FeedbackView: View {
4+
public init() { }
5+
public var body: some View {
6+
ScrollView {
7+
LazyVStack(spacing: 0) {
8+
ForEach(Feedback.samples) { item in
9+
FeedbackItem(item)
10+
11+
if item != Feedback.samples.last {
12+
Divider()
13+
}
14+
}
15+
}
16+
}
17+
.fixedSize(horizontal: false, vertical: true)
18+
.clipShape(RoundedRectangle(cornerRadius: 5))
19+
.overlay(
20+
RoundedRectangle(cornerRadius: 5)
21+
.inset(by: 1)
22+
.strokeBorder(
23+
Color(red: 0.255, green: 0.255, blue: 0.255),
24+
lineWidth: 1,
25+
antialiased: true
26+
)
27+
)
28+
}
29+
}
30+
31+
struct FeedbackItem: View {
32+
let feedback: Feedback
33+
34+
init(_ feedback: Feedback) {
35+
self.feedback = feedback
36+
}
37+
38+
var body: some View {
39+
HStack(alignment: .top) {
40+
41+
FeedbackStateIcon(state: feedback.state)
42+
Spacer().frame(width: 5)
43+
44+
VStack(spacing: 0) {
45+
HStack(spacing: 0) {
46+
FeedbackTitle(text: feedback.title)
47+
Spacer()
48+
HStack(spacing: 0) {
49+
Image(systemName: "message")
50+
Text("2")
51+
}
52+
.foregroundColor(.init(red: 0.518, green: 0.553, blue: 0.592))
53+
}
54+
55+
Spacer().frame(height: 8)
56+
57+
HStack(spacing: 0) {
58+
Text("opened on May 18, 2023")
59+
.font(.caption)
60+
.foregroundColor(Color.gray)
61+
Spacer()
62+
FeedbackLabel(text: feedback.type.rawValue)
63+
}
64+
}
65+
}
66+
.padding(.horizontal, 15)
67+
.padding(.vertical, 10)
68+
}
69+
}
70+
71+
struct FeedbackStateIcon: View {
72+
let state: FeedbackState
73+
74+
var body: some View {
75+
Group {
76+
switch state {
77+
case .open:
78+
Image(systemName: "smallcircle.filled.circle")
79+
.foregroundColor(.green)
80+
case .closed:
81+
Image(systemName: "checkmark.circle")
82+
.foregroundColor(.blue)
83+
}
84+
}
85+
.font(.body)
86+
}
87+
}
88+
89+
struct FeedbackTitle: View {
90+
let text: String
91+
92+
var body: some View {
93+
Text(text)
94+
.font(.headline)
95+
}
96+
}
97+
98+
struct FeedbackLabel: View {
99+
let text: String
100+
4101
var body: some View {
5-
Text("FeedbackKit Root View")
102+
Text(text)
103+
.font(.caption)
104+
.fontWeight(.light)
105+
.foregroundColor(.white)
106+
.padding(.horizontal, 6)
107+
.background(Color.gray.opacity(0.5))
108+
.clipShape(Capsule(style: .continuous))
6109
}
7110
}

0 commit comments

Comments
 (0)