Skip to content

Svelte: Expose F7 instances through <slot> "let" props #3899

@darrylyeo

Description

@darrylyeo

Currently, we have to use bind:this along with .instance() to access the internal Framework7 API of several Svelte components. Example from the docs:

<Sheet bind:this={component}>...</Sheet>

<script>
  let component;

  // to get instance in some method
  component.instance()
</script>

I think this boilerplate can be reduced in many cases. I suggest we have the components directly pass the instance as a <slot> prop:

<!-- components/sheet.svelte -->

<script>
    ...
    f7Sheet = f7.sheet.create(params)
</script>

...

<slot sheet={f7Sheet} />

Then we can use the API like this:

<Sheet let:sheet>
    <Button onClick={() => sheet.close()}>Close</Button>
</Sheet>

This can apply to <Actions>, <Messagebar>, <Panel>, <PhotoBrowser>, <Popup>, <Searchbar>, <Sheet>, and many other interactive elements.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions