Skip to content
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

Pseudo classes don't apply styles #99

Open
dominickbrasileiro opened this issue Dec 19, 2023 · 7 comments
Open

Pseudo classes don't apply styles #99

dominickbrasileiro opened this issue Dec 19, 2023 · 7 comments

Comments

@dominickbrasileiro
Copy link

dominickbrasileiro commented Dec 19, 2023

Hi there,

I'm trying to use the pseudo-states in a Next.js + Tailwind CSS project, but I can't make them work.

I have installed the add-on correctly in .storybook/main.js, and the menu appears in the local storybook.

This is a test story that I'm using to debug:

const Hover = () => <span className="text-white bg-blue-core hover:bg-red-core">Hover Test</span>
Hover.parameters = {
  pseudo: { hover: true },
}

Am I missing something here?

The pseudo-hover-all class is being applied to my root component #storybook-root, but it has no effect on the preview.

Screenshot 2023-12-18 at 9 06 04 PM

Screenshot 2023-12-18 at 9 04 34 PM

Versions

@storybook/nextjs: 7.5.1
@storybook/react: 7.5.1
storybook-addon-pseudo-states: 2.1.2

@jhancock532
Copy link

Hmm, I've noticed errors / warnings in my console when using this library that too many hover CSS rules were detected and that the addon would only be able to support a subset of them. It might be worth checking if you have a similar warning in the console as Tailwind could be exporting a lot.

If the library is working as expected, it should generate a CSS rule along the lines of .pseudo-hover-all .hover:bg-red-core { background: red; }. You could check to see if this style rule appears in DevTools and if any other style rule is overriding it.

@dominickbrasileiro
Copy link
Author

@jhancock532 thank you, my friend!
i see this warning in my console:

Reached maximum of 1000 pseudo selectors per sheet, skipping the rest.

a pseudo-hover class is injected into the component classes, but no styles are applied.
there aren't any styles overwriting it, and the rules don't appear in DevTools, so I'm guessing that is the problem.

have you worked around it, by any chance?

@surecloud-tstafford
Copy link

+1 for seeing this issue after upgrading to latest storybook (7)

@dominickbrasileiro
Copy link
Author

i haven't found any solution yet :/

@surecloud-tstafford
Copy link

surecloud-tstafford commented Jan 16, 2024

Us neither. We have an Angular project where this was working on version 6 then broken after the upgrade to latest 7.

Considering re-writing our scss with pseudo mixins so I can just apply them manually as standalone classes until this is resolved.

@jhancock532
Copy link

@dominickbrasileiro A workaround I considered was to add the missing styles to the webpage on page load. Unfortunately I've not implemented a complete solution yet as it's quite low priority / odd solution, but I made a draft of what should happen on CodePen: https://codepen.io/jhancock532/pen/qBJJOWE

  1. Fetch all the style rules used in the current webpage
  2. Identify the style rules that use psuedo-selectors and apply to the current component
  3. Duplicate these style rules, prefixing the .psuedo-classes class before them, and add them to the page

The above script would be added at the end of .storybook/preview.js - note that this is definitely a workaround as it ignores the existing addon logic and bypasses Storybook's conventional addon integration methods.

@oluoluoxenfree
Copy link

oluoluoxenfree commented Feb 1, 2024

@jhancock532 thank you, my friend! i see this warning in my console:

Reached maximum of 1000 pseudo selectors per sheet, skipping the rest.

a pseudo-hover class is injected into the component classes, but no styles are applied. there aren't any styles overwriting it, and the rules don't appear in DevTools, so I'm guessing that is the problem.

have you worked around it, by any chance?

This line is part of an if statement in the code with a break directly after; locally, if i remove the if/console/break block it works (there are console errors, but the pseudo states can be applied).

https://github.com/chromaui/storybook-addon-pseudo-states/blob/main/src/preview/rewriteStyleSheet.ts#L88-L90

What's the reason for the limit of a thousand, is it a performance issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants