Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
feat: use dynamic component to define container element (#229)
Browse files Browse the repository at this point in the history
Co-authored-by: VWSY (Vigan Shemsiu) <vwsy@novonordisk.com>
  • Loading branch information
shemsiu and nnzhadow committed Jun 5, 2022
1 parent a13e411 commit d2e9875
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ npm install vue-virtual-scroll-grid

| Name | Description | Type | Validation |
|----------------------------|-----------------------------------------------------------------------------------|----------------------------------------------------------------|------------------------------------------------------|
| `tag` | The HTML tag used as container element. Default value is `div` | `string` | Any valid HTML tag |
| `probeTag` | The HTML tag used as probe element. Default value is `div` | `string` | Any valid HTML tag |
| `length` | The number of items in the list | `number` | Required, an integer greater than or equal to 0 |
| `pageProvider` | The callback that returns a page of items as a promise. `pageNumber` start with 0 | `(pageNumber: number, pageSize: number) => Promise<unknown[]>` | Required |
| `pageProviderDebounceTime` | Debounce window in milliseconds on the calls to `pageProvider` | `number` | Optional, an integer greater than or equal to 0 |
| `pageSize` | The number of items in a page from the item provider (e.g. a backend API) | `number` | Required, an integer greater than or equal to 1 |
| `scrollTo` | Scroll to a specific item by index | `number` | Optional, an integer from 0 to the `length` prop - 1 |
| `scrollBehavior` | The behavior of `scrollTo`. Default value is `smooth` | `smooth` &#124; `auto` | Optional, a string to be `smooth` or `auto` |
| `scrollBehavior` | The behavior of `scrollTo`. Default value is `smooth` | `smooth` &#124; `auto` | Optional, a string to be `smooth` or `auto` |

Example:

Expand Down
19 changes: 15 additions & 4 deletions src/Grid.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div v-show="length > 0" ref="rootRef" :style="rootStyles">
<div
<component :is="tag" v-show="length > 0" ref="rootRef" :style="rootStyles">
<component
:is="probeTag"
:style="{
opacity: 0,
visibility: 'hidden',
Expand All @@ -12,7 +13,7 @@
ref="probeRef"
>
<slot name="probe" />
</div>
</component>

<template
v-for="internalItem in buffer"
Expand All @@ -32,7 +33,7 @@
:style="internalItem.style"
/>
</template>
</div>
</component>
</template>

<script lang="ts">
Expand Down Expand Up @@ -95,6 +96,16 @@ export default defineComponent({
default: "smooth",
validator: (value: string) => ["smooth", "auto"].includes(value),
},
tag: {
type: String as PropType<string>,
required: false,
default: 'div',
},
probeTag: {
type: String as PropType<string>,
required: false,
default: 'div',
},
},
setup(props) {
// template refs
Expand Down

0 comments on commit d2e9875

Please sign in to comment.