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

Feature request: define CSS in component file #296

Open
jamesarosen opened this issue Sep 7, 2018 · 7 comments
Open

Feature request: define CSS in component file #296

jamesarosen opened this issue Sep 7, 2018 · 7 comments

Comments

@jamesarosen
Copy link

jamesarosen commented Sep 7, 2018

We write a lot of our components in "single-file" form:

export default class MyComponent extends Component {
  layout = {
    <div class='{{styleNamespace}}__some-div'></div>
  }
}

It would be lovely to include the CSS in the same file. I don't know what that syntax would be, but borrowing an idea from Ruby, perhaps

export default class MyComponent extends Component {
  layout = {
    <div class='{{styleNamespace}}__some-div'></div>
  }
}

// component-css
&__some-div { color: purple; }

though that would require a custom parser for editors.

@jamesarosen
Copy link
Author

Or maybe even something like

export default class MyComponent extends Component {
  layout = {
    <style>
      &__some-div { color: purple; }
    </style>
    <div class='{{styleNamespace}}__some-div'></div>
  }
}

and a Broccoli processor that pulls <style> tags out of components and runs them through the component-css logic.

@webark
Copy link
Owner

webark commented Sep 7, 2018

hmmmm mmm mmmmmm mmm mm ....

I think you could write a separate preprocessor that moves the styles into it's own file, and just have that run before ECC. I'd have to think about what the best way to write that would be though. But it doesn't have to live in ECC.

@jamesarosen
Copy link
Author

it doesn't have to live in ECC

have that run before ECC

Those two go together nicely :)

@webark
Copy link
Owner

webark commented Sep 7, 2018

well.. sure. But you could use it with ember-css-modules also.. and would want it to run before that also..

@kleiram
Copy link
Contributor

kleiram commented Mar 6, 2019

Sorry for bumping this 😄

Perhaps it's an idea to have something like this (an I'm absolutely 100% unsure whether it's even possible with Broccoli):

export default class MyComponent extends Component {
  style = sass`
    & {
      background: palevioletred;
    }
  `;

  layout = hbs`
    <SomeOtherComponent />
  `;
}

I think a styled-componentish API might make it more recognisable for people coming from React too. I'm not sure about the API though.

@webark
Copy link
Owner

webark commented Mar 6, 2019

@kleiram i still think this would live better in some kind of babel plugin that was wrapped in an addon, and something that could live and be maintained in parallel to this addon.

@webark
Copy link
Owner

webark commented Mar 6, 2019

and the minimum of pulling out a chock of text and dumping it in a file is something that a babel or even maybe just a broccoli plugin could do with relative ease.

Not getting into where you are importing methods into the js file that you are then interpolating into the sass to be later processed by a sass or equivalent preprocessor.. then you are getting into something a bit more tricky... but still possible.

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

3 participants