yieldstudio/tailwind-merge-php

Merge Tailwind CSS classes without style conflicts

0.0.3 2023-07-19 12:28 UTC

This package is auto-updated.

Last update: 2024-09-19 15:12:20 UTC


README

Social Card of Tailwind Merge PHP

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.