(core) Makes the hex value editable in the color select

Summary:
 - reuses the textInput form the editableLabel module
 - adds a isValidHex utility function to gutil

Test Plan: - Adds test to the project test

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D2744
This commit is contained in:
Cyprien P
2021-03-04 12:04:02 +01:00
parent 92ef1f400c
commit 5e5bf3af9d
3 changed files with 28 additions and 10 deletions

View File

@@ -777,6 +777,15 @@ export function isColorDark(hexColor: string, isDarkBelow: number = 220): boolea
return luma < isDarkBelow;
}
/**
* Returns true if val is a valid hex color value. For instance: #aabbaa is valid, #aabba is not. Do
* not accept neither short notation nor hex with transparency, ie: #aab, #aabb and #aabbaabb are
* invalid.
*/
export function isValidHex(val: string): boolean {
return /^#([0-9A-F]{6})$/i.test(val);
}
/**
* Returns a promise that resolves to true if promise takes longer than timeoutMsec to resolve. If not