Skip to content

Commit aedfc1b

Browse files
Added function to initiate theme with proper saturation if instantiated with less than 100% saturation (#172)
1 parent c395082 commit aedfc1b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/contrast-colors/test/themeSetters.test.mjs

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ test('should set theme output to LCH', () => {
6262
});
6363

6464
// Saturation
65+
test('should set theme saturation to 60%', () => {
66+
const color = new Color({ name: 'Color', colorKeys: ['#2451FF', '#C9FEFE', '#012676'], ratios: [3, 4.5], colorspace: 'CAM02' });
67+
const theme = new Theme({ colors: [color], backgroundColor: '#f5f5f5', output: 'RGB', saturation: 60 });
68+
const themeColors = theme.contrastColorValues;
69+
70+
expect(themeColors).toEqual(['rgb(119, 142, 193)', 'rgb(90, 107, 187)']);
71+
});
6572
test('should set theme saturation to 60%', () => {
6673
const color = new Color({ name: 'Color', colorKeys: ['#2451FF', '#C9FEFE', '#012676'], ratios: [3, 4.5], colorspace: 'CAM02' });
6774
const theme = new Theme({ colors: [color], backgroundColor: '#f5f5f5', output: 'RGB' });

packages/contrast-colors/theme.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class Theme {
4141
throw new Error(`Output “${output}” not supported`);
4242
}
4343

44+
// Only run the update if saturation is set below 100%
45+
if(this._saturation < 100) this._updateColorSaturation(this._saturation);
46+
4447
this._findContrastColors();
4548
this._findContrastColorPairs();
4649
this._findContrastColorValues();

0 commit comments

Comments
 (0)