Remove the hex color requirement.
This commit is contained in:
parent
6eff95bfd3
commit
30b190dcdf
|
@ -4,7 +4,6 @@ import {type UserLabelsData, saveUserLabels} from "../../storage/common.js";
|
||||||
import {
|
import {
|
||||||
createElementFromString,
|
createElementFromString,
|
||||||
isColorBright,
|
isColorBright,
|
||||||
isValidHexColor,
|
|
||||||
log,
|
log,
|
||||||
querySelectorAll,
|
querySelectorAll,
|
||||||
themeColors,
|
themeColors,
|
||||||
|
@ -26,15 +25,6 @@ type State = {
|
||||||
username: string;
|
username: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const colorPattern: string = [
|
|
||||||
"^(?:#(?:", // (?:) are non-capturing groups.
|
|
||||||
"[a-f\\d]{8}|", // The order of 8 -> 6 -> 4 -> 3 character hex colors matters.
|
|
||||||
"[a-f\\d]{6}|",
|
|
||||||
"[a-f\\d]{4}|",
|
|
||||||
"[a-f\\d]{3})",
|
|
||||||
"|transparent)$", // "Transparent" is also allowed in the input.
|
|
||||||
].join("");
|
|
||||||
|
|
||||||
export class UserLabelsFeature extends Component<Props, State> {
|
export class UserLabelsFeature extends Component<Props, State> {
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -209,14 +199,7 @@ export class UserLabelsFeature extends Component<Props, State> {
|
||||||
};
|
};
|
||||||
|
|
||||||
colorChange = (event: Event) => {
|
colorChange = (event: Event) => {
|
||||||
let color: string = (event.target as HTMLInputElement).value.toLowerCase();
|
const color = (event.target as HTMLInputElement).value.toLowerCase();
|
||||||
if (!color.startsWith("#") && !color.startsWith("t") && color.length > 0) {
|
|
||||||
color = `#${color}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (color !== "transparent" && !isValidHexColor(color)) {
|
|
||||||
log('User Labels: Color must be a valid hex color or "transparent".');
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the color was changed through the preset values, also change the
|
// If the color was changed through the preset values, also change the
|
||||||
// selected color state.
|
// selected color state.
|
||||||
|
@ -379,7 +362,6 @@ export class UserLabelsFeature extends Component<Props, State> {
|
||||||
placeholder="Color"
|
placeholder="Color"
|
||||||
value={color}
|
value={color}
|
||||||
onInput={debounce(this.colorChange, 250)}
|
onInput={debounce(this.colorChange, 250)}
|
||||||
pattern={colorPattern}
|
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue