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

Histoire Tailwind css should be in a layer #721

Open
6 tasks done
mikaelh94 opened this issue May 20, 2024 · 4 comments
Open
6 tasks done

Histoire Tailwind css should be in a layer #721

mikaelh94 opened this issue May 20, 2024 · 4 comments
Labels
to triage This issue needs to be triaged

Comments

@mikaelh94
Copy link

Describe the bug

I use PrimeVue for my components, with the PrimeVue default style and my custom css on top of it.

PrimeVue's default styles are in a layer:

/* Order */
@layer reset, primevue;

When running Histoire, there is some Histoire/TW styles that are not in a layer and they override PrimeVue default styles:
histoire-app/src/app/style/main.pcss

*,
::before,
::after {
  box-sizing: border-box;
  border-width: 0;
  border-style: solid;
  border-color: #e5e7eb;
}

...

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  body,
  pre {
    margin: 0;
  }

Since a css property defined without any layer will always have more specificity than a layered css property, those global styles should be in the @layer base no ?
Like found in this tw issue

Look at my StackBlitz, the TW default border (border-color: #e5e7eb;) override my BaseInput invalid border color.

Reproduction

https://stackblitz.com/edit/histoire-vue3-starter-gvitle?file=src%2FBaseButton.story.vue

System Info

System:
    OS: macOS 14.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 78.06 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.20.2 - ~/.nvm/versions/node/v18.20.2/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v18.20.2/bin/yarn
    npm: 10.5.0 - ~/.nvm/versions/node/v18.20.2/bin/npm
  Browsers:
    Chrome: 125.0.6422.60
    Safari: 17.3.1
  npmPackages:
    @histoire/plugin-vue: ^0.17.17 => 0.17.17
    @vitejs/plugin-vue: ^5.0.4 => 5.0.4
    histoire: ^0.17.17 => 0.17.17
    vite: ^5.2.11 => 5.2.11

Used Package Manager

yarn

Validations

@mikaelh94 mikaelh94 added the to triage This issue needs to be triaged label May 20, 2024
Copy link

stackblitz bot commented May 20, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@andreLuis1506
Copy link

andreLuis1506 commented Jun 7, 2024

I have the same problem. the css leaks into ours components. In my case borders not work

@leje512
Copy link

leje512 commented Aug 20, 2024

i think that's the same problem as in #339

@nikosgpet
Copy link

nikosgpet commented Oct 11, 2024

It is hacky, but a way to put the css of histoire in a separate layer, is to include the following code into histoire.setup.ts :

  document.head
    .querySelectorAll('style[type=\'text/css\'][data-vite-dev-id*=\'histoire\']')
    .forEach((style) => {
      style.setAttribute('data-layer', 'histoire')
      const content = style.textContent
      if (!content?.includes('@layer')) {
        style.textContent = `@layer histoire {${content}}`
      }
    })

This will create a histoire layer and add existing styles inside.

This was inspired by the solution of @qexk #339 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

4 participants