Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing context menu panels to have different widths #1173

Merged
merged 7 commits into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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
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 `maxWidth` prop to `EuiModal` ([#1165](https://github.com/elastic/eui/pull/1165))
- Added `width` prop to `EuiContextMenu` panels ([#1173](https://github.com/elastic/eui/pull/1173))

## [`3.9.0`](https://github.com/elastic/eui/tree/v3.9.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