-
Notifications
You must be signed in to change notification settings - Fork 2
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
[#69] Tailwind 4 upgrade #81
Conversation
TW 4 changed the default border color to `currentColor` instead of gray-200 This change adds back gray-200 where it wasn't specified.
}, | ||
// Animation Keyframes | ||
'@keyframes dialog-in': { | ||
'0%': { transform: 'translateY(2rem)', opacity: '0' }, | ||
'100%': { transform: 'translateY(0px)', opacity: '1' }, | ||
}, | ||
'@keyframes dialog-out': { | ||
'0%': { transform: 'scale(1)', opacity: '1' }, | ||
'100%': { transform: 'scale(0.9)', opacity: '0' }, | ||
}, | ||
'@keyframes dialog-backdrop-in': { | ||
'0%': { opacity: '0' }, | ||
'100%': { opacity: '1' }, | ||
}, | ||
'@keyframes dialog-backdrop-out': { | ||
'0%': { opacity: '1' }, | ||
'100%': { opacity: '0' }, |
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.
These keyframes weren't ending up in the final CSS and I was also getting some Typescript errors.
I don't think nesting keyframes within a class is technically valid. Seems like TW4 must be a bit more strict.
The issue was resolved by moving them outside of .dialog
and making the opacity values strings.
'&[data-required] label .field-label': { | ||
'&::after': { | ||
'@apply content-["*"] text-red-600 align-super text-xs ml-2 font-medium': | ||
{}, | ||
}, | ||
'.dark &::after': { | ||
'@apply text-red-300': {}, | ||
}, |
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.
Nesting dark:text-red-300
inside of the ::after
selector was throwing the above error.
TW 4 docs recommend this setting to restore the TW 3 "selector" strategy for dark mode.
@custom-variant dark (&:where(.dark, .dark *));
However, I don't think TW3 used :where().
where()
seems to confuse TW's compiler when it's nested inside of ::after
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
'@tailwindcss/postcss': {}, |
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 could have opted for TW's vite plugin, but for now I kept things the way they were.
https://tailwindcss.com/docs/installation/using-vite
Wasn't sure if it would bypass all the other postcss features we use.
@@ -65,7 +65,7 @@ | |||
size: 'sm', | |||
title: 'Close', | |||
variant: 'subtle', | |||
class: 'absolute right-4 top-4 size-24 !min-h-0 [&_svg]:size-12', | |||
class: 'absolute right-4 top-4 size-24 min-h-0! [&_svg]:size-12', |
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.
Looks like !
for important moved to the end of the class in TW 4.
The TW4 upgrade guide makes no mention of important.
TW 3 Docs
https://v3.tailwindcss.com/docs/configuration#important-modifier
TW 4 Docs
https://tailwindcss.com/docs/styling-with-utility-classes#using-the-important-modifier
@@ -33,7 +33,7 @@ | |||
{% tag el with attrs|merge({ | |||
href: href, | |||
type: clickable and el == 'button' ? 'button' : null, | |||
class: classNames('inline-flex items-center justify-center gap-4 rounded-sm text-center font-medium focus:outline-none focus-visible:ring-4', { | |||
class: classNames('inline-flex items-center justify-center gap-4 rounded-xs text-center font-medium focus:outline-hidden focus-visible:ring-4', { |
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.
TW-4 renamed a few utilities to make them more consistent. The automated migration handled most of them.
@@ -15,7 +15,7 @@ | |||
|
|||
<header class="{{ cx( | |||
'border-b border-neutral-200 bg-neutral-100', | |||
'mdd:sticky mdd:top-0 mdd:z-50 mdd:bg-white mdd:shadow-md', | |||
'max-md:sticky max-md:top-0 max-md:z-50 max-md:bg-white max-md:shadow-md', |
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 had added some custom screens config to create max
media queries.
But this is now part of TW 4 (or might have been since 3 actually)
Overview
Upgrades Tailwind to v4.
Really wasn't that bad, the
npx @tailwindcss/upgrade@next
command worked well.Here are the manual changes I made (more details in code comments).
.border
class, TW usescurrentColor
instead of the default gray-200. I manually addedborder-gray-200
back to all instances ofborder
that lacked a color class.app.css
fortunately we didn't have a lot of unique changes other than our custom sizes and using the selector mode for our dark theme.max-
media queries.dark:xyz
variants within a ::after selector.@keyframes
in the dialog component.JavaScript components / utilities.
Making components and utilities in JavaScript files seems to be "second class" to just writing them in CSS files. I couldn't even find details in the docs.
They still can be imported in the CSS-based Tailwind Config.
I'm curious if we should migrate these to CSS files since that seems to be the way TW is hidden. We do lose intellisense when we stop using the JS-based components. But I find that a very minor annoyance.
<button>
tags use the default cursorI noticed this minor change in TW 4's upgrade guide.
https://tailwindcss.com/docs/upgrade-guide#buttons-use-the-default-cursor
Our button components manually have cursors applied. But I'm curious if this a default we want to restore.
Other notes & unanswered questions
PostCSS, Vite Plugin, etc
cssnano
needed?postcss-pxtorem
Production build contains all color custom properties.
Should we use
dark
as our "Reversed" style? What if we ever have a site that has a dark mode... but also needs a "reversed" section?resolveConfig went away. This is how we would import a JSON-ified version of TW into PHP. The Craft 5 starter doesn’t do this anymore, but it’ll need to be figured out for existing upgrades.
JavaScript plugins are considered “legacy”? How should we write things like button.js?
Starting Style is rad!
Looks like ! for important moved to the end of the class in TW 4.
v3.tailwindcss.com/docs/configuration#important-modifier
tailwindcss.com/docs/styling-with-utility-classes#using-the-important-modifier