Skip to content

Commit 008a08b

Browse files
committed
chore: Make bottom drawer's header and actions always aligned
1 parent 446fd0a commit 008a08b

File tree

5 files changed

+70
-32
lines changed

5 files changed

+70
-32
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
{
177177
"path": "lib/components/internal/widget-exports.js",
178178
"brotli": false,
179-
"limit": "977 kB",
179+
"limit": "978 kB",
180180
"ignore": "react-dom"
181181
}
182182
],

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,19 +332,28 @@ export const registerRuntimeBottomDrawer = () => {
332332

333333
mountContent: (container, mountContext) => {
334334
mount(
335-
<Drawer header={<Box variant="h2">Global drawer</Box>}>
335+
<Box padding={{ left: 'm' }}>
336336
<AutoIncrementCounter onVisibilityChange={mountContext?.onVisibilityChange}>
337337
global bottom panel
338338
{new Array(100).fill(null).map((_, index) => (
339339
<div key={index}>{index}</div>
340340
))}
341341
<div data-testid="circle-global-bottom-content">circle-global bottom content</div>
342342
</AutoIncrementCounter>
343-
</Drawer>,
343+
</Box>,
344344
container
345345
);
346346
},
347347
unmountContent: container => unmount(container),
348+
mountHeader: container => {
349+
mount(
350+
<Box variant="h2" padding="m">
351+
Global drawer
352+
</Box>,
353+
container
354+
);
355+
},
356+
unmountHeader: container => unmount(container),
348357
headerActions: [
349358
{
350359
type: 'icon-button',

src/app-layout/visual-refresh-toolbar/drawer/global-bottom-drawer.tsx

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function AppLayoutGlobalBottomDrawerImplementation({
8181
placement,
8282
} = widgetizedState;
8383
const drawerRef = useRef<HTMLDivElement>(null);
84+
const headerRef = useRef<HTMLHeadingElement>(null);
8485
const activeDrawerId = activeDrawer?.id ?? '';
8586

8687
const computedAriaLabels = {
@@ -258,43 +259,50 @@ function AppLayoutGlobalBottomDrawerImplementation({
258259
/>
259260
</div>
260261
)}
262+
<header className={styles['bottom-drawer-content-header']} ref={headerRef}>
263+
<div className={styles['bottom-drawer-content-header-content']}>
264+
{activeDrawer?.header ?? <div />}
265+
<div className={styles['bottom-drawer-actions']}>
266+
<ButtonGroup
267+
dropdownExpandToViewport={false}
268+
variant="icon"
269+
onItemClick={event => {
270+
switch (event.detail.id) {
271+
case 'close':
272+
onActiveGlobalBottomDrawerChange(null, { initiatedByUserAction: true });
273+
break;
274+
case 'expand':
275+
setExpandedDrawerId(isExpanded ? null : activeDrawerId);
276+
break;
277+
default:
278+
activeDrawer?.onHeaderActionClick?.(event);
279+
}
280+
}}
281+
ariaLabel="Global panel actions"
282+
items={drawerActions}
283+
__internalRootRef={(root: HTMLElement) => {
284+
if (!root) {
285+
return;
286+
}
287+
refs.close = {
288+
current: root.querySelector('[data-itemid="close"]') as unknown as Focusable,
289+
};
290+
}}
291+
/>
292+
</div>
293+
</div>
294+
</header>
261295
<div
262296
className={clsx(styles['drawer-content-container'], sharedStyles['with-motion-horizontal'])}
263297
data-testid={`awsui-app-layout-drawer-content-${activeDrawerId}`}
264298
>
265-
<div className={styles['drawer-actions']}>
266-
<ButtonGroup
267-
dropdownExpandToViewport={false}
268-
variant="icon"
269-
onItemClick={event => {
270-
switch (event.detail.id) {
271-
case 'close':
272-
onActiveGlobalBottomDrawerChange(null, { initiatedByUserAction: true });
273-
break;
274-
case 'expand':
275-
setExpandedDrawerId(isExpanded ? null : activeDrawerId);
276-
break;
277-
default:
278-
activeDrawer?.onHeaderActionClick?.(event);
279-
}
280-
}}
281-
ariaLabel="Global panel actions"
282-
items={drawerActions}
283-
__internalRootRef={(root: HTMLElement) => {
284-
if (!root) {
285-
return;
286-
}
287-
refs.close = { current: root.querySelector('[data-itemid="close"]') as unknown as Focusable };
288-
}}
289-
/>
290-
</div>
291299
<div
292300
className={styles['drawer-content']}
293301
style={{
294302
blockSize:
295303
isMobile || isExpanded
296304
? drawerFullScreenHeight
297-
: `${size - GAP_HEIGHT - RESIZE_HANDLER_HEIGHT}px`,
305+
: `${size - GAP_HEIGHT - RESIZE_HANDLER_HEIGHT - (headerRef?.current?.clientHeight ?? 0)}px`,
298306
}}
299307
>
300308
{activeDrawer?.content}

src/app-layout/visual-refresh-toolbar/drawer/styles.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,27 @@ $ai-drawer-heider-height: 41px;
457457
justify-content: center;
458458
}
459459

460+
> .bottom-drawer-content-header {
461+
display: flex;
462+
justify-content: space-between;
463+
align-items: center;
464+
inset-block-start: 0;
465+
box-sizing: border-box;
466+
467+
> .bottom-drawer-content-header-content {
468+
display: flex;
469+
flex: 1;
470+
align-items: center;
471+
justify-content: space-between;
472+
block-size: 100%;
473+
padding-inline-end: awsui.$space-m;
474+
475+
> .bottom-drawer-actions {
476+
display: flex;
477+
}
478+
}
479+
}
480+
460481
> .drawer-content-container {
461482
grid-template-columns: 1fr;
462483
grid-template-rows: auto;

src/app-layout/visual-refresh-toolbar/state/use-bottom-drawers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MutableRefObject, useRef, useState } from 'react';
44

55
import { fireNonCancelableEvent } from '../../../internal/events';
66
import { DrawerPayload, WidgetMessage } from '../../../internal/plugins/widget/interfaces';
7-
import { mapRuntimeConfigToDrawer } from '../../runtime-drawer';
7+
import { mapRuntimeConfigToAiDrawer } from '../../runtime-drawer';
88

99
export interface OnChangeParams {
1010
initiatedByUserAction: boolean;
@@ -32,7 +32,7 @@ export function useBottomDrawers({
3232
const [runtimeBottomDrawers, setRuntimeBottomDrawers] = useState<Array<DrawerPayload>>([]);
3333
const bottomDrawerWasOpenRef = useRef(false);
3434
bottomDrawerWasOpenRef.current = bottomDrawerWasOpenRef.current || !!activeBottomDrawerId;
35-
const bottomDrawers = runtimeBottomDrawers.map(mapRuntimeConfigToDrawer);
35+
const bottomDrawers = runtimeBottomDrawers.map(mapRuntimeConfigToAiDrawer);
3636

3737
function onActiveBottomDrawerResize({ id, size }: { id: string; size: number }) {
3838
setDrawerSizes(oldSizes => ({ ...oldSizes, [id]: size }));

0 commit comments

Comments
 (0)