Skip to content
Merged
14 changes: 9 additions & 5 deletions src/components/list_group/list_group_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,15 @@ export const EuiListGroupItem: FunctionComponent<EuiListGroupItemProps> = ({
let extraActionNode;

if (extraAction) {
const { iconType, alwaysShow, ...rest } = extraAction;

const extraActionClasses = classNames('euiListGroupItem__extraAction', {
'euiListGroupItem__extraAction-alwaysShow': alwaysShow,
});
const { iconType, alwaysShow, className, ...rest } = extraAction;

const extraActionClasses = classNames(
'euiListGroupItem__extraAction',
{
'euiListGroupItem__extraAction-alwaysShow': alwaysShow,
},
className
);

extraActionNode = (
<EuiButtonIconTyped
Expand Down
28 changes: 28 additions & 0 deletions src/components/nav_drawer/_nav_drawer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,31 @@
margin-left: 0;
}
}

@include euiBreakpoint('xs', 's', 'm', 'l') {
.euiNavDrawer__expandButtonLockAction {
display: none;
}
}

@include euiBreakpoint('xl') {
.euiNavDrawer-isLocked {
+ .euiNavDrawerPage .euiNavDrawerPage__pageBody {
// Shrink the content from the left so it's no longer overlapped by the nav drawer (ALWAYS)
margin-left: $euiNavDrawerWidthExpanded !important; // sass-lint:disable-line no-important
transition: margin $euiAnimSpeedFast $euiAnimSlightResistance;
}

&.euiNavDrawer-flyoutIsExpanded {
// Instead of one collapsed and one expanded, they're now both expanded
// Double the width of expanded sidebars
width: $euiNavDrawerWidthExpanded * 2 !important; // sass-lint:disable-line no-important
}
}

// In case they unlock while the flyout is expanded,
// the nav drawer doesn't actually get collapsed until an interaction
.euiNavDrawer-isExpanded.euiNavDrawer-flyoutIsExpanded {
width: $euiNavDrawerWidthExpanded * 2 !important; // sass-lint:disable-line no-important
}
}
97 changes: 83 additions & 14 deletions src/components/nav_drawer/nav_drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,56 @@ import { EuiNavDrawerGroup } from './nav_drawer_group';
import { EuiOutsideClickDetector } from '../outside_click_detector';
import { EuiI18n } from '../i18n';
import { EuiFlexItem } from '../flex';
import { throttle } from '../color_picker/utils';

export class EuiNavDrawer extends Component {
constructor(props) {
super(props);

this.state = {
isCollapsed: true,
isLocked: props.isLocked,
isCollapsed: !props.isLocked,
flyoutIsCollapsed: true,
outsideClickDisabled: true,
isManagingFocus: false,
toolTipsEnabled: true,
};
}

componentDidMount() {
if (this.props.isLocked) {
window.addEventListener('resize', this.functionToCallOnWindowResize);
}
}

componentWillUnmount() {
window.removeEventListener('resize', this.functionToCallOnWindowResize);
}

functionToCallOnWindowResize = throttle(() => {
if (window.innerWidth < 1200) {
this.collapseDrawer();
this.collapseFlyout();
}
// reacts every 50ms to resize changes and always gets the final update
}, 50);

timeoutID;

sideNavLockClicked = () => {
if (this.state.isLocked) {
window.removeEventListener('resize', this.functionToCallOnWindowResize);
} else {
window.addEventListener('resize', this.functionToCallOnWindowResize);
}

this.setState({
isLocked: !this.state.isLocked,
isCollapsed: false,
outsideClickDisabled: true,
});
};

toggleOpen = () => {
this.setState({
isCollapsed: !this.state.isCollapsed,
Expand All @@ -36,6 +70,16 @@ export class EuiNavDrawer extends Component {
}, 150);
};

collapseButtonClick = () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove the resize event listener in this function, also. Otherwise window resizing continues

if (this.state.isCollapsed) {
this.expandDrawer();
} else {
this.collapseDrawer();
}

this.collapseFlyout();
};

expandDrawer = () => {
this.setState({
isCollapsed: false,
Expand All @@ -54,6 +98,7 @@ export class EuiNavDrawer extends Component {
isCollapsed: true,
outsideClickDisabled: this.state.flyoutIsCollapsed ? true : false,
toolTipsEnabled: true,
isLocked: false,
});

// Scrolls the menu and flyout back to top when the nav drawer collapses
Expand Down Expand Up @@ -103,7 +148,7 @@ export class EuiNavDrawer extends Component {
flyoutIsCollapsed: false,
navFlyoutTitle: title,
navFlyoutContent: content,
isCollapsed: true,
isCollapsed: this.state.isLocked ? false : true,
toolTipsEnabled: false,
outsideClickDisabled: false,
});
Expand All @@ -115,12 +160,12 @@ export class EuiNavDrawer extends Component {
flyoutIsCollapsed: true,
navFlyoutTitle: null,
navFlyoutContent: null,
toolTipsEnabled: true,
toolTipsEnabled: this.state.isLocked ? false : true,
});
};

closeBoth = () => {
this.collapseDrawer();
if (!this.state.isLocked) this.collapseDrawer();
this.collapseFlyout();
};

Expand Down Expand Up @@ -158,6 +203,7 @@ export class EuiNavDrawer extends Component {
{
'euiNavDrawer-isCollapsed': this.state.isCollapsed,
'euiNavDrawer-isExpanded': !this.state.isCollapsed,
'euiNavDrawer-isLocked': this.state.isLocked,
'euiNavDrawer-flyoutIsCollapsed': this.state.flyoutIsCollapsed,
'euiNavDrawer-flyoutIsExpanded': !this.state.flyoutIsCollapsed,
},
Expand All @@ -172,22 +218,40 @@ export class EuiNavDrawer extends Component {
tokens={[
'euiNavDrawer.sideNavCollapse',
'euiNavDrawer.sideNavExpand',
'euiNavDrawer.sideNavLockExpanded',
'euiNavDrawer.sideNavLockCollapsed',
]}
defaults={['Collapse', 'Expand']}>
{([sideNavCollapse, sideNavExpand]) => (
defaults={[
'Collapse',
'Expand',
'Lock navigation open',
'Unlock navigation',
]}>
{([
sideNavCollapse,
sideNavExpand,
sideNavLockExpanded,
sideNavLockCollapsed,
]) => (
<EuiListGroupItem
label={this.state.isCollapsed ? sideNavExpand : sideNavCollapse}
iconType={this.state.isCollapsed ? 'menuRight' : 'menuLeft'}
size="s"
showToolTip={this.state.isCollapsed}
onClick={
this.state.isCollapsed
? () => {
this.expandDrawer();
this.collapseFlyout();
}
: () => this.collapseDrawer()
}
extraAction={{
className: 'euiNavDrawer__expandButtonLockAction',
color: 'text',
onClick: this.sideNavLockClicked,
iconType: this.state.isLocked ? 'lockOpen' : 'lock',
iconSize: 's',
'aria-label': sideNavLockExpanded,
title: this.state.isLocked
? sideNavLockCollapsed
: sideNavLockExpanded,
'aria-checked': this.state.isLocked ? true : false,
role: 'switch',
Comment thread
cchaos marked this conversation as resolved.
}}
onClick={this.collapseButtonClick}
data-test-subj={
this.state.isCollapsed
? 'navDrawerExpandButton-isCollapsed'
Expand Down Expand Up @@ -273,6 +337,11 @@ EuiNavDrawer.propTypes = {
* Display tooltips on side nav items
*/
showToolTips: PropTypes.bool,

/**
* Keep drawer locked open by default
*/
isLocked: PropTypes.bool,
};

EuiNavDrawer.defaultProps = {
Expand Down