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

Commit

Permalink
using constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Sugan G authored and Sugan G committed May 15, 2024
1 parent 52d9c7f commit 066ee15
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DrillInDefault extends React.Component {
selectedMenuKey={this.state.selectedMenuKey}
selectedChildKey={this.state.selectedChildKey}
ariaLabel="Sub Menu List"
variant="drill-in"
variant={NavigationSideMenu.Opts.Variants.DRILL_IN}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class DrillInExample extends React.Component {
routingStackBack={this.fakeRoutingBack}
selectedMenuKey={this.state.selectedMenuKey}
selectedChildKey={this.state.selectedChildKey}
variant="drill-in"
variant={NavigationSideMenu.Opts.Variants.DRILL_IN}
/>
);
}
Expand Down
18 changes: 9 additions & 9 deletions packages/terra-navigation-side-menu/src/NavigationSideMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as KeyCode from 'keycode-js';
import ThemeContext from 'terra-theme-context';
import StatusView from 'terra-status-view';
import MenuItem from './_MenuItem';
import VARIANTS from './constants';

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

Expand Down Expand Up @@ -89,12 +90,12 @@ const propTypes = {
/**
* Renders either Navigation Side Menu or Drill-IN
*/
variant: PropTypes.oneOf(['nav-side-menu', 'drill-in']),
variant: PropTypes.oneOf(['navigation-side-menu', 'drill-in']),
};

const defaultProps = {
menuItems: [],
variant: 'nav-side-menu',
variant: 'navigation-side-menu',
};

const processMenuItems = (menuItems) => {
Expand Down Expand Up @@ -328,12 +329,8 @@ class NavigationSideMenu extends Component {
this.handleEvents(event, item, key);
};

if (this.props.variant === 'drill-in' && key === 'empty-child-key') {
return <StatusView variant="no-data" />;
}

if (this.props.variant !== 'drill-in' && key === 'empty-child-key') {
return null;
if (key === 'empty-child-key') {
return this.props.variant === VARIANTS.DRILL_IN ? <StatusView variant="no-data" /> : null;
}

return (
Expand Down Expand Up @@ -399,7 +396,7 @@ class NavigationSideMenu extends Component {
}

const headerStyles = cx([
{ 'header-style': (variant === 'drill-in') },
{ 'header-style': (variant === VARIANTS.DRILL_IN) },
theme.className,
]);

Expand Down Expand Up @@ -451,5 +448,8 @@ class NavigationSideMenu extends Component {
NavigationSideMenu.propTypes = propTypes;
NavigationSideMenu.defaultProps = defaultProps;
NavigationSideMenu.contextType = ThemeContext;
NavigationSideMenu.Opts = {};
NavigationSideMenu.Opts.Variants = VARIANTS;

export default injectIntl(NavigationSideMenu);
export { VARIANTS };
9 changes: 5 additions & 4 deletions packages/terra-navigation-side-menu/src/_MenuItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as KeyCode from 'keycode-js';
import ChevronRight from 'terra-icon/lib/icon/IconChevronRight';
import VisuallyHiddenText from 'terra-visually-hidden-text';
import { IconDocuments, IconFolder } from 'terra-icon';
import VARIANTS from './constants';

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

Expand Down Expand Up @@ -56,7 +57,7 @@ const propTypes = {
/**
* Renders either Navigation Side Menu or Drill-IN
*/
variant: PropTypes.oneOf(['nav-side-menu', 'drill-in']),
variant: PropTypes.oneOf([VARIANTS.NAVIGATION_SIDE_MENU, VARIANTS.DRILL_IN]),
/**
* Indicates if menu item should be disabled.
*/
Expand Down Expand Up @@ -125,14 +126,14 @@ class MenuItem extends React.Component {
'menu-item',
{ 'is-selected': isSelected && !hasChevron },
{ 'is-active': this.state.active },
{ 'is-drill-in': (variant === 'drill-in') },
{ 'is-drill-in': (variant === VARIANTS.DRILL_IN) },
theme.className,
),
customProps.className);

const listItemClassNames = cx(
'list-item',
{ 'has-border': (variant === 'drill-in') },
{ 'has-border': (variant === VARIANTS.DRILL_IN) },
{ 'is-disabled': isDisabled },
);

Expand All @@ -150,7 +151,7 @@ class MenuItem extends React.Component {
onKeyDown={this.handleKeyDown}
aria-haspopup={hasChevron}
>
{variant === 'drill-in' && itemIcon && <span className={cx('icon')}>{itemIcon}</span>}
{variant === VARIANTS.DRILL_IN && itemIcon && <span className={cx('icon')}>{itemIcon}</span>}
<div className={cx('title')}>
{this.textRender()}
</div>
Expand Down
6 changes: 6 additions & 0 deletions packages/terra-navigation-side-menu/src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const VARIANTS = {
NAVIGATION_SIDE_MENU: 'navigation-side-menu',
DRILL_IN: 'drill-in',
};

export default VARIANTS;
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ exports[`Layout correctly applies the theme context className 1`] = `
onChange={[Function]}
routingStackBack={[Function]}
selectedMenuKey="menu"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<VisuallyHiddenText
aria-atomic="true"
Expand Down Expand Up @@ -255,7 +255,7 @@ exports[`Layout correctly applies the theme context className 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 1"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<MenuItem
data-menu-item="test1"
Expand Down Expand Up @@ -291,7 +291,7 @@ exports[`Layout correctly applies the theme context className 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 1"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<li
className="list-item"
Expand Down Expand Up @@ -322,7 +322,7 @@ exports[`Layout correctly applies the theme context className 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 2"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<MenuItem
data-menu-item="test2"
Expand Down Expand Up @@ -358,7 +358,7 @@ exports[`Layout correctly applies the theme context className 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 2"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<li
className="list-item"
Expand Down Expand Up @@ -389,7 +389,7 @@ exports[`Layout correctly applies the theme context className 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 3"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<MenuItem
data-menu-item="test3"
Expand Down Expand Up @@ -425,7 +425,7 @@ exports[`Layout correctly applies the theme context className 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 3"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<li
className="list-item"
Expand Down Expand Up @@ -456,7 +456,7 @@ exports[`Layout correctly applies the theme context className 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 4"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<MenuItem
data-menu-item="test4"
Expand Down Expand Up @@ -492,7 +492,7 @@ exports[`Layout correctly applies the theme context className 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 4"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<li
className="list-item"
Expand Down Expand Up @@ -565,7 +565,7 @@ exports[`Layout should render a NavigationSideMenu with a toolbar 1`] = `
Toolbar
</div>
}
variant="nav-side-menu"
variant="navigation-side-menu"
/>
`;

Expand Down Expand Up @@ -695,7 +695,7 @@ exports[`Layout should render a NavigationSideMenu with ariaLabel 1`] = `
onChange={[Function]}
routingStackBack={[Function]}
selectedMenuKey="menu"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<VisuallyHiddenText
aria-atomic="true"
Expand Down Expand Up @@ -822,7 +822,7 @@ exports[`Layout should render a NavigationSideMenu with ariaLabel 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 1"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<MenuItem
data-menu-item="test1"
Expand Down Expand Up @@ -858,7 +858,7 @@ exports[`Layout should render a NavigationSideMenu with ariaLabel 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 1"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<li
className="list-item"
Expand Down Expand Up @@ -889,7 +889,7 @@ exports[`Layout should render a NavigationSideMenu with ariaLabel 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 2"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<MenuItem
data-menu-item="test2"
Expand Down Expand Up @@ -925,7 +925,7 @@ exports[`Layout should render a NavigationSideMenu with ariaLabel 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 2"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<li
className="list-item"
Expand Down Expand Up @@ -956,7 +956,7 @@ exports[`Layout should render a NavigationSideMenu with ariaLabel 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 3"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<MenuItem
data-menu-item="test3"
Expand Down Expand Up @@ -992,7 +992,7 @@ exports[`Layout should render a NavigationSideMenu with ariaLabel 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 3"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<li
className="list-item"
Expand Down Expand Up @@ -1023,7 +1023,7 @@ exports[`Layout should render a NavigationSideMenu with ariaLabel 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 4"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<MenuItem
data-menu-item="test4"
Expand Down Expand Up @@ -1059,7 +1059,7 @@ exports[`Layout should render a NavigationSideMenu with ariaLabel 1`] = `
onKeyDown={[Function]}
tabIndex="-1"
text="Test Menu 4"
variant="nav-side-menu"
variant="navigation-side-menu"
>
<li
className="list-item"
Expand Down Expand Up @@ -1126,7 +1126,7 @@ exports[`Layout should render a NavigationSideMenu with default props 1`] = `
onChange={[Function]}
routingStackBack={[Function]}
selectedMenuKey=""
variant="nav-side-menu"
variant="navigation-side-menu"
/>
`;

Expand Down Expand Up @@ -1192,7 +1192,7 @@ exports[`Layout should render a NavigationSideMenu with selectedKey 1`] = `
onChange={[Function]}
routingStackBack={[Function]}
selectedMenuKey="menu"
variant="nav-side-menu"
variant="navigation-side-menu"
/>
`;

Expand Down

0 comments on commit 066ee15

Please sign in to comment.