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

Compressed switch styling #2327

Merged
merged 5 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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 @@

**Bug fixes**

- Added missing `compressed` styling to `EuiSwitch` ([#2327](https://github.com/elastic/eui/pull/2327))
- Corrected `EuiCodeBlock`'s proptype for `children` to be string or array of strings. ([#2324](https://github.com/elastic/eui/pull/2324))

## [`13.8.1`](https://github.com/elastic/eui/tree/v13.8.1)
Expand Down
19 changes: 19 additions & 0 deletions src-docs/src/views/form_controls/switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ export default class extends Component {
onChange={this.onChange}
disabled
/>

<EuiSpacer size="m" />

<EuiSwitch
label="I am a compressed switch"
checked={this.state.checked}
onChange={this.onChange}
compressed
/>

<EuiSpacer size="m" />

<EuiSwitch
label="I am a compressed, disabled switch"
checked={this.state.checked}
onChange={this.onChange}
compressed
disabled
/>
</Fragment>
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/form/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ $euiSwitchWidth: ($euiSize * 2.5) + $euiSizeXS !default;
$euiSwitchThumbSize: $euiSwitchHeight !default;
$euiSwitchIconHeight: $euiSize !default;

$euiSwitchHeightCompressed: $euiSize !default;
$euiSwitchWidthCompressed: $euiSize * 1.75 !default;
$euiSwitchThumbSizeCompressed: $euiSwitchHeightCompressed !default;

// Coloring
$euiFormBackgroundColor: tintOrShade($euiColorLightestShade, 60%, 40%) !default;
$euiFormBackgroundDisabledColor: darken($euiColorLightestShade, 2%) !default;
Expand All @@ -21,4 +25,4 @@ $euiFormBorderDisabledColor: transparentize($euiColorFullShade, .92) !default;
$euiFormCustomControlDisabledIconColor: shadeOrTint($euiColorMediumShade, 38%, 48.5%) !default; // exact 508c foreground for $euiColorLightShade
$euiFormControlDisabledColor: $euiColorMediumShade !default;
$euiFormControlBoxShadow: 0 1px 1px -1px transparentize($euiShadowColor, .8), 0 3px 2px -2px transparentize($euiShadowColor, .8);
$euiFormInputGroupLabelBackground: shadeOrTint($euiFormBackgroundDisabledColor, 0, 3%);
$euiFormInputGroupLabelBackground: shadeOrTint($euiFormBackgroundDisabledColor, 0, 3%);
57 changes: 57 additions & 0 deletions src/components/form/switch/_switch.scss
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@

.euiSwitch__thumb {
@include euiCustomControlDisabled;

border-color: $euiFormBorderColor;
background-color: lightOrDarkTheme(transparentize($euiColorMediumShade, .8), transparentize($euiColorMediumShade, .3));
}

Expand All @@ -116,6 +118,11 @@
}
}

.euiSwitch__input:checked:disabled ~ .euiSwitch__body {
background-color: lightOrDarkTheme(transparentize($euiColorMediumShade, .7), transparentize($euiColorMediumShade, .4));
}

// slight
snide marked this conversation as resolved.
Show resolved Hide resolved
.euiSwitch__input:not(:checked):not(:disabled) ~ .euiSwitch__body {
background-color: lightOrDarkTheme(transparentize($euiColorMediumShade, .8), transparentize($euiColorMediumShade, .3));
}
Expand All @@ -137,4 +144,54 @@
}
}
}

// Compressed switches operate very similar to the normal versions, but are smaller, contain no icon signifiers
&.euiSwitch--compressed {
min-height: $euiSwitchHeightCompressed;

.euiSwitch__label {
line-height: $euiSwitchHeightCompressed;
}

.euiSwitch__body {
pointer-events: none;
snide marked this conversation as resolved.
Show resolved Hide resolved
width: $euiSwitchWidthCompressed;
height: $euiSwitchHeightCompressed;
border-radius: $euiSwitchHeightCompressed;
}

.euiSwitch__thumb {
@include euiCustomControl($type: 'round', $size: ($euiSwitchThumbSizeCompressed) - 2px);

left: ($euiSwitchWidthCompressed) - (($euiSwitchThumbSizeCompressed) - 2px) - 1px;
top: 1px;
transition: border-color $euiAnimSpeedNormal $euiAnimSlightBounce, background-color $euiAnimSpeedNormal $euiAnimSlightBounce, left $euiAnimSpeedNormal $euiAnimSlightBounce, transform $euiAnimSpeedNormal $euiAnimSlightBounce;
}

.euiSwitch__track {
border-radius: $euiSwitchHeightCompressed;
}

.euiSwitch__input:not(:checked) ~ .euiSwitch__body {
.euiSwitch__thumb {
left: 1px;
}
}

// Compressed switches need slightly darker borders since they don't have icons
.euiSwitch__input:not(:checked) ~ .euiSwitch__body,
.euiSwitch__input:checked:disabled ~ .euiSwitch__body {
.euiSwitch__thumb {
border-color: $euiFormBorderColor;
}
}

// Similar additional treatment needed while checked
.euiSwitch__input:checked ~ .euiSwitch__body {
.euiSwitch__thumb {
border-color: $euiColorPrimary;
}
}

}
}
18 changes: 11 additions & 7 deletions src/components/form/switch/switch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react';
import React, { Component, Fragment } from 'react';

import PropTypes from 'prop-types';
import classNames from 'classnames';
Expand Down Expand Up @@ -54,13 +54,17 @@ export class EuiSwitch extends Component {
<span className="euiSwitch__body">
<span className="euiSwitch__thumb" />
<span className="euiSwitch__track">
<EuiIcon type="cross" size="m" className="euiSwitch__icon" />
{!compressed && (
<Fragment>
<EuiIcon type="cross" size="m" className="euiSwitch__icon" />

<EuiIcon
type="check"
size="m"
className="euiSwitch__icon euiSwitch__icon--checked"
/>
<EuiIcon
type="check"
size="m"
className="euiSwitch__icon euiSwitch__icon--checked"
/>
</Fragment>
)}
</span>
</span>

Expand Down