Comments (8)
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.
@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.
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.
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.
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.
@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.
@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.
Awesome! PRs are always welcome!
from surface.
Related Issues (20)
- Since update : no route found for POST after a <Form> is submitted HOT 1
- Improve error messaging when using `<#slot />` in template via `embed_sface/1` macro
- Setting which modules can pass context values outside of config
- Erlang Error in Elixir Language Server with Surface HOT 1
- [Using a plugin] Scoped CSS changes require two page reloads. HOT 1
- inputs_for/3 warning HOT 1
- Warnings on Select component with disabled property
- Props missing inside `handle_event()` `socket.assigns` map. HOT 3
- mix surface.init: no function clause matching in Sourceror.Zipper.down/1 HOT 3
- Support for LiveViewNative? HOT 5
- Submitted forms don't carry the "submitter" attribute
- Surface CSS scoping attributes don't work when root component is a component
- When using :on-click={"name", target="#target_id"} I cannot seem to get a sibling to target another sibling node that is rendered in the same parent. HOT 1
- Compatibility with LiveView 0.20 HOT 7
- Question: How would you make the sample tab component to use svg icons instead of font icons HOT 4
- Elixir 1.16: negative steps are not supported in String.slice/2, pass 1..-2//1 instead
- Malformed HTML when using LiveRedirect with another component inside HOT 1
- Mix.env() usage can cause troubles in release HOT 2
- Question: Form example on latest version HOT 2
- error: module Surface.Components.Form.Inputs is not loaded and could not be found. This may be happening because the module you are trying to load directly or indirectly depends on the current module<Description> HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from surface.