-
Notifications
You must be signed in to change notification settings - Fork 57
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
refactor: use external color handling #1611
Draft
haxxmaxx
wants to merge
6
commits into
main
Choose a base branch
from
crl/use-external-colors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+49
−1,553
Draft
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
import getStyling, { | ||
CONTRAST_THRESHOLD, | ||
DEFAULT_SELECTION_COLORS, | ||
getContrast, | ||
getContrastingColor, | ||
getOverridesAsObject, | ||
} from '../styling'; | ||
import getStyling, { DEFAULT_SELECTION_COLORS, getOverridesAsObject } from '../styling'; | ||
|
||
describe('styling', () => { | ||
let theme = {}; | ||
|
@@ -116,14 +110,14 @@ describe('styling', () => { | |
expect(styles.search.color).toEqual('object.listBox,content,color'); | ||
}); | ||
it('search - should get desired color if contrasting enough', () => { | ||
themeApi.getStyle = () => '#999'; | ||
themeApi.getStyle = () => '#888888'; | ||
const styles = getStyling({ app, themeApi, theme, components: [] }); | ||
expect(styles.search.color).toEqual('#999'); | ||
expect(styles.search.color).toEqual('#888888'); | ||
}); | ||
it('search - should get a better contrasting color if not good contrast against white', () => { | ||
themeApi.getStyle = () => '#aaa'; | ||
const styles = getStyling({ app, themeApi, theme, components: [] }); | ||
expect(styles.search.color).toEqual('#000'); | ||
expect(styles.search.color).toEqual('#000000'); | ||
}); | ||
it('header', () => { | ||
components = [ | ||
|
@@ -165,7 +159,7 @@ describe('styling', () => { | |
}, | ||
]; | ||
const POSSIBLE_COLOR = 'rgb(255, 255, 255)'; | ||
const CONTRASTING_TO_POSSIBLE = '#000'; | ||
const CONTRASTING_TO_POSSIBLE = '#000000'; | ||
|
||
themeApi.getStyle = (a, b, c) => (c === 'backgroundColor' ? POSSIBLE_COLOR : `${a},${b},${c}`); | ||
components[0].content.fontColor.color = '#FFFFFF'; | ||
|
@@ -200,65 +194,64 @@ describe('styling', () => { | |
}); | ||
}); | ||
|
||
const hasEnoughContrast = (a, b) => getContrast(a, b) > CONTRAST_THRESHOLD; | ||
// const hasEnoughContrast = (a, b) => getContrast(a, b) > CONTRAST_THRESHOLD; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: potentially move some of these tests to chart-modules |
||
|
||
describe('contrast', () => { | ||
it('should return undefined for unsupported or invalid color(s)', () => { | ||
expect(getContrast('rgb(0,0,0)', 'transparent')).toEqual(undefined); | ||
expect(getContrast('rgb(0,0,0)', 'asdasd')).toEqual(undefined); | ||
expect(getContrast('dsadasd', 'rgb(0,0,0)')).toEqual(undefined); | ||
}); | ||
// describe('contrast', () => { | ||
// it('should return undefined for unsupported or invalid color(s)', () => { | ||
// expect(getContrast('rgb(0,0,0)', 'transparent')).toEqual(undefined); | ||
// expect(getContrast('rgb(0,0,0)', 'asdasd')).toEqual(undefined); | ||
// expect(getContrast('dsadasd', 'rgb(0,0,0)')).toEqual(undefined); | ||
// }); | ||
|
||
it('should fallback to false when contrast is undefined for unsupported or invalid color(s)', () => { | ||
expect(hasEnoughContrast('#ddd', 'white')).toEqual(false); | ||
expect(hasEnoughContrast('#ccc', 'white')).toEqual(false); | ||
expect(hasEnoughContrast('rgb(0,0,0)', 'transparent')).toEqual(false); | ||
expect(hasEnoughContrast('transparent', 'transparent')).toEqual(false); | ||
expect(hasEnoughContrast('red', 'blue')).toEqual(true); | ||
expect(hasEnoughContrast('misspelled', 'hey hey')).toEqual(false); | ||
expect(hasEnoughContrast('misspelled', 'hey hey')).toEqual(false); | ||
expect(hasEnoughContrast('transparent', 'transparent')).toEqual(false); | ||
expect(hasEnoughContrast(' hsl (0, 0 , 0 , 1.0 )', '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast('hsl(0, 0, 0, 1)', '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast('hsl(0,0,0,1.0)', '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast(undefined, '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast('', '#FFF')).toEqual(false); | ||
}); | ||
it('should detect transparent colors and then always return false since we do not know color is behind the transparent color', () => { | ||
expect(hasEnoughContrast(' rgba (0, 0 , 0 , 0.2 )', '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast(' hsla (0, 0 , 0 , 0.2 )', '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast(' rgba (0, 0 , 0 , .2 )', '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast(' hsla (0, 0 , 0 , .2 )', '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast('rgba(0, 0, 0, 0)', '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast('rgba(0,0,0,0)', '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast('hsla(0, 0, 0, 0)', '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast('hsla(0,0,0,0)', '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast('transparent', '#FFF')).toEqual(false); | ||
}); | ||
it('should fallback to false for unsupported formats', () => { | ||
expect(hasEnoughContrast('rgb(0 0 0 / 0%', '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast('rgb(0 0 0 / 100%)', '#FFF')).toEqual(false); | ||
expect(hasEnoughContrast('rgb(255 255 255 / 0%)', '#000')).toEqual(false); | ||
expect(hasEnoughContrast('rgb(255 255 255 / 100%)', '#000')).toEqual(false); | ||
}); | ||
// it('should fallback to false when contrast is undefined for unsupported or invalid color(s)', () => { | ||
// expect(hasEnoughContrast('#ddd', 'white')).toEqual(false); | ||
// expect(hasEnoughContrast('#ccc', 'white')).toEqual(false); | ||
// expect(hasEnoughContrast('rgb(0,0,0)', 'transparent')).toEqual(false); | ||
// expect(hasEnoughContrast('transparent', 'transparent')).toEqual(false); | ||
// expect(hasEnoughContrast('red', 'blue')).toEqual(true); | ||
// expect(hasEnoughContrast('misspelled', 'hey hey')).toEqual(false); | ||
// expect(hasEnoughContrast('transparent', 'transparent')).toEqual(false); | ||
// expect(hasEnoughContrast(' hsl (0, 0 , 0 , 1.0 )', '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast('hsl(0, 0, 0, 1)', '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast('hsl(0,0,0,1.0)', '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast(undefined, '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast('', '#FFF')).toEqual(false); | ||
// }); | ||
// it('should detect transparent colors and then always return false since we do not know color is behind the transparent color', () => { | ||
// expect(hasEnoughContrast(' rgba (0, 0 , 0 , 0.2 )', '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast(' hsla (0, 0 , 0 , 0.2 )', '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast(' rgba (0, 0 , 0 , .2 )', '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast(' hsla (0, 0 , 0 , .2 )', '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast('rgba(0, 0, 0, 0)', '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast('rgba(0,0,0,0)', '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast('hsla(0, 0, 0, 0)', '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast('hsla(0,0,0,0)', '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast('transparent', '#FFF')).toEqual(false); | ||
// }); | ||
// it('should fallback to false for unsupported formats', () => { | ||
// expect(hasEnoughContrast('rgb(0 0 0 / 0%', '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast('rgb(0 0 0 / 100%)', '#FFF')).toEqual(false); | ||
// expect(hasEnoughContrast('rgb(255 255 255 / 0%)', '#000')).toEqual(false); | ||
// expect(hasEnoughContrast('rgb(255 255 255 / 100%)', '#000')).toEqual(false); | ||
// }); | ||
|
||
it('should not detect as transparent colors', () => { | ||
expect(hasEnoughContrast('rgba(0, 0, 0, 1)', '#FFF')).toEqual(true); | ||
expect(hasEnoughContrast('hsla(0,0,0,1.0)', '#FFF')).toEqual(true); | ||
expect(hasEnoughContrast('rgba(0,0,0,1.0)', '#FFF')).toEqual(true); | ||
expect(hasEnoughContrast('red', '#FFF')).toEqual(true); | ||
}); | ||
}); | ||
// it('should not detect as transparent colors', () => { | ||
// expect(hasEnoughContrast('rgba(0, 0, 0, 1)', '#FFF')).toEqual(true); | ||
// expect(hasEnoughContrast('hsla(0,0,0,1.0)', '#FFF')).toEqual(true); | ||
// expect(hasEnoughContrast('rgba(0,0,0,1.0)', '#FFF')).toEqual(true); | ||
// expect(hasEnoughContrast('red', '#FFF')).toEqual(true); | ||
// }); | ||
// }); | ||
|
||
describe('get contrasting color', () => { | ||
it('should prefer light color even though contrast is higher for desired color', () => { | ||
const bg = '#474747'; | ||
const c1 = getContrast('#000', bg); | ||
const c2 = getContrast('#fff', bg); | ||
expect(c1 > c2).toBeTruthy(); // although it does not make sense when comparing with the eye | ||
expect(getContrastingColor(bg, '#000')).toEqual('#FFF'); | ||
}); | ||
}); | ||
// describe('get contrasting color', () => { | ||
// it('should prefer light color even though contrast is higher for desired color', () => { | ||
// const bg = '#474747'; | ||
// const c1 = getContrast('#000', bg); | ||
// const c2 = getContrast('#fff', bg); | ||
// expect(c1 > c2).toBeTruthy(); // although it does not make sense when comparing with the eye | ||
// expect(getContrastingColor(bg, '#000')).toEqual('#FFF'); | ||
// }); | ||
// }); | ||
|
||
describe('getSelectionColors', () => { | ||
let themeSelectionColorsEnabled; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the contrast for this was actually pretty bad (< 3:1) which isn't acceptable in any case. Probably due to the incorrect contrast calculations, and the arbitrary threshold, this was considered good enough