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

Section on passing components as content #2

Open
insin opened this issue May 19, 2016 · 1 comment
Open

Section on passing components as content #2

insin opened this issue May 19, 2016 · 1 comment

Comments

@insin
Copy link
Contributor

insin commented May 19, 2016

I only have experience with React and Vue here (and Vue 2 may set the cat amongst the pigeons in feature comparisons when it also adds render() methods), so some examples of the sort of thing I mean.

React

http://facebook.github.io/react/docs/multiple-components.html#children
http://facebook.github.io/react/docs/top-level-api.html#react.children
https://discuss.reactjs.org/t/children-as-a-function-render-callbacks/626 - "render callbacks"

Placing all child contents

MyComponent#render():

<div>Before {this.props.children} After</div>
<MyComponent><p>Child 1</p><p>Child 2</p></MyComponent>

Passing rendered elements as props

MyComponent#render():

<div>
  {this.props.foo}
  {this.props.children}
  {this.props.bar}
</div>
<MyComponent bar={<p>Bar</p>} foo={<p>Foo</p>}>
  <p>Child 1</p><p>Child 2</p>
</MyComponent>

Dynamic component as a prop

MyComponent#getDefaultProps():

return {someProp: 'div'}

MyComponent#render():

<this.props.someProp>...</this.props.someProp>
<MyComponent/>
<MyComponent someProp={SomeOtherComponent}/>

Vue

https://vuejs.org/guide/components.html#Content-Distribution-with-Slots

Placing all child contents

MyComponent template:

<div>Before <slot></slot> After</div>
<my-component><p>Child 1</p><p>Child 2</p></my-component>

Named slots

MyComponent template:

<div>
  <slot name="foo"></slot>
  <slot></slot>
  <slot name="bar"></slot>
</div>
<my-component>
  <p slot="bar">Bar</p>
  <p slot="foo">Foo</p>
  <p>Child 1</p><p>Child 2</p>
</my-component>
@jeffcarp
Copy link
Owner

This is awesome!

In the Vue docs it says:

Vue.js implements a content distribution API that is modeled after with the current Web Components spec draft, using the special element to serve as distribution outlets for the original content.

So I was guessing Polymer was the same way but it looks like they use <content> and query selectors https://www.polymer-project.org/1.0/docs/devguide/local-dom#dom-distribution

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

No branches or pull requests

2 participants