1
+ import { Attachment , Popup , Button , Menu , popupFocusTrapBehavior } from '@stardust-ui/react'
2
+ import * as React from 'react'
1
3
import * as _ from 'lodash'
2
4
import { ChatMessageProps } from 'src/components/Chat/ChatMessage'
3
5
import { DividerProps } from 'src/components/Divider/Divider'
@@ -32,7 +34,9 @@ const statusMap: Map<UserStatus, StatusPropsExtendable> = new Map([
32
34
function generateChatMsgProps ( msg : MessageData , fromUser : UserData ) : ChatMessage {
33
35
const { content, mine } = msg
34
36
const msgProps : ChatMessage = {
35
- content,
37
+ content : msg . withAttachment
38
+ ? { content : createMessageContentWithAttachments ( content ) }
39
+ : content ,
36
40
mine,
37
41
tabIndex : 0 ,
38
42
timestamp : { content : msg . timestamp , title : msg . timestampLong } ,
@@ -44,6 +48,56 @@ function generateChatMsgProps(msg: MessageData, fromUser: UserData): ChatMessage
44
48
return msgProps
45
49
}
46
50
51
+ function createMessageContentWithAttachments ( content : string ) {
52
+ const contextMenu = (
53
+ < Menu
54
+ items = { [
55
+ { key : 'download' , content : 'Download' , icon : 'download' } ,
56
+ { key : 'linkify' , content : 'Get link' , icon : 'linkify' } ,
57
+ { key : 'tab' , content : 'Make this a tab' , icon : 'folder open' } ,
58
+ ] }
59
+ vertical
60
+ pills
61
+ />
62
+ )
63
+
64
+ const actionPopup = (
65
+ < Popup
66
+ accessibility = { popupFocusTrapBehavior }
67
+ trigger = {
68
+ < Button aria-label = "More attachment options" iconOnly circular icon = "ellipsis horizontal" />
69
+ }
70
+ content = { { content : contextMenu } }
71
+ />
72
+ )
73
+
74
+ return (
75
+ < >
76
+ < span >
77
+ { content } < a href = "/" > Some link </ a >
78
+ </ span >
79
+ < div style = { { marginTop : '20px' , display : 'flex' } } >
80
+ { _ . map ( [ 'MeetingNotes.pptx' , 'Document.docx' ] , ( fileName , index ) => (
81
+ < Attachment
82
+ icon = "file word outline"
83
+ aria-label = { `File attachment ${ fileName } . Press tab for more options Press Enter to open the file` }
84
+ header = { fileName }
85
+ action = { { icon : 'ellipsis horizontal' } }
86
+ renderAction = { ( ) => actionPopup }
87
+ data-is-focusable = { true }
88
+ styles = { {
89
+ '&:focus' : {
90
+ outline : '.2rem solid #6264A7' ,
91
+ } ,
92
+ ...( index === 1 ? { marginLeft : '15px' } : { } ) ,
93
+ } }
94
+ />
95
+ ) ) }
96
+ </ div >
97
+ </ >
98
+ )
99
+ }
100
+
47
101
function generateDividerProps ( props : DividerProps ) : Divider {
48
102
const { content, important, type = 'secondary' } = props
49
103
const dividerProps : Divider = { itemType : ChatItemTypes . divider , content, important, type }
0 commit comments