Skip to content

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

Closed

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.

Activity

  1. darrylyeo commented on Jun 3, 2021

    @darrylyeo
    Author

    For even more flexibility, the components could also export let the instance e.g. export let f7Sheet so component users can do <Sheet bind:f7Sheet={sheet}>.

  2. darrylyeo commented on Jul 8, 2021

    @darrylyeo
    Author

    Fantastic! 🎉

  3. added a commit that references this issue on Feb 23, 2024
    6029fd1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions