File tree 1 file changed +11
-2
lines changed
1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,15 @@ export function isValidHexCode(hexColor: string): boolean {
31
31
return isHexColor ;
32
32
}
33
33
34
+ // credit : https://github.com/validatorjs/validator.js/blob/master/src/lib/isHexColor.js
35
+ const getValidHEX = ( hex : string , defaultHex : string ) : string => {
36
+ const hexColor = / ^ # ? ( [ 0 - 9 A - F ] { 3 } | [ 0 - 9 A - F ] { 4 } | [ 0 - 9 A - F ] { 6 } | [ 0 - 9 A - F ] { 8 } ) $ / i. test ( hex . replace ( "##" , "#" ) ) ;
37
+ if ( hexColor ) {
38
+ return hex ;
39
+ }
40
+ return defaultHex ;
41
+ } ;
42
+
34
43
function hexToRgb ( hex : string ) : Rgb {
35
44
const sanitizedHex = hex . replace ( "##" , "#" ) ;
36
45
const colorParts = / ^ # ? ( [ a - f \d ] { 2 } ) ( [ a - f \d ] { 2 } ) ( [ a - f \d ] { 2 } ) $ / i. exec ( sanitizedHex ) ;
@@ -174,8 +183,8 @@ const useGetBrandingColours = ({
174
183
175
184
darkVal = normalizeHexCode ( darkVal , true ) ;
176
185
177
- const lightColourMap = createColorMap ( lightVal ) ;
178
- const darkColourMap = createColorMap ( darkVal ) ;
186
+ const lightColourMap = createColorMap ( getValidHEX ( lightVal , BRAND_COLOR ) ) ;
187
+ const darkColourMap = createColorMap ( getValidHEX ( darkVal , DARK_BRAND_COLOR ) ) ;
179
188
180
189
const theme = {
181
190
light : {
You can’t perform that action at this time.
0 commit comments