SurfaceUtils (surface_utils v0.1.0)
SurfaceUtils provides a include/2 macro which can import props from other components.
Use the included_props/2
function to pass included props to the component that is included.
For Example:
defmodule ComponentToInclude do
use Surface.Component
@doc "a boolean"
prop(boolean, :boolean)
def render(assigns) do
~F"""
ComponentToInclude
{#for prop <- __MODULE__.__props__()}
{assigns[prop.name]}
{/for}
"""
end
end
defmodule TestComponent do
use Surface.Component
import SurfaceUtils
include(ComponentToInclude)
prop(own_prop, :any)
def render(assigns) do
~F"""
{"my_props: #{@own_prop}"}
<ComponentToInclude {...included_props(assigns, ComponentToInclude)} />
"""
end
end
Summary
Functions
Allows a component to include props from another component.
Props can be selectively included similarly to Elixir's import
using only: [list_of_names]
and except: [list_of_names]
.
Will extract the values for the props that are in the assigns for the specified component. Usefull when wrapping another component and the values for the props need to be passed on.
Functions
Allows a component to include props from another component.
Props can be selectively included similarly to Elixir's import
using only: [list_of_names]
and except: [list_of_names]
.
included_props(assigns, other_component)
Will extract the values for the props that are in the assigns for the specified component. Usefull when wrapping another component and the values for the props need to be passed on.