Skip to content

Slots #50

@nihgwu

Description

@nihgwu

Currently Ripple support slots in the following way (code could be wrong)

component Card({ $children, $header, $footer }) {
  <div>
    <$header />
    <$children />
    <$footer />
  </div>
}

export component App() {
  <Card>
    component $header() {
      <div>{"card header"}</div>
    }
    <div>{"default content"}</div>
    component $footer() {
      <div>{"card footer"}</div>
    }
  </Card>
}

But it's to cumbersome in practice as you have to wrap your named slot with component slot_name() {} everywhere you use the component
In real world we'd hope consumer can use it as

<Card>
  <CardHeader />
  <CardContent />
  <CardFooter />
</Card>

CardHeader/CardContent/CardFooter are all wrapped slots

Rough ideas
given the complexity of template compilation and static analyse in build phase, we can provide shorthand for named slots without slots props like

<Card>
  slot $header {<CardHeader />} 
  <CardContent />
  <CardFooter />
</Card>

or

<Card>
  <$slot name='header'><CardHeader />}</$slot>
  <CardContent />
  <CardFooter />
</Card>

More context:
https://www.npmjs.com/package/create-slots
reactjs/rfcs#223

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions