Coder Social home page Coder Social logo

Comments (4)

cibernox avatar cibernox commented on September 13, 2024

I was thinking about this actually. With a handlebars AST tranformation all interpolations could be done in compile time.
I'd suggest some syntax like class="global-class {{someLocalPropertyLikeActiveOrDisabledOrSomething}} {{:moduleCSSClass}}"

I think that it removes the cognitive overhead of having a different attribute that text-editors don't know to autocomplete, and doing all the work in compilation time would save the component to have to hold javascript styles on it (even if it's a object that will never change)

from ember-css-modules.

dfreeman avatar dfreeman commented on September 13, 2024

I actually started down the path of doing template interpolation at compile time (I still have a proof-of-concept branch somewhere), but unfortunately it doesn't mesh well with class composition.

.foo {
  composes: bar;
}

Given the above, the CSS Modules compilation process doesn't change the definition of .foo to incorporate .bar's styles like a Sass @include or add the .foo selector to .bar's definition like @extend – in fact, the class definitions aren't changed at all.
Instead, the value for foo in the exported styles hash will contain references to the namespaced version of both foo and bar, so any element withclass={{styles.foo}} will end having both classes assigned.

This means that to statically interpolate the namespaced classes during template compilation, the stylesheets need to already have been processed, and we need access to that output from the AST transform. Ember CLI's build pipeline doesn't guarantee the former, and it actively prevents the latter, so I settled for pulling the class names at runtime.

Given that, I'd be hesitant to introduce a microsyntax like {{:moduleCSSClass}}, since it would just be notational shorthand for {{styles.moduleCSSClass}} rather than meaning something distinct at build time.

from ember-css-modules.

cibernox avatar cibernox commented on September 13, 2024

Given that, I'd be hesitant to introduce a microsyntax like {{:moduleCSSClass}}

No question, this microsyntax was only an idea to mark nodes for a possible precompilation by a handlebars AST. I doesn't makes sense just to save a few keystrokes if the interpolation happens in runtime.

from ember-css-modules.

dfreeman avatar dfreeman commented on September 13, 2024

This is now released as local-class="foo" in 0.4.0.

from ember-css-modules.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.