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

[EuiContextMenu] Add size prop #4409

Merged
merged 23 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
Expand Up @@ -2,6 +2,7 @@

- Reduced the size of the icons and clear button for compressed `EuiFormControlLayout` ([#4374](https://github.com/elastic/eui/pull/4374))
- Added ability for text input updates in `EuiDatePicker` ([#4243](https://github.com/elastic/eui/pull/4243))
- Added `size` prop to `EuiContextMenu` ([#4409](https://github.com/elastic/eui/pull/4409))
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved

## [`31.0.0`](https://github.com/elastic/eui/tree/v31.0.0)

Expand Down
32 changes: 32 additions & 0 deletions src-docs/src/views/context_menu/context_menu_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import SinglePanel from './single_panel';
const singlePanelSource = require('!!raw-loader!./single_panel');
const singlePanelHtml = renderToHtml(SinglePanel);

import Small from './small';
const smallSizeSource = require('!!raw-loader!./small');
const smallSizeHtml = renderToHtml(SinglePanel);

import ContentPanel from './content_panel';
const contentPanelSource = require('!!raw-loader!./content_panel');
const contentPanelHtml = renderToHtml(ContentPanel);
Expand Down Expand Up @@ -76,6 +80,34 @@ export const ContextMenuExample = {
),
demo: <SinglePanel />,
},
{
title: 'Sizes',
source: [
{
type: GuideSectionTypes.JS,
code: smallSizeSource,
},
{
type: GuideSectionTypes.HTML,
code: smallSizeHtml,
},
],
text: (
<div>
<p>
You can reduce the size of <strong>EuiContextMenu</strong> by
setting <EuiCode>size</EuiCode> to <EuiCode>s</EuiCode>.
</p>
<p>
Use the default size <EuiCode>m</EuiCode> for major actions such as
Share and Export which appear in top application menu items. Use the
smaller size <EuiCode>s</EuiCode> for actions that affect only a
single item and are repeated per row.
</p>
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
</div>
),
demo: <Small />,
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
},
{
title: 'Displaying custom elements',
source: [
Expand Down
106 changes: 106 additions & 0 deletions src-docs/src/views/context_menu/small.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import React, { useState } from 'react';

import {
EuiButton,
EuiContextMenu,
EuiIcon,
EuiPopover,
} from '../../../../src/components';

export default () => {
const [isPopoverOpen, setPopover] = useState(false);

const onButtonClick = () => {
setPopover(!isPopoverOpen);
};

const closePopover = () => {
setPopover(false);
};

const panels = [
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
{
id: 0,
title: 'This is a context menu',
items: [
{
name: 'Handle an onClick',
icon: <EuiIcon type="search" size="m" />,
onClick: () => {
closePopover();
},
},
{
name: 'Go to a link',
icon: 'user',
href: 'http://elastic.co',
target: '_blank',
},
{
name: 'Nest panels',
icon: 'user',
panel: 1,
},
{
name: 'You can add a tooltip',
icon: 'user',
toolTipTitle: 'Optional tooltip',
toolTipContent: 'Optional content for a tooltip',
toolTipPosition: 'right',
onClick: () => {
closePopover();
},
},
{
name: 'Disabled option',
icon: 'user',
toolTipContent: 'For reasons, this item is disabled',
toolTipPosition: 'right',
disabled: true,
onClick: () => {
closePopover();
},
},
],
},
{
id: 1,
initialFocusedItemIndex: 1,
title: 'Nest panels',
items: [
{
name: 'PDF reports',
icon: 'user',
onClick: () => {
closePopover();
},
},
{
name: 'Permalinks',
icon: 'user',
onClick: () => {
closePopover();
},
},
],
},
];

const button = (
<EuiButton iconType="arrowDown" iconSide="right" onClick={onButtonClick}>
Small context menu
</EuiButton>
);

return (
<EuiPopover
id="contextMenuExample"
button={button}
isOpen={isPopoverOpen}
closePopover={closePopover}
panelPaddingSize="none"
anchorPosition="downLeft">
<EuiContextMenu size="s" initialPanelId={0} panels={panels} />
</EuiPopover>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,79 @@ exports[`EuiContextMenu props panels and initialPanelId renders the referenced p
</div>
</div>
`;

exports[`EuiContextMenu props size m is rendered 1`] = `
<div
class="euiContextMenu"
>
<div
class="euiContextMenuPanel euiContextMenu__panel"
tabindex="0"
>
<button
class="euiContextMenuPanelTitle"
data-test-subj="contextMenuPanelTitleButton"
type="button"
>
<span
class="euiContextMenu__itemLayout"
>
<span
class="euiContextMenu__icon"
data-euiicon-type="arrowLeft"
/>
<span
class="euiContextMenu__text"
>
2
</span>
</span>
</button>
<div>
<div>
<div>
2
</div>
</div>
</div>
</div>
</div>
`;

exports[`EuiContextMenu props size s is rendered 1`] = `
<div
class="euiContextMenu euiContextMenu--small"
>
<div
class="euiContextMenuPanel euiContextMenu__panel"
tabindex="0"
>
<button
class="euiContextMenuPanelTitle"
data-test-subj="contextMenuPanelTitleButton"
type="button"
>
<span
class="euiContextMenu__itemLayout"
>
<span
class="euiContextMenu__icon"
data-euiicon-type="arrowLeft"
/>
<span
class="euiContextMenu__text"
>
2
</span>
</span>
</button>
<div>
<div>
<div>
2
</div>
</div>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,82 @@ exports[`EuiContextMenu props panels and initialPanelId renders the referenced p
</div>
`;

exports[`EuiContextMenu props size m is rendered 1`] = `
<div
class="euiContextMenu"
>
<div
class="euiContextMenuPanel euiContextMenu__panel"
tabindex="0"
>
<button
class="euiContextMenuPanelTitle"
data-test-subj="contextMenuPanelTitleButton"
type="button"
>
<span
class="euiContextMenu__itemLayout"
>
<span
class="euiContextMenu__icon"
data-euiicon-type="arrowLeft"
/>
<span
class="euiContextMenu__text"
>
2
</span>
</span>
</button>
<div>
<div>
<div>
2
</div>
</div>
</div>
</div>
</div>
`;

exports[`EuiContextMenu props size s is rendered 1`] = `
<div
class="euiContextMenu euiContextMenu--small"
>
<div
class="euiContextMenuPanel euiContextMenu__panel"
tabindex="0"
>
<button
class="euiContextMenuPanelTitle"
data-test-subj="contextMenuPanelTitleButton"
type="button"
>
<span
class="euiContextMenu__itemLayout"
>
<span
class="euiContextMenu__icon"
data-euiicon-type="arrowLeft"
/>
<span
class="euiContextMenu__text"
>
2
</span>
</span>
</button>
<div>
<div>
<div>
2
</div>
</div>
</div>
</div>
</div>
`;

exports[`EuiContextMenuPanel is rendered 1`] = `
<div
aria-label="aria-label"
Expand Down
11 changes: 11 additions & 0 deletions src/components/context_menu/_context_menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ $euiContextMenuWidth: $euiSize * 16;
.euiContextMenu__content {
padding: $euiSizeS;
}

&--small {
.euiContextMenuPanelTitle {
@include euiTitle('xxxs');
padding: $euiSizeS;
}

.euiContextMenuItem {
padding: $euiSizeS;
}
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/components/context_menu/_context_menu_item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@
flex-shrink: 0;
}
}

.euiContextMenu--small {
.euiContextMenuItem__text {
@include euiFontSizeS;
}
}
13 changes: 12 additions & 1 deletion src/components/context_menu/context_menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import React from 'react';
import { render, mount } from 'enzyme';
import { requiredProps, takeMountedSnapshot } from '../../test';

import { EuiContextMenu } from './context_menu';
import { EuiContextMenu, SIZES } from './context_menu';
import { setTimeout } from 'timers';

const panel3 = {
Expand Down Expand Up @@ -168,5 +168,16 @@ describe('EuiContextMenu', () => {
expect(takeMountedSnapshot(component)).toMatchSnapshot();
});
});
describe('size', () => {
SIZES.forEach((size) => {
it(`${size} is rendered`, () => {
const component = render(
<EuiContextMenu panels={panels} initialPanelId={2} size={size} />
);

expect(component).toMatchSnapshot();
});
});
});
});
});
Loading