vue-use-popperjs
TypeScript icon, indicating that this package has built-in type declarations

2.3.8 • Public • Published

Vue-use-popperjs

Vue-popper-js is complete popper solution powered by @popperjs.

npm

CI

Features

  • Fully customizable popover with hook function
  • (Vue 3 only) Popper component, with built-in support for Component, Teleport, and Transition

Documentation

To check out live examples and docs, visit here

Installation

Hook only

For vue@2 + @vue/composition-api

$ yarn add vue-use-popperjs@^1 @vue/composition-api

For vue@3:

$ yarn add vue-use-popperjs@^1

Hook + Component

For vue@3:

$ yarn add vue-use-popperjs
# $ yarn add vue-use-popperjs@^2

vue-use-popperjs@^2 only works with vue@3.

Basic Usage

Hook

<template>
  <button ref="button">Hover me!</button>
  <span ref="tooltip">Tooltip</span>
</template>

<script lang="ts">
  import { defineComponent, ref } from "vue";
  import { usePopperjs } from "vue-use-popperjs";

  export default defineComponent({
    setup() {
      const button = ref();
      const tooltip = ref();
      usePopperjs(button, tooltip);

      return { button, tooltip };
    },
  });
</script>

<style scoped>
  .vue-use-popperjs-none {
    display: none;
  }
</style>

Vue-use-popperjs automatically add .vue-use-popperjs-none class to popper when it is hidden, you can add following css to hide poppers:

.vue-use-popperjs-none {
  display: none;
}

Component

<template>
  <Popper reference-is="button" popper-is="span">
    <template #reference>Hover me!</template>
    Tooltip
  </Popper>
</template>

<script lang="ts">
  import { defineComponent } from "vue";
  import { Popper } from "vue-use-popperjs";

  export default defineComponent({
    components: {
      Popper,
    },
  });
</script>

Advanced Usage

Component

<template>
  <Popper
    reference-is="span"
    :reference-props="{ id: 'popcorn' }"
    popper-is="span"
    :popper-props="{ id: 'tooltip' }"
    :teleport-props="{ to: 'body' }"
    :transition-props="{ name: 'fade' }"
    :modifiers="modifiers"
  >
    Tooltip
    <div id="arrow" data-popper-arrow></div>
  </Popper>
</template>

<script lang="ts">
  import { defineComponent } from "vue";
  import { Popper } from "vue-use-popperjs";

  export default defineComponent({
    components: {
      Popper,
    },
    setup() {
      const modifiers = [
        {
          name: "offset",
          options: {
            offset: [0, 8],
          },
        },
      ];

      return { modifiers };
    },
  });
</script>

<style>
  .fade-enter-active,
  .fade-leave-active {
    transition: opacity 0.5s ease;
  }

  .fade-enter-from,
  .fade-leave-to {
    opacity: 0;
  }

  #popcorn {
    display: inline-block;
    width: 134px;
    height: 120px;
    background-image: url("https://popper.js.org/images/popcorn-box.svg");
  }

  #tooltip {
    display: inline-block;
    background: #643045;
    color: #ffffff;
    font-weight: bold;
    padding: 5px 10px;
    font-size: 13px;
    border-radius: 4px;
  }

  #arrow,
  #arrow::before {
    position: absolute;
    width: 8px;
    height: 8px;
    background: inherit;
  }

  #arrow {
    visibility: hidden;
  }

  #arrow::before {
    visibility: visible;
    content: "";
    transform: rotate(45deg);
  }

  [data-popper-placement^="top"] #arrow {
    bottom: -4px;
  }

  [data-popper-placement^="bottom"] #arrow {
    top: -4px;
  }

  [data-popper-placement^="left"] #arrow {
    right: -4px;
  }

  [data-popper-placement^="right"] #arrow {
    left: -4px;
  }
</style>

About

Buy Me A Coffee

Distributed under the MIT license. See LICENSE for more information.

https://github.com/iendeavor

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.3.8715latest
1.3.26version1
3.0.0-alpha.30alpha
2.3.8715version2

Version History

VersionDownloads (Last 7 Days)Published
3.0.0-alpha.30
2.3.8715
2.3.70
2.3.60
2.3.56
2.3.40
2.3.30
2.3.20
2.3.10
2.3.01
2.2.61
1.3.26
2.2.50
2.2.30
2.2.20
2.2.10
1.3.10
1.3.00
2.2.00
2.1.01
2.0.10
2.0.00
1.2.00
2.0.0-beta.20
2.0.0-beta.10
2.0.0-alpha.11
2.0.0-beta.00
1.2.0-beta.51
1.2.0-beta.40
1.2.0-beta.30
1.2.0-beta.20
1.2.0-beta.10
1.2.0-beta.00
1.1.10
1.1.00
0.1.300
0.1.290
0.1.280
0.1.270
0.1.260
0.1.250
0.1.240
0.1.230
0.1.220
0.1.210
0.1.200
0.1.190
0.1.180
0.1.170
0.1.160
0.1.150
0.1.140
0.1.120
0.1.111
0.1.100
0.1.90
0.1.80
0.1.70
0.1.60

Package Sidebar

Install

npm i vue-use-popperjs

Weekly Downloads

733

Version

2.3.8

License

MIT

Unpacked Size

339 kB

Total Files

17

Last publish

Collaborators

  • iendeavor