Coder Social home page Coder Social logo

simplebar-vue3's Introduction

!!! Please use native simplebar-vue library. This library is not maintained anymore.

simplebar-vue3

A Vue3 Wrapper for SimpleBar

Intallation

For npm and pnpm:

(npm or pnpm) install simplebar simplebar-vue3

For yarn:

yarn add simplebar simplebar-vue3

Usage

You need to import simplebar stylesheet in your main.(js|ts) file for scrollbar to look normal and work.

main.(js|ts)
import 'simplebar/dist/simplebar.min.css';

import { createApp } from 'vue';
import App from './App.vue';
createApp(App).mount('#app');

To use it in .vue files just import the component and use.

<template>
   <SimpleBar style="height: 500px; overflow-y: auto"> ... Content Goes here </SimpleBar>
</template>

<script setup>
   import { SimpleBar } from 'simplebar-vue3';
</script>
<!-- FOR NORMAL SCRIPT -->
<script>
   import { SimpleBar } from 'simplebar-vue3';
   import { defineComponent } from 'vue';

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

Accessing Simplebar Instance

Via event;

If you want to access simplebar instance by event you can use @created event.

<template>
   <SimpleBar
      @created="instance => {
         simplebarInstance = instance;
      }"
   >
   </SimpleBar>
</template>

<!-- Typescript is optional -->
<script setup lang="ts">
   import type { SimplebarInstanceRef } from 'simplebar-vue3';
   import { SimpleBar } from 'simplebar-vue3';
   import { ref } from 'vue';

   const simplebarInstance = ref<SimplebarInstanceRef>(null);
</script>
Via template ref;

You access simplebar instance ref

<template>
   <SimpleBar ref="simplebarInstance"> </SimpleBar>
   <!-- Or this behavior can be used but it will give type error probably -->
   <SimpleBar :ref="(instance) => { simplebarInstance = instance }"> </SimpleBar>
</template>

<!-- Typescript is optional -->
<script setup lang="ts">
   import type { SimplebarInstanceRef } from 'simplebar-vue3';
   import { SimpleBar } from 'simplebar-vue3';
   import { ref } from 'vue';

   const simplebarInstance = ref<SimplebarInstanceRef>(null);
</script>
Via composable;

In CHILD COMPONENTS you can use useSimplebar composable to access simplebar instance as a Ref.
NOTE: If you try access to instance before parent mounted this composable will return null;

parent.vue
<SimpleBar>
   <ChildComponent />
</SimpleBar>
child.vue
<!-- Typescript is optional -->
<script lang="ts">
   import { useSimplebar } from 'simplebar-vue3';
   import { onMounted } from 'vue';

   const simplebar = useSimplebar();
   onMounted(() => {
      simplebar.value.recalculate();
      simplebar.value.el.getBoundingClientRect();
      // or more
   });
</script>

Props

import { Options } from 'simplebar';

interface SimpleBarProps {
   /**
    * @default {'div'}
    */
   tag?: string;
   options?: Options;
}

TypeScript Support

This package has built-in typescript support for events and props it should work with .tsx files with no trouble.

To have types support in vue files we recommend you to use Volar plugin.
Volar
TypeScript Vue Plugin

simplebar-vue3's People

Contributors

darthsoup avatar denizcdemirci avatar kadiryazici avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simplebar-vue3's Issues

useSimplebar return type is wrong

Note: for support questions, please use stackoverflow. This repository's issues are reserved for feature requests and bug reports.

  • I'm submitting a ...

    • [ x] bug report
  • Do you want to request a feature or report a bug?
    report a bug

  • What is the current behavior?
    The useSimplebar hook definition is wrong

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via
    https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).

  • Please tell us about your environment:
    it shouldn't matter

Uncaught (in promise) SyntaxError: Invalid or unexpected token - simplebar-vue3

When using simplebar-vue3, i receive this error, if i remove it, it is working as expected.

image

I'm using like this.

import { SimpleBar } from "simplebar-vue3";
<SimpleBar style="height: 400px">
 // div
</SimpleBar>

Error is happening here;

image

I'm using the following version.

 "simplebar": "^5.3.8",
 "simplebar-vue3": "^0.2.0",
  "vite": "^3.0.9",
  "vue": "^3.2.38"

Good to know that: It is working fine in dev mode (windows), but not working in server (Linux). Please try with those to reproduce this problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.