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

Idea: add theme(theme) if using theme provider #53

Open
radenkovic opened this issue Sep 21, 2020 · 3 comments
Open

Idea: add theme(theme) if using theme provider #53

radenkovic opened this issue Sep 21, 2020 · 3 comments

Comments

@radenkovic
Copy link

radenkovic commented Sep 21, 2020

Hello there!

This package definitely helps a lot (I made those helpers by hand before figuring out there is a package).

Here's an idea

  background: ${(p) => p.theme.white || p.theme.red};

we can make shorthand because 90% of the time (at least for me) you just want to grab a variable from theme, something like jsonPath or lodash/get:

  background: ${theme('white', 'red')}

If you like the idea I can definitely make a PR.

Thanks in advance!

@sergioramos
Copy link
Member

sergioramos commented Sep 21, 2020

I like this idea a lot. A PR would be welcome.

I would be interested in a more generalist solution though. What about something like this?

import { getProp } from 'styled-is';

const theme = getProp('theme');

I'm not too happy with the getProp name, but couldn't come up with anything better.

@radenkovic
Copy link
Author

I'm not too happy with the getProp name, but couldn't come up with anything better.

I like how it's generalized, when I have time I can add this, will name it getProp or get, and we can rename it easily.

Also, should I handle it without errors (NO_OP), eg if theme.something.else is undefined, or to throw? I personally like no_op but it's harder to debug (though safer to use in production).

@radenkovic
Copy link
Author

This is ready 🎉
PR #54

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

No branches or pull requests

2 participants