Skip to content

Commit

Permalink
Center vertically and use responsive image for avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
OEvgeny committed Nov 7, 2024
1 parent c92ba8b commit 14bc69b
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 31 deletions.
211 changes: 211 additions & 0 deletions __tests__/html2/activity/avatar.aspect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script crossorigin="anonymous" src="https://unpkg.com/@babel/[email protected]/babel.min.js"></script>
<script crossorigin="anonymous" src="https://unpkg.com/[email protected]/umd/react.development.js"></script>
<script crossorigin="anonymous" src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script>
<script crossorigin="anonymous" src="/test-harness.js"></script>
<script crossorigin="anonymous" src="/test-page-object.js"></script>
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
</head>
<template id="avatars">
<svg data-for="1" xmlns="http://www.w3.org/2000/svg" width="75" height="150" viewBox="0 0 75 150">
<!-- Gradient Definitions -->
<defs>
<linearGradient id="tallGradient" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#0ea5e9"/>
<stop offset="100%" style="stop-color:#6366f1"/>
</linearGradient>
<linearGradient id="tallHighlight" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:rgba(255,255,255,0.2)"/>
<stop offset="100%" style="stop-color:rgba(255,255,255,0)"/>
</linearGradient>
</defs>

<!-- Base Rectangle -->
<rect width="75" height="150" rx="37.5" fill="url(#tallGradient)"/>

<!-- Highlight Overlay -->
<path d="M 0 0 L 75 0 L 75 75 Q 37.5 95 0 75 Z" fill="url(#tallHighlight)" opacity="0.5"/>

<!-- Face - Positioned in Upper Third -->
<!-- Eyes -->
<path d="M 25 55 Q 27 52 29 55" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>
<path d="M 46 55 Q 48 52 50 55" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>

<!-- Smile -->
<path d="M 25 70 Q 37.5 80 50 70" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>

<!-- Decorative Elements -->
<circle cx="37.5" cy="110" r="15" stroke="white" stroke-width="3" fill="none" opacity="0.3"/>
<circle cx="37.5" cy="110" r="7" stroke="white" stroke-width="2" fill="none" opacity="0.2"/>
</svg>
<svg data-for="2" xmlns="http://www.w3.org/2000/svg" width="150" height="75" viewBox="0 0 150 75">
<!-- Gradient Definitions -->
<defs>
<linearGradient id="wideGradient" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#84cc16"/>
<stop offset="100%" style="stop-color:#22c55e"/>
</linearGradient>
<linearGradient id="wideHighlight" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:rgba(255,255,255,0.25)"/>
<stop offset="100%" style="stop-color:rgba(255,255,255,0)"/>
</linearGradient>
</defs>

<!-- Base Rectangle -->
<rect width="150" height="75" rx="37.5" fill="url(#wideGradient)"/>

<!-- Highlight Overlay -->
<path d="M 0 0 Q 75 -10 150 0 L 150 40 Q 75 30 0 40 Z" fill="url(#wideHighlight)" opacity="0.5"/>

<!-- Face - Centered -->
<!-- Eyes -->
<path d="M 55 35 Q 58 32 61 35" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>
<path d="M 89 35 Q 92 32 95 35" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>

<!-- Smile -->
<path d="M 55 45 Q 75 55 95 45" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>

<!-- Decorative Elements -->
<circle cx="30" cy="37.5" r="8" stroke="white" stroke-width="2" fill="none" opacity="0.2"/>
<circle cx="120" cy="37.5" r="8" stroke="white" stroke-width="2" fill="none" opacity="0.2"/>
</svg>
</template>
<body>
<main id="webchat"></main>
<script type="text/babel" data-presets="env,stage-3,react">
const {
React: { useMemo },
WebChat: {
hooks: { useDirection }
}
} = window;

run(async function () {
await host.windowSize(undefined, 1280, document.getElementById('webchat'));

WebChat.renderWebChat(
{
directLine: await testHelpers.createDirectLineWithTranscript([
{
from: { role: 'bot' },
id: '1.0',
text: 'Cillum ea irure amet reprehenderit minim.',
timestamp: -300001,
type: 'message'
},
{
from: { role: 'bot' },
id: '1.1',
text: 'Minim ut laboris enim nostrud magna irure occaecat laborum occaecat ex.',
timestamp: -300001,
type: 'message'
},
{
channelData: { state: 'sent' },
from: { role: 'user' },
id: '2.0',
text: 'Tempor deserunt ut enim eu elit.',
timestamp: -300001,
type: 'message'
},
{
channelData: { state: 'sent' },
from: { role: 'user' },
id: '2.1',
text: 'Elit occaecat quis velit qui ad.',
timestamp: -300001,
type: 'message'
},
{
from: { role: 'bot' },
id: '3.0',
text: 'Nulla irure laborum officia tempor aute consequat eiusmod nisi velit ipsum magna.',
timestamp: -300001,
type: 'message'
},
{
from: { role: 'bot' },
id: '3.1',
text: 'Minim fugiat aute do ea veniam.',
timestamp: -300001,
type: 'message'
},
{
channelData: { state: 'sent' },
from: { role: 'user' },
id: '4.0',
text: 'This first activity has user avatar',
timestamp: 0,
type: 'message'
},
{
channelData: { state: 'sent' },
from: { role: 'user' },
id: '4.1',
text: 'This shows no avatar as the activities in the same group',
timestamp: 0,
type: 'message'
},
{
attachmentLayout: 'carousel',
attachments: [
{
contentType: 'image/jpeg',
contentUrl:
'https://raw.githubusercontent.com/compulim/BotFramework-MockBot/master/public/assets/surface1.jpg',
name: 'front of Surface Pro'
},
{
contentType: 'image/jpeg',
contentUrl:
'https://raw.githubusercontent.com/compulim/BotFramework-MockBot/master/public/assets/surface2.jpg',
name: 'back of Surface Pro'
}
],
from: { role: 'bot' },
id: '5.0',
text: 'Bot message with attachment',
timestamp: 0,
type: 'message'
},
{
from: { role: 'bot' },
id: '5.1',
text: 'Follow-up message within the group',
timestamp: 0,
type: 'message'
}
]),
store: testHelpers.createStore(),
styleOptions: {
botAvatarImage: `data:image/svg+xml;utf8,${encodeURIComponent(window.avatars.content.querySelector(`[data-for="1"]`).outerHTML)}`,
botAvatarInitials: 'Bot',
bubbleBackground: '#0063B1',
bubbleBorderColor: '#0063B1',
bubbleBorderRadius: 4,
bubbleFromUserBackground: '#0063B1',
bubbleFromUserBorderColor: '#0063B1',
bubbleFromUserBorderRadius: 4,
bubbleFromUserNubOffset: 0,
bubbleFromUserNubSize: 10,
bubbleFromUserTextColor: 'White',
bubbleNubOffset: 0,
bubbleNubSize: 10,
bubbleTextColor: 'White',
userAvatarInitials: 'You',
userAvatarImage: `data:image/svg+xml;utf8,${encodeURIComponent(window.avatars.content.querySelector(`[data-for="2"]`).outerHTML)}`,
}
},
document.getElementById('webchat')
);

await pageConditions.uiConnected();

await host.snapshot('local');
});
</script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 36 additions & 28 deletions __tests__/html2/activity/grouping.multipleAvatars.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,73 @@
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
<style type="text/css">
.webchat__avatar {
width: 40px;
height: 40px;
width: 100%;
height: auto;
}
</style>
</head>
<template id="avatars">
<svg data-for="1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<svg data-for="1" xmlns="http://www.w3.org/2000/svg" width="75" height="150" viewBox="0 0 75 150">
<!-- Gradient Definitions -->
<defs>
<linearGradient id="backgroundGradient" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#6366f1"/>
<stop offset="100%" style="stop-color:#a855f7"/>
<linearGradient id="tallGradient" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#0ea5e9"/>
<stop offset="100%" style="stop-color:#6366f1"/>
</linearGradient>
<linearGradient id="highlightGradient" x1="0%" y1="0%" x2="100%" y2="100%">
<linearGradient id="tallHighlight" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:rgba(255,255,255,0.2)"/>
<stop offset="100%" style="stop-color:rgba(255,255,255,0)"/>
</linearGradient>
</defs>

<!-- Base Circle -->
<circle cx="50" cy="50" r="50" fill="url(#backgroundGradient)"/>
<!-- Base Rectangle -->
<rect width="75" height="150" rx="37.5" fill="url(#tallGradient)"/>

<!-- Highlight Overlay -->
<path d="M 25 25 Q 50 0 75 25" fill="url(#highlightGradient)" opacity="0.5"/>
<path d="M 0 0 L 75 0 L 75 75 Q 37.5 95 0 75 Z" fill="url(#tallHighlight)" opacity="0.5"/>

<!-- Face -->
<!-- Face - Positioned in Upper Third -->
<!-- Eyes -->
<path d="M 35 45 Q 37 43 39 45" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>
<path d="M 61 45 Q 63 43 65 45" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>
<path d="M 25 55 Q 27 52 29 55" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>
<path d="M 46 55 Q 48 52 50 55" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>

<!-- Smile -->
<path d="M 35 60 Q 50 70 65 60" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>
<path d="M 25 70 Q 37.5 80 50 70" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>

<!-- Decorative Elements -->
<circle cx="37.5" cy="110" r="15" stroke="white" stroke-width="3" fill="none" opacity="0.3"/>
<circle cx="37.5" cy="110" r="7" stroke="white" stroke-width="2" fill="none" opacity="0.2"/>
</svg>
<svg data-for="2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<svg data-for="2" xmlns="http://www.w3.org/2000/svg" width="150" height="75" viewBox="0 0 150 75">
<!-- Gradient Definitions -->
<defs>
<linearGradient id="backgroundGradient2" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#ec4899"/>
<stop offset="100%" style="stop-color:#f97316"/>
<linearGradient id="wideGradient" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#84cc16"/>
<stop offset="100%" style="stop-color:#22c55e"/>
</linearGradient>
<linearGradient id="highlightGradient2" x1="0%" y1="0%" x2="100%" y2="100%">
<linearGradient id="wideHighlight" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:rgba(255,255,255,0.25)"/>
<stop offset="100%" style="stop-color:rgba(255,255,255,0)"/>
</linearGradient>
</defs>

<!-- Base Circle -->
<circle cx="50" cy="50" r="50" fill="url(#backgroundGradient2)"/>
<!-- Base Rectangle -->
<rect width="150" height="75" rx="37.5" fill="url(#wideGradient)"/>

<!-- Highlight Overlay -->
<path d="M 20 20 Q 50 0 80 20" fill="url(#highlightGradient2)" opacity="0.6"/>
<path d="M 0 0 Q 75 -10 150 0 L 150 40 Q 75 30 0 40 Z" fill="url(#wideHighlight)" opacity="0.5"/>

<!-- Face - Centered -->
<!-- Eyes -->
<path d="M 55 35 Q 58 32 61 35" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>
<path d="M 89 35 Q 92 32 95 35" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>

<!-- Face -->
<!-- Happy Eyes -->
<path d="M 35 45 Q 37 40 39 45" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>
<path d="M 61 45 Q 63 40 65 45" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>
<!-- Smile -->
<path d="M 55 45 Q 75 55 95 45" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>

<!-- Wide Smile -->
<path d="M 30 55 Q 50 70 70 55" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>
<!-- Decorative Elements -->
<circle cx="30" cy="37.5" r="8" stroke="white" stroke-width="2" fill="none" opacity="0.2"/>
<circle cx="120" cy="37.5" r="8" stroke="white" stroke-width="2" fill="none" opacity="0.2"/>
</svg>
</template>
<body>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions packages/component/src/Avatar/ImageAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const { useAvatarForBot, useAvatarForUser } = hooks;
const ROOT_STYLE = {
'& .webchat__imageAvatar__image': {
width: '100%',
height: '100%',
objectFit: 'cover'
height: 'auto'
}
};

Expand Down
4 changes: 3 additions & 1 deletion packages/component/src/Styles/StyleSet/ImageAvatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import CSSTokens from '../CSSTokens';

export default function createImageAvatarStyle() {
return {
aspectRatio: 1,
alignItems: 'center',
display: 'flex',
height: CSSTokens.SizeAvatar,
justifyContent: 'center',
overflow: ['hidden', 'clip'],
width: CSSTokens.SizeAvatar
};
Expand Down

0 comments on commit 14bc69b

Please sign in to comment.