Skip to content

Commit

Permalink
Update and add token values to improve accessibility (#24027)
Browse files Browse the repository at this point in the history
* theme: update neutral foreground and background tokens

Updates the values of some neutral foreground and background
tokens to achieve better color contrast to meet accessibility
requirements.

* theme: add new static foreground and background color tokens

* tooltip: update inverted color tokens.

* theme: update teams dark color tokens

* popover: update color tokens

Updates color tokens for Popover and adds a new Storybook story to make
it easier to see the different Popover appearances.

* checkbox: update color token

* theme: update high contrast token

* switch: update thumb/indicator color token

* spinner: update color tokens

* change files

* add new tokens to v9ThemeShim

* update avatar color tokens in styles

* update badge color tokens in styles

* change files

* switch: update background color token

Changed from `colorBrandBackground*` to `colorCompoundBrandBackground*`.

* badge: update color token for ghost/subtle appearance

* spinner: update color tokens and styles

Updates color tokens for better contrast and accessibility.
Simplifies some of the styling logic.

* theme: update high contrast color token

* tokens: update teams dark color neutral foreground inverted values

* tokens: update teams dark color neutral background inverted value

* theme-sass: add new color tokens

* theme-sass change files

* spinner: update vr tests for inverted appearance

Adds a background wrapper to ensure inverted Spinners are consistently
visible in all test cases.

* pr comments

* spinner: hard code inverted story background

We want to avoid using foreground tokens for backgrounds.
  • Loading branch information
spmonahan authored Aug 10, 2022
1 parent 5d985fa commit 1d0a728
Show file tree
Hide file tree
Showing 29 changed files with 322 additions and 79 deletions.
4 changes: 3 additions & 1 deletion apps/public-docsite-v9/src/shims/ThemeShim/v9ThemeShim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Theme as ThemeV9,
webLightTheme,
} from '@fluentui/react-components';
import { blackAlpha, whiteAlpha } from './themeDuplicates';
import { blackAlpha, whiteAlpha, grey } from './themeDuplicates';

/**
* Creates v9 color tokens from a v8 palette.
Expand Down Expand Up @@ -53,6 +53,7 @@ const mapAliasColors = (palette: IPalette, inverted: boolean): ColorTokens => {
colorNeutralForegroundInvertedPressed: palette.white,
colorNeutralForegroundInvertedSelected: palette.white,
colorNeutralForegroundOnBrand: palette.white,
colorNeutralForegroundInvertedStatic: palette.white,
colorNeutralForegroundInvertedLink: palette.white,
colorNeutralForegroundInvertedLinkHover: palette.white,
colorNeutralForegroundInvertedLinkPressed: palette.white,
Expand Down Expand Up @@ -85,6 +86,7 @@ const mapAliasColors = (palette: IPalette, inverted: boolean): ColorTokens => {
colorNeutralBackground5Pressed: palette.neutralLighter,
colorNeutralBackground5Selected: palette.neutralLighterAlt,
colorNeutralBackground6: palette.neutralLight,
colorNeutralBackgroundStatic: grey[20],
colorNeutralBackgroundInverted: palette.neutralSecondary,
colorSubtleBackground: 'transparent',
colorSubtleBackgroundHover: palette.neutralLighter,
Expand Down
156 changes: 122 additions & 34 deletions apps/vr-tests-react-components/src/stories/Spinner.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { Spinner } from '@fluentui/react-spinner';
import { tokens } from '@fluentui/react-theme';
import { TestWrapperDecoratorNoAnimation } from '../utilities/TestWrapperDecorator';

// Inverted Spinners are meant to be used over a dark background
// or photo. This wrapper ensures a dark background so the Spinners
// are consistently visible.
const InvertedWrapper: React.FC = ({ children }) => {
return <div style={{ background: tokens.colorPaletteBerryForeground1, padding: '10px' }}>{children}</div>;
};

storiesOf('Spinner converged', module)
.addDecorator(TestWrapperDecoratorNoAnimation)
.addStory('Primary', () => <Spinner className="test-class" />, {
Expand Down Expand Up @@ -75,79 +83,159 @@ storiesOf('Spinner converged', module)
includeHighContrast: true,
includeDarkMode: true,
})
.addStory('Inverted', () => <Spinner className="test-class" appearance="inverted" />, {
includeHighContrast: true,
includeDarkMode: true,
})
.addStory('Inverted with Label', () => <Spinner className="test-class" appearance="inverted" label="Loading" />, {
includeHighContrast: true,
includeDarkMode: true,
})
.addStory(
'Inverted',
() => (
<InvertedWrapper>
<Spinner className="test-class" appearance="inverted" />
</InvertedWrapper>
),
{
includeHighContrast: true,
includeDarkMode: true,
},
)
.addStory(
'Inverted with Label',
() => (
<InvertedWrapper>
<Spinner className="test-class" appearance="inverted" label="Loading" />
</InvertedWrapper>
),
{
includeHighContrast: true,
includeDarkMode: true,
},
)
.addStory(
'Inverted with Label Before',
() => <Spinner className="test-class" appearance="inverted" labelPosition="before" label="Loading" />,
() => (
<InvertedWrapper>
<Spinner className="test-class" appearance="inverted" labelPosition="before" label="Loading" />
</InvertedWrapper>
),
{
includeHighContrast: true,
includeDarkMode: true,
},
)
.addStory(
'Inverted with Label After',
() => <Spinner className="test-class" appearance="inverted" labelPosition="after" label="Loading" />,
() => (
<InvertedWrapper>
<Spinner className="test-class" appearance="inverted" labelPosition="after" label="Loading" />
</InvertedWrapper>
),
{
includeHighContrast: true,
includeDarkMode: true,
},
)
.addStory(
'Inverted with Label Above',
() => <Spinner className="test-class" appearance="inverted" labelPosition="above" label="Loading" />,
() => (
<InvertedWrapper>
<Spinner className="test-class" appearance="inverted" labelPosition="above" label="Loading" />
</InvertedWrapper>
),
{
includeHighContrast: true,
includeDarkMode: true,
},
)
.addStory(
'Inverted with Label Below',
() => <Spinner className="test-class" appearance="inverted" labelPosition="below" label="Loading" />,
() => (
<InvertedWrapper>
<Spinner className="test-class" appearance="inverted" labelPosition="below" label="Loading" />
</InvertedWrapper>
),
{
includeHighContrast: true,
includeDarkMode: true,
},
)
.addStory(
'Primary with Size Tiny',
() => (
<InvertedWrapper>
<Spinner className="test-class" appearance="inverted" size="tiny" />
</InvertedWrapper>
),
{
includeHighContrast: true,
includeDarkMode: true,
},
)
.addStory('Primary with Size Tiny', () => <Spinner className="test-class" appearance="inverted" size="tiny" />, {
includeHighContrast: true,
includeDarkMode: true,
})
.addStory(
'Inverted with Size Extra Small',
() => <Spinner className="test-class" appearance="inverted" size="extra-small" />,
() => (
<InvertedWrapper>
<Spinner className="test-class" appearance="inverted" size="extra-small" />
</InvertedWrapper>
),
{
includeHighContrast: true,
includeDarkMode: true,
},
)
.addStory(
'Inverted with Size Small',
() => (
<InvertedWrapper>
<Spinner className="test-class" appearance="inverted" size="small" />
</InvertedWrapper>
),
{
includeHighContrast: true,
includeDarkMode: true,
},
)
.addStory(
'Inverted with Size Medium',
() => (
<InvertedWrapper>
<Spinner className="test-class" appearance="inverted" size="medium" />
</InvertedWrapper>
),
{
includeHighContrast: true,
includeDarkMode: true,
},
)
.addStory(
'Inverted with Size Large',
() => (
<InvertedWrapper>
<Spinner className="test-class" appearance="inverted" size="large" />
</InvertedWrapper>
),
{
includeHighContrast: true,
includeDarkMode: true,
},
)
.addStory('Inverted with Size Small', () => <Spinner className="test-class" appearance="inverted" size="small" />, {
includeHighContrast: true,
includeDarkMode: true,
})
.addStory('Inverted with Size Medium', () => <Spinner className="test-class" appearance="inverted" size="medium" />, {
includeHighContrast: true,
includeDarkMode: true,
})
.addStory('Inverted with Size Large', () => <Spinner className="test-class" appearance="inverted" size="large" />, {
includeHighContrast: true,
includeDarkMode: true,
})
.addStory(
'Inverted with Size Extra Large',
() => <Spinner className="test-class" appearance="inverted" size="extra-large" />,
() => (
<InvertedWrapper>
<Spinner className="test-class" appearance="inverted" size="extra-large" />
</InvertedWrapper>
),
{
includeHighContrast: true,
includeDarkMode: true,
},
)
.addStory('Inverted with Huge', () => <Spinner className="test-class" appearance="inverted" size="huge" />, {
includeHighContrast: true,
includeDarkMode: true,
});
.addStory(
'Inverted with Huge',
() => (
<InvertedWrapper>
<Spinner className="test-class" appearance="inverted" size="huge" />
</InvertedWrapper>
),
{
includeHighContrast: true,
includeDarkMode: true,
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: update color tokens",
"packageName": "@fluentui/react-avatar",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: update color tokens",
"packageName": "@fluentui/react-badge",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: update color tokens",
"packageName": "@fluentui/react-checkbox",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: update color tokens",
"packageName": "@fluentui/react-popover",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: update color tokens",
"packageName": "@fluentui/react-spinner",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: update color tokens",
"packageName": "@fluentui/react-switch",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: update token values to fix failing color contrast",
"packageName": "@fluentui/react-theme",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "feat: add new color tokens",
"packageName": "@fluentui/react-theme-sass",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: update color tokens",
"packageName": "@fluentui/react-tooltip",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ const useColorStyles = makeStyles({
backgroundColor: tokens.colorNeutralBackground6,
},
brand: {
color: tokens.colorNeutralForegroundInverted,
color: tokens.colorNeutralForegroundInvertedStatic,
backgroundColor: tokens.colorBrandBackgroundStatic,
},
'dark-red': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const useRootStyles = makeStyles({
color: tokens.colorPaletteDarkOrangeForeground3,
},
'ghost-subtle': {
color: tokens.colorNeutralForegroundInverted,
color: tokens.colorNeutralForegroundInvertedStatic,
},
'ghost-success': {
color: tokens.colorPaletteGreenForeground3,
Expand Down Expand Up @@ -187,7 +187,7 @@ const useRootStyles = makeStyles({
color: tokens.colorPaletteDarkOrangeForeground3,
},
'outline-subtle': {
color: tokens.colorNeutralForegroundInverted,
color: tokens.colorNeutralForegroundInvertedStatic,
},
'outline-success': {
color: tokens.colorPaletteGreenForeground2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const useInputStyles = makeStyles({
},
[`& ~ .${checkboxClassNames.indicator}`]: {
backgroundColor: tokens.colorCompoundBrandBackground,
color: tokens.colorNeutralForegroundOnBrand,
color: tokens.colorNeutralForegroundInverted,
...shorthands.borderColor(tokens.colorCompoundBrandBackground),
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ const useStyles = makeStyles({
},

inverted: {
// TODO: neutral background inverted missing from superset and theme
backgroundColor: tokens.colorNeutralForeground1,
color: tokens.colorNeutralForegroundInverted,
backgroundColor: tokens.colorNeutralBackgroundStatic,
color: tokens.colorNeutralForegroundInvertedStatic,
},

brand: {
backgroundColor: tokens.colorBrandBackground,
// TODO: clarify with designers what foreground color should be with brand background,
color: tokens.colorNeutralForegroundInverted,
color: tokens.colorNeutralForegroundOnBrand,
},

smallPadding: {
Expand Down
Loading

0 comments on commit 1d0a728

Please sign in to comment.