Skip to content

Commit c90b079

Browse files
Inbal-Tishethanshar
authored andcommitted
replacing oneColor library with color library (#368)
1 parent b4ba0e3 commit c90b079

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
},
3939
"dependencies": {
4040
"babel-plugin-transform-inline-environment-variables": "^0.0.2",
41+
"color": "^3.1.0",
4142
"hoist-non-react-statics": "^3.0.0",
4243
"lodash": "^4.0.0",
43-
"onecolor": "^3.1.0",
4444
"prop-types": "^15.5.10",
4545
"react-native-animatable": "^1.1.0",
4646
"react-native-blur": "^3.1.1",

src/style/__tests__/colors.spec.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,25 @@ describe('services/AvatarService', () => {
5555
});
5656

5757
it('should handle color that does not exist in uilib', () => {
58-
expect(uut.getColorTint('#F1BE0B', 10)).toEqual('#b28c08');
59-
expect(uut.getColorTint('#F1BE0B', 20)).toEqual('#ca9f09');
60-
expect(uut.getColorTint('#F1BE0B', 30)).toEqual('#F1BE0B');
61-
expect(uut.getColorTint('#F1BE0B', 40)).toEqual('#f5d04d');
62-
expect(uut.getColorTint('#F1BE0B', 50)).toEqual('#f9e291');
63-
expect(uut.getColorTint('#F1BE0B', 60)).toEqual('#fbedbb');
64-
expect(uut.getColorTint('#F1BE0B', 70)).toEqual('#fdf4d6');
65-
expect(uut.getColorTint('#F1BE0B', 80)).toEqual('#fef9e7');
58+
expect(uut.getColorTint('#F1BE0B', 10).toLowerCase()).toEqual('#d2a50a');
59+
expect(uut.getColorTint('#F1BE0B', 20).toLowerCase()).toEqual('#deaf0a');
60+
expect(uut.getColorTint('#F1BE0B', 30).toLowerCase()).toEqual('#f1be0b');
61+
expect(uut.getColorTint('#F1BE0B', 40).toLowerCase()).toEqual('#f5d04d');
62+
expect(uut.getColorTint('#F1BE0B', 50).toLowerCase()).toEqual('#f9e291');
63+
expect(uut.getColorTint('#F1BE0B', 60).toLowerCase()).toEqual('#fbedbb');
64+
expect(uut.getColorTint('#F1BE0B', 70).toLowerCase()).toEqual('#fdf4d6');
65+
expect(uut.getColorTint('#F1BE0B', 80).toLowerCase()).toEqual('#fef9e7');
6666
});
6767

6868
it('should round down tint level to the nearest one', () => {
69-
expect(uut.getColorTint('#F1BE0B', 75)).toEqual('#fdf4d6');
70-
expect(uut.getColorTint('#F1BE0B', 25)).toEqual('#ca9f09');
71-
expect(uut.getColorTint('#F1BE0B', 35)).toEqual('#F1BE0B');
69+
expect(uut.getColorTint('#F1BE0B', 75).toLowerCase()).toEqual('#fdf4d6');
70+
expect(uut.getColorTint('#F1BE0B', 25).toLowerCase()).toEqual('#deaf0a');
71+
expect(uut.getColorTint('#F1BE0B', 35).toLowerCase()).toEqual('#f1be0b');
7272
});
7373

7474
it('should handle out of range tint levels and round them to the nearest one in range', () => {
75-
expect(uut.getColorTint('#F1BE0B', 3)).toEqual('#b28c08');
76-
expect(uut.getColorTint('#F1BE0B', 95)).toEqual('#fef9e7');
75+
expect(uut.getColorTint('#F1BE0B', 3).toLowerCase()).toEqual('#d2a50a');
76+
expect(uut.getColorTint('#F1BE0B', 95).toLowerCase()).toEqual('#fef9e7');
7777
});
7878
});
7979
});

src/style/colors.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from 'lodash';
2+
import Color from 'color';
23
import {colorsPalette} from './colorsPalette';
34

4-
const one = require('onecolor');
55

66
class Colors {
77
/**
@@ -46,7 +46,6 @@ class Colors {
4646
} else {
4747
throw new Error('rgba can work with either 2 or 4 arguments');
4848
}
49-
5049
return `rgba(${red}, ${green}, ${blue}, ${opacity})`;
5150
}
5251

@@ -66,34 +65,35 @@ class Colors {
6665
const darkRatios = [0.13, 0.08];
6766
const lightRatios = [0.27, 0.55, 0.72, 0.83, 0.9];
6867

69-
const colorKey = _.findKey(this, (value, key) => this[key] === color);
70-
7168
if (_.isUndefined(tintKey) || isNaN(tintKey) || _.isUndefined(color)) {
7269
console.error('"Colors.getColorTint" must accept a color and tintKey params');
7370
return color;
7471
}
7572

73+
const colorKey = _.findKey(this, (value, key) => this[key] === color);
74+
7675
if (colorKey) {
7776
const requiredColorKey = `${colorKey.slice(0, -2)}${tintKey}`;
7877
const requiredColor = this[requiredColorKey];
78+
7979
if (_.isUndefined(requiredColor)) {
8080
console.warn('"Colors.getColorTint" could not find color with this tint');
8181
return color;
8282
}
8383
return requiredColor;
84-
// Handles dynamic colors (non uilib colors)
85-
} else {
84+
} else { // Handles dynamic colors (non uilib colors)
8685
let tintLevel = Math.floor(Number(tintKey) / 10);
8786
tintLevel = Math.max(1, tintLevel);
8887
tintLevel = Math.min(8, tintLevel);
88+
8989
if (tintLevel === BASE_COLOR_LEVEL) {
9090
return color;
9191
} else if (tintLevel <= BASE_COLOR_LEVEL) {
9292
const darkRatio = darkRatios[tintLevel - 1];
93-
return one(color).darken(darkRatio).hex();
93+
return Color(color).darken(darkRatio).hex();
9494
} else {
9595
const lightRatio = lightRatios[tintLevel - 4];
96-
return one(color).mix('#ffffff', lightRatio).hex();
96+
return Color(color).mix(Color('#ffffff'), lightRatio).hex();
9797
}
9898
}
9999
}
@@ -103,7 +103,6 @@ function validateRGB(value) {
103103
if (isNaN(value) || value > 255 || value < 0) {
104104
throw new Error(`${value} is invalid rgb code, please use number between 0-255`);
105105
}
106-
107106
return value;
108107
}
109108

0 commit comments

Comments
 (0)