-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update context menu components to React 16.3 lifecycle (#887)
* Refactor EuiContextMenu to React 16.3 lifecycle * Refactor EuiContextMenuPanel to React 16.3 lifecycle, added more context menu examples * changelog * Delete commented-out code
- Loading branch information
1 parent
fcabc85
commit d3da542
Showing
6 changed files
with
322 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { | ||
Component, | ||
} from 'react'; | ||
|
||
import { | ||
EuiButton, | ||
EuiContextMenuPanel, | ||
EuiPopover, | ||
} from '../../../../src/components'; | ||
|
||
export default class extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.interval = undefined; | ||
|
||
this.state = { | ||
isPopoverOpen: false, | ||
}; | ||
} | ||
|
||
onButtonClick = () => { | ||
this.setState(prevState => ({ | ||
isPopoverOpen: !prevState.isPopoverOpen | ||
})); | ||
}; | ||
|
||
closePopover = () => { | ||
this.setState({ | ||
isPopoverOpen: false, | ||
}); | ||
}; | ||
|
||
render() { | ||
const button = ( | ||
<EuiButton | ||
size="s" | ||
iconType="arrowDown" | ||
iconSide="right" | ||
onClick={this.onButtonClick} | ||
> | ||
Click to show some content | ||
</EuiButton> | ||
); | ||
|
||
return ( | ||
<EuiPopover | ||
id="contentPanel" | ||
button={button} | ||
isOpen={this.state.isPopoverOpen} | ||
closePopover={this.closePopover} | ||
panelPaddingSize="s" | ||
anchorPosition="downLeft" | ||
> | ||
<EuiContextMenuPanel> | ||
This context menu doesn't render items, it passes a child instead. | ||
</EuiContextMenuPanel> | ||
</EuiPopover> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src-docs/src/views/context_menu/context_menu_with_content.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import React, { | ||
Component, | ||
} from 'react'; | ||
|
||
import { | ||
EuiButton, | ||
EuiContextMenu, | ||
EuiIcon, | ||
EuiPopover, | ||
EuiPanel, | ||
EuiCard | ||
} from '../../../../src/components'; | ||
|
||
function flattenPanelTree(tree, array = []) { | ||
array.push(tree); | ||
|
||
if (tree.items) { | ||
tree.items.forEach(item => { | ||
if (item.panel) { | ||
flattenPanelTree(item.panel, array); | ||
item.panel = item.panel.id; | ||
} | ||
}); | ||
} | ||
|
||
return array; | ||
} | ||
|
||
export default class extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
isPopoverOpen: false, | ||
}; | ||
|
||
const panelTree = { | ||
id: 0, | ||
title: 'View options', | ||
items: [{ | ||
name: 'Show fullscreen', | ||
icon: ( | ||
<EuiIcon | ||
type="search" | ||
size="m" | ||
/> | ||
), | ||
onClick: () => { this.closePopover(); window.alert('Show fullscreen'); }, | ||
}, { | ||
name: 'See more', | ||
icon: 'plusInCircle', | ||
panel: { | ||
id: 1, | ||
title: 'See more', | ||
content: ( | ||
<EuiPanel> | ||
<EuiCard | ||
icon={<EuiIcon size="l" type="bolt" />} | ||
title="More Details" | ||
description="This menu demonstrates using panels that have items and panels with content." | ||
/> | ||
</EuiPanel> | ||
) | ||
}, | ||
}], | ||
}; | ||
|
||
this.panels = flattenPanelTree(panelTree); | ||
} | ||
|
||
onButtonClick = () => { | ||
this.setState(prevState => ({ | ||
isPopoverOpen: !prevState.isPopoverOpen, | ||
})); | ||
}; | ||
|
||
closePopover = () => { | ||
this.setState({ | ||
isPopoverOpen: false, | ||
}); | ||
}; | ||
|
||
render() { | ||
const button = ( | ||
<EuiButton | ||
iconType="arrowDown" | ||
iconSide="right" | ||
onClick={this.onButtonClick} | ||
> | ||
Click me to load mixed content menu | ||
</EuiButton> | ||
); | ||
|
||
return ( | ||
<EuiPopover | ||
id="contextMenu" | ||
button={button} | ||
isOpen={this.state.isPopoverOpen} | ||
closePopover={this.closePopover} | ||
panelPaddingSize="none" | ||
withTitle | ||
anchorPosition="upLeft" | ||
> | ||
<EuiContextMenu | ||
initialPanelId={0} | ||
panels={this.panels} | ||
/> | ||
</EuiPopover> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.