From 7b4578ca2bdbe4d46692e569ef7774b254f86770 Mon Sep 17 00:00:00 2001 From: Scott Silvi Date: Wed, 4 Apr 2018 13:09:13 -0500 Subject: [PATCH] Add a fallback There are cases where I want to have a default value applied. I understand that I could do this like so: ``` const getFooterOverrides = theme('mode', { foo: p => p.theme.colors.red }) const Footer = styled.footer` color: blue; color: ${getFooterOverrides} ` ``` I run into problems with this approach when I'm using `attrs`, and have to do things like: ``` const StyledPopUp = styled(PopUpIcon).attrs({ color: p => getFooterOverrides(p) || 'blue' })` margin-left: 4px; ` ``` It'd be really nice to just have: ``` const getFooterOverrides = theme('mode', { defaultValue: 'blue' foo: p => p.theme.colors.red }) ``` --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index c2aed94..5a3bb65 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ function getThemeValue(name, props, values) { if (typeof value === 'function') { themeValue = value(values); } else { - themeValue = values[value]; + themeValue = values[value] || values.defaultValue; } if (typeof themeValue === 'function') {