-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write a postcss plugin that'd make this compatible with CSS modules #70
Comments
I want to elaborate on how this is integrates into a project. Just so that we are all on the same page. Lets start with a typical CSS module setup. I have my styles, e.g. .nose {
color: red;
}
.sky {
color: blue;
} I consume these styles using a really awesome plugin babel-plugin-react-css-modules, e.g. import React from 'react';
import './styles.css';
export default () => {
return <div styleName='sky'>
<div styleName='nose'></div>
</div>;
}; Two things happen when this project is built:
<style>
.nose_demo_j4jf {
color: red;
}
.sky_demo_14dg {
color: blue;
}
</style>
<div class='sky_demo_14dg'>
<div class='nose_demo_j4jf'></div>
</div
Now, I want my "nose" to change color depending on the size of they "sky". I can do this using EQCSS. @element ".sky" and (min-width: 300px) {
.nose {
color: purple;
}
} For this to work, we need a postcss plugin that'd render the following CSS output: .nose_demo_j4jf {
color: red;
}
.sky_demo_14dg {
color: blue;
}
@element ".sky_demo_14dg" and (min-width: 300px) {
.nose_demo_j4jf {
color: purple;
}
} This way EQCSS is able to recognize the target element. |
@tomhodgins made a good suggestion that left my mind. As a compromise, in context of React applications at least, you can write CSS inside a component. Using import styles from './styles.scss';
const eqcss = `
@element ".${styles.sky}" and (min-width: 300px) {
.${styles.nose} {
color: purple;
}
}
`;
export default () => {
return <div>
<style>{eqcss}</style>
<div styleName='sky'>
<div styleName='nose'></div>
</div>
</div>;
}; This still requires you to write CSS separately from the main stylesheets (assuming you are maintaining CSS in a separate file in the first place and not using something like |
Why can't this be a separate project? There is a new cool technology in JS land every 6 months that supposedly will take over the world. This project is a shim for future browser functionality. Yes I know that CSS modules is also, but the way most React projects do it is well beyond that. Sorry to be gruff but I was forced to work with CSS Modules on a project and I had to work around it constantly (no I'm not against CSS modules, just the religious application). |
This is a huge problem for me. I can't use this library without being able to use it on v-dom elements. :/ |
@kennymalac Do you have any code samples for what you're trying to do? The way EQCSS works is by looking through the DOM for any element(s) matching the supplied It should be able to handle new HTML dynamically being added to the DOM just fine, but you'll need to add those elements to the DOM before EQCSS becomes 'aware' of them and has a chance to find, measure, test, and apply the styles. If you're not married to EQCSS, this is one of ~thirty plugins I have for extending CSS - there's a big chance rather than trying to wrangle with EQCSS (by far the largest of them) there might be a smaller plugin that suits what you're trying to do that's easier to integrate into your toolchain or workflow, but I'd need to see what you're trying to do, hear an explanation of what you want, and to understand the elements, events, and styles you're working with :D |
Unfortunately I can't really provide code samples as this code is
proprietary. However, I haven't really seen this use case for any other
project so it seems unique to this problem.
I have height as a static prop on a widget (synced from a redux store to a
table describing each widget). The height is a static prop that is
resizable but I want to add an offset to the display height based on the
size of the user's screen size (so they can resize the widget and have it
look consistent for all variants that are applied at each
max-width/max-height combo). So I decided to write code that simulates the
content at the largest size, but media queries can only be simulated by
changing the entire viewport size, which would look janky and be bad UX.
Problem with adding an offset based on screen size is the media query css
is impossible to simulate. All this gets server side generated (WYSIWG Is
in react, the site is generated from a template).
It's a horrible problem to have, so I tried to do element queries and base
the content resizing on that; I tried react-bounds and some others for
applying a class on resize but they are missing various things so I'm
writing something that wraps react-measure and does the content resize by
applying a parent class alongside the width simulation (that way height is
saved to store as the height at a specific width). My code is buggy but
it's close to working, but I will have to duplicate the effort for the
server side generated code - lol?
EQCSS was giving me null for the styles array, I'm assuming this is because
of rerendering happening on react and the elements losing the data-* props?
I think it may impact performance to have global listening on the DOM for
element queries anyway but I could be wrong - I'm doing bounds checking in
a similar way, but the diffing on the dimensions is stored locally on the
wrapper... but it sucks to have to do that in JS rather than CSS.
|
A large portion of user base is excluded because there is no integration with CSS modules.
The actual plugin is not complicated. All it needs to do is:
@element ".myDiv" and (min-width: 300px) {
@element ".generatedClassName" and (min-width: 300px) {
This issue has been raised with postcss team (css-modules/css-modules#169). However, no one has picked it up since. Presumably, because there is lack of overlapping userbase between the two communities.
The text was updated successfully, but these errors were encountered: