diff --git a/.bundlewatch.config.json b/.bundlewatch.config.json index ff6ddbd208..8632c5f9d6 100644 --- a/.bundlewatch.config.json +++ b/.bundlewatch.config.json @@ -30,7 +30,7 @@ }, { "path": "./dist/css/boosted.min.css", - "maxSize": "40.25 kB" + "maxSize": "40.5 kB" }, { "path": "./dist/js/boosted.bundle.js", diff --git a/scss/_mixins.scss b/scss/_mixins.scss index 1362ff3e4b..2430089b1b 100644 --- a/scss/_mixins.scss +++ b/scss/_mixins.scss @@ -30,7 +30,6 @@ @import "mixins/lists"; @import "mixins/forms"; @import "mixins/table-variants"; -@import "mixins/star-rating"; // Boosted mod // Skins @import "mixins/border-radius"; diff --git a/scss/_variables.scss b/scss/_variables.scss index 4e85ef9303..31ef29c686 100644 --- a/scss/_variables.scss +++ b/scss/_variables.scss @@ -1180,15 +1180,28 @@ $form-check-btn-check-disabled-opacity: null !default; $form-check-inline-margin-end: 1rem !default; // Boosted mod: Star rating -$form-star-size: 1.5625rem !default; -$form-star-size-sm: 1.25rem !default; -$form-star-margin-between: -.125rem !default; +$form-star-size: 1.5625rem !default; +$form-star-size-sm: 1.25rem !default; +$form-star-margin-between: -.125rem !default; + +$form-star-rating-checked-color: $accessible-orange !default; +$form-star-rating-unchecked-color: $gray-700 !default; +$form-star-rating-hover-color: $black !default; + +$form-star-rating-dark-checked-color: $primary !default; +$form-star-rating-dark-unchecked-color: $gray-500 !default; +$form-star-rating-dark-hover-color: $white !default; + +$form-star-rating-checked-icon: escape-svg(url("data:image/svg+xml,")) !default; +$form-star-rating-unchecked-icon: escape-svg(url("data:image/svg+xml,")) !default; +$form-star-rating-sm-checked-icon: escape-svg(url("data:image/svg+xml,")) !default; +$form-star-rating-sm-unchecked-icon: escape-svg(url("data:image/svg+xml,")) !default; //fusv-disable -$form-star-focus-color: $black !default; // Deprecated in v5.2.3 -$form-star-focus-outline: var(--#{$prefix}border-width) solid $form-star-focus-color !default; // Deprecated in v5.2.3 -$form-star-focus-color-dark: $white !default; // Deprecated in v5.2.3 -$form-star-focus-outline-dark: var(--#{$prefix}border-width) solid $form-star-focus-color-dark !default; // Deprecated in v5.2.3 -$form-star-focus-box-shadow: $input-btn-focus-box-shadow !default; // Deprecated in v5.2.3 +$form-star-focus-color: $black !default; // Deprecated in v5.2.3 +$form-star-focus-outline: var(--#{$prefix}border-width) solid $form-star-focus-color !default; // Deprecated in v5.2.3 +$form-star-focus-color-dark: $white !default; // Deprecated in v5.2.3 +$form-star-focus-outline-dark: var(--#{$prefix}border-width) solid $form-star-focus-color-dark !default; // Deprecated in v5.2.3 +$form-star-focus-box-shadow: $input-btn-focus-box-shadow !default; // Deprecated in v5.2.3 //fusv-enable // End mod diff --git a/scss/forms/_star-rating.scss b/scss/forms/_star-rating.scss index e41eb9801f..f50faf0888 100644 --- a/scss/forms/_star-rating.scss +++ b/scss/forms/_star-rating.scss @@ -3,31 +3,52 @@ // .star-rating { - &.disabled, + --#{$prefix}star-rating-checked-color: #{$form-star-rating-checked-color}; + --#{$prefix}star-rating-unchecked-color: #{$form-star-rating-unchecked-color}; + --#{$prefix}star-rating-hover-color: #{$form-star-rating-hover-color}; + --#{$prefix}star-rating-checked-icon: #{$form-star-rating-checked-icon}; + --#{$prefix}star-rating-unchecked-icon: #{$form-star-rating-unchecked-icon}; + font-size: $form-star-size; + &:disabled { pointer-events: none; + --#{$prefix}star-rating-checked-color: var(--#{$prefix}border-color-translucent); + --#{$prefix}star-rating-unchecked-color: var(--#{$prefix}border-color-translucent); } > label { - display: block; + cursor: pointer; + } + + > label, + span { float: left; width: 1em; height: 1em; - font-size: $form-star-size; - cursor: pointer; - @include form-star-rating($accessible-orange); + + &::before { + display: block; + width: 100%; + height: 100%; + mask-image: var(--#{$prefix}star-rating-checked-icon); + content: ""; + background-color: var(--#{$prefix}star-rating-checked-color); + } &:not(:first-of-type){ margin-left: $form-star-margin-between; } } - > input:checked ~ label { - @include form-star-rating($gray-500); + > input:checked ~ label::before, + .checked ~ span::before { + mask-image: var(--#{$prefix}star-rating-unchecked-icon); + background-color: var(--#{$prefix}star-rating-unchecked-color); } - > input:checked + label { - @include form-star-rating($accessible-orange); + > input:checked + label::before { + mask-image: var(--#{$prefix}star-rating-checked-icon); + background-color: var(--#{$prefix}star-rating-checked-color); } > [data-focus-visible-added]:focus + label { @@ -36,45 +57,30 @@ box-shadow: inset 0 0 0 add(1px, $focus-visible-inner-width) var(--#{$prefix}focus-visible-inner-color); } - &:hover input + label { - @include form-star-rating($black); + &:hover input + label::before { + mask-image: var(--#{$prefix}star-rating-checked-icon); + background-color: var(--#{$prefix}star-rating-hover-color); } - > input:hover ~ label { - @include form-star-rating($gray-500); + > input:hover ~ label::before { + mask-image: var(--#{$prefix}star-rating-unchecked-icon); + background-color: var(--#{$prefix}star-rating-unchecked-color); } - > input:hover + label { - @include form-star-rating($black); + > input:hover + label::before { + mask-image: var(--#{$prefix}star-rating-checked-icon); + background-color: var(--#{$prefix}star-rating-hover-color); } } .star-rating-dark { - > label { - @include form-star-rating($brand-orange); - } - - > input:checked ~ label { - @include form-star-rating($gray-700); - } - - > input:checked + label { - @include form-star-rating($brand-orange); - } - - &:hover input + label { - @include form-star-rating($white); - } - - > input:hover ~ label { - @include form-star-rating($gray-700); - } - - > input:hover + label { - @include form-star-rating($white); - } + --#{$prefix}star-rating-checked-color: #{$form-star-rating-dark-checked-color}; + --#{$prefix}star-rating-unchecked-color: #{$form-star-rating-dark-unchecked-color}; + --#{$prefix}star-rating-hover-color: #{$form-star-rating-dark-hover-color}; } -.star-rating-sm > label { +.star-rating-sm { + --#{$prefix}star-rating-checked-icon: #{$form-star-rating-sm-checked-icon}; + --#{$prefix}star-rating-unchecked-icon: #{$form-star-rating-sm-unchecked-icon}; font-size: $form-star-size-sm; } diff --git a/scss/mixins/_star-rating.scss b/scss/mixins/_star-rating.scss index 4a040a9bc3..71e466faa7 100644 --- a/scss/mixins/_star-rating.scss +++ b/scss/mixins/_star-rating.scss @@ -1,3 +1,5 @@ +@include deprecate("`form-star-rating()`", "v5.3.2", "v6.0.0"); + // scss-docs-start form-star-rating-mixin @mixin form-star-rating($color) { background-image: escape-svg(url("data:image/svg+xml,")); diff --git a/site/content/docs/5.3/forms/checks-radios.md b/site/content/docs/5.3/forms/checks-radios.md index 14f33fa961..78a3d3c86d 100644 --- a/site/content/docs/5.3/forms/checks-radios.md +++ b/site/content/docs/5.3/forms/checks-radios.md @@ -368,19 +368,19 @@ Star rating system is built on top of radios. Simply add `.star-rating` to a `Results relevance - + - + - + - + - + {{< /example >}} @@ -395,19 +395,19 @@ Star ratings come with a smaller variant: `.star-rating-sm`. Results relevance - + - + - + - + - + {{< /example >}} @@ -422,45 +422,67 @@ Add `.star-rating-dark` to the `.star-rating` for a dark variant. Results relevance - + - + - + - + - + {{< /example >}} +### Readonly + +Make star ratings readable but non-editable by using ``s instead of `` elements. + +{{< example >}} +
+

Star rating: rated 3 out of 5

+ + +
+{{< /example >}} + ### Disabled Make star ratings look inactive inside or outside a form by adding the `disabled` boolean attribute to the `
` element and the `checked` boolean attribute to any `` element. {{< example >}} -
- - +
+ -rated 3 stars out of 5 + + +
+

Disabled star rating: rated 3 out of 5

+ {{< /example >}} @@ -479,4 +501,6 @@ Variables for switches: ### Sass mixins +{{< deprecated-in "5.3.2" >}} + {{< scss-docs name="form-star-rating-mixin" file="scss/mixins/_star-rating.scss" >}} diff --git a/site/content/docs/5.3/migration.md b/site/content/docs/5.3/migration.md index a43f53f592..3949b9cdc7 100644 --- a/site/content/docs/5.3/migration.md +++ b/site/content/docs/5.3/migration.md @@ -33,6 +33,16 @@ If you need more details about the changes, please refer to the [v5.3.2 release] - New In order to improve accessibility for people suffering from any form of color blindness, we added a visual cue to form elements on error when focused so information does not rely exclusively on color anymore. Although is has no direct impact, you might want to apply this same modification within your custom form controls if you have any. - New Labels related to mandatory form fields have been improved for better accessibility. A ` (required)` element has been added to ensure correct restitution by assistive technologies like screen readers. Please reflect these modifications into your websites. +- New Star rating now has a `readonly` state. + +- Warning Star rating has been slightly changed for accessibility purpose; a visually hidden `span` matching the title attribute was added and color contrast of inactive stars has been updated. Please reflect this modification into your websites. + + ```diff + - + + + ``` +- Deprecated The `form-star-rating()` mixin is now deprecated. We now use a `mask-image` CSS property to display the stars in this form element. + ### CSS and Sass variables -
@@ -59,6 +69,16 @@ If you need more details about the changes, please refer to the [v5.3.2 release]
  • $accordion-dark-button-hover-bg
  • $footer-accordion-active-color
  • $footer-accordion-btn-hover-bg
  • +
  • $form-star-rating-checked-color
  • +
  • $form-star-rating-checked-icon
  • +
  • $form-star-rating-dark-checked-color
  • +
  • $form-star-rating-dark-hover-color
  • +
  • $form-star-rating-dark-unchecked-color
  • +
  • $form-star-rating-hover-color
  • +
  • $form-star-rating-sm-checked-icon
  • +
  • $form-star-rating-sm-unchecked-icon
  • +
  • $form-star-rating-unchecked-color
  • +
  • $form-star-rating-unchecked-icon
  • $local-nav-active-bg
  • $local-nav-active-color
  • $local-nav-active-marker-width