Skip to content

PWA-1841 & PWA-2302: Convert CSS to Tailwind#3686

Merged
anthoula merged 27 commits intodevelopfrom
brendan/PWA-1895-monarch
Mar 31, 2022
Merged

PWA-1841 & PWA-2302: Convert CSS to Tailwind#3686
anthoula merged 27 commits intodevelopfrom
brendan/PWA-1895-monarch

Conversation

@jimbo
Copy link
Contributor

@jimbo jimbo commented Feb 1, 2022

Description

Convert as many CSS rules to Tailwind (via composes) as possible.

Related Issue

Closes PWA-1841 & PWA-2302.

Acceptance

Verification Stakeholders

Specification

Verification Steps

Test scenario(s) for direct fix/feature

Full regression needed; some discrepancies are acceptable within reason.

Test scenario(s) for any existing impacted features/areas

Test scenario(s) for any Magento Backend Supported Configurations

--

Is Browser/Device testing needed?

Yes; all components are affected across all devices.

Any ad-hoc/edge case scenarios that need to be considered?

TBD.

Screenshots / Screen Captures (if appropriate)

Breaking Changes (if any)

Components TBD. All styles are changing.

Checklist

  • I have added tests to cover my changes, if necessary.
  • I have added translations for new strings, if necessary.
  • I have updated the documentation accordingly, if necessary.

@jimbo jimbo added the version: Major This changeset includes incompatible API changes and its release necessitates a Major version bump. label Feb 1, 2022
@pwa-studio-bot
Copy link
Collaborator

pwa-studio-bot commented Feb 1, 2022

Messages
📖

Associated JIRA tickets: PWA-1895.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next pr-test build run (assuming they are fixed).
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

Generated by 🚫 dangerJS against 0554955

@brendanfalkowski
Copy link
Contributor

@jimbo Heads up, Prettier broke all the arbitrary values in Tailwind that contain spaces. TW specifies these have to be written without spaces to work. Example:

checkoutPage.module.css

# Original
composes: lg_grid-cols-[2fr,1fr] from global;

# Prettier version, space added, TW won't generate the rule so it doesn't apply
composes: lg_grid-cols-[2fr, 1fr] from global;

Screen Shot 2022-02-03 at 12 11 51 PM

@jimbo jimbo force-pushed the brendan/PWA-1895-monarch branch from de05be7 to 38fbbc9 Compare February 3, 2022 22:02
@fooman
Copy link
Contributor

fooman commented Feb 13, 2022

Might an underscore work?

<div class="grid grid-cols-[1fr_500px_2fr]">
  <!-- ... -->
</div>

@brendanfalkowski
Copy link
Contributor

brendanfalkowski commented Feb 14, 2022

@fooman That should solve the conflict Prettier causes after we update to TW3. This build is still on TW2 because the work started before TW3 was released. It's probably why they changed from , to _ for a space-replacement character in arbitrary values.

Under TW2 using _ will generate the class, but the character isn't replaced, so the final CSS isn't valid.

Screen Shot 2022-02-14 at 9 22 24 AM

Temporarily, we'll have to wrap the broken declarations with prettier ignore comments so we don't lose track of the regressions, and revisit in the TW3 update.

Added a PR into this PR to patch this temporarily: #3704

@@ -1,10 +1,10 @@
{
"name": "@magento/pwa-theme-venia",
"name": "@magento/pwa-theme-base",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we hold off renaming the package until the next release? Technically, this is still the Venia theme.

@drpayyne
Copy link
Contributor

drpayyne commented Mar 7, 2022

What's the reason behind composing Tailwind classes from the global namespace instead of embedding them directly in HTML tags? From first glance, it looks like there's a lot of repetition so I'm curious as to what's the reason causing this to be less-important. Thanks.

line-height: 1;
pointer-events: auto;
text-align: center;
composes: items-center from global;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be sorted below inline-flex

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@brendanfalkowski
Copy link
Contributor

@drpayyne Using Tailwind inside CSS Modules isn't a perfect solution (it causes some specific issues), but it solves most of the problems this solution was architected for: support theming without changing JSX or requiring TW adoption for backward compatibility.

There is a lot of repetition when authoring, but it doesn't affect the build size so the benefits of Tailwind aren't lost. The classes written into JSX components are essentially a static API. Existing implementations aren't required to use Tailwind, and if all JSX changed we'd be forcing them to migrate all their custom CSS into TW as most CSS imports would be removed. Additionally, extensions can use the "targets" functionality on CSS without having affecting JSX, which reduces the long-term maintenance scope for implementations.

Copy link
Contributor

@jcalcaben jcalcaben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial issues I noticed while clicking through the storefront and comparing

@@ -24,14 +26,15 @@

.submenu_active {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently, the mega menu stays hidden even on hover in this PR

we should add a definition for the inactive state:

.submenu_inactive {
    composes: submenu;

    composes: hidden from global;
}

and make the necassary changes to submenu.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. This is a general change in pattern, too.

Currently, we often make one state the default and use composition to override properties for the remaining states; the loader inserts module rulesets in order, so later rulesets take precedence over earlier ones and everything works as expected.

With Tailwind, the order of rulesets is predetermined for the global stylesheet. When everything is composing from these global rules, ruleset order within a module makes no difference. This means we need an individual ruleset for each state; in this case, it was submenu_inactive.

.root:focus {
box-shadow: -6px 6px rgb(var(--venia-brand-color-1-100));
composes: disabled_border-gray-400 from global;
composes: disabled_pointer-events-none from global;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Button disabled state looks off with grey border and text on a blue background.

Shouldn't it be white border and text on a grey background?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

borderColor: theme => ({
button: theme('colors.gray.600'),
error: theme('colors.red.400'),
info: theme('colors.emerald.600'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

colors.emerald doesn't seem to work even though it's a default entry in the Tailwind Color Palette.

you can test this out by click on an Add to Favorites link and looking at the toast. It should have a green-ish border, but it is gray.

Weirdly enough, colors.green works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, they fixed this in Tailwind 3, which we aren't using yet. Fixed.

}

.controls {
composes: border from global;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be border-l

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

@jcalcaben jcalcaben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional feedback

}

.link {
composes: root from '../LinkButton/linkButton.module.css';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be refactored to remove the cross-component dependency.

This currently renders as a center justified list of blue links instead of the left justified list of grey items

Copy link
Contributor Author

@jimbo jimbo Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Also, I agree. We should get rid of all cross-component dependencies, since Tailwind handles deduplication for us now automatically. If we really need some shared CSS, we can write a Tailwind plugin.

}
.addButton {
composes: border-2 from global;
composes: border-solid from global;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be border-dashed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

.dropdown {
align-items: center;
composes: absolute from global;
composes: bg-xxx from global;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a valid value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Removed this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to mention this entry is also missing composes: bg-white from global;
Right now it's rendering a clear background.

button: '20',
buttonHover: '21',
buttonFocus: '22',
dropdown: '50',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may need to split this into headerDropDown and contentDropDown.

currently, this is being used in the dropdown module in the Legacy Mini Cart and it is causing the modal to render on top of the header when you scroll down

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Let me know if you spot any issues as a result of my change here—seems good to me.

@jimbo jimbo dismissed jcalcaben’s stale review March 22, 2022 20:34

James is out, but changes approved

@pwa-test-bot
Copy link

pwa-test-bot bot commented Mar 29, 2022

Successfully started codebuild job for cypress

@devpatil7
Copy link
Contributor

run cypress

@pwa-test-bot
Copy link

pwa-test-bot bot commented Mar 30, 2022

Successfully started codebuild job for cypress

@devpatil7
Copy link
Contributor

run cypress

@pwa-test-bot
Copy link

pwa-test-bot bot commented Mar 30, 2022

Successfully started codebuild job for cypress

@devpatil7
Copy link
Contributor

run cypress

@pwa-test-bot
Copy link

pwa-test-bot bot commented Mar 31, 2022

Successfully started codebuild job for cypress

@devpatil7
Copy link
Contributor

run cypress

@pwa-test-bot
Copy link

pwa-test-bot bot commented Mar 31, 2022

Successfully started codebuild job for cypress

@devpatil7
Copy link
Contributor

run lighthouse-desktop

@pwa-test-bot
Copy link

pwa-test-bot bot commented Mar 31, 2022

Successfully started codebuild job for lighthouse-desktop

@devpatil7
Copy link
Contributor

run lighthouse-mobile

@pwa-test-bot
Copy link

pwa-test-bot bot commented Mar 31, 2022

Successfully started codebuild job for lighthouse-mobile

@devpatil7
Copy link
Contributor

run lighthouse-mobile

@pwa-test-bot
Copy link

pwa-test-bot bot commented Mar 31, 2022

Successfully started codebuild job for lighthouse-mobile

@devpatil7
Copy link
Contributor

run lighthouse-mobile

@pwa-test-bot
Copy link

pwa-test-bot bot commented Mar 31, 2022

Successfully started codebuild job for lighthouse-mobile

@devpatil7
Copy link
Contributor

QA Approved.

Copy link
Contributor

@anthoula anthoula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review LGTM ⭐

@brendanfalkowski
Copy link
Contributor

🎉🎉🎉

@slide13
Copy link

slide13 commented May 19, 2022

@jimbo @jcalcaben I apologize for writing in a closed pr, but tell me, why do we use composes from the global space to write css through css modules with tailwind, except for writing styles through the apply utility? in this case, we lose autocomplete, and incorrect classes are ignored and simply not applied without errors.
As an example, why not instead of this:

    composes: appearance-none from global;
    composes: border-2 from global;
    composes: border-solid from global;
    composes: flex-textInput from global;
    composes: h-[2.5rem] from global;
    composes: inline-flex from global;
    composes: m-0 from global;
    composes: max-w-full from global;
    composes: rounded-md from global;
    composes: text-colorDefault from global;
    composes: w-full from global;

use this:

@apply appearance-none
    border-2
    border-solid
    flex-textInput
    h-[2.5rem]
    inline-flex
    m-0
    max-w-full
    rounded-md
    text-colorDefault
    w-full

@devpatil7 devpatil7 deleted the brendan/PWA-1895-monarch branch February 8, 2023 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:pwa-theme-venia pkg:venia-concept pkg:venia-ui Progress: done version: Major This changeset includes incompatible API changes and its release necessitates a Major version bump.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants