ember-component-css icon indicating copy to clipboard operation
ember-component-css copied to clipboard

Doesn't work with flag template-only-glimmer-components

Open aklkv opened this issue 5 years ago • 18 comments

with this add-on installed and template-only-glimmer-components turned on wrapping div is being created. It would be nice to provide an element as root to attach auto generated class to.

aklkv avatar Aug 27 '18 09:08 aklkv

I guess I have to use tagName property in component.js

aklkv avatar Aug 27 '18 09:08 aklkv

I'm not familiar with template only components and ember-component-css, but maybe try using <div class={{styleNamespace}}></div> in your template?

topaxi avatar Aug 27 '18 09:08 topaxi

this would generate two divs with auto generated class: screenshot 2018-08-27 02 46 22

aklkv avatar Aug 27 '18 09:08 aklkv

the only way I was able to get it working correctly is by doing the following:

  init() {
    this._super(...arguments);
    this.tagName = 'div';
    this.classNames =['main-navbar', 'sticky', 'navCTA'];
    this.classNameBindings = ['styleNamespace'];
  }

and result is : screenshot 2018-08-27 02 54 39

It would be useful to have logic not to generate outer div if {{styleNamespace}} is used in the template

aklkv avatar Aug 27 '18 09:08 aklkv

I have done I little more digging. The way template-only-glimmer-components is that if there is now component.js file in the component folder outer div will not be generated. Feather more, here it looks like if tagName is not set on component the outer div will be generated even if I am already using {{styleNamespace}} inside the component. I guess to solve it would need to add additional check if {{styleNamespace}} is present in component template.

aklkv avatar Aug 27 '18 10:08 aklkv

Ya. Template only components aren't currently working with this. The proposed change that is under development will be to use ahtmlbars-ast-plugin transformation and wrap the template in a let block that gives access to styleNamespace in the template.

webark avatar Aug 27 '18 17:08 webark

right now to do a "tagless" component with ECC, you have to set the tagName to '' in the component.js file and then use styleNamespace in the template.

webark avatar Aug 27 '18 17:08 webark

I know that isn't what a template-only-glimmer-components is, but until the new version is complete, that will be what you have to do.

webark avatar Aug 27 '18 17:08 webark

@webark Thanks a lot for quick reply! Let me know if you need a hand getting this working. I would be happy to help!

aklkv avatar Aug 27 '18 21:08 aklkv

What's the status on this? Since it also affects glimmer components I think as well.

knownasilya avatar Apr 09 '19 13:04 knownasilya

Indeed it does, I have already asked this question in discord. But I guess it will take some time to make it forward compatible. I am more then willing to help but with some directions from maintainer

aklkv avatar Apr 09 '19 13:04 aklkv

Hit this today when working with Glimmer and Sparkles components. Is there any movement forward to get something working for those cases?

rtablada avatar Apr 15 '19 21:04 rtablada

When working with Sparkles Components you can do something like:

import Component from 'sparkles-component';
import podNames from 'ember-component-css/pod-names';

export default class ReportConfigButton extends Component {
  get styleNamespace() {
    return podNames['foo-bar'];
  }
}

Where foo-bar is the path for the current component.

I'd imagine that this is similar to what would be wanted when working with the let AST transform since at build time we have access to the current module path.

rtablada avatar Apr 15 '19 21:04 rtablada

ya. if you look in PR #300, you can see the template transform that does that. (i ended up just doing a string adjustment cause it’s always wrapping i don’t have to go through the complexity of a handlebars transform)

That PR is held up due to me not really loving the babel transform that adds the styleNamespace into the component js files, and considering having to manually do the imports for addons similarly to how you do the templates with importing the layout

webark avatar Apr 16 '19 14:04 webark

In Ember 3.13

with this add-on installed and template-only-glimmer-components turned on wrapping div is being created.

is no longer true, and if you disable template-only-glimmer-components classes aren't generated either

reproduction: https://github.com/knownasilya/repro-3.13-component-css-bug

knownasilya avatar Sep 27 '19 14:09 knownasilya

Screen Shot 2019-09-27 at 12 08 55 PM The issue from a discussion with @rwjblue

knownasilya avatar Sep 27 '19 16:09 knownasilya

import podNames from 'ember-component-css/pod-names';

This doesn't work in Ember 3.15 podNames contains:

default:
  components: "__components__dfa48"

BryanCrotaz avatar Dec 27 '19 11:12 BryanCrotaz

@BryanCrotaz I’m sorry that you are running into this issue. :/ I will release the new beta version soon where you should have access to the class.

webark avatar Dec 27 '19 14:12 webark