Created
April 11, 2022 21:51
-
-
Save olets/87172a3735bed57aaa067afcabeeadfd to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mixin focus() { | |
&:focus, | |
&:hover { | |
@content; | |
} | |
} | |
$btn-saturate-default: 25%; | |
$btn-lighten-default: 4%; | |
$btn-darken-default: 5%; // see also ecomm/molecules/button.scss | |
@mixin btn-saturate-or-lighten($color, $amount: $btn-saturate-default) { | |
// `saturate(color, percentage)` can, depending on `color` and `percentage`, return `color` | |
// This function enhances `saturate()` with a `lighten()` fallback. | |
$saturated: saturate($color, $amount); | |
$lightened: lighten($color, $amount * $btn-lighten-default / $btn-saturate-default); | |
$result: $color; | |
@if $saturated != $color { | |
$result: $saturated; | |
} @else if $lightened != $color { | |
$result: $lightened; | |
} | |
background: $result; | |
} | |
@mixin btn-darken($color) { | |
background: darken($color, $btn-darken-default); | |
} | |
@mixin btn-lighten($color) { | |
background: lighten($color, $btn-lighten-default); | |
} | |
@mixin btn-default-hover-and-active($color) { | |
@include focus() { | |
@include btn-saturate-or-lighten($color); | |
} | |
&:active { | |
@include btn-darken($color); | |
} | |
} | |
.my-button { | |
$color: red; | |
background: $color; | |
@include btn-default-hover-and-active($color); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.my-button { | |
background: red; | |
} | |
.my-button:focus, .my-button:hover { | |
background: #ff1414; | |
} | |
.my-button:active { | |
background: #e60000; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"sass": { | |
"compiler": "Ruby Sass/3.7.4", | |
"extensions": {}, | |
"syntax": "SCSS", | |
"outputStyle": "expanded" | |
}, | |
"autoprefixer": false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment