Add styles to tailwind
I've come across an scenario where i need to use this from tailwind:
bg-red-600, bg-cyan-600 and bg-green-500,
i have read the docs, but not sure if i understand what needs to be done to be able to use these...
they are going to be used in a custom view.
33 Replies
bump
Solution
thanks for pointing me in the right direction!
Sorry, i'm lost. I followed the instructions and then tried to add both dark:bg-red-500 and bg-red-500 to my custom view.
nothing changed. could you please point me to a place where this is explained?
i've runned npm run build.
Did you also add the the theme.css to your panel and vite.config.js
yes.
i've added this to my input: [
resources/css/filament/landslag/theme.css
, ]
and this to my panel:
->viteTheme('resources/css/filament/landslag/theme.css')Only other thing that comes to mind is that your resources/views aren’t included in the content array in the tailwind config.
content: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/.blade.php',
'./storage/framework/views/.php',
'./resources/views/*/.blade.php',
],
and the view i'm trying to add bg-red-500 to is in resources/views/livewire/landslag/weekplan/exercise-cell.blade.php
‘./resources/views/*/.blade.php’
Ha. Guess, discord doesn’t like double asterisks.
nope, 🙂 i have two asterisk there
Why do you have storage in there?
Everything looks fine. That’s the only thing that seems odd to me.
might be from when i had v2? not sure.
Maybe try clearing the cache too. Both in the console and your browser.
Hello @torriv it might be useful but I have experience what I you've experience idk why I can't use tailwind colors in blade directly but I've got it working by creating custom class in theme.css then use that class into the blade component
This shouldn’t be necessary. Something else is off.
Thanks. i'll do that if i can't figure it out. but there should be possible without it.
I can run some tests when I get to work.
ok. i removed storage, and cleared all cache. no changes.
just to make sure everything is set up correctly, here is the files:
tailwind.config.js (root)
vite.config.js
resources\css\filament\landslag\tailwind.config.js
Thank you 🙂
Can you show me your theme.css file.
@import '/vendor/filament/filament/resources/css/theme.css';
@config 'tailwind.config.js';
Try this, since you have a root tailwind.
@config ‘./tailwind.config.js’
nothing changed after npm run build and also clear cache
That surprises me. Hmm. Ok.
It’ll be about an hour before I can check.
no problem 🙂
i also checked devtools, and it is using the correct theme.
resources/css/filament/landslag/theme.css
Oh, your views in the theme TW config aren’t looking in your livewire directory. It’s only looking in views/filament.
That was it!! thank you!! 🙂
just something else i found out:
if i do like this:
it won't generate the colors, but if i hardcode them first and recompile, and then put back the dynamic code. it works. is this normal?
Tailwind doesn't play well with dynamic classes. You need to let it know where to look for them
https://tailwindcss.com/docs/content-configuration#dynamic-class-names
do you get the values from the DB? If not, you need to update
tailwind.config.js
and add the file that has the class name.
Add a path to the content array eg
@torrivi'm just doing this in a helper file:
and $intensity values are from DB.
ok then add the path to the
getIntensityColorClass()
method to tailwind.config.js
To the file that has that method, like the example abovePerfect! thank you 🙂
Hello, can you help me? I have the same problem i try to create a new theme but app return me this error: file_put_contents(C:\xampp\htdocs\myproject\postcss.config.js): Failed to open stream: Permission denied. Is it normal? thank you in advance
You have a permission issue on the server.
the system create a folder called "postcss.config.js"
I am in local
I haven't tried in a production server yet, I'm trying locally with xampp. I opened the terminal as administrator but nothing changed
IUt's not really a filament issue, it's a server config issue. It sounds XAMPP doesn't have write permissions for the postcss.config.js file.