Skip to content

Commit

Permalink
fix(web-styles): adds styles for form-range in forced-color/high-cont…
Browse files Browse the repository at this point in the history
…rast mode (#159)

The form-range CSS-Component now supports high-contrast-mode, incl. styled track, progress, knob and knob-focus when selected
  • Loading branch information
oliverschuerch authored Jul 14, 2022
1 parent 78db28a commit d2c903c
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-seahorses-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/web-styles': patch
---

Add styles for form-range in fourced-color/high-contrast mode
19 changes: 0 additions & 19 deletions .stylelintrc.js

This file was deleted.

15 changes: 15 additions & 0 deletions packages/web-styles/.stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"plugins": ["stylelint-scss"],
"extends": [
"stylelint-config-sass-guidelines",
"stylelint-prettier/recommended"
],
"rules": {
"order/properties-alphabetical-order": null,
"max-nesting-depth": 5,
"selector-max-compound-selectors": 5,
"selector-max-id": 1,
"selector-no-qualifying-type": [true, { "ignore": ["attribute", "class"] }],
"function-url-quotes": null
}
}
2 changes: 1 addition & 1 deletion packages/web-styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"prebuild": "npm run clean",
"build": "gulp build",
"build:ci": "gulp build",
"lint": "stylelint src/**/*.scss --config ../../.stylelintrc.js",
"lint": "stylelint src/**/*.scss",
"lint:fix": "stylelint src/**/*.scss --fix",
"format": "prettier src/**/*.scss --write",
"test": "jest",
Expand Down
74 changes: 70 additions & 4 deletions packages/web-styles/src/components/form-range.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
@use '../themes/bootstrap/overrides' as *;
@use '../themes/bootstrap/forms' as bf;

@use '../variables/commons';
@use '../variables/color';
@use '../variables/spacing';
@use '../variables/components/forms';
@use '../mixins/utilities';

.form-range {
// see https://jira.post.ch/browse/COWF-209
Expand All @@ -15,15 +17,20 @@
--ratio: calc((var(--val) - var(--min)) / var(--range));
--sx: calc(0.5 * 1.5em + var(--ratio) * (100% - 1.5em));

&:not(:disabled):not(.disabled) {
&::-moz-range-thumb {
border-radius: 50%;
box-sizing: border-box;
}

&:not(:disabled, .disabled) {
&::-webkit-slider-runnable-track {
background: linear-gradient(color.$black, color.$black) 0 / var(--sx) 100% no-repeat
color.$gray-20;
background: linear-gradient(color.$black, color.$black) 0 / var(--sx) 100%;
background-repeat: no-repeat;
background-color: color.$gray-20;
}

&::-moz-range-progress {
background: color.$black;
background-color: color.$black;
}
}

Expand All @@ -43,3 +50,62 @@
transform: translateY(#{-0.5 * forms.$form-range-height});
}
}

@include utilities.high-contrast-mode() {
.form-range {
// linear-gradient is forced to the value of "none" in forced-color mode
// so, the "forced-color-adjust" property is necessary for "linear-gradient" to continue to work
forced-color-adjust: none;

&:not(:disabled, .disabled) {
&::-webkit-slider-runnable-track {
background: linear-gradient(Highlight, Highlight) 0 / var(--sx) 100%;
background-repeat: no-repeat;
background-color: ButtonBorder;
}

&::-webkit-slider-thumb {
background-color: ButtonFace;
border-color: ButtonBorder;
}

&::-moz-range-track {
background-color: ButtonText;
}

&::-moz-range-progress {
background-color: Highlight;
}

&::-moz-range-thumb {
background-color: ButtonFace;
border-color: ButtonText;
}

&:focus-visible {
&::-webkit-slider-thumb {
outline-offset: commons.$border-thick;
outline: commons.$border-thick solid Highlight;
}

&::-moz-range-thumb {
outline-offset: commons.$border-thick;
outline: commons.$border-thick solid Highlight;
}
}
}

&:disabled,
&.disabled {
&::-webkit-slider-thumb {
background-color: ButtonFace;
border-color: ButtonBorder;
}

&::-moz-range-thumb {
background-color: ButtonFace;
border-color: ButtonBorder;
}
}
}
}

0 comments on commit d2c903c

Please sign in to comment.