yieldstudio / tailwind-merge-php
Merge Tailwind CSS classes without style conflicts
Installs: 52 837
Dependents: 1
Suggesters: 0
Security: 0
Stars: 48
Watchers: 2
Forks: 1
Open Issues: 2
Requires
- php: >=8.1
Requires (Dev)
- laravel/framework: ^9|^10
- laravel/pint: ^1.10
- orchestra/testbench: 7.*|8.*
- pestphp/pest: ^v1|^v2.2.3
- phpstan/phpstan: ^1.10
Suggests
- laravel/framework: Want to use Tailwind Merge PHP with Laravel ?
README
Efficiently merge Tailwind CSS classes in PHP without style conflicts
This package allows you to merge multiple Tailwind CSS classes and automatically resolves conflicts between them without headaches.
tailwind-merge-php is a PHP port of the excellent tailwind-merge created by dcastil.
- Supports Tailwind v3.0 up to v3.3
- First-class support for Laravel
Installation
composer require yieldstudio/tailwind-merge-php
Usage
use YieldStudio\TailwindMerge\TailwindMerge; use YieldStudio\TailwindMerge\TailwindMergeConfig; // Singleton $twMerge = TailwindMerge::instance(); $twMerge->merge('w-8 h-8 rounded-full rounded-lg'); // w-8 h-8 rounded-lg // Custom instance $twMerge = new TailwindMerge(TailwindMergeConfig::default()); // Config is optional $twMerge->merge('w-8 h-8 rounded-full rounded-lg'); // w-8 h-8 rounded-lg
Laravel Support
You can publish the configuration file with:
php artisan vendor:publish --provider="YieldStudio\TailwindMerge\Laravel\TailwindMergeServiceProvider"
Using the tw
helper
tw('w-8 h-8 rounded-full rounded-lg'); // w-8 h-8 rounded-lg
Using Blade directive
<div @tw('w-8 h-8 rounded-full rounded-lg')></div> // will be <div class="w-8 h-8 rounded-lg"></div>
Using Blade components
// avatar.blade.php <div {{ $attributes->tw('w-8 h-8 rounded-full') }}></div> // header.blade.php <x-avatar class="rounded-lg" /> // will be <div class="w-8 h-8 rounded-lg"></div>
Configuration & plugins
✍️ Complete documentation is being written
Unit tests
To run the tests, just run composer install
and composer test
.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you've found a bug regarding security please mail contact@yieldstudio.fr instead of using the issue tracker.
Credits
- James Hemery
- Special thanks to dcastil who built tailwind-merge
License
The MIT License (MIT). Please see License File for more information.