twMerge in Sage 10

Is there a way to use the method twMerge inside a component (using its attributes).

for exmaple, lets say:

<x-something class="text-4xl bg-blue />

while a $attribute->twMerge([‘class’ => ‘text-3xl font-bold uppercase bg-red’]) resolves all conflicts etc.

I know there are some php-tailwind-merge repos, but I was wondering if I could just hook another attribute into the blade’s ComponentAttributeBag and how I could possible do it.

1 Like

I mean, Sage uses Blade-PHP/Laravel components under the hood,
so this Laravel/Blade-PHP extension for twMerge could work near out of the box:

2 Likes

Did you ever try using it? Sadly I had quite a few issues, setting things up (maybe it was another package, Im not quite sure).

Will check, thou Im still wondering what I would need to do, in order to use my custom methods (or hook my custom methods) inside the blade attributes.

I hadn’t seen that tailwind-merge-laravel package before, it looks really good :heart_eyes:

Can you elaborate?

Their README looks pretty solid. Can you provide some code that you’ve tried?

I tried this and another one I think, thou the other one didn’t work at all.

I double checked this one and got it running (yipie), using 4.0.0 acorn, thou haven’t actually found the time to make the adjustments. I don’t know where to start honestly. It just says “twMerge does not exist”

Ahh it was very simple, just added the package into the theme via the providers. Thanks a lot for the help. :slight_smile:

3 Likes

for acorn 3 / laravel 9 ive tested GitHub - YieldStudio/tailwind-merge-php: Merge multiple Tailwind CSS classes and automatically resolves conflicts between them without headaches ! First-class support for Laravel ✨ and works great.
same as above it self registers so install and go.
Once ive migrated to acorn 4 / laravel 10 i’d migrate to https://github.com/gehrisandro/tailwind-merge-laravel

1 Like

Running into issues when moving from sage’s composer file (for acorn 4 and twMerge package) to bedrocks composer. Acorn 4.0.2 works perfectly fine on bedrock, thou for some reason once the twMerge package is installed, everything stops working (even after removing it- I have to remove the acorn package as well and re-install it)

Getting this issue:
172.18.0.2 - 06/Feb/2024:12:04:29 +0000 “GET /wp/wp-admin/index.php” 500
NOTICE: PHP message: PHP Fatal error: Cannot redeclare __() (previously declared in /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:952) in /var/www/html/web/wp/wp-includes/l10n.php on line 298
172.18.0.2 - 06/Feb/2024:12:04:30 +0000 “GET /wp/wp-admin/index.php” 500

1 Like

Ah, it looks like that package requires laravel/framework as a dependency instead of depending on specific packages from the Illuminate namespace, which is making it incompatible with Acorn

2 Likes

Figured. Im running acorn from within bedrock now and use twMerge from within the sage theme’s composer file.
Maybe I’ll find a better solution in the future, but it works for now ig :smile:

1 Like

created a ticket for using with acorn, using only needed illuminate packages.

the creator also has a non laravel version of the package
https://github.com/gehrisandro/tailwind-merge-php

2 Likes