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

Only allow classnames & compile inline styles #3

Open
geelen opened this issue Nov 26, 2015 · 1 comment
Open

Only allow classnames & compile inline styles #3

geelen opened this issue Nov 26, 2015 · 1 comment

Comments

@geelen
Copy link

geelen commented Nov 26, 2015

What if there was a kind of uninline project that meant that projects using inline styles could use a component that expected only classes?

As an author I write a component like this:

export default props => {
  let {theme, children} = props

  return <header className={theme.header}>
    <h1 className={theme.title}>{children}</h1>
  </header>
}

As a user on a project that uses inline styles, I could be doing something like this:

export default () => {
  let inlineStyles = {
    header: {
      margin: 40
    },
    title: {
      lineHeight: 1,
      fontSize: '4rem'
    }
  }

  <MyComponent theme={uninline(inlineStyles)}>Sneaky Class Times!</MyComponent>
}

The automatically generated classnames would have lower specificity than inline styles but we could mitigate that by either adding !important to every rule 😱 or asking the user to add an ID of #uninlined somewhere to their project and generating CSS that looks like this:

:export {
  header: 204a1c693ef27e;
  title: 1aafe63c034927;
}
#uninlined .204a1c693ef27e {
  margin: 40px;
}
#uninlined .1aafe63c034927 {
  line-height: 1;
  font-size: 4rem;
}

Adding the #uninlined id could be optional but if it's mandatory it will mean much fewer specificity surprises down the track.

Basically an inline styles to ICSS compiler. Thoughts?

@chantastic
Copy link

@geelen holy crapy. so, i apparently never sign into Discord. i really like this idea. still seem like a good idea to you?

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