Replies: 3 comments 1 reply
-
What are you thinking around making the aliasing the components modules easier? Right now the component API is a bit verbose for my taste. I think what I'd ideally like is are a bunch of components files inside a So instead of: # flex.ex
defmodule MyAppWeb.Components.Flex do
use Temple.Component
render do
div class: "flex #\{@class}" do
@inner_content
end
end
end
# index.html.exs
alias MyAppWeb.Components.Flex
c Flex, class: "justify-between items-center", id: "arnold" do
div do: "Hi"
div do: "I'm"
div do: "Arnold"
div do: "Schwarzenegger"
end we'd have: # flex.html.exs
div class: "flex #\{@class}" do
@inner_content
end
# index.html.exs
flex class: "justify-between items-center", id: "arnold" do
div do: "Hi"
div do: "I'm"
div do: "Arnold"
div do: "Schwarzenegger"
end If it's possible to write your own macro to do that I guess that would be fine, but it would be a nice alternative syntax to support natively I think! The majority of my use cases are simply extracting reusable HTML widgets into separate files. Usually I have some app-global components that are reused everywhere and sometimes I also have some view-local components that are only used in the current view. It would be nice if both cases could be supported side-by-side! |
Beta Was this translation helpful? Give feedback.
-
The syntax that you show (that was previously supported) adds complexity to the implementation and uncertainty to the usage. I don't think I'll be considering adding support for that syntax, but I'll denote some of the the drawbacks here.
The pros of the current approach are basically the opposites of the drawbacks, but I'll list them here
|
Beta Was this translation helpful? Give feedback.
-
My idea for auto-aliasing component might be a helper like # my_app_web.ex
defmodule MyAppWeb do
#...
def view do # or live_view, or live_component, etc
# ...
alias_components MyAppWeb.Component, "my_app_web/components"
end
# ...
end This would be a small helper to navigate a directory and be able to cobble together the module based on the prefix and the file name. This would be a one time add as long as you follow a convention that you set for yourself. |
Beta Was this translation helpful? Give feedback.
-
The Component API is definitely getting better, but I don't think it's all the way there.
Things I'd like to see are
Please use this discussion thread to discuss things you like about components, question, or any changes you'd like to propose (functions, syntax, features, etc).
Beta Was this translation helpful? Give feedback.
All reactions