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

Bugfix/media-query and selectors placeholders #6

Merged
merged 6 commits into from
Nov 5, 2017
Merged

Bugfix/media-query and selectors placeholders #6

merged 6 commits into from
Nov 5, 2017

Conversation

Tomekmularczyk
Copy link
Contributor

@Tomekmularczyk Tomekmularczyk commented Oct 29, 2017

It's my first public PR ever on GitHub, so if done something against common rules, made too many commits or brute forced the solution, I would like to know and I will try to fix it.

I tested the library on my local project with a component like:

const constants = Object.freeze({
  bsSM: 'screen and (min-width: 768px)',
  h6: 'h6',
});

export default (
  <span>
    <h6>sdfdsds</h6>
    <style jsx global>{`
      body {
        margin: 0;
        padding: 0;
        font-family: sans-serif;

        @media ${constants.bsSM} {
          background-color: red;
        }

        ${constants.h6} {
          font-size: 5rem;
        }
      }
    `}</style>
  </span>
);

and it seems to work fine.

@Tomekmularczyk
Copy link
Contributor Author

I have added a test and fixed #7

Copy link
Owner

@giuseppeg giuseppeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, thanks for contributing man.
Did you test these changes in a real application with styled-jsx?

Nit pick can you remove the semicolons to keep it consistent with the other plugins?

test.js Outdated

it('works with media queries placeholders', () => {
assert.equal(
plugin('p { display: block; @media %%styled-jsx-placeholder-0%% { color: red; } }', {}).trim(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test for

@media (min-width: %%styled-jsx-placeholder-0%%) {}

and

@media (%%styled-jsx-placeholder-0%%) {}

@Tomekmularczyk
Copy link
Contributor Author

@giuseppeg yes, I tried it in a real application with styled-jsx.

I have removed semicolons.

I also updated test for media queries. Unfortunately something like this:

@media (%%styled-jsx-placeholder-0%%)

is causing:

Error: media feature required in media query expression

to fix that it would probably (maybe not) require another matcher. As far I know regex is computationally heavy so this case is not worth it in my opinion. Though I can try to fix it if you want.

@giuseppeg
Copy link
Owner

@Tomekmularczyk no worries, this is perfect for now. Awesome job <3 thank you so much.
I am thinking of a way to make this process less painful for styled-jsx plugins in general so that plugins authors don't have to deal with this stuff. For now what we've got is ok though.

@giuseppeg giuseppeg merged commit 5711efe into giuseppeg:master Nov 5, 2017
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

Successfully merging this pull request may close these issues.

2 participants