Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a defaultValue fallback for theme #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mergebandit
Copy link

@mergebandit mergebandit commented Apr 4, 2018

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
})

And then simply say ...

const StyledPopUp = styled(PopUpIcon).attrs({
  color: getFooterOverrides
})`
  margin-left: 4px;
`

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
})
```
@mergebandit mergebandit changed the title Add a fallback Add a defaultValue fallback for theme Apr 4, 2018
@sturmenta
Copy link

You can also do

export const Container = styled(View)(
  props => ({
    backgroundColor: colors.principal(props),
    textColor: colors.principalText(props),
  }),
);

and in colors file

export default {
  principal:          props => theme('mode', { 'light': '#039BE5', 'dark: '#000420'})(props),
  principalText:      props => theme('mode', { 'light': '#000000', 'dark: '#000000'})(props),
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants