Skip to content

Commit 1ddf559

Browse files
committed
Return self if color not found.
1 parent 57125da commit 1ddf559

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/theme/utils.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ export const extendTheme = (theme, extension) => mergeDeepRight(theme, extension
55

66
export const propOrElse = (pathName, defaultValue) => props => pathOr(defaultValue, pathName, props)
77

8-
export const getOrElse = (pathName, defaultValue) => ({ theme }) =>
9-
pathOr(defaultValue, pathName, theme)
8+
export const getOrElse =
9+
(pathName, defaultValue) =>
10+
({ theme }) =>
11+
pathOr(defaultValue, pathName, theme)
1012

1113
export const getSizeUnit = ({ theme }) => path(["constants", "SIZE_UNIT"], theme)
1214

@@ -20,7 +22,7 @@ export const calcSize = expr => props => {
2022

2123
export const getColor = colorPath => {
2224
const colorPaths = Array.isArray(colorPath) ? colorPath : [colorPath]
23-
return getOrElse(["colors", ...colorPaths], "#fff")
25+
return getOrElse(["colors", ...colorPaths], colorPath || "#fff")
2426
}
2527

2628
export const getRgbColor = (colorPath, opacity = 1) => {
@@ -35,22 +37,23 @@ export const getRgbColor = (colorPath, opacity = 1) => {
3537
}
3638
}
3739

38-
export const getSizeBy = (multiplier = 1) => props => {
39-
const size = (getSizeUnit(props) || 0) * multiplier
40-
return `${size}px`
41-
}
40+
export const getSizeBy =
41+
(multiplier = 1) =>
42+
props => {
43+
const size = (getSizeUnit(props) || 0) * multiplier
44+
return `${size}px`
45+
}
4246

4347
export const getGutterHeight = ({ theme }) => {
4448
const gutterValue = path(["constants", "GUTTER_HEIGHT"], theme) || 0
4549
return `${gutterValue}px`
4650
}
4751

48-
export const getValidatedControlColor = (
49-
defaultColorPath = "border",
50-
defaultDisabledPath = "disabled"
51-
) => ({ theme, success, error, disabled }) => {
52-
if (success) return getColor(["success"])({ theme })
53-
if (error) return getColor(["error"])({ theme })
54-
if (disabled) return getColor([defaultDisabledPath])({ theme })
55-
return getColor([defaultColorPath])({ theme })
56-
}
52+
export const getValidatedControlColor =
53+
(defaultColorPath = "border", defaultDisabledPath = "disabled") =>
54+
({ theme, success, error, disabled }) => {
55+
if (success) return getColor(["success"])({ theme })
56+
if (error) return getColor(["error"])({ theme })
57+
if (disabled) return getColor([defaultDisabledPath])({ theme })
58+
return getColor([defaultColorPath])({ theme })
59+
}

0 commit comments

Comments
 (0)