From 34fad20bb6390271b018f42455b94ae461ba0863 Mon Sep 17 00:00:00 2001 From: mm <25961416+mlmoravek@users.noreply.github.com> Date: Fri, 17 May 2024 14:36:40 +0200 Subject: [PATCH] feat(radio): use mask for radio button svgs (#27) --- src/assets/scss/components/_checkbox.scss | 15 ++++--- src/assets/scss/components/_radio.scss | 54 ++++++++++++++--------- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/assets/scss/components/_checkbox.scss b/src/assets/scss/components/_checkbox.scss index c89b54e..1595159 100644 --- a/src/assets/scss/components/_checkbox.scss +++ b/src/assets/scss/components/_checkbox.scss @@ -52,11 +52,9 @@ $checkbox-line-height: 1.5 !default; &__input { width: var(--#{$prefix}checkbox-size, $checkbox-size); height: var(--#{$prefix}checkbox-size, $checkbox-size); - outline: none; margin: 0; + outline: none; vertical-align: top; - background-position: center; - background-size: contain; -webkit-appearance: none; -moz-appearance: none; appearance: none; @@ -64,13 +62,19 @@ $checkbox-line-height: 1.5 !default; print-color-adjust: exact; flex-shrink: 0; cursor: pointer; - background-repeat: no-repeat; box-shadow: var(--#{$prefix}checkbox-box-shadow, $checkbox-box-shadow); background-color: var( --#{$prefix}checkbox-background-color, $checkbox-background-color ); + background-position: center; + background-size: contain; + background-repeat: no-repeat; + + transition: background var(--#{$prefix}transition-duration) + var(--#{$prefix}transition-timing); + border-radius: var( --#{$prefix}checkbox-border-radius, $checkbox-border-radius @@ -88,9 +92,6 @@ $checkbox-line-height: 1.5 !default; $checkbox-border-style ); - transition: background var(--#{$prefix}transition-duration) - var(--#{$prefix}transition-timing); - &--checked { background-color: var( --#{$prefix}checkbox-active-background-color, diff --git a/src/assets/scss/components/_radio.scss b/src/assets/scss/components/_radio.scss index fd80001..1542205 100644 --- a/src/assets/scss/components/_radio.scss +++ b/src/assets/scss/components/_radio.scss @@ -1,7 +1,7 @@ @use "sass:list"; /* @docs */ -$radio-active-background-color: var(--#{$prefix}primary) !default; +$radio-active-background-color: $primary !default; $radio-checked-box-shadow-length: 0 0 0.5em !default; $radio-checked-box-shadow-opacity: 0.8 !default; $radio-box-shadow: $control-box-shadow !default; @@ -13,18 +13,25 @@ $radio-line-height: 1.25 !default; /* @docs */ // filled svg calculation -@function svg_radio_fill($color, $background-color: "transparent") { - $start: ''; - $content: ''; +@function svg_radio_fill() { + $start: ''; + $content: '' + + '' + + '' + + '' + ""; + $end: ""; @return svg-encode("#{$start}#{$content}#{$end}"); } // empty svg calculation -@function svg_radio_empty($color) { - $start: ''; - $content: ''; +@function svg_radio_empty() { + $start: ''; + $content: '' + + '' + + '' + + ""; $end: ""; @return svg-encode("#{$start}#{$content}#{$end}"); @@ -39,27 +46,34 @@ $radio-line-height: 1.25 !default; margin-right: var(--#{$prefix}radio-margin-sibiling, $radio-margin-sibiling); &__input { + font-size: var(--#{$prefix}radio-font-size, inherit); width: var(--#{$prefix}radio-size, $radio-size); height: var(--#{$prefix}radio-size, $radio-size); margin: 0; vertical-align: top; - background-position: center; - background-size: contain; -webkit-appearance: none; -moz-appearance: none; appearance: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; - border-radius: 50%; cursor: pointer; + box-shadow: var(--#{$prefix}radio-box-shadow, $radio-box-shadow); + border-radius: 50%; + background: var( + --oruga-radio-active-background-color, + $radio-active-background-color + ); + mask-image: url(svg_radio_empty()); + background-image: none; + background-position: center; + background-size: contain; background-repeat: no-repeat; + transition: background var(--#{$prefix}transition-duration) var(--#{$prefix}transition-timing); - box-shadow: var(--#{$prefix}radio-box-shadow, $radio-box-shadow); - background-image: url(svg_radio_empty($radio-active-background-color)); &--checked { - background-image: url(svg_radio_fill($radio-active-background-color)); + mask-image: url(svg_radio_fill()); } } @@ -71,22 +85,20 @@ $radio-line-height: 1.25 !default; opacity: var(--#{$prefix}radio-disabled-opacity, $radio-disabled-opacity); } + // size variants @each $name, $value in $sizes { &--#{$name} { - font-size: var(--#{$prefix}radio-font-size-#{$name}, $value); + --#{$prefix}radio-font-size: #{$value}; + --#{$prefix}radio-size: #{$value}; } } + + // color variants @each $name, $pair in $colors { $color: list.nth($pair, 1); $color-invert: list.nth($pair, 2); &--#{$name} { - .o-radio__input { - background-image: url(svg_radio_empty($color)); - - &--checked { - background-image: url(svg_radio_fill($color, $color-invert)); - } - } + --oruga-radio-active-background-color: #{$color}; } } }