Skip to content

Commit

Permalink
#14 #88 Update documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
azurepolarbear committed Jun 2, 2024
1 parent 83746ee commit 022c0e5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
12 changes: 12 additions & 0 deletions docs/release-notes/v0.6.0-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,20 @@ declare interface Palette {
* palette, black (#000000), and white (#FFFFFF).
*/
readonly CONTRAST_MAP: {
/**
* The colors in the palette that pass the WCAG AA standard when
* compared to black (#000000). This list should NOT contain
* white (#FFFFFF) unless it is a color listed in the palette.
*/
'#000000': string[],

/**
* The colors in the palette that pass the WCAG AA standard when
* compared to white (#FFFFFF). This list should NOT contain
* black (#000000) unless it is a color listed in the palette.
*/
'#FFFFFF': string[],

[HEX: string]: string[]
},

Expand Down
12 changes: 12 additions & 0 deletions src/main/color/palette/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,20 @@ export interface Palette {
* palette, black (#000000), and white (#FFFFFF).
*/
readonly CONTRAST_MAP: {
/**
* The colors in the palette that pass the WCAG AA standard when
* compared to black (#000000). This list should NOT contain
* white (#FFFFFF) unless it is a color listed in the palette.
*/
'#000000': string[],

/**
* The colors in the palette that pass the WCAG AA standard when
* compared to white (#FFFFFF). This list should NOT contain
* black (#000000) unless it is a color listed in the palette.
*/
'#FFFFFF': string[],

[HEX: string]: string[]
},

Expand Down
25 changes: 19 additions & 6 deletions src/test/shared/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,20 @@ export function checkForPaletteNameKeyMatch(map: StringMap<Palette>): void {

export function checkForValidContrastMap(palette: Palette): void {
checkForValidPalette(palette);
expect(palette.CONTRAST_MAP['#000000']).not.toContain('#FFFFFF');
expect(palette.CONTRAST_MAP['#FFFFFF']).not.toContain('#000000');

const validHexes: string[] = palette.COLORS.map((color: PaletteColor): string => {
return color.HEX;
});
validHexes.push('#000000');
validHexes.push('#FFFFFF');

if (validHexes.indexOf('#000000') < 0) {
expect(palette.CONTRAST_MAP['#FFFFFF']).not.toContain('#000000');
validHexes.push('#000000');
}

if (validHexes.indexOf('#FFFFFF') < 0) {
expect(palette.CONTRAST_MAP['#000000']).not.toContain('#FFFFFF');
validHexes.push('#FFFFFF');
}

for (const key in palette.CONTRAST_MAP) {
checkForValidHexColorString(key);
Expand All @@ -79,14 +85,21 @@ export function checkForValidContrastMap(palette: Palette): void {
checkForValidHexColorString(hex);
expect(validHexes).toContain(hex);

const meetsRatio: boolean =
const meetsNormalRatio: boolean =
ColorContrastAssessor.meetsContrastStandard(
key,
hex,
ContrastStandard.AA,
ContrastFontSize.NORMAL
);
expect(meetsRatio).toBeTruthy();
const meetsLargeRatio: boolean =
ColorContrastAssessor.meetsContrastStandard(
key,
hex,
ContrastStandard.AA,
ContrastFontSize.LARGE
);
expect(meetsNormalRatio && meetsLargeRatio).toBeTruthy();
}
}
}

0 comments on commit 022c0e5

Please sign in to comment.