Created
December 21, 2022 02:23
-
-
Save extralam/e02ee7ff174d3414f16ff3079d576be1 to your computer and use it in GitHub Desktop.
A simple helper function for TailwindCss, responsive Tailwindcss
This file contains hidden or 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
<?php | |
if (! function_exists('tailclass')) { | |
function tailclass($key, $default = null) { | |
$default = $classArr['default'] ?? []; | |
unset($classArr['default']); | |
$result = $default; | |
foreach($classArr as $key => $value) { | |
$responsive_class = explode(" ", $value); | |
foreach($responsive_class as $item){ | |
$result .= ' ' . $key . ':' . $item; | |
} | |
} | |
return $result; | |
} | |
} |
This file contains hidden or 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
<?php | |
$tailClass = [ 'sm' => 'text-xl font-bold', 'md' => 'text-2xl font-bold' , 'default' => 'text-base' ]; | |
echo tailclass($tailClass); | |
// result : text-base sm:text-xl sm:font-bold md:text-2xl md:font-bold |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment