Coder Social home page Coder Social logo

Comments (5)

nkbt avatar nkbt commented on June 15, 2024 6

πŸ‘ to @oliverbenns

I do the same and believe this is the most reasonable approach. Let's stop adding side-effects and do just plain composition.

from css-modules.

joeybaker avatar joeybaker commented on June 15, 2024 5

If you want to, you can work around the problem with the :global syntax, but I think this is a place where you'll find that bootstrap's way of thinking and the "component" way of thinking endorsed by css-modules don't agree. Bootstrap's ButtonGroup breaks one of the core-tenants: no more conflicts. If a parent component can change the way a child behaves, we no longer have encapsulation.

Some alternative approaches:

  1. Have buttons take a prop that allows their styling to match what a button group would do. This might come close to eliminating the need for a ButtonGroup component.
  2. Have your button group component set its own classnames on its button children. This is kinda "magical" and breaks encapsulation, but might come the closest to what you want.
  3. Create a whole new ButtonGroup component that doesn't use the Button component at all.

IMHO

from css-modules.

oliverbenns avatar oliverbenns commented on June 15, 2024 1

I did @joeybaker 's second suggestion not too long ago. Gist

from css-modules.

princed avatar princed commented on June 15, 2024

There's one trick to make this work:

/* button.css */
.button { 
  composes: button from ".../buttongroup.css"
  ... 
}

/* buttongroup.css */
.buttonGroup > .button { ... }

still transforms to something like

.button---3h-GD { ... }
.buttonGroup---3qigr > .button---3t-2h { ... }

but exported from "button.css" styles object now looks like

{
  button: "button---3h-GD button---3t-2h"
  //  ...
}

Thus any modification you may want to apply to .button inbuttongroup.css will work inside button group.

Obvious downside: button.css has buttongroup.css as a dependency.

from css-modules.

bladeSk avatar bladeSk commented on June 15, 2024

For anyone coming here from the search, here's another trick you can use. This one uses a @value import and is arguably cleaner/less hacky: #147 (comment)

from 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.