Coder Social home page Coder Social logo

Comments (2)

dfreeman avatar dfreeman commented on September 13, 2024 1

In general, component inheritance tends to be difficult to work with because HTML/Handlebars templates don't have any notion of inheritance. As you rightly point out, CSS modules compound this problem by making you also repeat your class usage everywhere.

One option would be to do something like this:

// app/features/components/base-card/component.js
import styles from './styles';

export default Component.extend({
  baseStyles: styles
  // ...
});

You'd then be able to reference the base class's styles like class={{baseStyles.name}} in the template for your derived component templates like app-card.

However, if possible I would take a step back and look at whether you might be able achieve the reuse you're after with composition rather than inheritance. In general I've found composing derived components from more general base ones to be a lot less painful than trying to manage such reuse via subclassing.

What if instead of extending base-card, app-card's template just invoked {{base-card}}? You could imagine using something like ember-block-slots or ember-named-yields to make different sections of your base card overridable on a case by case basis, without having to duplicate the markup of the entire card structure.

Looking at your app-card example, it looks like you're wanting to adjust the styles for one fairly deeply-nested class. Without knowing the full details, the icon might be a good candidate to be a slot with some default content in base-card that could be overridden in app-card's usage of it.

ember-power-select is a good example of a component that's built up this way (though with only a single yield rather than using multiple slots).

from ember-css-modules.

dfreeman avatar dfreeman commented on September 13, 2024

@duro I'm going to go ahead and close this since I don't think there are any actionable changes here for the addon, but if you have further thoughts or questions please feel free to reopen or start a new issue.

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.