forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatConversationReferencePill.swift
More file actions
75 lines (70 loc) · 2.65 KB
/
Copy pathChatConversationReferencePill.swift
File metadata and controls
75 lines (70 loc) · 2.65 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import OmiTheme
import SwiftUI
/// One conversation-reference presentation shared by the composer and the
/// accepted user turn. The lifecycle changes its trailing action, not its
/// identity or visual language: staged references are removable; persisted
/// references reopen the canonical conversation detail.
struct ChatConversationReferencePill: View {
let reference: ChatComposerReference
var onRemove: (() -> Void)? = nil
var onOpen: (() -> Void)? = nil
var body: some View {
Group {
if let onOpen {
Button(action: onOpen) {
pillContent(showsOpenIndicator: true)
}
.buttonStyle(.plain)
.help("Open \(reference.displayTitle)")
.accessibilityLabel("Open attached conversation: \(reference.displayTitle)")
.accessibilityIdentifier("chat-conversation-reference-\(reference.sourceID)-open")
} else {
pillContent(showsOpenIndicator: false)
}
}
.background(Ink.rowFillHover)
.clipShape(RoundedRectangle(cornerRadius: OmiChrome.smallControlRadius, style: .continuous))
.overlay(
RoundedRectangle(cornerRadius: OmiChrome.smallControlRadius, style: .continuous)
.strokeBorder(Ink.separator, lineWidth: 1)
)
.accessibilityElement(children: .contain)
}
private func pillContent(showsOpenIndicator: Bool) -> some View {
HStack(spacing: OmiSpacing.xs) {
Image(systemName: reference.kind.systemImage)
.scaledFont(size: OmiType.caption, weight: .medium)
.foregroundColor(Ink.secondary)
VStack(alignment: .leading, spacing: 0) {
Text(reference.displayTitle)
.scaledFont(size: OmiType.caption, weight: .medium)
.foregroundColor(Ink.primary)
.lineLimit(1)
.truncationMode(.middle)
Text(reference.displaySubtitle)
.scaledFont(size: OmiType.micro)
.foregroundColor(Ink.secondary)
.lineLimit(1)
}
.frame(maxWidth: 230, alignment: .leading)
if showsOpenIndicator {
Image(systemName: "arrow.up.right")
.scaledFont(size: OmiType.micro, weight: .semibold)
.foregroundColor(Ink.secondary)
.frame(width: 18, height: 18)
} else if let onRemove {
Button(action: onRemove) {
Image(systemName: "xmark")
.scaledFont(size: OmiType.micro, weight: .semibold)
.foregroundColor(Ink.secondary)
.frame(width: 18, height: 18)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.accessibilityLabel("Remove \(reference.displayTitle)")
}
}
.padding(.horizontal, OmiSpacing.sm)
.padding(.vertical, OmiSpacing.xs)
}
}