Skip to content

Commit

Permalink
Allowing context menu panels to have different widths (#1173)
Browse files Browse the repository at this point in the history
  • Loading branch information
cchaos authored Sep 11, 2018
1 parent ca4e952 commit 6558b71
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `euiFacetButton` and `euiFacetGroup` ([#1167](https://github.com/elastic/eui/pull/1167))
- Added `width` prop to `EuiContextMenu` panels ([#1173](https://github.com/elastic/eui/pull/1173))

## [`3.10.0`](https://github.com/elastic/eui/tree/v3.10.0)

Expand Down
16 changes: 11 additions & 5 deletions src-docs/src/views/context_menu/context_menu_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,17 @@ export const ContextMenuExample = {
code: contextMenuWithContentHtml,
}],
text: (
<p>
Context menu panels can be passed React elements through the
<EuiCode>content</EuiCode> prop instead of <EuiCode>items</EuiCode>. The panel
will display your custom content without modification.
</p>
<div>
<p>
Context menu panels can be passed React elements through the
<EuiCode>content</EuiCode> prop instead of <EuiCode>items</EuiCode>. The panel
will display your custom content without modification.
</p>
<p>
If your panel contents have different widths or you need to ensure that a specific
context menu panel has a certain width, add <code>width: [number of pixels]</code> to the panel tree.
</p>
</div>
),
demo: <ContextMenuWithContent />,
}],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class extends Component {
icon: 'plusInCircle',
panel: {
id: 1,
width: 400,
title: 'See more',
content: (
<EuiPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ exports[`EuiContextMenu props panels and initialPanelId allows you to click the
exports[`EuiContextMenu props panels and initialPanelId allows you to click the title button to go back to the previous panel 2`] = `
<div
class="euiContextMenu"
style="height: 0px;"
style="height: 0px; width: 400px;"
>
<div
class="euiContextMenuPanel euiContextMenu__panel euiContextMenuPanel-txOutRight"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ exports[`EuiContextMenu props panels and initialPanelId allows you to click the
exports[`EuiContextMenu props panels and initialPanelId allows you to click the title button to go back to the previous panel 2`] = `
<div
class="euiContextMenu"
style="height: 0px;"
style="height: 0px; width: 400px;"
>
<div
class="euiContextMenuPanel euiContextMenu__panel euiContextMenuPanel-txOutRight"
Expand Down
1 change: 1 addition & 0 deletions src/components/context_menu/_context_menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ $euiContextMenuWidth: $euiSize * 16;

.euiContextMenu {
width: $euiContextMenuWidth;
max-width: 100%;
position: relative;
overflow: hidden;
transition: height $euiAnimSpeedFast $euiAnimSlightResistance;
Expand Down
8 changes: 7 additions & 1 deletion src/components/context_menu/context_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const EuiContextMenuPanelItemShape = PropTypes.shape({

export const EuiContextMenuPanelShape = PropTypes.shape({
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
width: PropTypes.number, // Pixel value to set the panel width to
content: PropTypes.node, // Either content or items array should be given.
items: PropTypes.arrayOf(EuiContextMenuPanelItemShape),
title: PropTypes.string,
Expand Down Expand Up @@ -299,12 +300,17 @@ export class EuiContextMenu extends Component {
outgoingPanel = this.renderPanel(this.state.outgoingPanelId, 'out');
}

const width =
this.state.idToPanelMap[this.state.incomingPanelId] &&
this.state.idToPanelMap[this.state.incomingPanelId].width ?
this.state.idToPanelMap[this.state.incomingPanelId].width : undefined;

const classes = classNames('euiContextMenu', className);

return (
<div
className={classes}
style={{ height: this.state.height }}
style={{ height: this.state.height, width: width }}
{...rest}
>
{outgoingPanel}
Expand Down
1 change: 1 addition & 0 deletions src/components/context_menu/context_menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const panel2 = {
const panel1 = {
id: 1,
title: '1',
width: 400,
items: [{
name: '2a',
panel: 2,
Expand Down
1 change: 1 addition & 0 deletions src/components/context_menu/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ declare module '@elastic/eui' {
title: string;
items?: EuiContextMenuPanelItemDescriptor[];
content?: React.ReactNode;
width?: number;
}

export type EuiContextMenuProps = CommonProps &
Expand Down

0 comments on commit 6558b71

Please sign in to comment.