Skip to content

Rebuild number... four? - #29

Merged
geelen merged 60 commits into
masterfrom
regexps-begone
Sep 27, 2016
Merged

geelen merged 60 commits into
masterfrom
regexps-begone

Conversation

@geelen

@geelen geelen commented Sep 23, 2016

Copy link
Copy Markdown
Member

I've lost count how many times I've torn this down and started again. But I've had to build a lot less this time around than previously, which is a good thing.

I think we need a good way of testing this end-to-end. Maybe just test renderToString() or should we use Jest snapshots or something? Anyway, I'm not 100% that there weren't regressions so port your test projects to @next and try it out.

API as described in #27. Using a modified PostCSS parser and postcss nested to do the actual parsing, and deferring all parsing until render time. ComponentStyle is where the action is, it almost certainly needs breaking up into a few different utils so we can implement global and keyframes.

Anyway, if your projects still work with this now we should get this merged and on latest and build up from here. Apart from perf issues because of the delayed parsing (which might actually not be a real problem in the end) this is going to be a WAY better place to start from.

@geelen

geelen commented Sep 24, 2016

Copy link
Copy Markdown
Member Author

OH BTW I just implemented context so you can do this

const Half = styled.div`
  padding: 1rem;
  > h2 {
    margin: 0;
    padding: 1rem;
  }
`

const SecondHalf = styled(Half)`
  background: #ccc;
  ${define({
    fg: 'white',
    bg: '#444'
  })}
`

const Button = styled.div`
  color: ${inherit('fg', 'black')}
  background: ${inherit('bg', 'none')}
  cursor: pointer;
  padding: 0.5em 1em;
  border: 1px solid;
`

export default () => (
  <Container>
    <Half>
      <h3>This is normal</h3>
      <Button>Ok</Button>
    </Half>
    <SecondHalf>
      <h3>This is inverted</h3>
      <Button>Ok</Button>
    </SecondHalf>
  </Container>
)

define and inherit are simple aliases and I'm definitely not sure about them yet. To do it manually you'd do:

const SecondHalf = styled(Half)`
  background: #ccc;
  ${(props, context) => {
    context.fg = 'white'
    context.bg = '#444'
  }}
`

const Button = styled.div`
  color: ${(props, context) => context.fg || 'black'}
  background: ${(props, context) => context.bg || 'none'}
  cursor: pointer;
  padding: 0.5em 1em;
  border: 1px solid;
`

I did originally think about merging props and context when these functions get called but idk.

Anyway, I think context-passing is going to be the big thing that unlocks theming.

@geelen

geelen commented Sep 24, 2016

Copy link
Copy Markdown
Member Author

Published at styled-components@next if you wanna play.

@geelen

geelen commented Sep 25, 2016

Copy link
Copy Markdown
Member Author

Changed up the syntax for these function interpolations:

const SecondHalf = styled(Half)`
  background: #ccc;
  ${props => props.updateTheme({
    fg: 'white',
    bg: '#444'
  })}
`

const Button = styled.div`
  color: ${props => props.theme.fg || 'black'}
  background: ${props => props.theme.bg || 'none'}
  cursor: pointer;
  padding: 0.5em 1em;
  border: 1px solid;
`

Better than the alternatives, published as v0.1.6 or @next. I think this now PRETTY GREAT and I'm keen to get it shipped FOR REAL so we can start working on DOCUMENTATION AND OTHER THINGS

@mxstbr

mxstbr commented Sep 25, 2016

Copy link
Copy Markdown
Member

Shipit

@geelen geelen mentioned this pull request Sep 26, 2016
@geelen

geelen commented Sep 26, 2016

Copy link
Copy Markdown
Member Author

@mxstbr can you look into this appveyor thing and merge this if it's all good?

@geelen

geelen commented Sep 26, 2016

Copy link
Copy Markdown
Member Author

Version 0.1.9 published with tag next btw

@mxstbr

mxstbr commented Sep 27, 2016

Copy link
Copy Markdown
Member

🎉 🎉 🎉 🎉

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