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

EuiInputPopover docs #2269

Merged
merged 11 commits into from
Sep 5, 2019
58 changes: 58 additions & 0 deletions src-docs/src/views/popover/input_popover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React, { useState } from 'react';

import {
EuiInputPopover,
EuiFieldText,
EuiSpacer,
} from '../../../../src/components';

export default () => {
const [inputWidth, setInputWidth] = useState(200);
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [isPopoverOpenTwo, setIsPopoverOpenTwo] = useState(false);
const toggleIsPopoverOpen = (shouldBeOpen = !isPopoverOpen) => {
setIsPopoverOpen(shouldBeOpen);
};
const toggleIsPopoverOpenTwo = (shouldBeOpen = !isPopoverOpenTwo) => {
setIsPopoverOpenTwo(shouldBeOpen);
};

const input = <EuiFieldText onFocus={() => toggleIsPopoverOpen()} />;

const inputTwo = (
<EuiFieldText
onFocus={() => {
setInputWidth(400);
toggleIsPopoverOpenTwo();
}}
style={{ width: inputWidth }}
/>
);

return (
<React.Fragment>
<EuiInputPopover
id="popover"
input={input}
isOpen={isPopoverOpen}
closePopover={() => {
toggleIsPopoverOpen(false);
}}>
Popover content
</EuiInputPopover>

<EuiSpacer />

<EuiInputPopover
id="popover"
input={inputTwo}
isOpen={isPopoverOpenTwo}
closePopover={() => {
toggleIsPopoverOpenTwo(false);
setInputWidth(200);
}}>
Popover will adjust in size as the input does
</EuiInputPopover>
</React.Fragment>
);
};
48 changes: 48 additions & 0 deletions src-docs/src/views/popover/popover_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { GuideSectionTypes } from '../../components';

import {
EuiCode,
EuiInputPopover,
EuiPopover,
EuiPopoverTitle,
EuiPopoverFooter,
Expand Down Expand Up @@ -51,6 +52,10 @@ import PopoverBlock from './popover_block';
const popoverBlockSource = require('!!raw-loader!./popover_block');
const popoverBlockHtml = renderToHtml(PopoverBlock);

import InputPopover from './input_popover';
const inputPopoverSource = require('!!raw-loader!./input_popover');
const inputPopoverHtml = renderToHtml(PopoverBlock);

const popOverSnippet = `<EuiPopover
button={button}
isOpen={this.state.isPopoverOpen}
Expand Down Expand Up @@ -126,6 +131,13 @@ const popoverBlockSnippet = `<EuiPopover
<!-- Popover anchor is display block -->
</EuiPopover>`;

const inputPopoverSnippet = `<EuiInputPopover
input={input}
isOpen={this.state.isPopoverOpen}
closePopover={this.closePopover}>
<!-- Popover content attached to input -->
</EuiInputPopover>`;

export const PopoverExample = {
title: 'Popover',
sections: [
Expand Down Expand Up @@ -338,6 +350,42 @@ export const PopoverExample = {
),
demo: <PopoverHTMLElementAnchor />,
},
{
title: 'Popover attached to input element',
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
source: [
{
type: GuideSectionTypes.JS,
code: inputPopoverSource,
},
{
type: GuideSectionTypes.HTML,
code: inputPopoverHtml,
},
],
text: (
<div>
<p>
<EuiCode>EuiInputPopover</EuiCode> is a specialized popover
component intended to be used with form elements. Stylistically, the
popover panel is
{'"attacted"'} to the input. Functionally, the popover opens on
click focus and will allow for natural tab order.
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
</p>
<p>
Although some assumptions are made about keyboard behavior,
consumers should provide specific key event handlers depending on
the use case. For instance, a <EuiCode>type=text</EuiCode> input or
<EuiCode>EuiColorPicker</EuiCode> could use the down key to trigger
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
popout opening, but this interaction would not be appropriate for{' '}
<EuiCode>type=number</EuiCode> inputs as they natively bind to the
down key.
</p>
</div>
),
props: { EuiInputPopover },
snippet: inputPopoverSnippet,
demo: <InputPopover />,
},
{
title: 'Popover on a fixed element',
source: [
Expand Down
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export { EuiPagination, EuiPaginationButton } from './pagination';
export { EuiPanel } from './panel';

export {
EuiInputPopover,
EuiPopover,
EuiPopoverTitle,
EuiPopoverFooter,
Expand Down