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 all 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `14.0.0`.
- Added missing `compressed` styling to `EuiSwitch` ([#2327](https://github.com/elastic/eui/pull/2327))

## [`14.0.0`](https://github.com/elastic/eui/tree/v14.0.0)

Expand Down
1 change: 1 addition & 0 deletions src-docs/src/views/form_compressed/form_compressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default class extends Component {
name="switch"
checked={this.state.isSwitchChecked}
onChange={this.onSwitchChange}
compressed
/>
</EuiFormRow>

Expand Down
1 change: 1 addition & 0 deletions src-docs/src/views/form_compressed/form_horizontal.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export default class extends Component {
name="switch"
checked={this.state.isSwitchChecked}
onChange={this.onSwitchChange}
compressed
/>
</EuiFormRow>
</EuiPanel>
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
2 changes: 1 addition & 1 deletion src/components/form/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
padding: $size / 2;
}

border: 1px solid shadeOrTint($euiColorLightestShade, 18%, 30%);
border: 1px solid $euiFormCustomControlBorderColor;
background: $euiColorEmptyShade no-repeat center;

@if $type == 'round' {
Expand Down
9 changes: 7 additions & 2 deletions src/components/form/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ $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;
$euiFormBorderOpaqueColor: shadeOrTint(desaturate(adjust-hue($euiColorPrimary, 22), 22.95), 26%, 60%) !default;
$euiFormBorderColor: transparentize($euiFormBorderOpaqueColor, .9) !default;
$euiFormBorderDisabledColor: transparentize($euiFormBorderOpaqueColor, .9) !default;
$euiFormCustomControlDisabledIconColor: shadeOrTint($euiColorMediumShade, 38%, 48.5%) !default; // exact 508c foreground for $euiColorLightShade
$euiFormCustomControlBorderColor: shadeOrTint($euiColorLightestShade, 18%, 30%) !default;
$euiFormControlDisabledColor: $euiColorMediumShade !default;
$euiFormControlBoxShadow: 0 1px 1px -1px transparentize($euiShadowColor, .8), 0 3px 2px -2px transparentize($euiShadowColor, .8) !default;
$euiFormInputGroupLabelBackground: shadeOrTint($euiFormBackgroundDisabledColor, 0, 3%) !default;
$euiFormControlBoxShadow: 0 1px 1px -1px transparentize($euiShadowColor, .8), 0 3px 2px -2px transparentize($euiShadowColor, .8);
$euiFormInputGroupLabelBackground: shadeOrTint($euiFormBackgroundDisabledColor, 0, 3%);
56 changes: 56 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));
}

// Slightly darker background when in a checked state.
.euiSwitch__input:not(:checked):not(:disabled) ~ .euiSwitch__body {
background-color: lightOrDarkTheme(transparentize($euiColorMediumShade, .8), transparentize($euiColorMediumShade, .3));
}
Expand All @@ -137,4 +144,53 @@
}
}
}

// 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 {
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: $euiFormCustomControlBorderColor;
}
}

// 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