Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(useVirtualList): add useVirtualList function #710

Merged
merged 3 commits into from
Sep 17, 2021

Conversation

caozhong1996
Copy link
Contributor

hi~, I hope to do a trivial thing for vueuse:

virtual list migrating from ahooks to Composition API

@antfu
Copy link
Member

antfu commented Sep 2, 2021

Does the usage for this function requires certain styles on the client side? If so, I'd feel it's better to be wrapped with a component instead of a compassable function for easier usage (which in this way, will be out-of-scope of VueUse)

@caozhong1996
Copy link
Contributor Author

This is the minimal requirement of useVirtualList.

<script setup lang="ts">
import { useVirtualList } from '.'

const { list, containerProps, wrapperProps } = useVirtualList(
  Array.from(Array(99999).keys()),
  {
    itemHeight: 22,
  },
)

</script>
<template>
  <div>
    <div
      v-bind="containerProps"
      style="height: 300px;"
    >
      <div v-bind="wrapperProps">
        <div
          v-for="ele in list"
          :key="ele.index"
        >
          Row: {{ ele.data }}
        </div>
      </div>
    </div>
  </div>
</template>

@caozhong1996
Copy link
Contributor Author

Yes, It's more like a headless component.
是的,它更像是一个无头组件。

Sometimes component libraries do not fully meet our requirements.
有时候组件库并不完全满足我们的要求。

For example, component's style is not satisfied, but we need their internal logic.
例如组件的样式不满足,但是我们需要组件的内部逻辑。

Unfortunately, current vue component library does not support using without UI.
不幸的是,当前的vue组件库并不支持在无UI的情况下使用。

I believe the composition API can solve this problem.
我相信 composition API 可以解决这个问题。

Will vueuse take consider of headless component ?
vueuse会考虑无头组件这个方向吗?

My English is not very good, thanks.
我的英语不太好,谢谢!

@Jay214
Copy link
Contributor

Jay214 commented Sep 3, 2021

I had the same idea, but I don't think this implementation is very elegant after trying

@antfu
Copy link
Member

antfu commented Sep 3, 2021

I see. That does make some sense. We do have some headless versions of compsoables. https://vueuse.org/guide/components.html

I guess for this, we might better to advocate to use component version first, then fallback to composable for advanced usages. /cc @wheatjs WDYT?

@wheatjs
Copy link
Member

wheatjs commented Sep 4, 2021

I see. That does make some sense. We do have some headless versions of compsoables. https://vueuse.org/guide/components.html

I guess for this, we might better to advocate to use component version first, then fallback to composable for advanced usages. /cc @wheatjs WDYT?

Seems like it would be useful. Wondering about how this might work on the body though. Like if you wanted the scroll container to be the body not sure if that would be possible with the renderless component unless maybe we allow users to set that as a prop.

Copy link
Member

@antfu antfu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reduce the usage example in README.md to show the minimal requirements?

Also, it would be great if you can create component.ts for headless component in @vueuse/components (Refer to a4199cd)

Thanks.

@caozhong1996
Copy link
Contributor Author

OK, I'll do it tomorrow.

@caozhong1996 caozhong1996 changed the title feat(useVirtualList): add useVirtualList function [WIP]feat(useVirtualList): add useVirtualList function Sep 14, 2021
@caozhong1996
Copy link
Contributor Author

Hi, I think It's ready ! @antfu

@caozhong1996 caozhong1996 changed the title [WIP]feat(useVirtualList): add useVirtualList function feat(useVirtualList): add useVirtualList function Sep 15, 2021
@antfu antfu self-requested a review September 17, 2021 06:24
@antfu antfu merged commit bde7f1a into vueuse:main Sep 17, 2021
@caozhong1996
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants