-
Notifications
You must be signed in to change notification settings - Fork 4
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
Enable Tailwind utility and component classes #675
Conversation
This pull request has been linked to Shortcut Story #141242: Enable Tailwind utility classes. |
Codecov Report
@@ Coverage Diff @@
## main #675 +/- ##
=======================================
Coverage 90.62% 90.62%
=======================================
Files 23 23
Lines 384 384
Branches 96 96
=======================================
Hits 348 348
Misses 36 36 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size-limit report
Path | Size |
---|---|
components | 56.05 KB (0%) |
styles | 244.2 KB (+98.4% 🔺) |
🤔 addition of TW utility classes def does increase the size |
oof yeah 😬 also that math is weird to me lol, looks like the current size of 2 thoughts:
|
packages/components/README.md
Outdated
<div class="hidden md:block lg:inline"> | ||
``` | ||
- Where the expectation is `display: none ` for breakpoints smaller than 768px, `display: block `for 768px - 1023px, and `display: inline ` for >= 1024px. However since Bootstrap applies the `!important` property, all screen sizes show `display: none`. | ||
- This can be circumvented with the `@apply` directive or using custom CSS with regular media queries to scope styling into a different class name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's provide an example to make it easiest to understand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size-limit report
Path | Size |
---|---|
components | 56.05 KB (0%) |
styles | 4.16 KB (+6.06% 🔺) |
Ok with the purging, the size drops a lot, is 4.16kb reasonable? @anniehu4 |
SWEET, yeah that's super reasonable 🙌 I'm fine with adding JIT mode here or in a separate PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size-limit report
Path | Size |
---|---|
components | 56.05 KB (0%) |
styles | 4.03 KB (+2.94% 🔺) |
Test pr: #678 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so excited!! 1 last small comment & suggestions for the README but overall looks great
* This injects Tailwind's component classes and any component classes | ||
* registered by plugins. | ||
*/ | ||
@tailwind components; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My read of https://tailwindcss.com/docs/extracting-components#extracting-component-classes-with-apply is that this is where the @apply
-ed stuff goes.
But I thought we were already getting those in the compiled css? 🤔
Is it possible we're now duplicating anything from @apply
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Jin noted that the components.css
class contains really few things: https://unpkg.com/[email protected]/dist/components.css. My read of that section was that you can use @layer
to control specificity, but it doesn't overlap with the content of @tailwind components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if the component classes are not being used, they should be purged out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you're right. Looks like @apply
stuff gets inlined right into the .module.css file, not put in components
.
* This injects Tailwind's utility classes and any utility classes registered | ||
* by plugins. | ||
*/ | ||
@tailwind utilities; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hadn't thought of this until now, but another option is to allow utility classes in stories, but only use @apply
in component styles. (And definitely allow utility classes in apps)
Then there's no chance for conflicts and no unfortunate increase in size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or put another way:
I think the value in utility classes is in storybook stories and in an app. So we don't necessarily need to actually use them in the design system components if we don't want to.
(If we do want to then that's fine too)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense to me! It's essentially what we're doing already (since global.css
is only used in the storybook file), but we could be more explicit by only purge
-ing story files. I'm less worried about the size since according to Tailwind,
When removing unused styles with Tailwind, it’s very hard to end up with more than 10kb of compressed CSS
there is an argument that it's easier to just follow the standard convention though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separated components
and utilities
as suggested into tailwindUtilities.css
which is imported into .storybook/preview.tsx
for storybook use in eds
Let me know if that's not proper naming conventions
* This injects Tailwind's utility classes and any utility classes registered | ||
* by plugins. | ||
*/ | ||
@tailwind utilities; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to put the @tailwind
stuff in another file. Something like src/styles/tailwind.css
.
That way an App already using Tailwind (like Traject is/will?) can use it's own Tailwind stuff instead of importing 2 of them (one from here and one from the app), by only importing src/styles/tailwind.css
if it's not already doing so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can certainly rename this file. It currently only contains tailwind
stuff, and it's actually not even imported in traject
because there were issues with including all of the base styles (traject defines its own tailwind.base.css
instead)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay. I assumed there was other stuff going on in it, but it makes sense that there's not.
Naming it tailwind.css
sometime might make it more clear when to (and not to) include it in an app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size-limit report
Path | Size |
---|---|
components | 56.05 KB (0%) |
styles | 4.13 KB (+5.26% 🔺) |
Co-authored-by: Annie Hu <[email protected]>
@@ -1,6 +1,8 @@ | |||
const variableTokens = require("@chanzuckerberg/eds-tokens/lib/json/css-variables-nested.json"); | |||
const staticTokens = require("@chanzuckerberg/eds-tokens/lib/json/variables-nested.json"); | |||
module.exports = { | |||
mode: "jit", | |||
purge: ["./src/**/*.{js,jsx,ts,tsx}"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we only want to use the classes in stories for this repo, and we expect other apps to configure their own purge
templates (which is reasonable), we could make this
purge: ["./src/**/*.{js,jsx,ts,tsx}"], | |
purge: ["./src/**/*.stories.{js,jsx,ts,tsx}"], |
to enforce that more
and we could add a comment here about the rationale, e.g. "The main value in utility classes for EDS is in storybook stories. We avoid using them in component styles so there's no chance for conflicts with other libraries."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed and added comment above line and in readme
@@ -1,6 +1,7 @@ | |||
import "@chanzuckerberg/eds-tokens/lib/css/variables.css"; | |||
import "../src/styles/fonts.css"; | |||
import "../src/styles/global.css"; | |||
import "../src/styles/tailwindUtilities.css"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it'd be nice to mirror the naming convention in traject?
global.css
->tailwind-base.css
(I think we should rename this in traject, will leave a comment in the other PR)tailwindUtilities.css
->tailwind-utilities.css
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 This makes sense to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed as suggested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size-limit report
Path | Size |
---|---|
components | 56.05 KB (0%) |
styles | 4.1 KB (+4.65% 🔺) |
* feat(tailwind): enable utility classes and add tw- prefix * feat(tailwind): introduces script to add tw- prefix in css files * feat(tailwind): process components css to add tw- prefixes * revert prefixing script and prefixes * revert tw- prefix for tailwind utility classes * feat(tailwind): enable tailwind component classes * docs(tailwind): describe tailwind class usage * docs(tailwind): revise tailwind utility class usage * feat(tailwind): enable tailwind purge * feat(tailwind): enable tailwind jit mode * feat(tailwind): broaden TW purge scope to incl js jsx ts * feat(tailwind): move import tailwind utilities for storybook only * chore(tailwind): move properties to top f tailwind config object * docs(tailwind): update tw custom class with example * docs(tailwind): update tw conflict description Co-authored-by: Annie Hu <[email protected]> * docs(tailwind): udpate tw example * fix(tailwind): specify tailwind purge and add related doc Co-authored-by: Annie Hu <[email protected]>
Summary:
Decided to go with path 3. of living with the occasional conflict since there shouldn't be many.
My approach to dealing with conflicts is to use the
@apply
directive or custom styling to scope styling into a different class name.Examples and details are given in the components readme (./packages/components/README.md)
Test Plan:
CI tests, especially visual regression tests pass