Skip to content

Commit

Permalink
feat: upgrade TinyColor to 3.3.1, new method "onBackground"
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaello committed Jan 1, 2021
1 parent 8b30909 commit 858ebdb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
38 changes: 38 additions & 0 deletions __tests__/Tinycolor_tests.re
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,44 @@ describe("set and get alpha (also tests clone())", () => {
});
});

describe("onBackground()", () => {
let blue = TinyColor.makeFromString("blue");
let red = TinyColor.makeFromString("red");
test("get back same color when no transparency", () => {
switch (blue, red) {
| (Some(blue), Some(red)) =>
expect(TinyColor.onBackground(blue, red) |> TinyColor.toHexString)
== "#0000ff"
| _ => expect(true) == false
}
});

test("get back background color when full transparency", () => {
switch (blue, red) {
| (Some(blue), Some(red)) =>
let blueTransparent = TinyColor.setAlpha(0.0, blue);
expect(
TinyColor.onBackground(blueTransparent, red) |> TinyColor.toHexString,
)
== "#ff0000";
| _ => expect(true) == false
}
});

test("get back mixed color when partly transparent", () => {
switch (blue, red) {
| (Some(blue), Some(red)) =>
let bluePartlyTransparent = TinyColor.setAlpha(0.5, blue);
expect(
TinyColor.onBackground(bluePartlyTransparent, red)
|> TinyColor.toHexString,
)
== "#800080";
| _ => expect(true) == false
}
});
});

describe("getBrightness()", () => {
test("getting brightness for light color", () => {
let color = TinyColor.makeFromString("white");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"bs-platform": "^8.4.2"
},
"dependencies": {
"@ctrl/tinycolor": "^3.1.3"
"@ctrl/tinycolor": "^3.3.1"
}
}
2 changes: 2 additions & 0 deletions src/TinyColor.re
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ let setAlpha = (alphaValue: float, color: t): t => {
setAlpha(colorClone, alphaValue);
};

[@bs.send] external onBackground: (t, t) => t = "onBackground";

/* STRING REPRESENTATIONS */

[@bs.send] external toHsv: t => Js.t('hsv) = "toHsv";
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@
exec-sh "^0.3.2"
minimist "^1.2.0"

"@ctrl/tinycolor@^3.1.3":
version "3.1.3"
resolved "https://registry.yarnpkg.com/@ctrl/tinycolor/-/tinycolor-3.1.3.tgz#3406f90fd04a394a83fe874b763b7d89edffd4c1"
integrity sha512-dHamDINLG/gF4Q6m3Ndnn4nGfLUCmvhY6Oweudqr2hMAMTIB2NvFrNW5HyjtdbqjNz9Z/unvA+/GI9QqBRgX0g==
"@ctrl/tinycolor@^3.3.1":
version "3.3.1"
resolved "https://registry.yarnpkg.com/@ctrl/tinycolor/-/tinycolor-3.3.1.tgz#fa0efcf813daa43f8a6aef3ddaa80f7e66f1278e"
integrity sha512-jUJrjU62MUgHDSu5JfONfgRM2V7GfN5KknsygfIbxwRZXGeayIzxk4O9GiYgEAr9DG5HJThTF5+a5x3wtrOKzQ==

"@glennsl/bs-jest@^0.6.0":
version "0.6.0"
Expand Down

0 comments on commit 858ebdb

Please sign in to comment.