Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Adding LiveView Component to Heroicons #1

Closed
wants to merge 2 commits into from

Conversation

bmalum
Copy link

@bmalum bmalum commented Apr 11, 2021

First of all - thank you for providing the base package. I did almost the same, for my component library and then noticed your hex package.

I decided to added my (tbh very small part) to your package. I can fully understand if you think that this should not be included in your package, because it adds more dependencies.

Let me know if there is something to improve!

Copy link
Owner

@mveytsman mveytsman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR!

I've been thinking about doing this as well so I really appreciate it.

I'm trying to figure out what the situation is where I want a component in a LiveView app for these. E.g. in my LiveView app I do

<%= Heroicons.Solid.server(class: "ml-6 w-12 h-12 text-green-400" %>

What does adding live components buy us? We're now being more verbose as

<%= live_component @socket, Heroicons.LiveComponent, type: :outline, icon: :server, class: "ml-6 w-12 h-12 text-green-400" %>

We could gain some more efficient diffing, e.g if you change the class in a diff a component would be able to send a smaller diff, but I think we'd need to get the SVG into the render function with the classes as part of the assigns for that to work.

@bmalum were you writing LiveView code where having a component would have been really helpful?


def render(%{type: :outline, class: class, icon: icon} = assigns) do
~L"""
<%= apply(Elixir.Heroicons.Outline, icon, [%{class: class}]) |> Phoenix.HTML.raw %>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the functions return html safe data, is the call to raw necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point - you are right - I updated this part.

Signed-off-by: Martin Karrer <martin@bmalum.com>
@bmalum
Copy link
Author

bmalum commented Apr 11, 2021

I usually also do use <%= Heroicons.Solid.server(class: "ml-6 w-12 h-12 text-green-400" %> but now I have to use Heroicons in a very long dynamic List for showing a state (list is used by multiple users) - so I was thinking about that every item in this list can be a component and update it with send_update or I can go even smaller and just update the icon.

Maybe I'm wrong but I thought to get a minimal diff as possible, best way is to use components and send_update this was my use case. Maybe a niche 😉

@mveytsman
Copy link
Owner

mveytsman commented Apr 11, 2021

That makes sense!

I have a feeling that as written the component diffs would be the same and would have the entire SVG in it even if you're updating just the class.

@mveytsman
Copy link
Owner

I think the stateless function components (phoenixframework/phoenix_live_view#1428) are exactly what we need here. I'm going to close this in favor or #3

@mveytsman mveytsman closed this Apr 24, 2021
mveytsman pushed a commit that referenced this pull request Sep 2, 2022
Return to compile-time generation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants