Skip to content

Commit 4bdd55f

Browse files
remove react import, turn delay into mandatory parameter, also allow rgb / rgba theme values
1 parent fa18472 commit 4bdd55f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/FetchLoading.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
import React, { FC } from 'react'
1+
import { FC } from 'react'
22
import './index.css'
33

44
type FetchLoadingProps = {
55
theme?: string
66
}
77
type DotProps = {
8-
delay?: number
8+
delay: number
99
}
1010

1111
const isValidHex = (color: string): boolean =>
12-
/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(color)
12+
/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color)
1313

14-
const Dot: FC<DotProps & FetchLoadingProps> = ({ delay = 0, theme }) => {
15-
const background = theme && isValidHex(theme) ? theme : '#52525c'
14+
const isValidRGB = (color: string): boolean => {
15+
return (
16+
/^rgb\((\s*(2((5[0-5])|([0-4][0-9]))|(1[0-9]{2})|([0-9]?[0-9])),){2}\s*(2((5[0-5])|([0-4][0-9]))|(1[0-9]{2})|([0-9]?[0-9]))\s*\)$/i.test(
17+
color
18+
) ||
19+
/^rgba\((\s*(2((5[0-5])|([0-4][0-9]))|(1[0-9]{2})|([0-9]?[0-9])),){2}\s*(2((5[0-5])|([0-4][0-9]))|(1[0-9]{2})|([0-9]?[0-9])),\s*(1.0)|(0.[0-9]{1,2})\s*\)$/i.test(
20+
color
21+
)
22+
)
23+
}
24+
25+
const Dot: FC<DotProps & FetchLoadingProps> = ({ delay, theme }) => {
26+
const background =
27+
theme && (isValidHex(theme) || isValidRGB(theme)) ? theme : '#52525c'
1628
return (
1729
<div
1830
style={{

0 commit comments

Comments
 (0)