Skip to content

Commit 30c4e35

Browse files
committed
feat: Tela drawer
1 parent 5730732 commit 30c4e35

34 files changed

+1333
-77
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
{
168168
"path": "lib/components/internal/widget-exports.js",
169169
"brotli": false,
170-
"limit": "800 kB",
170+
"limit": "808 kB",
171171
"ignore": "react-dom"
172172
}
173173
],

pages/app-layout/runtime-drawers.page.tsx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33
import React, { useContext, useRef, useState } from 'react';
4+
import ReactDOM, { unmountComponentAtNode } from 'react-dom';
45

56
import {
67
AppLayout,
8+
Box,
79
Button,
810
ContentLayout,
911
Header,
@@ -14,12 +16,14 @@ import {
1416
Toggle,
1517
} from '~components';
1618
import { AppLayoutProps } from '~components/app-layout';
19+
import { useMobile } from '~components/internal/hooks/use-mobile';
1720
import awsuiPlugins from '~components/internal/plugins';
1821

1922
import './utils/external-widget';
2023
import AppContext, { AppContextType } from '../app/app-context';
2124
import { Breadcrumbs, Containers, CustomDrawerContent } from './utils/content-blocks';
2225
import { drawerLabels } from './utils/drawers';
26+
import { AutoIncrementCounter } from './utils/external-widget';
2327
import appLayoutLabels from './utils/labels';
2428
import { splitPaneli18nStrings } from './utils/strings';
2529

@@ -31,6 +35,79 @@ type DemoContext = React.Context<
3135
}>
3236
>;
3337

38+
const AIDrawer = () => {
39+
const isMobile = useMobile();
40+
41+
return (
42+
<div
43+
style={{
44+
background: 'white',
45+
paddingInlineEnd: isMobile ? undefined : '16px',
46+
paddingInlineStart: isMobile ? undefined : '16px',
47+
}}
48+
>
49+
<Box variant="h2" padding={{ bottom: 'm' }}>
50+
Chat demo
51+
</Box>
52+
<AutoIncrementCounter />
53+
{new Array(100).fill(null).map((_, index) => (
54+
<div key={index}>Tela content</div>
55+
))}
56+
</div>
57+
);
58+
};
59+
60+
awsuiPlugins.appLayout.registerDrawer({
61+
id: 'amazon-q',
62+
type: 'global-ai',
63+
resizable: true,
64+
isExpandable: true,
65+
defaultSize: 500,
66+
preserveInactiveContent: false,
67+
68+
ariaLabels: {
69+
closeButton: 'Close button',
70+
content: 'Content',
71+
triggerButton: 'Trigger button for ai drawer',
72+
resizeHandle: 'Resize handle',
73+
exitExpandedModeButton: 'Service Console',
74+
},
75+
76+
trigger: {
77+
iconSvg: `<svg viewBox="0 0 16 16" focusable="false">
78+
<circle stroke-width="2" stroke="currentColor" fill="none" cx="8" cy="8" r="7" />
79+
<circle stroke-width="2" stroke="currentColor" fill="none" cx="8" cy="8" r="3" />
80+
</svg>`,
81+
customIcon: `
82+
<svg width="58" height="32" viewBox="0 0 58 32" fill="none">
83+
<rect width="58" height="32" rx="4" fill="url(#paint0_radial_102_125756)"/>
84+
<path fill-rule="evenodd" clip-rule="evenodd" d="M29.8558 15.5099V16.3724L29.1338 16.8195L28.4016 16.3714V15.5109L29.1338 15.0659L29.8558 15.5099ZM29.3719 22.919C29.2192 23.0015 29.0379 23.0015 28.8851 22.919L23.2842 19.8761C23.1202 19.7875 23.0184 19.6164 23.0184 19.4291V12.5663C23.0184 12.38 23.1212 12.2089 23.2852 12.1193L28.8872 9.08148C28.9625 9.03972 29.045 9.01936 29.1285 9.01936C29.212 9.01936 29.2945 9.03972 29.3709 9.08148L34.9719 12.1193C35.1369 12.2089 35.2387 12.38 35.2387 12.5663V19.1144L30.874 16.376V15.2253C30.874 15.0481 30.7824 14.8841 30.6316 14.7914L29.4015 14.0358C29.2395 13.937 29.0338 13.936 28.8699 14.0348L27.6275 14.7904C27.4757 14.8831 27.3831 15.047 27.3831 15.2253V16.6571C27.3831 16.8343 27.4757 16.9982 27.6275 17.0909L28.8689 17.8516C28.9503 17.9025 29.042 17.927 29.1346 17.927C29.2273 17.927 29.321 17.9015 29.4025 17.8506L30.3628 17.2569L34.7397 20.0034L29.3719 22.919ZM35.4577 11.2236L29.8577 8.18687C29.4004 7.93737 28.8566 7.93839 28.4004 8.18585L22.7994 11.2236C22.3065 11.4915 22 12.0057 22 12.5658V19.4286C22 19.9897 22.3065 20.504 22.7984 20.7708L28.3994 23.8136C28.6275 23.9379 28.878 24 29.1285 24C29.3791 24 29.6296 23.9379 29.8577 23.8136L35.4587 20.7708C35.9505 20.504 36.2571 19.9897 36.2571 19.4286V12.5658C36.2571 12.0057 35.9505 11.4915 35.4577 11.2236Z" fill="white"/>
85+
<defs>
86+
<radialGradient id="paint0_radial_102_125756" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(63.1768 -2.85617) rotate(151.113) scale(78.0669 84.498)">
87+
<stop stop-color="#B8E7FF"/>
88+
<stop offset="0.3" stop-color="#0099FF"/>
89+
<stop offset="0.45" stop-color="#5C7FFF"/>
90+
<stop offset="0.6" stop-color="#8575FF"/>
91+
<stop offset="0.8" stop-color="#962EFF"/>
92+
</radialGradient>
93+
</defs>
94+
</svg>
95+
`,
96+
},
97+
98+
onResize: event => {
99+
console.log('resize', event.detail);
100+
},
101+
onToggle: event => {
102+
console.log('toggle', event.detail);
103+
},
104+
105+
mountContent: container => {
106+
ReactDOM.render(<AIDrawer />, container);
107+
},
108+
unmountContent: container => unmountComponentAtNode(container),
109+
});
110+
34111
export default function WithDrawers() {
35112
const [activeDrawerId, setActiveDrawerId] = useState<string | null>(null);
36113
const [helpPathSlug, setHelpPathSlug] = useState<string>('default');
@@ -125,6 +202,13 @@ export default function WithDrawers() {
125202
>
126203
Resize circle3-global drawer to 500px
127204
</Button>
205+
206+
<Button onClick={() => awsuiPlugins.appLayout.openDrawer('amazon-q')} data-testid="open-drawer-button">
207+
Open the left global drawer
208+
</Button>
209+
<Button onClick={() => awsuiPlugins.appLayout.closeDrawer('amazon-q')}>
210+
Close the left global drawer
211+
</Button>
128212
</SpaceBetween>
129213
</SpaceBetween>
130214
}

pages/app-layout/utils/external-widget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ awsuiPlugins.appLayout.registerDrawer({
9292
unmountContent: container => unmountComponentAtNode(container),
9393
});
9494

95-
const AutoIncrementCounter: React.FC<{
95+
export const AutoIncrementCounter: React.FC<{
9696
onVisibilityChange?: (callback: (isVisible: boolean) => void) => void;
9797
}> = ({ children, onVisibilityChange }) => {
9898
const [count, setCount] = useState(0);

0 commit comments

Comments
 (0)