Using Color.fromHex with invalid input should return null

This commit is contained in:
Martin Aeschlimann
2017-08-12 13:31:59 +02:00
parent eae6de3488
commit d3a80dc181
2 changed files with 13 additions and 5 deletions

View File

@@ -1032,9 +1032,13 @@ export class Color {
return new Color(color.r, color.g, color.b, color.a / 255);
}
static fromHex(hex: string): Color {
const color = BaseColor.fromHex(hex).rgba;
return new Color(color.r, color.g, color.b, color.a / 255);
static fromHex(hex: string): Color | null {
let baseColor = BaseColor.Format.CSS.parseHex(hex);
if (baseColor) {
const rgba = baseColor.rgba;
return new Color(rgba.r, rgba.g, rgba.b, rgba.a / 255);
}
return null;
}
}