Skip to content

use:popper action (instead of component based API) #1

Open
@FezVrasta

Description

@FezVrasta

The existing <Popper /> component doesn't feel right, it does absolutely nothing, if not allow the consumers to pass props down and retrieve the result.

The README example could be written as follows and everything would still work:

<Popper
  reference={referenceElement}
  popper={popperElement}
  options={popperOptions}
  bind:styles
  bind:attributes
/>

<button bind:this={referenceElement}>Reference Element</button>
<div
  bind:this={popperElement}
  class="tooltip"
  style={css(styles.popper)}
  {...attributes.popper}>
  Popper Element
  <div bind:this={arrowElement} class="arrow" style={css(styles.arrow)} />
</div>

A cleaner approach could be the use:action API.

<script>
  let styles = {};
  let attributes = {};
</script>

<button
  use:popper={{ popperElement, options }}
  on:popperUpdate={evt => {
    styles = evt.detail.styles;
    attributes = evt.detail.attributes;
  }}
>
  Reference Element
</button>

Here's a basic example:
https://codesandbox.io/s/trusting-butterfly-704gd?file=/popperAction.js

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions