Code Monkey home page Code Monkey logo

Comments (8)

zamith avatar zamith commented on July 30, 2024

Since you're not really taking advantage of Surface (at from the example), have you tried using the Raw component?

defmodule Foo do
  use Surface.Component
  import Phoenix.HTML.Link

  alias Surface.Components.Raw

  property(links, :list, default: ["foo", "bar", "baz"])

  def render(assigns) do
    ~H"""
    <div>
      <#Raw>
        <%= for l <- assigns[:links] do %>
          <%= link to: "#" do %>
            <span><%= l %></span>
          <% end %>
        <% end %>
      </#Raw>
    </div>
    """
  end
end

There is still the issue that Surface interpolates everything with = which maybe @msaraiva is addressing in #15, but it should solve your particular problem.

from surface.

mathewdgardner avatar mathewdgardner commented on July 30, 2024

@zamith This does get around it like manually using <a>...</a> does. However, in this convoluted example I'd prefer the later over the former.

I guess I'm really just wondering if there is any compatibility between Surface and all the helpers we know and love. It seems the answer is yes with the use of #Raw but that is not intuitive or obvious to newcomers.

from surface.

msaraiva avatar msaraiva commented on July 30, 2024

Just like React, Surface cannot accept partial/incomplete expressions and probably never will since it has to generate a valid tree structure of the HTML/Components nodes at compile-time. So we can only accept complete expressions that can be be fully assigned to a particular node/attribute.

I have some further comments about this here #23 (comment).

In general, you should avoid having too much logic in your template. In case you do, and the available directives (:for, :if, etc.) are not enough, it's probably a smell and a sign that the logic is getting too complex and you should consider moving that code to someplace else.

If for any particular reason you really need to use something like <% ... %>, just create a separate function and use ~L or ~E. You can call that function directly in your Surface template using {{}}.

<#RAW> can be an alternative as well, however I would first investigate the complexity of the logic and see if it could be moved to a better place before going that road.

from surface.

mathewdgardner avatar mathewdgardner commented on July 30, 2024

I ran into this converting some partials into surface components. The complexity was just in creating a link using a do block so that some inner html could be set. My contrived example is just that, contrived, to illustrate it.

I suppose it just means there should be another <Link> component that wraps the use of phoenix helpers?

from surface.

msaraiva avatar msaraiva commented on July 30, 2024

I suppose it just means there should be another component that wraps the use of phoenix helpers?

Exactly! Maybe we can come up with an alternative in the future to make this work somehow, but for now, our only options are: move to a separate function or create a wrapper component. The goal is to create builtin components for the most common helpers so we can provide a nice development experience.

Sorry @msaraiva, I don't mean to pummel you with issues. This is great package and I can't wait to see it reach v1.0.0!

No worries. That's why I'm here for :) I'm glad you're enjoying.

from surface.

msaraiva avatar msaraiva commented on July 30, 2024

@mathewdgardner feel free to bring any real case you already needed (like Link). This kind of feedback is important so we can decide which builtin components should be added first.

from surface.

mathewdgardner avatar mathewdgardner commented on July 30, 2024

@msaraiva Good deal, I have several issues I've kept track of as I've learned how to use Surface. I can keep posting them in separate issues to keep them contained if they are welcome.

I can also put together a PR for a link component.

from surface.

msaraiva avatar msaraiva commented on July 30, 2024

Awesome! PRs are always welcome!

from surface.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.