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

Buttons in stories use serif fonts when using tailwind CSS #289

Closed
hrvelic opened this issue Apr 21, 2023 · 5 comments · Fixed by #368
Closed

Buttons in stories use serif fonts when using tailwind CSS #289

hrvelic opened this issue Apr 21, 2023 · 5 comments · Fixed by #368
Assignees
Labels
bug Something isn't working

Comments

@hrvelic
Copy link

hrvelic commented Apr 21, 2023

OS: macOS Monterey 12.6.5
Elixir: 1.14.3-otp-25
Phoenix: 1.7.1
LiveView: 0.18.18
Tailwind: 3.3.1
Phoenix Storybook: 0.5.2
Browsers tested: Brave (Chrome), Firefox

Steps to reproduce:

  1. Create a Phoenix project.
  2. Add Phoenix Storybook to the project.
  3. Run phoenix and go to core component button stories generated by storybook by default. All buttons will show serif fonts.

Setting fonts in CSS files using utilities layer will not change anything.

Current workaround is to always create a container for stories with buttons with "font-sans" class on it, but this is both tedious and error-prone.

@stuartc
Copy link

stuartc commented Apr 26, 2023

I've just run into this myself, it looks like the .lsb-sandbox class overrides the html selector that Tailwind uses to set the default font.

I've worked around it by putting the following in storybook.css:

.lsb-sandbox {
  font-family: inherit !important;
}

As an aside, this happens in both the regular and iframe container strategies.

@cblavier cblavier self-assigned this Oct 10, 2023
@cblavier
Copy link
Contributor

Hey there, sorry for the late answer.
I'm working again on the storybook for a few weeks, so I can now help :)

I was able to reproduce the issue and I think the missing part is the important setting in tailwind.config.js
It should be set to a value matching the sandbox_class parameter in storybook.ex file.

I will amend the documentation and fix the generators.

@cblavier cblavier added the bug Something isn't working label Oct 11, 2023
@cblavier cblavier linked a pull request Oct 11, 2023 that will close this issue
@pochampagne
Copy link

Hey @cblavier

I have the exact same problem but I did set the important setting in tailwind.config.js, matching the sandbox_class parameter in my storybook.ex

Any idea, what could cause that ?

@pochampagne
Copy link

Hey @cblavier

I have the exact same problem but I did set the important setting in tailwind.config.js, matching the sandbox_class parameter in my storybook.ex

Any idea, what could cause that ?

I finally make it use my own font by adding this css in storybook.css

.lsb-sandbox {
  font-family: inherit !important;
  -webkit-font-smoothing: auto !important;
}

@cblavier
Copy link
Contributor

cblavier commented Nov 6, 2023

The idea is that anything rendered by the storybook is sandboxed, and won't be polluted by any styles defined by the storybook library itself.

The fact that your components render with a serif font is due to the fact that sandbox is working well, and CSS in the sandbox is properly reset

Feel free to have a look at the demo repository to get an example: https://github.com/phenixdigital/phoenix_storybook_demo/blob/main/assets/css/app.css

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants