Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

docs(ChatPane): Add attachments and link to chat pane messages in prototype #514

Merged
merged 10 commits into from
Nov 26, 2018
1 change: 1 addition & 0 deletions docs/src/prototypes/chatPane/services/dataMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ChatMock {
timestamp: timestamp.short,
timestampLong: timestamp.long,
isImportant: random.boolean(),
withAttachment: random.boolean(),
}

return message
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Attachment, Popup, Button, Menu, popupFocusTrapBehavior } from '@stardust-ui/react'
import * as React from 'react'
import * as _ from 'lodash'
import { ChatMessageProps } from 'src/components/Chat/ChatMessage'
import { DividerProps } from 'src/components/Divider/Divider'
Expand Down Expand Up @@ -32,7 +34,9 @@ const statusMap: Map<UserStatus, StatusPropsExtendable> = new Map([
function generateChatMsgProps(msg: MessageData, fromUser: UserData): ChatMessage {
const { content, mine } = msg
const msgProps: ChatMessage = {
content,
content: msg.withAttachment
? { content: createMessageContentWithAttachments(content) }
: content,
mine,
tabIndex: 0,
timestamp: { content: msg.timestamp, title: msg.timestampLong },
Expand All @@ -44,6 +48,56 @@ function generateChatMsgProps(msg: MessageData, fromUser: UserData): ChatMessage
return msgProps
}

function createMessageContentWithAttachments(content: string) {
const contextMenu = (
<Menu
items={[
{ key: 'download', content: 'Download', icon: 'download' },
{ key: 'linkify', content: 'Get link', icon: 'linkify' },
{ key: 'tab', content: 'Make this a tab', icon: 'folder open' },
]}
vertical
pills
/>
)

const actionPopup = (
<Popup
accessibility={popupFocusTrapBehavior}
trigger={
<Button aria-label="More attachment options" iconOnly circular icon="ellipsis horizontal" />
}
content={{ content: contextMenu }}
/>
)

return (
<>
<span>
{content} <a href="/"> Some link </a>
</span>
<div style={{ marginTop: '20px', display: 'flex' }}>
{_.map(['MeetingNotes.pptx', 'Document.docx'], (fileName, index) => (
<Attachment
icon="file word outline"
aria-label={`File attachment ${fileName}. Press tab for more options Press Enter to open the file`}
header={fileName}
action={{ icon: 'ellipsis horizontal' }}
renderAction={() => actionPopup}
data-is-focusable={true}
styles={{
'&:focus': {
outline: '.2rem solid #6264A7',
},
...(index === 1 ? { marginLeft: '15px' } : {}),
}}
/>
))}
</div>
</>
)
}

function generateDividerProps(props: DividerProps): Divider {
const { content, important, type = 'secondary' } = props
const dividerProps: Divider = { itemType: ChatItemTypes.divider, content, important, type }
Expand Down
1 change: 1 addition & 0 deletions docs/src/prototypes/chatPane/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface MessageData {
from: string
isImportant: boolean
mine: boolean
withAttachment?: boolean
}

export interface ChatData {
Expand Down