Comments (5)
π 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.
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:
- 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. - 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. - Create a whole new
ButtonGroup
component that doesn't use theButton
component at all.
IMHO
from css-modules.
I did @joeybaker 's second suggestion not too long ago. Gist
from css-modules.
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.
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)
- Class name prop not overriding component styles HOT 4
- Issue with duplicate class hashes
- Does the order of implementation of a class matter when there are two classes with the same parameters? HOT 1
- typo in https://github.com/css-modules/css-modules/blob/master/docs/local-scope.md HOT 1
- RFC: Support for hashing more types of identifiers HOT 8
- Another rant about not being able to import a class from another file
- not so good logo HOT 1
- Compose classes with attribute selector
- Best way to override styling found in module a based on module b. HOT 1
- How pseudo class :global should workοΌ HOT 2
- ID vs Class
- Rules nesting HOT 1
- Understanding "composes" peer classes HOT 2
- It should throw an error if you use a class that doesn't exist
- Proposal: Handover Official Lead of CSS Modules to Devon Govett HOT 1
- Define how CSS modules interacts with `@layer` HOT 1
- bug: composes keyword does not work inside nested class
- how to style child Component when child and parent both use css.module? HOT 1
- Late loading of CSS Module creating layout shift - Next.js 14
- Is there a way to support native nesting selector `&`?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from css-modules.