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

[terra-outline-view] Add icon for nav-side-menu #2154

Merged
merged 4 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const FolderTreeItem = ({
intl,
}) => {
const theme = useContext(ThemeContext);
const isFolder = subfolderItems?.length > 0;
const isFolder = subfolderItems?.length >= 0;
const itemNode = useRef();
const subFolderNode = useRef();

Expand Down Expand Up @@ -128,7 +128,7 @@ const FolderTreeItem = ({
</ul>
) : null;

const itemIcon = subfolder ? <IconFolder a11yLabel={intl.formatMessage({ id: 'Terra.folder-tree.folder-icon' })} /> : icon;
const itemIcon = subfolder && !icon ? <IconFolder a11yLabel={intl.formatMessage({ id: 'Terra.folder-tree.folder-icon' })} /> : icon;
const expandCollapseIcon = isExpanded
? <IconCaretDown height="8px" width="8px" style={{ verticalAlign: 'baseline' }} /> // eslint-disable-line react/forbid-component-props
: <IconCaretRight height="8px" width="8px" style={{ verticalAlign: 'baseline' }} />; // eslint-disable-line react/forbid-component-props
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { IconDocuments } from 'terra-icon';
import { IconDocuments, IconHospital } from 'terra-icon';
import OutlineView from 'terra-outline-view';

const data = {
Expand All @@ -21,6 +21,7 @@ const data = {
{ id: 'item-1-level-3-1', label: 'Very Very Very Very Very Very Very Long Name Test', icon: <IconDocuments /> },
{ id: 'item-2-level-3-1', label: 'Even Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger Name Test', icon: <IconDocuments /> },
],
icon: <IconHospital />,
},
],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { IconDocuments } from 'terra-icon';
import { IconDocuments, IconHospital } from 'terra-icon';
import OutlineView from 'terra-outline-view';

const DefaultOutlineView = () => {
Expand All @@ -9,6 +9,8 @@ const DefaultOutlineView = () => {
const [expandedItems, setExpandedItems] = React.useState({
projects: false,
tests: false,
details: false,
test2: false,
});

const handleExpandCollapseKeys = (key) => {
Expand Down Expand Up @@ -98,7 +100,7 @@ const DefaultOutlineView = () => {
isExpanded={expandedItems.tests}
onSelect={() => { setSelectedKey('tests'); }}
onToggle={() => { handleExpandCollapseKeys('tests'); }}
icon={<IconDocuments />}
icon={<IconHospital />}
subfolderItems={[
(<OutlineView.Item
label="very_very_very_very_very_very_very_long_name_test.txt"
Expand All @@ -121,10 +123,28 @@ const DefaultOutlineView = () => {
isSelected={selectedKey === 'longer-name-test'}
onSelect={() => { setSelectedKey('longer-name-test'); }}
/>),
(<OutlineView.Item
label="test2"
key="test2"
isSelected={selectedKey === 'test2'}
onSelect={() => { setSelectedKey('test2'); }}
isExpanded={expandedItems.test2}
onToggle={() => { handleExpandCollapseKeys('test2'); }}
subfolderItems={[]}
/>),
]}
/>),
]}
/>
<OutlineView.Item
label="Details"
key="details"
isSelected={selectedKey === 'details'}
onSelect={() => { setSelectedKey('details'); }}
isExpanded={expandedItems.details}
onToggle={() => { handleExpandCollapseKeys('details'); }}
subfolderItems={[]}
/>
</OutlineView>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/terra-navigation-side-menu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"terra-content-container": "^3.0.0",
"terra-icon": "^3.19.0",
"terra-theme-context": "^1.9.0",
"terra-visually-hidden-text": "^2.0.0"
"terra-visually-hidden-text": "^2.0.0",
"terra-status-view": "^4.76.0"
},
"peerDependencies": {
"react": "^16.8.5",
Expand Down
8 changes: 6 additions & 2 deletions packages/terra-navigation-side-menu/src/MenuItem.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
color: var(--terra-navigation-side-menu-item-hover-chevron-color, #bcbfc0);
}
}

&:focus {
box-shadow: var(--terra-navigation-side-menu-item-focus-box-shadow, none);
outline: var(--terra-navigation-side-menu-focus-outline, 2px dashed #000);
Expand Down Expand Up @@ -125,7 +125,7 @@
box-shadow: var(--terra-navigation-side-menu-item-focus-box-shadow, none);
outline: var(--terra-navigation-side-menu-focus-outline, 2px dashed #000);
outline-offset: var(--terra-navigation-side-menu-focus-outline-offset, -2px);

/* stylelint-disable-next-line max-nesting-depth */
.chevron {
color: var(--terra-navigation-side-menu-item-selected-focus-chevron-color, #909496);
Expand Down Expand Up @@ -156,4 +156,8 @@
width: var(--terra-navigation-side-menu-item-chevron-width, 0.8em);
}
}

.icon {
margin-right: 10px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ContentContainer from 'terra-content-container';
import VisuallyHiddenText from 'terra-visually-hidden-text';
import * as KeyCode from 'keycode-js';
import ThemeContext from 'terra-theme-context';
import StatusView from 'terra-status-view';
import MenuItem from './_MenuItem';

import styles from './NavigationSideMenu.module.scss';
Expand Down Expand Up @@ -94,6 +95,8 @@ const processMenuItems = (menuItems) => {
metaData: item.metaData,
hasSubMenu: item.hasSubMenu,
isRootMenu: item.isRootMenu,
icon: item.icon,
showIcon: item.showIcon,
};
if (item.childKeys) {
item.childKeys.forEach((key) => {
Expand Down Expand Up @@ -306,6 +309,10 @@ class NavigationSideMenu extends Component {
this.handleEvents(event, item, key);
};

if (key === 'empty-child-key') {
return <StatusView variant="no-data" />;
}

return (
<MenuItem
id={item.id}
Expand All @@ -317,6 +324,8 @@ class NavigationSideMenu extends Component {
onKeyDown={onKeyDown}
data-menu-item={key}
tabIndex={(tabIndex === 0 && !(this.onBack)) ? '0' : '-1'}
icon={item.icon}
showIcon={item.showIcon}
/>
);
}
Expand Down
15 changes: 15 additions & 0 deletions packages/terra-navigation-side-menu/src/_MenuItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ThemeContext from 'terra-theme-context';
import * as KeyCode from 'keycode-js';
import ChevronRight from 'terra-icon/lib/icon/IconChevronRight';
import VisuallyHiddenText from 'terra-visually-hidden-text';
import { IconFolder, IconCaretRight, IconCaretDown } from 'terra-icon';

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

Expand Down Expand Up @@ -43,6 +44,15 @@ const propTypes = {
* tabIndex for the menu item.
* */
tabIndex: PropTypes.string,
/**
* @private
* The icon to display to the left for the menu item.
*/
icon: PropTypes.element,
/**
* If enabled, this prop will show the icon to the left for the menu item.
*/
showIcon: PropTypes.bool,
};

class MenuItem extends React.Component {
Expand Down Expand Up @@ -94,10 +104,14 @@ class MenuItem extends React.Component {
intl,
isSelected,
text,
icon,
showIcon,
...customProps
} = this.props;
const theme = this.context;

const itemIcon = hasChevron && !icon ? <IconFolder /> : icon;

const itemClassNames = classNames(cx(
'menu-item',
{ 'is-selected': isSelected },
Expand All @@ -120,6 +134,7 @@ class MenuItem extends React.Component {
onKeyDown={this.handleKeyDown}
aria-haspopup={hasChevron}
>
{showIcon && <span className={cx('icon')}>{itemIcon}</span>}
<div className={cx('title')}>
{this.textRender()}
</div>
Expand Down
20 changes: 17 additions & 3 deletions packages/terra-outline-view/src/OutlineView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,21 @@ class OutlineView extends Component {

buildSideMenuItems = (items) => {
if (items) {
const menuItems = [{ key: 'menu', text: this.props.title, childKeys: items.map(k => k.key) }];
const menuItems = [{ key: 'menu', text: this.props.title, childKeys: items.map(k => k.key) }, { key: 'empty-child-key', text: 'Empty' }];
const sideMenuItems = [];
items.forEach(item => {
let childKeys;
if (item && item.props.subfolderItems) {
childKeys = item.props.subfolderItems.length ? item.props.subfolderItems.map(k => k.key) : ['empty-child-key'];
}
menuItems.push({
key: item.key,
text: item.props.label,
id: item.id,
childKeys: (item && item.props.subfolderItems) ? item.props.subfolderItems.map(k => k.key) : [],
childKeys: childKeys || [],
icon: item.props.icon,
showIcon: true,
hasSubMenu: item && item.props.subfolderItems && item.props.subfolderItems.length === 0,
});
if (item && item.props.subfolderItems) {
const subMenuItems = this.buildSideMenuSubItems(item.props.subfolderItems);
Expand All @@ -145,11 +152,18 @@ class OutlineView extends Component {
if (items) {
const sideMenuItems = [];
items.forEach(item => {
let childKeys;
if (item && item.props.subfolderItems) {
childKeys = item.props.subfolderItems.length ? item.props.subfolderItems.map(k => k.key) : ['empty-child-key'];
}
sideMenuItems.push({
key: item.key,
text: item.props.label,
id: item.id,
childKeys: (item && item.props.subfolderItems) ? item.props.subfolderItems.map(k => k.key) : [],
childKeys: childKeys || [],
icon: item.props.icon,
showIcon: true,
hasSubMenu: item && item.props.subfolderItems && item.props.subfolderItems.length === 0,
});
if (item && item.props.subfolderItems) {
const subMenuItems = this.buildSideMenuSubItems(item.props.subfolderItems);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const propTypes = {
label: PropTypes.string.isRequired,
/**
* The icon to display to the left of the name.
* Icon usage is restricted to Documents or Hospital.
*/
icon: PropTypes.element,
/**
Expand Down
Loading