Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] feat: support windows high contrast mode #5524

Merged
merged 23 commits into from Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .stylelintrc
Expand Up @@ -21,6 +21,7 @@
"no-invalid-position-at-import-rule": [true, {
"ignoreAtRules": ["use"]
}],
"scss/media-feature-value-dollar-variable": null,
"selector-max-universal": 1
}
}
6 changes: 6 additions & 0 deletions packages/core/src/common/_typography-colors.scss
Expand Up @@ -63,6 +63,12 @@
box-shadow: none;
color: inherit;
}

@media (forced-colors: active) and (prefers-color-scheme: dark) {
// Windows High Contrast dark theme
border: 1px solid $pt-high-contrast-mode-border-color;
box-shadow: none;
}
}

.#{$ns}-key,
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/common/_variables.scss
Expand Up @@ -145,3 +145,13 @@ $pt-dark-popover-box-shadow: 0 0 0 1px $pt-dark-popover-border-color,
$pt-dark-tooltip-box-shadow: 0 2px 4px rgba($black, $pt-dark-drop-shadow-opacity),
0 8px 24px rgba($black, $pt-dark-drop-shadow-opacity) !default;
$pt-dark-toast-box-shadow: $pt-dark-elevation-shadow-3 !default;

// Colors used for Windows high contrast mode
// Because high contrast mode doesn't actually obey any colors we define, but uses system colors,
// we define these variables in terms of System colors so that it's easier to understand the intent.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be helpful to link to documentation here, like https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/system_color_keywords

// See https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/system_color_keywords for more info on system colors.
$pt-high-contrast-mode-border-color: buttonborder;
$pt-high-contrast-mode-active-background-color: highlight;
$pt-high-contrast-mode-disabled-border-color: graytext;
$pt-high-contrast-mode-disabled-text-color: graytext;
$pt-high-contrast-mode-disabled-background-color: graytext;
17 changes: 17 additions & 0 deletions packages/core/src/components/button/_button-group.scss
Expand Up @@ -115,6 +115,23 @@ Styleguide button-group
.#{$ns}-button {
@include pt-button-minimal();
}

@media (forced-colors: active) and (prefers-color-scheme: dark) {
// Because we give even minimal buttons a border in high contrast mode, we need to handle border styles
// similar to how we handle non-minimal buttons

&:not(:first-child) {
border-bottom-left-radius: 0;
border-left: none;
border-top-left-radius: 0;
}

&:not(:last-child) {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
margin-right: -$button-border-width;
}
}
}

.#{$ns}-popover-wrapper,
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/components/button/_button.scss
Expand Up @@ -193,6 +193,11 @@ Styleguide button
&.#{$ns}-active {
background: $orange3;
color: $pt-text-color;

@media (forced-colors: active) and (prefers-color-scheme: dark) {
// Windows High Contrast dark theme
background: $pt-high-contrast-mode-active-background-color;
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions packages/core/src/components/button/_common.scss
Expand Up @@ -129,6 +129,11 @@ $button-intents: (
background: $button-background-color-active-disabled;
}
}

@media (forced-colors: active) and (prefers-color-scheme: dark) {
// Windows High Contrast dark theme
border: 1px solid $pt-high-contrast-mode-border-color;
}
}

@mixin pt-button-default-colors() {
Expand All @@ -146,6 +151,11 @@ $button-intents: (
@mixin pt-button-active() {
background-color: $button-background-color-active;
box-shadow: $button-box-shadow-active;

@media (forced-colors: active) and (prefers-color-scheme: dark) {
// Windows High Contrast dark theme
background: $pt-high-contrast-mode-active-background-color;
}
}

@mixin pt-button-disabled() {
Expand Down Expand Up @@ -182,13 +192,25 @@ $button-intents: (
&.#{$ns}-disabled {
@include pt-button-intent-disabled($default-color);
}

@media (forced-colors: active) and (prefers-color-scheme: dark) {
// Windows High Contrast dark theme
border: 1px solid $pt-high-contrast-mode-border-color;
box-shadow: none;
}
}

@mixin pt-button-intent-disabled($default-color) {
background-color: rgba($default-color, 0.5);
border-color: transparent;
box-shadow: none;
color: $button-intent-color-disabled;

@media (forced-colors: active) and (prefers-color-scheme: dark) {
// Windows High Contrast dark theme
border-color: $pt-high-contrast-mode-disabled-border-color;
color: $pt-high-contrast-mode-disabled-border-color;
}
}

// N.B. this mixin cannot be used on pseudo element selectors because it will produce invalid CSS
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/components/callout/_callout.scss
Expand Up @@ -42,6 +42,11 @@ Styleguide callout
}
}

// High contrast mode hides backgrounds, so we need to use a border instead
@media (forced-colors: active) and (prefers-color-scheme: dark) {
border: 1px solid $pt-high-contrast-mode-border-color;
}

&.#{$ns}-callout-icon {
padding-left: ($pt-grid-size * 2) + $pt-icon-size-large;

Expand Down Expand Up @@ -76,6 +81,10 @@ Styleguide callout
&.#{$ns}-intent-#{$intent} {
background-color: rgba($color, 0.1);

@media (forced-colors: active) and (prefers-color-scheme: dark) {
border: 1px solid $pt-high-contrast-mode-border-color;
}

&[class*="#{$ns}-icon-"]::before,
> .#{$ns}-icon:first-child,
.#{$ns}-heading {
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/components/card/_card.scss
Expand Up @@ -54,6 +54,12 @@ $dark-elevation-shadows: (
background-color: $dark-card-background-color;
box-shadow: $pt-dark-elevation-shadow-0;
}

// High contrast mode hides box-shadows, so we need to use a border instead
@media (forced-colors: active) and (prefers-color-scheme: dark) {
border: 1px solid $pt-high-contrast-mode-border-color;
box-shadow: none;
}
}

@for $index from 1 through length($elevation-shadows) {
Expand All @@ -64,6 +70,10 @@ $dark-elevation-shadows: (
.#{$ns}-dark & {
box-shadow: nth($dark-elevation-shadows, $index);
}

@media (forced-colors: active) and (prefers-color-scheme: dark) {
border: 1px solid $pt-high-contrast-mode-border-color;
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/components/dialog/_dialog.scss
Expand Up @@ -84,6 +84,10 @@ $dialog-padding: $pt-grid-size * 1.5 !default;
box-shadow: $pt-dark-dialog-box-shadow;
color: $pt-dark-text-color;
}

@media (forced-colors: active) and (prefers-color-scheme: dark) {
border: 1px solid $pt-high-contrast-mode-border-color;
}
}

.#{$ns}-dialog-header {
Expand Down Expand Up @@ -126,6 +130,10 @@ $dialog-padding: $pt-grid-size * 1.5 !default;
color: $pt-dark-icon-color;
}
}

@media (forced-colors: active) and (prefers-color-scheme: dark) {
border-bottom: 1px solid $pt-high-contrast-mode-border-color;
}
}

.#{$ns}-dialog-body {
Expand Down
20 changes: 20 additions & 0 deletions packages/core/src/components/drawer/_drawer.scss
Expand Up @@ -47,6 +47,10 @@ $dark-drawer-background-color: $dark-gray4 !default;
right: 0;

top: 0;

@media (forced-colors: active) and (prefers-color-scheme: dark) {
border-bottom: 1px solid $pt-high-contrast-mode-border-color;
}
}

&.#{$ns}-position-bottom {
Expand All @@ -70,6 +74,10 @@ $dark-drawer-background-color: $dark-gray4 !default;
left: 0;

right: 0;

@media (forced-colors: active) and (prefers-color-scheme: dark) {
border-top: 1px solid $pt-high-contrast-mode-border-color;
}
}

&.#{$ns}-position-left {
Expand All @@ -93,6 +101,10 @@ $dark-drawer-background-color: $dark-gray4 !default;

top: 0;
width: $drawer-default-size;

@media (forced-colors: active) and (prefers-color-scheme: dark) {
border-right: 1px solid $pt-high-contrast-mode-border-color;
}
}

&.#{$ns}-position-right {
Expand All @@ -116,6 +128,10 @@ $dark-drawer-background-color: $dark-gray4 !default;

top: 0;
width: $drawer-default-size;

@media (forced-colors: active) and (prefers-color-scheme: dark) {
border-left: 1px solid $pt-high-contrast-mode-border-color;
}
}

&.#{$ns}-dark,
Expand All @@ -137,6 +153,10 @@ $dark-drawer-background-color: $dark-gray4 !default;
padding-left: $drawer-padding;
position: relative;

@media (forced-colors: active) and (prefers-color-scheme: dark) {
border-bottom: 1px solid $pt-high-contrast-mode-border-color;
}

.#{$ns}-icon-large,
.#{$ns}-icon {
color: $pt-icon-color;
Expand Down
Expand Up @@ -31,6 +31,12 @@
box-shadow: input-transition-shadow($input-shadow-color-focus, true), $input-box-shadow-focus;
}

@media (forced-colors: active) and (prefers-color-scheme: dark) {
&:not(.#{$ns}-disabled)::before {
border: 1px solid $pt-high-contrast-mode-border-color;
}
}

@each $intent, $color in $pt-intent-colors {
&.#{$ns}-intent-#{$intent} {
.#{$ns}-editable-text-content,
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/components/forms/_common.scss
Expand Up @@ -121,6 +121,10 @@ $control-group-stack: (
&.#{$ns}-disabled {
@include pt-input-disabled();
}

@media (forced-colors: active) and (prefers-color-scheme: dark) {
border: 1px solid $pt-high-contrast-mode-border-color;
}
}

@mixin pt-input-placeholder() {
Expand Down