{"id":23512766,"url":"https://github.com/baethon/tailwind-class-collapse","last_synced_at":"2025-05-13T19:29:11.830Z","repository":{"id":62491139,"uuid":"247050552","full_name":"baethon/tailwind-class-collapse","owner":"baethon","description":"Collapse list of Tailwind CSS classes","archived":false,"fork":false,"pushed_at":"2020-08-24T13:19:07.000Z","size":44,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-26T19:20:22.518Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baethon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-13T10:57:45.000Z","updated_at":"2020-08-24T13:19:10.000Z","dependencies_parsed_at":"2022-11-02T11:16:17.770Z","dependency_job_id":null,"html_url":"https://github.com/baethon/tailwind-class-collapse","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baethon%2Ftailwind-class-collapse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baethon%2Ftailwind-class-collapse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baethon%2Ftailwind-class-collapse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baethon%2Ftailwind-class-collapse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baethon","download_url":"https://codeload.github.com/baethon/tailwind-class-collapse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254012555,"owners_count":21999285,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-25T13:19:23.887Z","updated_at":"2025-05-13T19:29:11.770Z","avatar_url":"https://github.com/baethon.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/baethon/tailwind-class-collapse.svg?branch=master)](https://travis-ci.org/baethon/tailwind-class-collapse)\n\n---\n\n# baethon/tailwind-class-collapse\n\nRemoves Tailwind class names keeping the rightmost class of the same type.\n\n## Installation\n\n```\ncomposer require baethon/tailwind-class-collapse\n```\n\n## Usage\n\n```php\nuse function Baethon\\Tailwind\\class_collapse as tailwind_class_collapse;\n\n$class = tailwind_class_collapse('shadow font-bold text-gray-700 py-2 px-4 rounded text-center inline-block focus:shadow-outline focus:outline-none bg-blue-500 text-white hover:bg-blue-400');\n\n// shadow font-bold py-2 px-4 rounded text-center inline-block focus:shadow-outline focus:outline-none bg-blue-500 text-white hover:bg-blue-400\n```\n\n## Why collapse?\n\nI'll use an example. Consider following [snippet](https://codepen.io/radmen/pen/WNvzdYB):\n\n```html\n\u003cbutton class=\"shadow font-bold text-gray-700 py-2 px-4 rounded text-center inline-block focus:shadow-outline focus:outline-none bg-blue-500 text-white hover:bg-blue-400\" type=\"submit\"\u003eSign In\u003c/button\u003e\n```\n\nAs you can see, the `text-white` did not apply correctly. It's overwritten by the `text-gray-700`. To fix this, you need to remove the `text-gray-700` class.\n\nEasy right? Well, things get complicated when you have a solution which appends some classes based on a set of predicates. To avoid the issue one should set condition statements making simple things complex.\n\n## How does it work?\n\n`class_collapse()` groups Tailwind classes by their purpose (or, in most cases, by the CSS property they set). It splits the class list by space and preserves only the rightmost class of the same type. The package supports Tailwinds [pseudo-class variants](https://tailwindcss.com/docs/pseudo-class-variants).\n\n## Supported Tailwind versions\n\nFor now, the package supports only Tailwind v1.2. It's possible to add class definitions for other versions, however I don't intend doing this now. If you'd like to add support for different Tailwind version feel free to open a PR.\n\n## Testing\n\n```\ncomposer test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaethon%2Ftailwind-class-collapse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaethon%2Ftailwind-class-collapse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaethon%2Ftailwind-class-collapse/lists"}