Skip to content

Commit

Permalink
Simplify EuiFormControlLayout styles.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed May 24, 2018
1 parent d622d46 commit f4fe254
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 87 deletions.
1 change: 0 additions & 1 deletion src-docs/src/views/form_controls/form_control_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export default () => (
<EuiSpacer size="m" />

<EuiFormControlLayout
compressed
isLoading
clear={{ onClick: () => {} }}
icon="search"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports[`EuiFormControlLayout props clear onClick is rendered 1`] = `
class="euiFormControlLayout"
>
<div
class="euiFormControlLayout__icons"
class="euiFormControlLayout__icons euiFormControlLayout__icons--right"
>
<button
class="euiFormControlLayout__clear customClass"
Expand Down Expand Up @@ -55,78 +55,90 @@ exports[`EuiFormControlLayout props icon is rendered as a string 1`] = `
<div
class="euiFormControlLayout"
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiFormControlLayout__icon euiFormControlLayout__icon--left"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
<div
class="euiFormControlLayout__icons"
>
<g
fill-rule="evenodd"
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiFormControlLayout__icon"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M7.5 2.236L1.618 14h11.764L7.5 2.236zm.894-.447l5.882 11.764A1 1 0 0 1 13.382 15H1.618a1 1 0 0 1-.894-1.447L6.606 1.789a1 1 0 0 1 1.788 0z"
/>
<path
d="M7 6h1v5H7zM7 12h1v1H7z"
/>
</g>
</svg>
<g
fill-rule="evenodd"
>
<path
d="M7.5 2.236L1.618 14h11.764L7.5 2.236zm.894-.447l5.882 11.764A1 1 0 0 1 13.382 15H1.618a1 1 0 0 1-.894-1.447L6.606 1.789a1 1 0 0 1 1.788 0z"
/>
<path
d="M7 6h1v5H7zM7 12h1v1H7z"
/>
</g>
</svg>
</div>
</div>
`;

exports[`EuiFormControlLayout props icon is rendered as an object 1`] = `
<div
class="euiFormControlLayout"
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiFormControlLayout__icon euiFormControlLayout__icon--left customClass"
data-test-subj="myIcon"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
<div
class="euiFormControlLayout__icons"
>
<g
fill-rule="evenodd"
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiFormControlLayout__icon customClass"
data-test-subj="myIcon"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M7.5 2.236L1.618 14h11.764L7.5 2.236zm.894-.447l5.882 11.764A1 1 0 0 1 13.382 15H1.618a1 1 0 0 1-.894-1.447L6.606 1.789a1 1 0 0 1 1.788 0z"
/>
<path
d="M7 6h1v5H7zM7 12h1v1H7z"
/>
</g>
</svg>
<g
fill-rule="evenodd"
>
<path
d="M7.5 2.236L1.618 14h11.764L7.5 2.236zm.894-.447l5.882 11.764A1 1 0 0 1 13.382 15H1.618a1 1 0 0 1-.894-1.447L6.606 1.789a1 1 0 0 1 1.788 0z"
/>
<path
d="M7 6h1v5H7zM7 12h1v1H7z"
/>
</g>
</svg>
</div>
</div>
`;

exports[`EuiFormControlLayout props icon side left is rendered 1`] = `
<div
class="euiFormControlLayout"
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiFormControlLayout__icon euiFormControlLayout__icon--left"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
<div
class="euiFormControlLayout__icons"
>
<g
fill-rule="evenodd"
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiFormControlLayout__icon"
height="16"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M7.5 2.236L1.618 14h11.764L7.5 2.236zm.894-.447l5.882 11.764A1 1 0 0 1 13.382 15H1.618a1 1 0 0 1-.894-1.447L6.606 1.789a1 1 0 0 1 1.788 0z"
/>
<path
d="M7 6h1v5H7zM7 12h1v1H7z"
/>
</g>
</svg>
<g
fill-rule="evenodd"
>
<path
d="M7.5 2.236L1.618 14h11.764L7.5 2.236zm.894-.447l5.882 11.764A1 1 0 0 1 13.382 15H1.618a1 1 0 0 1-.894-1.447L6.606 1.789a1 1 0 0 1 1.788 0z"
/>
<path
d="M7 6h1v5H7zM7 12h1v1H7z"
/>
</g>
</svg>
</div>
</div>
`;

Expand All @@ -135,7 +147,7 @@ exports[`EuiFormControlLayout props icon side right is rendered 1`] = `
class="euiFormControlLayout"
>
<div
class="euiFormControlLayout__icons"
class="euiFormControlLayout__icons euiFormControlLayout__icons--right"
>
<svg
aria-hidden="true"
Expand Down Expand Up @@ -165,7 +177,7 @@ exports[`EuiFormControlLayout props isLoading is rendered 1`] = `
class="euiFormControlLayout"
>
<div
class="euiFormControlLayout__icons"
class="euiFormControlLayout__icons euiFormControlLayout__icons--right"
>
<div
class="euiLoadingSpinner euiLoadingSpinner--medium"
Expand Down
19 changes: 6 additions & 13 deletions src/components/form/form_control_layout/_form_control_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@
pointer-events: none;
}

.euiFormControlLayout__icon--left {
position: absolute;
top: $euiFormControlPadding;
left: $euiFormControlPadding;

@at-root {
.euiFormControlLayout--compressed#{&} {
top: $euiFormControlPadding--compressed;
}
}
}

.euiFormControlLayout__icon--button {
pointer-events: all;
height: $euiSize;
Expand All @@ -51,9 +39,9 @@

.euiFormControlLayout__icons {
position: absolute;
right: $euiFormControlPadding;
top: 0;
bottom: 0;
left: $euiFormControlPadding;
display: flex;
align-items: center;

Expand All @@ -62,6 +50,11 @@
}
}

.euiFormControlLayout__icons--right {
left: auto;
right: $euiFormControlPadding;
}

.euiFormControlLayout__clear {
@include euiFormControlLayout__clear('.euiFormControlLayout__clearIcon');
}
Expand Down
32 changes: 14 additions & 18 deletions src/components/form/form_control_layout/form_control_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import classNames from 'classnames';
import { EuiIcon } from '../../icon';
import { EuiLoadingSpinner } from '../../loading';

const iconSideToClassNameMap = {
left: 'euiFormControlLayout__icon--left',
right: '',
};

export const ICON_SIDES = Object.keys(iconSideToClassNameMap);
export const ICON_SIDES = ['left', 'right'];

export class EuiFormControlLayout extends Component {
render() {
Expand Down Expand Up @@ -77,7 +72,6 @@ export class EuiFormControlLayout extends Component {

const iconClasses = classNames(
'euiFormControlLayout__icon',
iconSideToClassNameMap[iconSide],
iconClassName,
{
'euiFormControlLayout__icon--button': onIconClick,
Expand Down Expand Up @@ -133,32 +127,34 @@ export class EuiFormControlLayout extends Component {
);
}

// If the icon is on the right, it should be placed after the clear button in the DOM.
if (optionalIconSide === 'right') {
return (
let leftIcons;

if ( optionalIconSide === 'left') {
leftIcons = (
<div className="euiFormControlLayout__icons">
{optionalClear}
{optionalLoader}
{optionalIcon}
</div>
);
}

let optionalRightIcons;
let rightIcons;

if (optionalClear || optionalLoader) {
optionalRightIcons = (
<div className="euiFormControlLayout__icons">
// If the icon is on the right, it should be placed after the clear button in the DOM.
if (optionalClear || optionalLoader || optionalIconSide === 'right') {
rightIcons = (
<div className="euiFormControlLayout__icons euiFormControlLayout__icons--right">
{optionalClear}
{optionalLoader}
{optionalIconSide === 'right' ? optionalIcon : undefined}
</div>
);
}


return (
<Fragment>
{optionalIcon}
{optionalRightIcons}
{leftIcons}
{rightIcons}
</Fragment>
);
}
Expand Down

0 comments on commit f4fe254

Please sign in to comment.