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

Added display prop to EuiPopover #2112

Merged
merged 9 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
45 changes: 45 additions & 0 deletions src-docs/src/views/popover/popover_block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { Component } from 'react';

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

export default class PopoverContainer extends Component {
constructor(props) {
super(props);

this.state = {
isPopoverOpen: false,
};
}

onButtonClick = () => {
this.setState({
isPopoverOpen: !this.state.isPopoverOpen,
});
};

closePopover = () => {
this.setState({
isPopoverOpen: false,
});
};

setPanelRef = node => (this.panel = node);

render() {
const button = (
<EuiButton onClick={this.onButtonClick} fullWidth>
This button is expanded
</EuiButton>
);

return (
<EuiPopover
button={button}
isOpen={this.state.isPopoverOpen}
closePopover={this.closePopover}
display="block">
<div>This is a popover</div>
</EuiPopover>
);
}
}
37 changes: 37 additions & 0 deletions src-docs/src/views/popover/popover_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ import PopoverFixed from './popover_fixed';
const popoverFixedSource = require('!!raw-loader!./popover_fixed');
const popoverFixedHtml = renderToHtml(PopoverFixed);

import PopoverBlock from './popover_block';
const popoverBlockSource = require('!!raw-loader!./popover_block');
const popoverBlockHtml = renderToHtml(PopoverBlock);

const popOverSnippet = `<EuiPopover
button={button}
isOpen={this.state.isPopoverOpen}
Expand Down Expand Up @@ -114,6 +118,14 @@ const popoverFixedSnippet = `<EuiPopover
<!-- Popover on a fixed element -->
</EuiPopover>`;

const popoverBlockSnippet = `<EuiPopover
button={button}
isOpen={this.state.isPopoverOpen}
closePopover={this.closePopover}
display="block">
<!-- Popover anchor is display block -->
</EuiPopover>`;

export const PopoverExample = {
title: 'Popover',
sections: [
Expand Down Expand Up @@ -349,5 +361,30 @@ export const PopoverExample = {
snippet: popoverFixedSnippet,
demo: <PopoverFixed />,
},
{
title: 'Popover as display block',
cchaos marked this conversation as resolved.
Show resolved Hide resolved
source: [
{
type: GuideSectionTypes.JS,
code: popoverBlockSource,
},
{
type: GuideSectionTypes.HTML,
code: popoverBlockHtml,
},
],
text: (
<div>
<p>
Popover anchors are forced to be{' '}
cchaos marked this conversation as resolved.
Show resolved Hide resolved
<EuiCode>display: inline-block</EuiCode> so they do not force block
display on inline triggers. If you do need to change this to block
display, just add <EuiCode>display=&quot;block&quot;</EuiCode>
</p>
</div>
),
snippet: popoverBlockSnippet,
demo: <PopoverBlock />,
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ exports[`EuiInMemoryTable behavior pagination 1`] = `
</EuiButtonEmpty>
}
closePopover={[Function]}
display="inlineBlock"
hasArrow={true}
id="customizablePagination"
isOpen={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ exports[`EuiQuickSelectPopover is rendered 1`] = `
</EuiButtonEmpty>
}
closePopover={[Function]}
display="inlineBlock"
hasArrow={true}
id="QuickSelectPopover"
isOpen={false}
Expand Down Expand Up @@ -111,6 +112,7 @@ exports[`EuiQuickSelectPopover isAutoRefreshOnly 1`] = `
</EuiButtonEmpty>
}
closePopover={[Function]}
display="inlineBlock"
hasArrow={true}
id="QuickSelectPopover"
isOpen={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ exports[`EuiSuperSelect props more props are propogated to each option 2`] = `
}
className="euiSuperSelect"
closePopover={[Function]}
display="inlineBlock"
hasArrow={false}
isOpen={true}
ownFocus={false}
Expand Down
26 changes: 13 additions & 13 deletions src/components/popover/__snapshots__/popover.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ exports[`EuiPopover props anchorPosition leftCenter is rendered 1`] = `
</div>
`;

exports[`EuiPopover props display block is rendered 1`] = `
<div
class="euiPopover euiPopover--anchorDownCenter euiPopover--displayBlock"
id="2"
>
<div
class="euiPopover__anchor"
>
<button />
</div>
</div>
`;

exports[`EuiPopover props isOpen defaults to false 1`] = `
<div
class="euiPopover euiPopover--anchorDownCenter"
Expand Down Expand Up @@ -335,16 +348,3 @@ exports[`EuiPopover props panelPaddingSize is rendered 1`] = `
</div>
</div>
`;

exports[`EuiPopover props withTitle is rendered 1`] = `
<div
class="euiPopover euiPopover--anchorDownCenter euiPopover--withTitle"
id="2"
>
<div
class="euiPopover__anchor"
>
<button />
</div>
</div>
`;
8 changes: 8 additions & 0 deletions src/components/popover/_popover.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
display: inline-block;
}

.euiPopover--displayBlock {
display: block;

.euiPopover__anchor {
display: block;
}
}

/**
* 1. Can expand further, but it looks weird if it's smaller than the originating button.
* 2. Animation happens on the panel.
Expand Down
12 changes: 12 additions & 0 deletions src/components/popover/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ const anchorPositionToClassNameMap = {

export const ANCHOR_POSITIONS = Object.keys(anchorPositionToClassNameMap);

const displayToClassNameMap = {
inlineBlock: undefined,
block: 'euiPopover--displayBlock',
};

export const DISPLAY = Object.keys(displayToClassNameMap);

const DEFAULT_POPOVER_STYLES = {
top: 50,
left: 50,
Expand Down Expand Up @@ -413,12 +420,14 @@ export class EuiPopover extends Component {
zIndex,
initialFocus,
attachToAnchor,
display,
...rest
} = this.props;

const classes = classNames(
'euiPopover',
anchorPositionToClassNameMap[anchorPosition],
displayToClassNameMap[display],
{
'euiPopover-isOpen': this.state.isOpening,
'euiPopover--withTitle': withTitle,
Expand Down Expand Up @@ -553,6 +562,8 @@ EuiPopover.propTypes = {
}),
/** Style and position alteration for arrow-less, left-aligned attachment. Intended for use with inputs as anchors, à la EuiColorPicker */
attachToAnchor: PropTypes.bool,
/** CSS display type for both the popover and anchor */
display: PropTypes.oneOf(DISPLAY),
};

EuiPopover.defaultProps = {
Expand All @@ -561,4 +572,5 @@ EuiPopover.defaultProps = {
anchorPosition: 'downCenter',
panelPaddingSize: 'm',
hasArrow: true,
display: 'inlineBlock',
};
4 changes: 2 additions & 2 deletions src/components/popover/popover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ describe('EuiPopover', () => {
});

describe('props', () => {
describe('withTitle', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

withTitle is no longer a valid prop

describe('display block', () => {
test('is rendered', () => {
const component = render(
<EuiPopover
id={getId()}
withTitle
display="block"
button={<button />}
closePopover={() => {}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exports[`FieldValueSelectionFilter active - field is global 1`] = `
</EuiFilterButton>
}
closePopover={[Function]}
display="inlineBlock"
hasArrow={true}
id="field_value_selection_0"
isOpen={false}
Expand Down Expand Up @@ -76,6 +77,7 @@ exports[`FieldValueSelectionFilter active - fields in options 1`] = `
</EuiFilterButton>
}
closePopover={[Function]}
display="inlineBlock"
hasArrow={true}
id="field_value_selection_0"
isOpen={false}
Expand Down Expand Up @@ -135,6 +137,7 @@ exports[`FieldValueSelectionFilter inactive - field is global 1`] = `
</EuiFilterButton>
}
closePopover={[Function]}
display="inlineBlock"
hasArrow={true}
id="field_value_selection_0"
isOpen={false}
Expand Down Expand Up @@ -193,6 +196,7 @@ exports[`FieldValueSelectionFilter inactive - fields in options 1`] = `
</EuiFilterButton>
}
closePopover={[Function]}
display="inlineBlock"
hasArrow={true}
id="field_value_selection_0"
isOpen={false}
Expand Down Expand Up @@ -251,6 +255,7 @@ exports[`FieldValueSelectionFilter render - all configurations 1`] = `
</EuiFilterButton>
}
closePopover={[Function]}
display="inlineBlock"
hasArrow={true}
id="field_value_selection_0"
isOpen={false}
Expand Down Expand Up @@ -296,6 +301,7 @@ exports[`FieldValueSelectionFilter render - fields in options 1`] = `
</EuiFilterButton>
}
closePopover={[Function]}
display="inlineBlock"
hasArrow={true}
id="field_value_selection_0"
isOpen={false}
Expand Down Expand Up @@ -354,6 +360,7 @@ exports[`FieldValueSelectionFilter render - multi-select OR 1`] = `
</EuiFilterButton>
}
closePopover={[Function]}
display="inlineBlock"
hasArrow={true}
id="field_value_selection_0"
isOpen={false}
Expand Down Expand Up @@ -399,6 +406,7 @@ exports[`FieldValueSelectionFilter render - options as a function 1`] = `
</EuiFilterButton>
}
closePopover={[Function]}
display="inlineBlock"
hasArrow={true}
id="field_value_selection_0"
isOpen={false}
Expand Down Expand Up @@ -444,6 +452,7 @@ exports[`FieldValueSelectionFilter render - options as an array 1`] = `
</EuiFilterButton>
}
closePopover={[Function]}
display="inlineBlock"
hasArrow={true}
id="field_value_selection_0"
isOpen={false}
Expand Down