Be warned what i'm trying to do is not conventional at all.
I'm trying to store tailwindcss class names in the config files. This is so that I can make a dynamic component. And some of the components may shares the same class name. Let me demonstrate further:
Config/Theme/Component.php
return[
'text' => [
'size' => 'text-sm'
]
]
Config/Theme/Component.php
return[
'componentA' => [
'color' => 'bg-gray-500',
'size' => config('theme.global.text.size') // currently returns null
] ,
'componentB' => [
'color' => 'bg-red-500',
'size' => config('theme.global.text.size') // currently returns null
]
]
I want both componentA and componentB size to use the same value declared from global.php so if i want to change the size of bot component, I will have to just change it from global.php without the need to change the size value one by one in component.php. Further use case is as below:
App/Views/Component/ComponentA.php
public $size;
public function __construct(){
$this->size = config('theme.component.text.size');
}
Should i decided that ComponentA uses its own size instead of the size from global.php, I would just need to change the size value in component.php.
These are the methods that I've tried previously:
Method 1:
Inject the size value from global.php into the component itself as below:
App/Views/Component/ComponentA.php
public $size;
public function __construct(){
$this->size = config('theme.global.text.size');
}
Cons: should i decided that ComponentA uses its own size instead of the size from global.php, I would need to change $size declaration in ComponentA.php from global.php to component.php. Configurations should be done only in configuration files.
Method2:
Instead of grouping global.php or component.php under the same subfolder, just put them into separate subfolder as below:
config
|--Theme
| |--global.php
|--Component
|--style.php
Or just put them in root config folder as below:
config
|--global.php
|--style.php
Cons: Not an eye candy since their purpose are the same and there's lot of configuration file in between global.php and style.php.
The reason im storing these class names in config file is so that I can easily access them by just using helper function config(). I've tried storing the classes in json and yaml but that would result with excessive use of if else/switch statement.