Skip to content

Commit

Permalink
refactor(utils): refactor aria color (element-plus#3742)
Browse files Browse the repository at this point in the history
  • Loading branch information
btea authored Sep 30, 2021
1 parent 18e6810 commit fd06ac1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/utils/aria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

/**
Expand Down
18 changes: 7 additions & 11 deletions packages/utils/color.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
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 {
red: parseInt(rawColor.slice(0, 2), 16),
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,
}
}

Expand Down

0 comments on commit fd06ac1

Please sign in to comment.