I am trying to make a website builder where users can set colors based on their needs just by clicking the colors. The main problem, the color is not working. Here is the function
function generateTemplateClass($input)
{
$class = [];
$style = [];
if ($input && count($input) > 0) {
foreach ($input as $key => $item) {
switch ($key) {
case 'backgroundColor':
$style[] = "background-color: {$item}";
$class[] = "bg-[{$item}]";
break;
case 'textColor':
$style[] = "color: {$item}";
$class[] = "text-[{$item}]";
break;
}
}
}
$result = [
'class' => $class,
'style' => $style,
];
return $result;
}
Blade file:
<nav class="{{$class}} border-gray-200 fixed w-full block z-30 top-0 border-b" data-accordion="collapse">
.....
</nav>
Output:
<nav class="bg-[#010432] text-[#e6e5ff] border-gray-200 fixed w-full block z-30 top-0 border-b" data-accordion="collapse">
.....
</nav>
Right now, I am trying to achieve it with using styles but I want to use tailwind class which is easier. How do I generate class based on user color inputs. Thank you