Code Monkey home page Code Monkey logo

Comments (5)

joerichsen avatar joerichsen commented on July 30, 2024

First of all: Surface looks really. really great!

I was just wondering what you mean by Slots?

Is it something like this? https://daveceddia.com/pluggable-slots-in-react-components/

from surface.

mazz-seven avatar mazz-seven commented on July 30, 2024

I think it's more like Vue or Svelte slots.
https://svelte.dev/tutorial/named-slots
https://vuejs.org/v2/guide/components-slots.html

from surface.

msaraiva avatar msaraiva commented on July 30, 2024

It's basically the same concept that can be found in other libs like Vue.js and Svelte, like @mazz-seven pointed out.

from surface.

joerichsen avatar joerichsen commented on July 30, 2024

OK, thanks to both of you for clarifying :-)

from surface.

saverio-kantox avatar saverio-kantox commented on July 30, 2024

I think it can be done using children:

defmodule SlottedComponent do
  defmodule Body do
    # it should be a normal, not a data component
  end
  defmodule Header do
    # it should be a normal, not a data component
  end

  property headers, :children, group: :Header
  property bodies, :children, group: :Body

  def render(assigns) do
    ~H"""
    <div class="container">
      <header :if={{ @headers }}>
         <div :for={{ h <- @headers }}>{{ h.inner_content.() }}</div>
      </header>
      <main :if={{ @bodies }}>
         <div :for={{ b <- @bodies }}>{{ b.inner_content.() }}</div>
      </main>
    </div>
    """
  end
end

defmodule MyView do
  def render(assigns) do
    ~H"""
    <SlottedComponent>
      <Header>Hello</Header>
      <Body>World</Body>
    </SlottedComponent>
    """
  end
end

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.