Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Hackathon keyboard shortcuts #3048

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: Adds top navigation and hide header check
Katie George committed Nov 21, 2024

Verified

This commit was signed with the committer’s verified signature.
Kikobeats Kiko Beats
commit e53998e7f7821849a6480f4ad42ab79e2bedd39a
6 changes: 6 additions & 0 deletions pages/app/components/header.scss
Original file line number Diff line number Diff line change
@@ -27,3 +27,9 @@
color: #eee;
}
}

/* stylelint-disable */
body[data-hide-header='true'] .header {
display: none;
}
/* stylelint-enable */
92 changes: 88 additions & 4 deletions pages/keyboard-shortcut-hackathon/demo.page.tsx
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import React, { useContext, useEffect, useRef, useState } from 'react';

import { AppLayout, ContentLayout, Drawer, Header, SpaceBetween, SplitPanel } from '~components';
import { AppLayout, ContentLayout, Drawer, Header, SpaceBetween, SplitPanel, Toggle, TopNavigation } from '~components';
import { AppLayoutProps } from '~components/app-layout';

import AppContext, { AppContextType } from '../app/app-context';
@@ -28,6 +28,7 @@ export default function WithDrawers() {

const [splitPanelOpen, setSplitPanelOpen] = useState(true);
const [navigationOpen, setNavigationOpen] = useState(true);
const [hideHeader, setHideHeader] = useState(false);

const disableContentPaddings = urlParams.disableContentPaddings ?? false;
const appLayoutRef = useRef<AppLayoutProps.Ref>(null);
@@ -53,16 +54,23 @@ export default function WithDrawers() {
}, [activeDrawerId]);

useEffect(() => {
let keyPressed: any = {};

const handleKeyDown = (event: any) => {
if (event.key === 'h') {
keyPressed[event.key + event.location] = true;

if (keyPressed.Control1 === true && keyPressed['/0'] === true) {
// Check for spacebar press
event.preventDefault(); // Prevent default spacebar behavior
if (activeDrawerId !== null) {
setActiveDrawerId(null);
} else if (activeDrawerId === null) {
setActiveDrawerId('keyboard-shortcuts');
}

keyPressed = {};
}
console.log(keyPressed);
};

document.addEventListener('keydown', handleKeyDown);
@@ -106,6 +114,72 @@ export default function WithDrawers() {

return (
<ScreenshotArea gutters={false}>
<TopNavigation
identity={{
href: '#',
title: 'Super fancy service',
}}
utilities={[
{
type: 'button',
iconName: 'notification',
title: 'Notifications',
ariaLabel: 'Notifications (unread)',
badge: true,
disableUtilityCollapse: false,
},
{
type: 'menu-dropdown',
iconName: 'settings',
ariaLabel: 'Settings',
title: 'Settings',
onItemClick: event => {
if (event.detail.id === 'keyboard-shortcuts') {
setActiveDrawerId('keyboard-shortcuts');
}
},
items: [
{
id: 'keyboard-shortcuts',
text: 'Keyboard shortcuts',
},
],
},
{
type: 'menu-dropdown',
text: 'Customer Name',
description: '[email protected]',
iconName: 'user-profile',
items: [
{ id: 'profile', text: 'Profile' },
{ id: 'preferences', text: 'Preferences' },
{ id: 'security', text: 'Security' },
{
id: 'support-group',
text: 'Support',
items: [
{
id: 'documentation',
text: 'Documentation',
href: '#',
external: true,
externalIconAriaLabel: ' (opens in new tab)',
},
{ id: 'support', text: 'Support' },
{
id: 'feedback',
text: 'Feedback',
href: '#',
external: true,
externalIconAriaLabel: ' (opens in new tab)',
},
],
},
{ id: 'signout', text: 'Sign out' },
],
},
]}
/>
<AppLayout
ref={appLayoutRef}
ariaLabels={{ ...appLayoutLabels, ...drawerLabels }}
@@ -118,6 +192,16 @@ export default function WithDrawers() {
<Header variant="h1" description="Sometimes you need custom drawers to get the job done.">
Testing Keyboard shortcuts
</Header>

<Toggle
onChange={() => {
document.body.setAttribute('data-hide-header', `${!hideHeader}`);
setHideHeader(!hideHeader);
}}
checked={hideHeader}
>
Hide header
</Toggle>
</SpaceBetween>
}
>
@@ -223,8 +307,8 @@ function DrawerContent() {
header="Panels"
items={[
{
key: 'Toggle help panel',
value: 'h',
key: 'Toggle keyboard shortcuts',
value: '^ + /',
},
{
key: 'Toggle split panel',