Download the PHP package devanoxltd/tailwind-class-merge-php without Composer
On this page you can find all versions of the php package devanoxltd/tailwind-class-merge-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download devanoxltd/tailwind-class-merge-php
More information about devanoxltd/tailwind-class-merge-php
Files in devanoxltd/tailwind-class-merge-php
Package tailwind-class-merge-php
Short Description TailwindClassMerge for PHP merges multiple Tailwind CSS classes by automatically resolving conflicts between them
License MIT
Informations about the package tailwind-class-merge-php
TailwindClassMerge for PHP allows you to merge multiple Tailwind CSS classes and automatically resolves conflicts between classes by removing classes conflicting with a class defined later.
A PHP port of tailwind-merge by dcastil. And clone and improve from tailwind-merge-php by gehrisandro.
Supports Tailwind v3.0 up to v3.4.
If you find this package helpful, please consider sponsoring the maintainer:
- Devanox Private Limited: github.com/sponsors/devanoxltd
Attention: This package is still in early development.
If you are using Laravel, you can use the TailwindClassMerge for Laravel
Table of Contents
- Get Started
- Usage
- Cache
- Configuration
- Contributing
Get Started
Requires PHP 8.1+
First, install TailwindClassMerge via the Composer package manager:
Then, use the TailwindClassMerge
class to merge your Tailwind CSS classes:
You can adjust the configuration of TailwindClassMerge
by using the factory to create a new instance:
For more information on how to configure TailwindClassMerge
, see the Configuration section.
Usage
TailwindClassMerge
is not only capable of resolving conflicts between basic Tailwind CSS classes, but also handles more complex scenarios:
It's possible to pass the classes as a string, an array or a combination of both:
Cache
For a better performance, TailwindClassMerge
can cache the results of the merge operation.
To activate pass your cache instance to the withCache
method.
It accepts any PSR-16 compatible cache implementation.
When you are making changes to the configuration make sure to clear the cache.
Configuration
If you are using Tailwind CSS without any extra config, you can use TailwindClassMerge right away. And stop reading here.
If you're using a custom Tailwind config, you may need to configure TailwindClassMerge as well to merge classes properly.
By default TailwindClassMerge is configured in a way that you can still use it if all the following apply to your Tailwind config:
- Only using color names which don't clash with other Tailwind class names
- Only deviating by number values from number-based Tailwind classes
- Only using font-family classes which don't clash with default font-weight classes
- Sticking to default Tailwind config for everything else
If some of these points don't apply to you, you need to customize the configuration.
This is an example to add a custom font size of "very-large":
For a more detailed explanation of the configuration options, visit the original package documentation.
Contributing
Thank you for considering contributing to TailwindClassMerge for PHP
! The contribution guide can be found in the CONTRIBUTING.md file.
TailwindClassMerge for PHP is an open-sourced software licensed under the MIT license.