Skip to content

Commit

Permalink
Moving super_select to super_select_control and
Browse files Browse the repository at this point in the history
putting popover stuff into super_select
  • Loading branch information
cchaos committed Jun 26, 2018
1 parent 5664493 commit 8f27db0
Show file tree
Hide file tree
Showing 20 changed files with 475 additions and 241 deletions.
103 changes: 46 additions & 57 deletions src-docs/src/views/super_select/super_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import React, {
import {
EuiSuperSelect,
EuiSpacer,
EuiContextMenuItem,
EuiContextMenuPanel,
EuiPopover,
EuiText,
EuiIcon,
EuiContextMenuItem,
EuiHorizontalRule,
} from '../../../../src/components';

export default class extends Component {
Expand All @@ -23,9 +22,10 @@ export default class extends Component {
text: 'Option one',
display: (
<Fragment>
<EuiText size="s">
<h3>Option one</h3>
<p>Has a short description giving more detail to the option.</p>
<strong>Option one</strong>
<EuiSpacer size="xs" />
<EuiText size="s" color="subdued">
<p className="euiTextColor--subdued">Has a short description giving more detail to the option.</p>
</EuiText>
</Fragment>
),
Expand All @@ -39,9 +39,10 @@ export default class extends Component {
),
display: (
<Fragment>
<EuiText size="s">
<h3>Option Two</h3>
<p>Has a short description giving more detail to the option.</p>
<strong>Option two</strong>
<EuiSpacer size="xs" />
<EuiText size="s" color="subdued">
<p className="euiTextColor--subdued">Has a short description giving more detail to the option.</p>
</EuiText>
</Fragment>
),
Expand All @@ -51,9 +52,10 @@ export default class extends Component {
text: 'Option three has a super long text to see if it will truncate or what',
display: (
<Fragment>
<EuiText size="s">
<h3>Option Three</h3>
<p>Has a short description giving more detail to the option.</p>
<strong>Option three</strong>
<EuiSpacer size="xs" />
<EuiText size="s" color="subdued">
<p className="euiTextColor--subdued">Has a short description giving more detail to the option.</p>
</EuiText>
</Fragment>
),
Expand All @@ -66,18 +68,6 @@ export default class extends Component {
};
}

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

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

onChange = e => {
this.setState({
value: e.target.value,
Expand All @@ -92,44 +82,35 @@ export default class extends Component {
};

render() {
const button = (
<EuiSuperSelect
options={this.options}
value={this.state.value}
onChange={this.onChange}
onClick={this.onButtonClick}
aria-label="Use aria labels when no actual label is in use"
/>
);

const items = this.options.map((option, index) => {
return (
<EuiContextMenuItem
key={index}
icon={this.state.value === option.value ? "check" : "empty"}
onClick={() => this.itemClicked(option.value)}
>
{option.display}
</EuiContextMenuItem>
<Fragment>
<EuiContextMenuItem
key={index}
icon={this.state.value === option.value ? "check" : "empty"}
onClick={() => this.itemClicked(option.value)}
layoutAlign="top"
>
{option.display}
</EuiContextMenuItem>
{index < this.options.length - 1 &&
<EuiHorizontalRule margin="none" />
}
</Fragment>
);
});

return (
<Fragment>
<EuiPopover
style={{ width: '100%', maxWidth: '400px' }}
id="singlePanel"
button={button}
<EuiSuperSelect
options={this.options}
value={this.state.value}
onChange={this.onChange}
isOpen={this.state.isPopoverOpen}
closePopover={this.closePopover}
panelPaddingSize="none"
anchorPosition="downRight"
aria-label="Use aria labels when no actual label is in use"
>
<EuiContextMenuPanel
items={items}
style={{ width: '100%' }}
/>
</EuiPopover>
{items}
</EuiSuperSelect>

<EuiSpacer size="m" />

Expand All @@ -139,7 +120,9 @@ export default class extends Component {
onChange={this.onChange}
disabled
aria-label="Use aria labels when no actual label is in use"
/>
>
{items}
</EuiSuperSelect>

<EuiSpacer size="m" />

Expand All @@ -149,7 +132,9 @@ export default class extends Component {
onChange={this.onChange}
isLoading
aria-label="Use aria labels when no actual label is in use"
/>
>
{items}
</EuiSuperSelect>

<EuiSpacer size="m" />

Expand All @@ -160,7 +145,9 @@ export default class extends Component {
isLoading
disabled
aria-label="Use aria labels when no actual label is in use"
/>
>
{items}
</EuiSuperSelect>

<EuiSpacer size="m" />

Expand All @@ -169,7 +156,9 @@ export default class extends Component {
value={this.state.value}
onChange={this.onChange}
compressed
/>
>
{items}
</EuiSuperSelect>
</Fragment>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ exports[`CollapsedItemActions render 1`] = `
<EuiContextMenuItem
disabled={false}
icon={undefined}
layoutAlign="center"
onClick={[Function]}
toolTipPosition="right"
>
default1
</EuiContextMenuItem>,
<EuiContextMenuItem
layoutAlign="center"
onClick={[Function]}
toolTipPosition="right"
/>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
"<EuiContextMenuPanel items={{...}} hasFocus={true}>
<div className=\\"euiContextMenuPanel\\" onKeyDown={[Function]} tabIndex=\\"0\\" onAnimationEnd={[Function]}>
<div>
<EuiContextMenuItem data-counter={0} toolTipPosition=\\"right\\" buttonRef={[Function: bound ]}>
<EuiContextMenuItem data-counter={0} toolTipPosition=\\"right\\" layoutAlign=\\"center\\" buttonRef={[Function: bound ]}>
<button disabled={[undefined]} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={0}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand All @@ -125,7 +125,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
</span>
</button>
</EuiContextMenuItem>
<EuiContextMenuItem data-counter={1} toolTipPosition=\\"right\\" buttonRef={[Function: bound ]}>
<EuiContextMenuItem data-counter={1} toolTipPosition=\\"right\\" layoutAlign=\\"center\\" buttonRef={[Function: bound ]}>
<button disabled={[undefined]} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={1}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand All @@ -143,7 +143,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
"<EuiContextMenuPanel items={{...}} hasFocus={true}>
<div className=\\"euiContextMenuPanel\\" onKeyDown={[Function]} tabIndex=\\"0\\" onAnimationEnd={[Function]}>
<div>
<EuiContextMenuItem data-counter={0} toolTipPosition=\\"right\\" buttonRef={[Function: bound ]}>
<EuiContextMenuItem data-counter={0} toolTipPosition=\\"right\\" layoutAlign=\\"center\\" buttonRef={[Function: bound ]}>
<button disabled={[undefined]} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={0}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand All @@ -152,7 +152,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
</span>
</button>
</EuiContextMenuItem>
<EuiContextMenuItem data-counter={1} toolTipPosition=\\"right\\" buttonRef={[Function: bound ]}>
<EuiContextMenuItem data-counter={1} toolTipPosition=\\"right\\" layoutAlign=\\"center\\" buttonRef={[Function: bound ]}>
<button disabled={[undefined]} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={1}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand Down Expand Up @@ -190,7 +190,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
"<EuiContextMenuPanel watchedItemProps={{...}} items={{...}} hasFocus={true}>
<div className=\\"euiContextMenuPanel\\" onKeyDown={[Function]} tabIndex=\\"0\\" onAnimationEnd={[Function]}>
<div>
<EuiContextMenuItem data-counter={0} toolTipPosition=\\"right\\" buttonRef={[Function: bound ]}>
<EuiContextMenuItem data-counter={0} toolTipPosition=\\"right\\" layoutAlign=\\"center\\" buttonRef={[Function: bound ]}>
<button disabled={[undefined]} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={0}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand All @@ -199,7 +199,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
</span>
</button>
</EuiContextMenuItem>
<EuiContextMenuItem data-counter={1} toolTipPosition=\\"right\\" buttonRef={[Function: bound ]}>
<EuiContextMenuItem data-counter={1} toolTipPosition=\\"right\\" layoutAlign=\\"center\\" buttonRef={[Function: bound ]}>
<button disabled={[undefined]} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={1}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand All @@ -217,7 +217,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
"<EuiContextMenuPanel watchedItemProps={{...}} items={{...}} hasFocus={true}>
<div className=\\"euiContextMenuPanel\\" onKeyDown={[Function]} tabIndex=\\"0\\" onAnimationEnd={[Function]}>
<div>
<EuiContextMenuItem data-counter={2} toolTipPosition=\\"right\\" buttonRef={[Function: bound ]}>
<EuiContextMenuItem data-counter={2} toolTipPosition=\\"right\\" layoutAlign=\\"center\\" buttonRef={[Function: bound ]}>
<button disabled={[undefined]} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={2}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand All @@ -226,7 +226,7 @@ exports[`EuiContextMenuPanel updating items and content updates to items should
</span>
</button>
</EuiContextMenuItem>
<EuiContextMenuItem data-counter={3} toolTipPosition=\\"right\\" buttonRef={[Function: bound ]}>
<EuiContextMenuItem data-counter={3} toolTipPosition=\\"right\\" layoutAlign=\\"center\\" buttonRef={[Function: bound ]}>
<button disabled={[undefined]} className=\\"euiContextMenuItem\\" type=\\"button\\" data-counter={3}>
<span className=\\"euiContextMenu__itemLayout\\">
<span className=\\"euiContextMenuItem__text\\">
Expand Down
5 changes: 0 additions & 5 deletions src/components/context_menu/_context_menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,3 @@ $euiContextMenuWidth: $euiSize * 16;
.euiContextMenu__icon {
margin-right: $euiSizeS;
}

.euiContextMenu__itemLayout {
display: flex;
align-items: center;
}
16 changes: 16 additions & 0 deletions src/components/context_menu/_context_menu_item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@
.euiContextMenuItem__arrow {
align-self: flex-end;
}

.euiContextMenu__itemLayout {
display: flex;
align-items: center;

&.euiContextMenu__itemLayout--bottom {
align-items: flex-end;
}
&.euiContextMenu__itemLayout--top {
align-items: flex-start;
}

.euiContextMenu__icon {
flex-shrink: 0;
}
}
20 changes: 18 additions & 2 deletions src/components/context_menu/context_menu_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import { EuiToolTip } from '../tool_tip';

import { getSecureRelForTarget } from '../../services';

const layoutAlignToClassNames = {
center: null,
top: 'euiContextMenu__itemLayout--top',
bottom: 'euiContextMenu__itemLayout--bottom',
};

export const LAYOUT_ALIGN = Object.keys(layoutAlignToClassNames);

export class EuiContextMenuItem extends Component {
static propTypes = {
children: PropTypes.node,
Expand Down Expand Up @@ -40,6 +48,10 @@ export class EuiContextMenuItem extends Component {
href: PropTypes.string,
target: PropTypes.string,
rel: PropTypes.string,
/**
* How to align icon with content of button
*/
layoutAlign: PropTypes.oneOf(LAYOUT_ALIGN),
};

render() {
Expand All @@ -51,6 +63,7 @@ export class EuiContextMenuItem extends Component {
icon,
buttonRef,
disabled,
layoutAlign,
toolTipTitle,
toolTipContent,
toolTipPosition,
Expand Down Expand Up @@ -98,8 +111,10 @@ export class EuiContextMenuItem extends Component {
'euiContextMenuItem-isDisabled': disabled,
});

const layoutClasses = classNames('euiContextMenu__itemLayout', layoutAlignToClassNames[layoutAlign]);

const buttonInner = (
<span className="euiContextMenu__itemLayout">
<span className={layoutClasses}>
{iconInstance}
<span className="euiContextMenuItem__text">
{children}
Expand Down Expand Up @@ -161,5 +176,6 @@ export class EuiContextMenuItem extends Component {
}

EuiContextMenuItem.defaultProps = {
toolTipPosition: 'right',
toolTipPosition: "right",
layoutAlign: "center",
};
5 changes: 4 additions & 1 deletion src/components/form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export {
} from './radio';
export { EuiRange } from './range';
export { EuiSelect } from './select';
export { EuiSuperSelect } from './super_select';
export {
EuiSuperSelect,
EuiSuperSelectControl,
} from './super_select';
export { EuiSwitch } from './switch';
export { EuiTextArea } from './text_area';
export { EuiValidatableControl } from './validatable_control';
Loading

0 comments on commit 8f27db0

Please sign in to comment.