Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | 1x 2x 1x 3x 1x 19x 1x 12x 27x 27x 27x 10x 16x 27x 1x 20x 1x 1x 1x 1x 1x 8x 1x 5x 1x 4x 1x 13x | // Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
import React from 'react';
import classNames from 'classnames';
import { Avatar } from '../avatar';
import { UtilityIcon } from '../icons/base/example';
import TypingIcon from '../dynamic-icons/typing';
export const Chat = props => (
<section
role="log"
className={classNames('slds-chat', {
'slds-chat_past': props.isPast
})}
>
{props.children}
</section>
);
export const ChatList = props => (
<ul className="slds-chat-list">{props.children}</ul>
);
export const ChatListItem = props => (
<li
className={classNames('slds-chat-listitem', {
'slds-chat-listitem_bookend': props.type === 'bookend',
'slds-chat-listitem_event': props.type === 'event',
'slds-chat-listitem_inbound': props.type === 'inbound',
'slds-chat-listitem_outbound': props.type === 'outbound'
})}
>
{props.children}
</li>
);
export const ChatMessage = props => (
<div
className={classNames('slds-chat-message', {
'slds-chat-message_faux-avatar': props.hasFauxAvatar
})}
>
{props.children}
</div>
);
export const ChatMessageBody = props => {
const chatTextClasses = {
'slds-chat-message__text': !props.messageType,
'slds-chat-message__text_inbound':
!props.messageType && props.type === 'inbound',
'slds-chat-message__text_outbound':
!props.messageType && props.type === 'outbound',
'slds-chat-message__text_outbound-agent':
!props.messageType && props.type === 'outbound-agent',
'slds-chat-message__text_unsupported-type':
!props.messageType && props.type === 'unsupported-type',
'slds-chat-message__text_delivery-failure':
!props.messageType && props.type === 'delivery-failure',
'slds-chat-message__text_sneak-peek':
!props.messageType && props.hasSneakPeek
};
const chatFileClasses = {
'slds-chat-message__file': props.messageType === 'file',
'slds-chat-message__file_inbound':
props.messageType === 'file' && props.type === 'inbound',
'slds-chat-message__file_outbound':
props.messageType === 'file' && props.type === 'outbound'
};
const chatImageClasses = {
'slds-chat-message__image': props.messageType === 'image',
'slds-chat-message__image_inbound':
props.messageType === 'image' && props.type === 'inbound',
'slds-chat-message__image_outbound':
props.messageType === 'image' && props.type === 'outbound'
};
const renderChildrenWrapper = () => {
if (props.messageType === 'image' || props.messageType === 'file') {
return props.children;
} else {
return (
<span aria-hidden={props.hasSneakPeek ? 'true' : null}>
{props.children}
</span>
);
}
};
return (
<div
className={classNames('slds-chat-message__body', {
'slds-chat-message__file_loading':
props.messageType === 'file' && props.isLoading,
'slds-chat-message__image_loading':
props.messageType === 'image' && props.isLoading
})}
>
{props.name && props.timeStamp && props.isPast && (
<ChatMessageTimeStamp
isPast
name={props.name}
timeStamp={props.timeStamp}
/>
)}
<div
className={classNames(
chatTextClasses,
chatFileClasses,
chatImageClasses
)}
>
{props.isTyping && (
<TypingIcon
isAnimated
isPaused={props.isPaused}
assistiveText="Customer is typing"
title="Customer is typing"
/>
)}
{props.type === 'unsupported-type' && (
<ChatIcon symbol="warning" assistiveText="Warning" />
)}
{props.children && renderChildrenWrapper()}
{props.type === 'delivery-failure' && (
<ChatMessageDeliveryFailure>
{props.deliveryFailureReason}
</ChatMessageDeliveryFailure>
)}
</div>
{props.type === 'delivery-failure' ? (
<div className="slds-grid slds-grid_align-spread slds-grid_vertical-align-start">
{props.name && props.timeStamp && !props.isPast && (
<ChatMessageTimeStamp
name={props.name}
timeStamp={props.timeStamp}
/>
)}
{props.type === 'delivery-failure' && (
<ChatMessageAction symbol="redo" actionTitle="Resend" />
)}
</div>
) : (
props.name &&
props.timeStamp &&
!props.isPast && (
<ChatMessageTimeStamp name={props.name} timeStamp={props.timeStamp} />
)
)}
</div>
);
};
const ChatMessageTimeStamp = props => (
<div
className="slds-chat-message__meta"
aria-label={`said ${props.name} at ${props.timeStamp}`}
>
{props.isPast ? <b>{props.name}</b> : props.name} • {props.timeStamp}
</div>
);
const ChatMessageDeliveryFailure = props => (
<div className="slds-chat-message__text_delivery-failure-reason" role="alert">
<ChatIcon symbol="error" />
<span>{props.children}</span>
</div>
);
const ChatMessageAction = props => (
<button className="slds-button slds-chat-message__action slds-m-top_xxx-small">
<UtilityIcon
assistiveText={false}
title={false}
className="slds-icon_xx-small"
containerClassName="slds-chat-icon"
symbol={props.symbol}
/>
<span>{props.actionTitle}</span>
</button>
);
export const ChatAvatar = props => (
<Avatar
className="slds-avatar_circle slds-chat-avatar"
ariaHidden={props.ariaHidden}
>
<abbr
className="slds-avatar__initials slds-avatar__initials_inverse"
title={props.name}
>
{props.initials}
</abbr>
</Avatar>
);
export const ChatEvent = props => (
<div
className={classNames('slds-chat-event', {
'slds-has-error': props.hasError
})}
role={props.hasError && 'alert'}
>
<div className="slds-chat-event__body">
<ChatIcon symbol={props.symbol} assistiveText={props.iconAssistiveText} />
<p>
{props.children} • {props.timeStamp}
</p>
</div>
{props.agentMessage && (
<div className="slds-chat-event__agent-message">{props.agentMessage}</div>
)}
</div>
);
export const ChatBookend = props => (
<div
className={classNames('slds-chat-bookend', {
'slds-chat-bookend_stop': props.type === 'stop'
})}
>
<ChatIcon symbol={props.type === 'start' ? 'chat' : 'end_chat'} />
<p>
Chat {props.type === 'stop' ? 'ended' : 'started'} by <b>{props.name}</b>{' '}
• {props.timeStamp}
</p>
</div>
);
export const ChatIcon = props => (
<UtilityIcon
assistiveText={props.assistiveText || false}
className={classNames('slds-icon_x-small slds-icon-text-default', {
'slds-icon-text-default': props.symbol === 'error',
'slds-icon-text-warning': props.symbol === 'warning'
})}
containerClassName="slds-chat-icon"
symbol={props.symbol}
title={props.assistiveText || false}
/>
);
|