yieldstudio/tailwind-merge-php

Merge Tailwind CSS classes without style conflicts
76,655 49
Install
composer require yieldstudio/tailwind-merge-php
Latest Version:0.0.3
PHP:>=8.1
License:MIT
Last Updated:Jul 19, 2023
Links: GitHub  ·  Packagist
Maintainer: JamesHemery

Efficiently merge Tailwind CSS classes in PHP without style conflicts

Latest Version GitHub Workflow Status Total Downloads

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

License

The MIT License (MIT). Please see License File for more information.

Related Packages

goodm4ven/tailwind-merge

Resolves TailwindCSS class conflicts in between Laravel Blade component calls

1,716 1
marcorieser/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically...

4,232 0
gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically...

1,090,642 342
sikessem/ui

Blade and TailwindCSS components to design faster.

2,947 2