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

Use tailwind instead of gt-[wh]- helper classes #29423

Merged
merged 5 commits into from
Feb 27, 2024

Conversation

lunny
Copy link
Member

@lunny lunny commented Feb 26, 2024

Follow #29357

  • Replace gt-w-* -> tw-w-* and remove gt-w-*
  • Replace gt-h-* -> tw-h-* and remove gt-h-*

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 26, 2024
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 26, 2024
@github-actions github-actions bot added the modifies/templates This PR modifies the template files label Feb 26, 2024
@silverwind
Copy link
Member

Remove gt-w-full from helpers.css if there are no more occurences. We can do more such migrations in one PR, does not have to be 1 property per PR.

@delvh
Copy link
Member

delvh commented Feb 26, 2024

I agree with removing the helper class, but I disagree with more than one property per PR.
From my previous experience, the smaller and easier a PR can be reviewed, the faster it will be merged, as we've seen with the jQuery removal.

@silverwind
Copy link
Member

I agree with removing the helper class, but I disagree with more than one property per PR. From my previous experience, the smaller and easier a PR can be reviewed, the faster it will be merged, as we've seen with the jQuery removal.

Fine with me in any case.

@wxiaoguang
Copy link
Contributor

I agree with removing the helper class, but I disagree with more than one property per PR.

Similar classes could be done in the same PR. eg: gt-w-* / gt-h-* to tw-w-* / tw-h-*

@github-actions github-actions bot added modifies/frontend and removed modifies/templates This PR modifies the template files labels Feb 26, 2024
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 26, 2024
@wxiaoguang
Copy link
Contributor

One more question, do the tw- classes have "!important"? Otherwise it can't replace gt- directly.

@lunny lunny marked this pull request as ready for review February 26, 2024 12:42
@lunny
Copy link
Member Author

lunny commented Feb 26, 2024

I agree with removing the helper class, but I disagree with more than one property per PR. From my previous experience, the smaller and easier a PR can be reviewed, the faster it will be merged, as we've seen with the jQuery removal.

I did some of them because the previous changes are too small. I think it's still small enough to be reviewed.

Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

#29423 (comment)

Without !important, tw-* might not work in some cases.

@lunny
Copy link
Member Author

lunny commented Feb 26, 2024

One more question, do the tw- classes have "!important"? Otherwise it can't replace gt- directly.

I don't think these tw- classes have "!important", but at my previous checks, they works well.

@delvh
Copy link
Member

delvh commented Feb 26, 2024

@silverwind
Copy link
Member

silverwind commented Feb 26, 2024

No, tailwind classes like tw-w-full have no !important. I think it can be achieved per-class via ! prefix, e.g. !tw-w-full. Would not recommend setting this important config option, but instead do it case-per-case.

@delvh
Copy link
Member

delvh commented Feb 26, 2024

The config option is intended exactly for our usecase:
Introducing tailwind to an existing system.

@silverwind
Copy link
Member

So yes, this ! prefix would be a topic to look out for for the migration. We could go the lazy route and migrate the gt- prefixes to !tw- or we check case-by-case basis whether important was necessary.

@silverwind
Copy link
Member

silverwind commented Feb 26, 2024

The config option is intended exactly for our usecase: Introducing tailwind to an existing system.

Yes, it's equivalent to adding the ! on all classes, but the class prefix gives the option to later remove it on a per-case basis.

Long-term I think removing unnecessary !important would be better, so I would recommend we migrate gt- to !tw- now, ideally dropping all ! that are not needed, but I see that as optional during migration.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Feb 26, 2024

Then it needs to test every change carefully. To see whether it needs !important.

Otherwise, gt- can't be replaced by tw- directly, because some !important is used to "fine tune" the existing styles.

So what do you think about these possible approaches?

  1. 👍 Test every change when replacing gt- to tw-, only use ! when necessary
    • There are a lot, for example, gt-df / gt-p-* / gt-m-* is everywhere, including some pages which are not easily seen.
  2. 🚀 Replace all gt- to !tw-
  3. 🎉 Add !important to all tw-

@silverwind
Copy link
Member

silverwind commented Feb 26, 2024

👍 and 🚀 are both acceptable for me. 🎉 would be too limiting long-term.

Assuming @lunny has tested the cases here, this PR would be an example of an ideal 👍 where all !important are removed.

@silverwind silverwind self-requested a review February 26, 2024 14:24
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Feb 26, 2024

Sorry but it is not really fully tested. At least, I can see:

class="page-content ui container center tw-w-screen 

.page-content .ui.ui.ui.container:not(.fluid) {
  width: 1280px;
  max-width: calc(100% - 64px);
  margin-left: auto;
  margin-right: auto;
}

@wxiaoguang
Copy link
Contributor

Assuming @lunny has tested the cases here, this PR would be an example of an ideal 👍 where all !important are removed.

If we would like to avoid regression, then we can't assume anything.

If we would like to tolerate some regressions, then maybe the rule could be relaxed.

@silverwind
Copy link
Member

If we would like to avoid regression, then we can't assume anything.

Yes, that' why I redacted my review actually 😆.

@silverwind
Copy link
Member

silverwind commented Feb 26, 2024

I wonder thought: Is there ever any case where !important actually matters for tailwind styles? I can't think of any case where tailwind CSS should not override non-tailwind CSS because in such a scenario, one would instead remove the tailwind class.

I'm starting leaning towards option 3 actually, the only downside is that the CSS would end up a few bytes bigger because of all these !important strings, but it will compress well.

@wxiaoguang
Copy link
Contributor

I'm starting leaning towards option 3 actually, the only downside is that the CSS would end up a few bytes bigger because of all these !important strings, but it will compress well.

That's also my first preference. But I guess few people would agree with it if I said so 😁 so I spent some more time on "finding bugs".

@silverwind
Copy link
Member

silverwind commented Feb 26, 2024

I think the only case where !important would actually matter is if a tailwind class maps to multiple CSS properties and you want one of them !important and the other not.

But I think such cases are rare enough that one can always write custom CSS and I think we likely won't even encounter them because as far as I understand, 99% of tailwind classes map to exactly 1 CSS property. Any classes that map to more than 1 property are breaking the concept of "atomic CSS" and should be avoided anways.

Copy link
Member

@delvh delvh left a comment

Choose a reason for hiding this comment

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

LGTM apart from the pending rewrite to the chosen important mechanism

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 26, 2024
@silverwind
Copy link
Member

I strongly believe 🎉 is the way to go now. Developers should not have to worry about CSS precedence when using a atomic CSS framework like tailwind.

@zokkis
Copy link
Contributor

zokkis commented Feb 26, 2024

The title should be "Use tw-w-* instead of gt-w-" or something like "Use tailwind for width instead of gt-w-"

@delvh delvh changed the title Use tw-w-full instead of gt-w-full Use tw-[wh]-.* instead of gt-[wh]-.* Feb 26, 2024
@delvh delvh changed the title Use tw-[wh]-.* instead of gt-[wh]-.* Use tailwind instead of gt-[wh]- helper classes Feb 26, 2024
@silverwind
Copy link
Member

I strongly believe 🎉 is the way to go now. Developers should not have to worry about CSS precedence when using a atomic CSS framework like tailwind.

#29437 for this.

lunny pushed a commit that referenced this pull request Feb 27, 2024
As per discussion in #29423, I
think this is the right way that does not burden developers having to
think about CSS precedence which should be irrelevant with an atomic CSS
framework.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Feb 27, 2024

After #29437 , I think it is safe to use tw- to replace gt- directly now.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 27, 2024
@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 27, 2024
@silverwind silverwind enabled auto-merge (squash) February 27, 2024 14:06
@silverwind silverwind merged commit 9a8c90e into go-gitea:main Feb 27, 2024
26 checks passed
@GiteaBot GiteaBot added this to the 1.22.0 milestone Feb 27, 2024
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 27, 2024
@lunny lunny deleted the lunny/use_tw_instead_gt branch February 27, 2024 14:41
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 29, 2024
* giteaofficial/main: (23 commits)
  Fix wrong test usage of `AppSubURL` (go-gitea#29459)
  Improve contrast on blame timestamp, fix double border (go-gitea#29482)
  Fix/Improve `processWindowErrorEvent` (go-gitea#29407)
  Apply compact padding to small buttons with svg icons (go-gitea#29471)
  Fix counter display number incorrectly displayed on the page (go-gitea#29448)
  Fix incorrect user location link on profile page (go-gitea#29474)
  Fix workflow trigger event bugs (go-gitea#29467)
  Fix URL calculation in clone input box (go-gitea#29470)
  Remove jQuery from the "find file" page (go-gitea#29456)
  Move generate from module to service (go-gitea#29465)
  The job should always run when `if` is `always()` (go-gitea#29464)
  Recolor dark theme to blue shade (go-gitea#29283)
  Let ctx.FormOptionalBool() return optional.Option[bool] (go-gitea#29461)
  Implement actions badge svgs (go-gitea#28102)
  Fix missed return (go-gitea#29450)
  Use tailwind instead of `gt-[wh]-` helper classes (go-gitea#29423)
  Lock issues and pulls faster (go-gitea#29436)
  Allow to change primary email before account activation (go-gitea#29412)
  Update docs about `DEFAULT_ACTIONS_URL` (go-gitea#29442)
  Only use supported sort order for "explore/users" page (go-gitea#29430)
  ...
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants