Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
[workspace-v1-epic] Add WorkspaceLayout and SkipTos (#244)
Browse files Browse the repository at this point in the history
* Initial files, next will start pulling apart.

* Stubs for layout and skip to.

* Basic functionality working, need to updated translations.

* Update translation labels.

* Big mess...

* Working example with skipTos

* Test file structor and workspace layout doc entry.

* File cleanup and further doc.

* Spec file with examples, needs jest.

* Updated tests and screenshots.

* Update lint resource paths.

* Add change log.

* PR comments, update doc, add id, fix tests.

* Updates for PR, address dot notation.

* Correct route.

* Add todos for i18n.

* Adding translations. Adding consumption docs for workspace.

* Fixing lint.

* Getting tests to pass

* PR tweaks

* Adding NotificationBanner doc

* Adding workspace to demo example

* Rendering layout actions in demo

* Update src/terra-dev-site/app/components.2/ApplicationNavigation.app.mdx

Co-authored-by: Ben Cai <[email protected]>

* Removing errant TODOs

Co-authored-by: Tyler Biethman <[email protected]>
Co-authored-by: Tyler Biethman <[email protected]>
Co-authored-by: Ben Cai <[email protected]>
  • Loading branch information
4 people authored Jul 19, 2021
1 parent 7330ff8 commit 5bac448
Show file tree
Hide file tree
Showing 115 changed files with 2,774 additions and 766 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Added
* Local file inclusion of terra-application-navigation
* Added ApplicationNavigationActionsContext to application-navigation
* Added WorkspaceLayout to local ApplicationNavigation instance

## 1.48.0 - (June 15, 2021)

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"keycode-js": "^3.1.0",
"mutationobserver-shim": "0.3.3",
"prop-types": "^15.5.8",
"react-draggable": "^4.4.3",
"react-onclickoutside": "^6.7.1",
"resize-observer-polyfill": "^1.4.1",
"terra-action-footer": "^2.61.0",
Expand Down
17 changes: 16 additions & 1 deletion src/application-navigation/ApplicationNavigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {
useRef, useCallback, Suspense,
} from 'react';
import PropTypes from 'prop-types';
import uuidv4 from 'uuid/v4';
import TerraApplicationNavigation from './private/ApplicationNavigation';
import {
titleConfigPropType, navigationItemsPropType, extensionItemsPropType, utilityItemsPropType, userConfigPropType,
Expand All @@ -12,6 +13,7 @@ import ApplicationLoadingOverlay, { ApplicationLoadingOverlayProvider } from '..
import { ApplicationStatusOverlayProvider } from '../application-status-overlay';
import { NavigationPromptCheckpoint, navigationPromptResolutionOptionsShape, getUnsavedChangesPromptOptions } from '../navigation-prompt';
import { ApplicationIntlContext } from '../application-intl';
import ApplicationNavigationWorkspace from './private/workspace-layout/ApplicationNavigationWorkspace';

const propTypes = {
/**
Expand Down Expand Up @@ -44,6 +46,10 @@ const propTypes = {
* An element to render within the ApplicationNavigation utility menu, shifted to the drawer at the `medium` breakpoint and below.
*/
hero: PropTypes.element,
/**
* The base id used to generate ids of workspace, navigation, utility, and extension items
*/
id: PropTypes.string,
/**
* An array of configuration objects with information specifying the creation of navigation items. These items
* are rendered within the ApplicationNavigation header at larger breakpoints and within the drawer menu at smaller breakpoints.
Expand Down Expand Up @@ -116,6 +122,10 @@ const propTypes = {
* These items are rendered within the popup utility menu at larger breakpoints and within the drawer menu at smaller breakpoints.
*/
utilityItems: utilityItemsPropType,
/**
* An ApplicationNavigationWorkspace element and it's associated ApplicationNavigationWorkspaceItems.
*/
workspace: PropTypes.element,
};

const ApplicationNavigation = ({
Expand All @@ -125,6 +135,7 @@ const ApplicationNavigation = ({
disablePromptsForNavigationItems,
extensionItems,
hero,
id,
navigationItems,
navigationPromptResolutionOptions,
notifications,
Expand All @@ -138,10 +149,11 @@ const ApplicationNavigation = ({
titleConfig,
userConfig,
utilityItems,
workspace,
}) => {
const applicationIntl = React.useContext(ApplicationIntlContext);

const navigationPromptCheckpointRef = useRef();
const idRef = React.useRef(uuidv4());

const onSelectNavigationItem = useCallback((selectedItemKey) => {
if (disablePromptsForNavigationItems) {
Expand All @@ -167,6 +179,7 @@ const ApplicationNavigation = ({

return (
<TerraApplicationNavigation
id={id || idRef.current}
hero={hero}
notifications={notifications}
titleConfig={titleConfig}
Expand All @@ -182,6 +195,7 @@ const ApplicationNavigation = ({
onSelectHelp={onSelectHelp}
onSelectLogout={propOnSelectLogout && onSelectLogout}
onDrawerMenuStateChange={onDrawerMenuStateChange}
workspace={workspace}
>
<ApplicationLoadingOverlayProvider>
<ApplicationStatusOverlayProvider>
Expand All @@ -201,5 +215,6 @@ const ApplicationNavigation = ({
};

ApplicationNavigation.propTypes = propTypes;
ApplicationNavigation.Workspace = ApplicationNavigationWorkspace;

export default ApplicationNavigation;
15 changes: 12 additions & 3 deletions src/application-navigation/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import {
titleConfigPropType, navigationItemsPropType, extensionItemsPropType, utilityItemsPropType, userConfigPropType,
titleConfigPropType,
navigationItemsPropType,
extensionItemsPropType,
utilityItemsPropType,
userConfigPropType,
} from './private/utils/propTypes';
import ApplicationNavigationActionsContext from './ApplicationNavigationActionsContext';
import ApplicationNavigation from './ApplicationNavigation';

export default ApplicationNavigation;
export {
titleConfigPropType, navigationItemsPropType, extensionItemsPropType, utilityItemsPropType, userConfigPropType,
titleConfigPropType,
navigationItemsPropType,
extensionItemsPropType,
utilityItemsPropType,
userConfigPropType,
ApplicationNavigationActionsContext,
};

63 changes: 53 additions & 10 deletions src/application-navigation/private/ApplicationNavigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { shouldRenderCompactNavigation } from './utils/helpers';
import {
titleConfigPropType, userConfigPropType, navigationItemsPropType, extensionItemsPropType, utilityItemsPropType,
} from './utils/propTypes';
import WorkspaceLayout from './workspace-layout/WorkspaceLayout';

import styles from './ApplicationNavigation.module.scss';

Expand Down Expand Up @@ -108,6 +109,10 @@ const propTypes = {
* A collection of child elements to render within the ApplicationNavigation body.
*/
children: PropTypes.node,
/**
* An ApplicationNavigation.Workspace element to be presented within the layout.
*/
workspace: PropTypes.element,
};

const defaultProps = {
Expand All @@ -134,6 +139,7 @@ const ApplicationNavigation = ({
onSelectUtilityItem,
notifications,
children,
workspace,
}) => {
const drawerMenuRef = useRef();
const contentLayoutRef = useRef();
Expand All @@ -145,9 +151,11 @@ const ApplicationNavigation = ({
const drawerMenuIsOpenRef = useRef(false);
const closeMenuCallbackRef = useRef();
const renderedNavItemKeyRef = useRef(activeNavigationItemKey);
const skipToWorkspaceActionRef = useRef();

const [drawerMenuIsOpen, setDrawerMenuIsOpen] = useState(false);
const [popupMenuIsOpen, setPopupMenuIsOpen] = useState(false);
const [renderSkipToWorkspace, setRenderSkipToWorkspace] = useState(false);

const closeMenuEvent = 'terra-application-navigation.dismiss-menu';

Expand Down Expand Up @@ -273,6 +281,19 @@ const ApplicationNavigation = ({
);
}

function createWorkspaceAction() {
let skipToAction;
if (renderSkipToWorkspace) {
skipToAction = () => {
if (!skipToWorkspaceActionRef.current) {
return;
}
skipToWorkspaceActionRef.current();
};
}
return skipToAction;
}

function renderCompactHeader() {
return (
<CompactHeader
Expand All @@ -295,6 +316,7 @@ const ApplicationNavigation = ({
onSelectHelp={onSelectHelp}
onSelectLogout={onSelectLogout}
id={id}
skipToWorkspaceAction={createWorkspaceAction()}
/>
);
}
Expand All @@ -321,6 +343,7 @@ const ApplicationNavigation = ({
onSelectSettings={onSelectSettings}
onSelectHelp={onSelectHelp}
onSelectLogout={onSelectLogout}
skipToWorkspaceAction={createWorkspaceAction()}
/>
);
}
Expand Down Expand Up @@ -442,6 +465,35 @@ const ApplicationNavigation = ({
const theme = React.useContext(ThemeContext);
const appNavClassNames = cx('application-navigation', theme.className);

const renderMain = () => {
const skipToCallback = action => {
skipToWorkspaceActionRef.current = action;

if (action && !renderSkipToWorkspace) {
setRenderSkipToWorkspace(true);
}
};

return (
<WorkspaceLayout
id={`${id}-workspace-layout`}
workspace={workspace}
skipToCallback={skipToCallback}
>
<main
ref={mainContainerRef}
tabIndex="-1"
role="main"
className={cx('main-container')}
aria-labelledby={hiddenMainTitle ? 'main-inner-title' : null}
>
{hiddenMainTitle}
{children}
</main>
</WorkspaceLayout>
);
};

return (
<div className={appNavClassNames}>
<div
Expand All @@ -457,16 +509,7 @@ const ApplicationNavigation = ({
className={cx('content-layout', { 'drawer-menu-is-open': drawerMenuIsOpen })}
>
{shouldRenderCompactNavigation(activeBreakpoint) ? renderCompactHeader() : renderHeader()}
<main
ref={mainContainerRef}
tabIndex="-1"
role="main"
className={cx('main-container')}
aria-labelledby={hiddenMainTitle ? 'main-inner-title' : null}
>
{hiddenMainTitle}
{children}
</main>
{renderMain()}
<Overlay
className={cx('overlay')}
isOpen={drawerMenuIsOpen}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:local {
.clinical-lowlight-theme {
--terra-application-resize-handle-hover-background-color: rgba(34, 42, 46, 0.6);
--terra-application-resize-handle-dragging-background-color: rgba(34, 42, 46, 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:local {
.clinical-lowlight-theme {
--terra-application-workspace-layout-workspace-overlay-background-color: rgba(0, 0, 0, 0.3);
}
}
18 changes: 18 additions & 0 deletions src/application-navigation/private/header/_CompactHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ const propTypes = {
* A configuration object with information pertaining to the application's user.
*/
userConfig: userConfigPropType,
/**
* Action to tie to the skipToLink for workspace.
*/
skipToWorkspaceAction: PropTypes.func,
};

const defaultProps = {
Expand Down Expand Up @@ -169,6 +173,7 @@ const CompactHeader = ({
intl,
hero,
userConfig,
skipToWorkspaceAction,
}) => {
const [navigationIsOpen, setNavigationIsOpen] = useState(false);
const [utilitiesIsOpen, setUtilitiesIsOpen] = useState(false);
Expand Down Expand Up @@ -333,11 +338,24 @@ const CompactHeader = ({
);
}

function renderSkipToWorkspace() {
if (!skipToWorkspaceAction) {
return undefined;
}

return (
<button type="button" role="link" onClick={skipToWorkspaceAction} className={cx('skip-content-button')}>
{intl.formatMessage({ id: 'terraApplication.workspace.skipToLabel' })}
</button>
);
}

return (
<header role="banner" className={cx('compact-header')}>
<button type="button" role="link" onClick={onSelectSkipToContent} className={cx('skip-content-button')}>
{intl.formatMessage({ id: 'terraApplication.navigation.header.skipToContentTitle' })}
</button>
{renderSkipToWorkspace()}
{renderMenuButton()}
<div className={cx('title-container')}>
{renderTitle()}
Expand Down
18 changes: 18 additions & 0 deletions src/application-navigation/private/header/_Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ const propTypes = {
* If `onSelectLogout` is not provided, the Logout action button will not be rendered.
*/
onSelectLogout: PropTypes.func,
/**
* Action to tie to the skipToLink for workspace.
*/
skipToWorkspaceAction: PropTypes.func,
};

const defaultProps = {
Expand Down Expand Up @@ -129,6 +133,7 @@ const Header = ({
onSelectSettings,
onSelectHelp,
onSelectLogout,
skipToWorkspaceAction,
}) => {
function renderTitle() {
if (!titleConfig) {
Expand Down Expand Up @@ -198,11 +203,24 @@ const Header = ({
);
}

function renderSkipToWorkspace() {
if (!skipToWorkspaceAction) {
return undefined;
}

return (
<button type="button" role="link" onClick={skipToWorkspaceAction} className={cx('skip-content-button')}>
{intl.formatMessage({ id: 'terraApplication.workspace.skipToLabel' })}
</button>
);
}

return (
<header role="banner" className={cx('header')}>
<button type="button" role="link" onClick={onSelectSkipToContent} className={cx('skip-content-button')}>
{intl.formatMessage({ id: 'terraApplication.navigation.header.skipToContentTitle' })}
</button>
{renderSkipToWorkspace()}
<div className={cx('title-container')}>
{renderTitle()}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:local {
.orion-fusion-theme {
--terra-application-resize-handle-hover-background-color: rgba(34, 42, 46, 0.6);
--terra-application-resize-handle-dragging-background-color: rgba(34, 42, 46, 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:local {
.orion-fusion-theme {
--terra-application-workspace-layout-workspace-overlay-background-color: rgba(0, 0, 0, 0.3);
}
}
4 changes: 2 additions & 2 deletions src/application-navigation/private/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ function logoutUtilityItemId(appNavId) {
return utilityItemId(appNavId, 'TerraLogout');
}

function extensionItemId(appNavId, extenstionItemKey) {
return itemId(appNavId, 'ExtensionItem', extenstionItemKey);
function extensionItemId(appNavId, extensionItemKey) {
return itemId(appNavId, 'ExtensionItem', extensionItemKey);
}

export default {
Expand Down
Loading

0 comments on commit 5bac448

Please sign in to comment.