Created
March 26, 2021 09:36
-
-
Save lukeraymonddowning/a6151d5ca9abf580307c91b1f4241ee9 to your computer and use it in GitHub Desktop.
Tailwind specificity helper for Laravel Blade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ComponentAttributeBag::macro('fallback', function($classes) { | |
$fallbacks = Collection::wrap($classes) | |
->mapWithKeys(fn($partial, $fallback) => is_int($fallback) ? [$partial => Str::of($partial)->before("-")->when(Str::contains("-", $partial), fn($string) => $string->append('-'))->__toString()] : [$fallback => $partial]) | |
->toArray(); | |
return $this->class($fallbacks); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: