Comments (7)
+1
This is an issue if you're using for example markdown-loader or any third-party where it returns pure html. We'd have to overwrite the loader to add a className to the elements.
Keen to know what is the best way to achieve this.
I'm going to cc @markdalgleish the godfather of CSS modules π
from css-modules.
from css-modules.
from css-modules.
@nkbt not really a solution when you're dealing with 3rd party and can't just drop a :global
. To be honest I don't mind to style each one but I guess my friend @peduarte will get mad at this π
from css-modules.
That is not a solution. It is merely a workaround!
Why would you sacrifice the basic behaviour of CSS?
I have a better solution which I will post here later.
from css-modules.
Ok first, I am extremely disappointed with the lack of essential documentation.
I think it's selfish that a a tool such as this is released without informing users that the most common thing CSS is used for will not work.
I think by now every half-decent front end developer understand that isolating and modularising your UI Components is a good thing, but frankly, it is something that can be done with CSS alone.
Tools like this is not supposed to remove the default functionality of CSS, it is supposed to enhance it, and take it to the next level.
I think that whoever is responsible for this documentation, all the developers writing articles about css-modules hoping to get more Twitter followers should let their readers know.
On a separate note, here is a half-decent solution, if someone is really that desperate to use this half-built tool:
Based on my current workflow: webpack + react + css-loader + postcss-loader + cssnext-loader
_Refactored/simplified for example purpose_
base.css
We use cssnext to define our variables and custom media queries
:root {
--color-text: #333;
--size-s: 1.618rem;
--size-l: 4.236rem;
}
@custom-media --medium-viewport (min-width: 768px);
typography.css
Shared component β supposed to be extended by using css-module's compose
π
/* Get access to cssnext variables */
@import './base.css';
.small {
font-size: var(--size-s);
}
.large {
font-size: var(--size-l);
}
color.css
Shared component β supposed to be extended by using css-module's compose
π
/* Get access to cssnext variables */
@import './base.css';
.text {
color: var(--color-text);
}
global.css
This is where you can define some default styling for native html elements
@import './base.css';
body {
/* half-decent solution */
font-size: var(--size-s);
/* ideal solution */
composes: small from './typography.css';
}
h1 {
/* half-decent solution */
font-size: var(--size-l);
/* ideal solution */
composes: large from './typography.css';
}
p {
/* half-decent solution */
color: var(--color-text);
/* ideal solution */
composes: text from './color.css';
}
component.css
This is your component, the CSS here will be namespaced (what css-modules is for)
/* component title */
.title {
/* Here it works because this is not a HTML element selector */
composes: color from './color.css'
}
Although this solution is not perfect, using _cssnext_ allows me to still have my variables and custom media queries which can be used to style native HTML selector and used to extend my CSS modules.
I am happy to hear if anything else has found a nicer approach.
βοΈ
from css-modules.
@peduarte that comment is completely unacceptable. This is the CSS Modules issue tracker, a place for open, respectful discussion about an incredibly nascent project. You call us "selfish", attempt to impose your own "purpose" on the project, claim I'm only interested in gaining twitter followers & call the project "half-built". I won't tolerate self-righteous entitled vitriol on this issue tracker, not by you or anyone else.
Furthermore, you @-spammed myself & many knowledgable CSS people (none of whom are part of the CSS Modules team) on Twitter 3 times in order for someone to help. Yet you ignored @nkbt who has been active on this tracker and answered your question almost immediately. You went from "I can't find a solution" to "this project is selfish/half-built" in 3 hours!. 1am to 4am my local time.
I'm closing and locking this discussion as a result. This is an open source project, learn to be respectful and cooperate or go somewhere else.
p.s. The real pity is that the original question is surprising behaviour and does need explanation. So if someone would like to raise another issue around the same question I'll jump on and answer it.
from css-modules.
Related Issues (20)
- Compose class inside media query
- Late styles loading in Next 13 HOT 3
- 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
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.