From b20c69b15a41cd86383fd78e1511a63ab287bdf4 Mon Sep 17 00:00:00 2001 From: orangemug Date: Wed, 29 Nov 2017 18:00:52 +0000 Subject: [PATCH 1/2] Catch invalid color during parse. --- src/components/fields/ColorField.jsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/fields/ColorField.jsx b/src/components/fields/ColorField.jsx index 1ff229a..73776c6 100644 --- a/src/components/fields/ColorField.jsx +++ b/src/components/fields/ColorField.jsx @@ -50,7 +50,16 @@ class ColorField extends React.Component { } get color() { - return Color(this.props.value || '#fff').rgb() + let color = Color("rgb(255,255,255)"); + + // Catch invalid color. + try { + return Color(this.props.value).rgb() + } + catch(err) { + console.warn("Error parsing color: ", err); + } + return color; } render() { From a50b09e5a26161323cd4b5277675c46f2a1fbd25 Mon Sep 17 00:00:00 2001 From: orangemug Date: Wed, 29 Nov 2017 18:07:03 +0000 Subject: [PATCH 2/2] Tidy logic. --- src/components/fields/ColorField.jsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/fields/ColorField.jsx b/src/components/fields/ColorField.jsx index 73776c6..25b1670 100644 --- a/src/components/fields/ColorField.jsx +++ b/src/components/fields/ColorField.jsx @@ -50,16 +50,14 @@ class ColorField extends React.Component { } get color() { - let color = Color("rgb(255,255,255)"); - // Catch invalid color. try { return Color(this.props.value).rgb() } catch(err) { console.warn("Error parsing color: ", err); + return Color("rgb(255,255,255)"); } - return color; } render() {