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

[5.x] Reverse spaces in RTL #10184

Merged
merged 2 commits into from
Jul 12, 2024
Merged

[5.x] Reverse spaces in RTL #10184

merged 2 commits into from
Jul 12, 2024

Conversation

peimn
Copy link
Contributor

@peimn peimn commented May 23, 2024

The Super button uses space-x-4, which has not been styled for RTL layout.

@jackmcdade
Copy link
Member

Why are we overriding space- utilities to do margins? I didn't realize this was even in there. We should be able to remove it entirely. The whole point of using them is to put space between items — I really really really don't like setting rtl:mr-2 and ltr-ml-2 stuff everywhere when you can just use space-x-2 on the container.

@peimn
Copy link
Contributor Author

peimn commented May 23, 2024

Exactly. My solution is not to replace space-* with m[r/l]-*!

The class space-x-4 is used here in buttons.css in your latest update for the super button:

.super-btn {
    @apply p-4 flex items-start hover:bg-gray-200 border border-transparent rounded-md space-x-4;
.
.
.

@peimn
Copy link
Contributor Author

peimn commented May 23, 2024

Additionally, your idea to replace all margins with spaces will reduce the number of classes and keep the code clear and concise.
I can implement this change if you believe it is a better approach for the RTL layout.

@jackmcdade
Copy link
Member

jackmcdade commented May 23, 2024

Right, but what's going on the rtl.css file? Shouldn't the space-x- classes handle the spacing without any adjustment on our part? Maybe I'm confused and going too quick just looking at code rather than experimenting...

@jasonvarga
Copy link
Member

I think the issue here is the question... Why are we doing this >:not([hidden])~:not([hidden]) stuff?

@peimn
Copy link
Contributor Author

peimn commented May 23, 2024

Aha, I understand! Tailwind calculates spaces on the left side, so as you can see here, we move the calculation to the right.

/* LTR tailwind */
.space-* {
    margin-right: calc(**rem* var(--tw-space-x-reverse));
    margin-left: calc(**rem* calc(1 - var(--tw-space-x-reverse)));
}
/* RTL tailwind */
.space-* {
    margin-left: calc(**rem* var(--tw-space-x-reverse));
    margin-right: calc(**rem* calc(1 - var(--tw-space-x-reverse)));
}

@jasonvarga
Copy link
Member

How about this? tailwindlabs/tailwindcss#2017 (comment)

@peimn
Copy link
Contributor Author

peimn commented May 23, 2024

I didn't know that! I first found a solution and then copied and pasted it. I will update code!

@jackmcdade
Copy link
Member

jackmcdade commented May 23, 2024

It would be really nice if tailwind just automatically flipped it for you in RTL mode! TIL how space-x actually works 😅

@jackmcdade
Copy link
Member

Maybe those rtl.css classes are the simplest solution 🤔

@jackmcdade
Copy link
Member

There's also this https://github.com/20lives/tailwindcss-rtl

@peimn
Copy link
Contributor Author

peimn commented May 23, 2024

Two or three weeks ago, I did the same thing for another project and replaced all left and right elements with start and end. I think I'll apply the same approach for Statamic, but I've previously implemented RTL for Statamic months ago using this method of finding the first solution and implementing it! I'm uncertain whether all the plugins for RTL are functioning smoothly, as I've tested them and haven't found a complete solution. I tend to focus heavily on details, which might contribute to the challenge. However, I haven't tried testing this one yet!

@peimn peimn changed the title [5.x] Fix super btn rtl margin [5.x] Reverse spaces in RTL May 23, 2024
@jasonvarga jasonvarga requested a review from jackmcdade May 24, 2024 13:59
@peimn
Copy link
Contributor Author

peimn commented May 24, 2024

@jackmcdade I've converted classes to start, end variant, seems that most of the layout is ok except a few elements like bg-gradients, we can keep them as they are before and convert others to simples version. I need to investigate further to ensure everything is okay. Once I'm certain, I'll push the changes.

@jackmcdade
Copy link
Member

@peimn is this ready for review?

@peimn
Copy link
Contributor Author

peimn commented May 29, 2024

Yes, it is ready. This update only addresses the reverse issue. I will send a separate pull request to handle the removal of ltr: rtl: stuff and replace them with CSS rules and Tailwind classes.

@jasonvarga jasonvarga merged commit 8e3da59 into statamic:5.x Jul 12, 2024
17 checks passed
@peimn peimn deleted the fix/super-btn-rtl branch July 12, 2024 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants