Hi Elixir/Phoenix Community
Since I’ve learnt about Phoenix.Component, I have created few components to be used in LiveView such as CardComponent, TableComponent and etc.
Why
I am using Tailwindcss + DaisyUI for all the styling. I use the CardComponent like
<.card>
card content
</.card>
in LiveView, so in case I want to change the card styling, I only change it in CardComponent only.
Questions
-
Is this a good practice?
Phoenix has Phoenix.Component and even tailwindcss recommended us to. But I am new to Elixir and Phoenix, is the the case? -
How to import multiple components/Helpers?
- Since I have created many components, and some components are widely use, I would like to import these components and make it available globally just like the
<.modal></modal>
in live_helpers.ex when we created phoenix app. - I know I can
import TestWeb.CardComponent
inside test_web.ex and maybe import all other components as well. This is messy right? - I would like to use the existing live_helpers.ex to import common components and make them available for all liveview. But how??
- I have created many components in
text_web/components/xxx_component.ex
. For maintainability, one component one file, instead of put all of them into live_helpers.ex
- Since I have created many components, and some components are widely use, I would like to import these components and make it available globally just like the
The mentioned approach in 2. is what came up to my brain base on my existing experience and it might not be the final or correct approach. If you have better idea, it would be GREAT!
Extra
I just realize DailyUI + LiveView.JS is very powerful! DaisyUI doesn’t require javascript (example dropdown) and I can use LiveView.JS to add_class to make it dropdown. no AlpineJS required for basic use cases