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

Feature: added .alert, .warning and .success colors to switch input #8065

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/pages/switch.md
Expand Up @@ -29,6 +29,37 @@ Give the `<input>` a unique ID and point the `<label>` to it with the `for` attr

---

## Coloring

Switch paddle can be colored, using the .success`, `.warning` or `.alert` classes.

```html_example
<div class="switch">
<input class="switch-input" id="exampleColorSwitch1" type="checkbox" name="exampleColorSwitch1">
<label class="switch-paddle success" for="exampleColorSwitch1">
<span class="show-for-sr">Pat the cat</span>
</label>
</div>

<div class="switch">
<input class="switch-input" id="exampleColorSwitch2" type="checkbox" name="exampleColorSwitch2">
<label class="switch-paddle warning" for="exampleColorSwitch2">
<span class="show-for-sr">Disable the cat</span>
</label>
</div>

<div class="switch">
<input class="switch-input" id="exampleColorSwitch3" type="checkbox" name="exampleColorSwitch3">
<label class="switch-paddle alert" for="exampleColorSwitch3">
<span class="show-for-sr">Delete cat food?</span>
</label>
</div>
```

Alternatively, in your css, use following selector: `input:checked~.switch-paddle.yourclass`, where `yourclass` is a class name of your choice.

---

## Radio Switch

You can also use `<input type="radio">` instead of `checkbox` to create a series of options.
Expand Down
22 changes: 22 additions & 0 deletions scss/components/_switch.scss
Expand Up @@ -14,6 +14,18 @@ $switch-background: $medium-gray !default;
/// @type Color
$switch-background-active: $primary-color !default;

/// Background active color of a switch - semantic success
/// @type Color
$switch-background-active-success: $success-color !default;

/// Background active color of a switch - semantic warning
/// @type Color
$switch-background-active-warning: $warning-color !default;

/// Background active color of a switch - semantic alert
/// @type Color
$switch-background-active-alert: $alert-color !default;

/// Height of a switch, with no class applied.
/// @type Number
$switch-height: 2rem !default;
Expand Down Expand Up @@ -116,6 +128,16 @@ $switch-paddle-transition: all 0.25s ease-out !default;
input:checked ~ & {
background: $switch-background-active;

&.success {
background: $switch-background-active-success;
}
&.warning {
background: $switch-background-active-warning;
}
&.alert {
background: $switch-background-active-alert;
}

&::after {
#{$global-left}: 2.25rem;
}
Expand Down