Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/style/__tests__/colors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ describe('style/Colors', () => {
});

it('should return undefined for color that does not exist in our colors palette.', () => {
uut.anotherViolet = '#5A48F5';
expect(uut.getSystemColorByHex('#5A48F5')).toEqual('violet30');
expect(uut.getSystemColorByHex('#5A48F5', GetColorsByHexOptions)).toEqual(undefined);
expect(uut.getSystemColorByHex('#5A48F5', {validColors: [...SYSTEM_COLORS, 'primary']})).toEqual('primary');
expect(uut.getSystemColorByHex('#5A48F5', {validColors: [...SYSTEM_COLORS, 'anotherViolet']})).toEqual('anotherViolet');
});
});
});
11 changes: 4 additions & 7 deletions src/style/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import _ from 'lodash';
import Color from 'color';
import {OpaqueColorValue} from 'react-native';
import tinycolor from 'tinycolor2';
import {colorsPalette, themeColors} from './colorsPalette';
import {colorsPalette} from './colorsPalette';
import DesignTokens from './designTokens';
import DesignTokensDM from './designTokensDM';
//@ts-ignore
Expand All @@ -20,7 +20,7 @@ export class Colors {
private shouldSupportDarkMode = false;

constructor() {
const colors = Object.assign(colorsPalette, themeColors);
const colors = Object.assign(colorsPalette);
Object.assign(this, colors);
this.loadSchemes({light: DesignTokens, dark: DesignTokensDM});

Expand Down Expand Up @@ -185,7 +185,7 @@ export class Colors {
const shouldReverseOnDark =
!options?.avoidReverseOnDark && this.shouldSupportDarkMode && Scheme.getSchemeType() === 'dark';
const key = shouldReverseOnDark ? colorKeys[colorKeys.length - 1 - keyIndex] : tintKey;

const requiredColorKey = `${colorKey.slice(0, -2)}${key}`;
const requiredColorKey1 = `${colorKey.slice(0, -1)}${key}`;
const requiredColor = this[requiredColorKey] || this[requiredColorKey1];
Expand Down Expand Up @@ -355,10 +355,7 @@ function threeDigitHexToSix(value: string) {
return value.replace(/./g, '$&$&');
}

const TypedColors = Colors as ExtendTypeWith<
typeof Colors,
typeof colorsPalette & typeof themeColors & typeof DesignTokens
>;
const TypedColors = Colors as ExtendTypeWith<typeof Colors, typeof colorsPalette & typeof DesignTokens>;
const colorObject = new TypedColors();
colorObject.loadColors(colorsPalette);
export default colorObject;
6 changes: 1 addition & 5 deletions src/style/colorsPalette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,4 @@ const extraFixColorsMap = {
'#fff': 'white'
};

const themeColors = {
primary: colorsPalette.violet30
};

export {colorsPalette, themeColors, extraFixColorsMap};
export {colorsPalette, extraFixColorsMap};