refactor(utils): refactor aria color (#3742)

This commit is contained in:
btea 2021-09-30 02:07:44 -05:00 committed by GitHub
parent 18e6810ac4
commit fd06ac17c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 14 deletions

View File

@ -27,9 +27,9 @@ export const isVisible = (element: HTMLElement) => {
export const obtainAllFocusableElements = (
element: HTMLElement
): HTMLElement[] => {
return Array.from(element.querySelectorAll(FOCUSABLE_ELEMENT_SELECTORS))
.filter(isFocusable)
.filter(isVisible) as HTMLElement[]
return Array.from(
element.querySelectorAll<HTMLElement>(FOCUSABLE_ELEMENT_SELECTORS)
).filter((item: HTMLElement) => isFocusable(item) && isVisible(item))
}
/**

View File

@ -1,11 +1,8 @@
export function calcColorChannels(c: string) {
let rawColor = c.replace('#', '')
if (/^[0-9a-fA-F]{3}$/.test(rawColor)) {
const color = rawColor.split('')
for (let i = 2; i >= 0; i--) {
color.splice(i, 0, color[i])
}
rawColor = color.join('')
rawColor =
rawColor[0].repeat(2) + rawColor[1].repeat(2) + rawColor[2].repeat(2)
}
if (/^[0-9a-fA-F]{6}$/.test(rawColor)) {
return {
@ -13,12 +10,11 @@ export function calcColorChannels(c: string) {
green: parseInt(rawColor.slice(2, 4), 16),
blue: parseInt(rawColor.slice(4, 6), 16),
}
} else {
return {
red: 255,
green: 255,
blue: 255,
}
}
return {
red: 255,
green: 255,
blue: 255,
}
}