Skip to content

Commit

Permalink
Implement styling improvements for forced-colors mode
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas committed Jul 12, 2022
1 parent 94096b3 commit 33a0c44
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/blocks/MediaBlock.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
position: relative;
padding: 0;
cursor: pointer;
outline: $draftail-contrast-border;
outline: $draftail-contrast-outline;

// stylelint-disable
&:focus {
Expand Down
1 change: 1 addition & 0 deletions examples/components/Modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $spacing-modal: 0.5rem;
z-index: $modal-z-index;
background-color: $color-bg-modal;
animation: modal-in 0.2s $easing-circ 0s backwards;
outline: $draftail-contrast-outline-modal;

&[dir="rtl"],
[dir="rtl"] & {
Expand Down
12 changes: 12 additions & 0 deletions examples/entities/TooltipEntity.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
.TooltipEntity {
cursor: pointer;

@media (forced-colors: active) {
color: LinkText;
}

&__icon {
color: $TEAL_WAGTAIL;
margin-inline-end: 0.2em;
width: 1em;
height: 1em;

@media (forced-colors: active) {
color: currentColor;
}
}

&__text {
background: $LIGHT_BLUE_EEF8FF;
border-bottom: 1px dotted $TEAL_WAGTAIL;

@media (forced-colors: active) {
border-bottom-color: currentColor;
}
}
}
3 changes: 2 additions & 1 deletion src/api/constants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ describe("constants", () => {
"verticalAlign": "middle",
},
"MARK": Object {
"backgroundColor": "yellow",
"backgroundColor": "Mark",
"color": "MarkText",
},
"QUOTATION": Object {
"fontStyle": "italic",
Expand Down
3 changes: 2 additions & 1 deletion src/api/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ export const CUSTOM_STYLE_MAP = {
borderRadius: "3px",
},
[INLINE_STYLE.MARK]: {
backgroundColor: "yellow",
backgroundColor: "Mark",
color: "MarkText",
},
[INLINE_STYLE.QUOTATION]: {
fontStyle: "italic",
Expand Down
4 changes: 4 additions & 0 deletions src/blocks/DividerBlock.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
background: $color-light-grey;
height: 1px;
margin: 10px 0;

@media (forced-colors: active) {
background: CanvasText;
}
}
1 change: 0 additions & 1 deletion src/components/DraftailEditor.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.#{$DRAFTAIL}Editor {
--draftail-offset-inline-start: 2rem;
--draftail-editor-padding: #{$draftail-editor-padding};
--draftail-text-direction: 1;

background-color: $draftail-editor-background;
Expand Down
26 changes: 21 additions & 5 deletions src/components/Toolbar/BlockToolbar/ComboBox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
border-radius: $draftail-tooltip-radius;
font-size: $draftail-editor-font-size;
box-shadow: 5px 5px 20px rgba(0, 0, 0, 0.1);
outline: $draftail-contrast-border;
outline: $draftail-contrast-outline-modal;
}

.#{$DRAFTAIL}ComboBox__label {
Expand Down Expand Up @@ -48,7 +48,11 @@
padding: 10px;
font-size: 1rem;
font-weight: 700;
border-top: 4px solid transparent;
border-top: $draftail-contrast-outline;

@media (forced-colors: active) {
color: GrayText;
}
}

.#{$DRAFTAIL}ComboBox__menu {
Expand All @@ -59,7 +63,7 @@
.#{$DRAFTAIL}ComboBox__status,
.#{$DRAFTAIL}ComboBox__option {
padding: 10px;
border: 1px solid transparent;
border: $draftail-contrast-outline;
font-size: 0.875rem;
font-weight: 700;
line-height: 1.4;
Expand All @@ -69,8 +73,11 @@
&[aria-selected="true"] {
background-color: $color-light-grey;
border-color: currentColor;
outline: 6px solid transparent;
outline-offset: -6px;

@media (forced-colors: active) {
background: Highlight;
color: HighlightText;
}
}
}

Expand All @@ -80,3 +87,12 @@
margin-inline-start: 6px;
margin-inline-end: 6px;
}

.#{$DRAFTAIL}ComboBox__option-icon,
.#{$DRAFTAIL}ComboBox__option-text {
// Force the text to CanvasText as forced colors automatically
// adds a Canvas outline behind text.
@media (forced-colors: active) {
color: CanvasText;
}
}
2 changes: 1 addition & 1 deletion src/components/Toolbar/InlineToolbar/InlineToolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
color: $draftail-editor-chrome-text;
border-radius: $draftail-toolbar-radius;
border-bottom: $draftail-toolbar-border-bottom;
border: $draftail-contrast-border;
outline: $draftail-contrast-outline-modal;
}

.#{$DRAFTAIL}InlineToolbar__target {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Toolbar/MetaToolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
padding: $controls-spacing;
background-color: $draftail-editor-background;
color: $draftail-editor-chrome;
border-top: 1px solid transparent;
border-top: $draftail-contrast-outline;
}
13 changes: 13 additions & 0 deletions src/components/Toolbar/ToolbarButton.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ $button-font-size: 1rem;
background: transparent;
color: inherit;
border: 1px solid transparent;
outline: $draftail-contrast-outline;
font-size: $button-font-size;
font-weight: 600;
cursor: pointer;
Expand All @@ -25,11 +26,23 @@ $button-font-size: 1rem;
&--active {
background-color: $button-active-color;
border: 1px solid $button-active-border-color;

@media (forced-colors: active) {
// Force the text to CanvasText as forced colors automatically
// adds a Canvas outline behind text.
background: Highlight;
color: HighlightText;
border-color: currentColor;
}
}

&__label {
display: inline-block;
vertical-align: middle;
height: 1em;

@media (forced-colors: active) {
color: CanvasText;
}
}
}
2 changes: 1 addition & 1 deletion src/components/Toolbar/ToolbarTooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ button[data-draftail-balloon] {

background: $balloon-bg;
border-radius: $balloon-radius;
border: $draftail-contrast-border;
outline: $draftail-contrast-outline-modal;
color: $balloon-text-color;
content: attr(aria-label);
padding: 0.5em 1em;
Expand Down
1 change: 1 addition & 0 deletions src/components/Tooltip/Tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
color: inherit;
border-radius: 0;
font-size: inherit;
outline: $draftail-contrast-outline-modal;

.tippy-content {
padding: 0;
Expand Down
33 changes: 33 additions & 0 deletions stylelint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,38 @@ module.exports = {
// Only allow logical values.
"text-align": ["start", "end", "center"],
},
"scale-unlimited/declaration-strict-value": [
["color", "fill", "stroke", "/-color/"],
{
ignoreKeywords: [
"currentColor",
"inherit",
"transparent",
"initial",
"none",
"unset",
"Canvas",
"CanvasText",
"LinkText",
"VisitedText",
"ActiveText",
"ButtonFace",
"ButtonText",
"ButtonBorder",
"Field",
"FieldText",
"Highlight",
"HighlightText",
"SelectedItem",
"SelectedItemText",
"Mark",
"MarkText",
"GrayText",
"AccentColor",
"AccentColorText",
],
},
],
"value-keyword-case": null,
},
};

0 comments on commit 33a0c44

Please sign in to comment.