Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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: $euiSwitchHeight * .5 !default;
$euiSwitchWidthCompressed: $euiSwitchWidth * .5 !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%);
51 changes: 51 additions & 0 deletions src/components/form/switch/_switch.scss
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,55 @@
}
}
}

// 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;
font-size: $euiFontSizeXS;
}

.euiSwitch__body {
pointer-events: none;
Comment thread
snide marked this conversation as resolved.
Outdated
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: $euiColorMediumShade;
}
}

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