Skip to content

Commit

Permalink
Interaction state hover for checkbox (#2122)
Browse files Browse the repository at this point in the history
* πŸ’„ Add function that calculates hover color

* πŸ’„ Apply transition

* ♻️ πŸ’„ Move helper function to shared location

#2128 also needs to
calculate color in the exact same way
  • Loading branch information
jkaltoft authored Mar 25, 2022
1 parent 04939cb commit 5b56b1a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions libs/core/src/scss/interaction-state/_index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@forward 'focus';
@forward 'hover';
@forward 'layer' hide apply-state;
@forward 'utilities';
20 changes: 20 additions & 0 deletions libs/core/src/scss/interaction-state/_utilities.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@use 'sass:color';
@use 'layer';
@use '../utils';

@function get-state-color($variant, $loudness: layer.$default-loudness, $flip: false) {
$_background: utils.get-color($variant, $getValueOnly: true);

$_lightness: 0% !default;

@if $flip {
$_lightness: utils.get-loudness($loudness);
} @else {
// negative number means "make it darker"
$_lightness: -1 * utils.get-loudness($loudness);
}

$hover-color: #{color.scale($_background, $lightness: $_lightness)};

@return $hover-color;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ $default-checkbox-radio-size: map.get(utils.$checkbox-radio-sizes, 'md');
--background-checked: #{utils.get-color('success')};
--border-color-checked: #{utils.get-color('success')};

@include interaction-state.apply-hover {
--background-checked: #{interaction-state.get-state-color('success')};
}

&:active {
--background-checked: #{utils.get-color('success-shade')};
--border-color-checked: #{utils.get-color('success-shade')};
Expand All @@ -31,6 +35,10 @@ $default-checkbox-radio-size: map.get(utils.$checkbox-radio-sizes, 'md');
--background-checked: #{utils.get-color('black')};
--border-color-checked: #{utils.get-color('black')};

@include interaction-state.apply-hover {
--background-checked: #{interaction-state.get-state-color('black', 'xxl', $flip: true)};
}

&:active {
--checkmark-color: #{utils.get-color('white-shade')};
--background-checked: #{utils.get-color('black-tint')};
Expand All @@ -57,6 +65,11 @@ $default-checkbox-radio-size: map.get(utils.$checkbox-radio-sizes, 'md');

ion-checkbox {
@include interaction-state.apply-focus-part($part: 'container');
@include interaction-state.apply-hover {
--background: #{interaction-state.get-state-color('white', 's')};
}

--transition: #{utils.get-transition-duration('quick')};

--size: #{$checkbox-icon-size};
--checkmark-width: #{utils.size('xxxs')};
Expand Down

0 comments on commit 5b56b1a

Please sign in to comment.