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

Add as and item props to Vue Virtualizer #464

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/vue/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
/** @jsxImportSource vue */
import { ref, defineComponent, watch, StyleValue, PropType, VNode } from "vue";
import {
ref,
defineComponent,
watch,
StyleValue,
PropType,
VNode,
NativeElements,
} from "vue";
import { ItemResizeObserver } from "../core/resizer";
import { isRTLDocument } from "../core/environment";

Expand All @@ -18,6 +26,7 @@ export const ListItem = /*#__PURE__*/ defineComponent({
_hide: { type: Boolean },
_isHorizontal: { type: Boolean },
_isSSR: { type: Boolean },
_as: { type: String as PropType<keyof NativeElements>, required: true },
},
setup(props) {
const elementRef = ref<HTMLDivElement>();
Expand All @@ -40,6 +49,7 @@ export const ListItem = /*#__PURE__*/ defineComponent({
_hide: hide,
_isHorizontal: isHorizontal,
_isSSR: isSSR,
_as: Element,
} = props;

const style: StyleValue = {
Expand All @@ -57,9 +67,9 @@ export const ListItem = /*#__PURE__*/ defineComponent({
}

return (
<div ref={elementRef} style={style}>
<Element ref={elementRef} style={style}>
{children}
</div>
</Element>
);
};
},
Expand Down
18 changes: 16 additions & 2 deletions src/vue/Virtualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ComponentOptionsWithObjectProps,
ComponentObjectPropsOptions,
PropType,
NativeElements,
} from "vue";
import {
SCROLL_IDLE,
Expand Down Expand Up @@ -103,6 +104,16 @@ const props = {
* Reference to the scrollable element. The default will get the parent element of virtualizer.
*/
scrollRef: Object as PropType<HTMLElement>,
/**
* Component or element type for container element.
* @defaultValue "div"
*/
as: { type: String as PropType<keyof NativeElements>, default: "div" },
/**
* Component or element type for item element.
* @defaultValue "div"
*/
item: { type: String as PropType<keyof NativeElements>, default: "div" },
} satisfies ComponentObjectPropsOptions;

export const Virtualizer = /*#__PURE__*/ defineComponent({
Expand Down Expand Up @@ -215,6 +226,8 @@ export const Virtualizer = /*#__PURE__*/ defineComponent({
return () => {
rerender.value;

const Element = props.as;
const ItemElement = props.item;
const count = props.data.length;

const [startIndex, endIndex] = store._getRange();
Expand Down Expand Up @@ -244,12 +257,13 @@ export const Virtualizer = /*#__PURE__*/ defineComponent({
_children={e}
_isHorizontal={isHorizontal}
_isSSR={isSSR}
_as={ItemElement}
/>
);
}

return (
<div
<Element
ref={containerRef}
style={{
// contain: "content",
Expand All @@ -263,7 +277,7 @@ export const Virtualizer = /*#__PURE__*/ defineComponent({
}}
>
{items}
</div>
</Element>
);
};
},
Expand Down
21 changes: 18 additions & 3 deletions src/vue/WindowVirtualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
SlotsType,
ComponentOptionsWithObjectProps,
ComponentObjectPropsOptions,
PropType,
NativeElements,
} from "vue";
import {
SCROLL_IDLE,
Expand Down Expand Up @@ -49,6 +51,16 @@ const props = {
* If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.
*/
horizontal: Boolean,
/**
* Component or element type for container element.
* @defaultValue "div"
*/
as: { type: String as PropType<keyof NativeElements>, default: "div" },
/**
* Component or element type for item element.
* @defaultValue "div"
*/
item: { type: String as PropType<keyof NativeElements>, default: "div" },
} satisfies ComponentObjectPropsOptions;

export const WindowVirtualizer = /*#__PURE__*/ defineComponent({
Expand Down Expand Up @@ -121,7 +133,9 @@ export const WindowVirtualizer = /*#__PURE__*/ defineComponent({

return () => {
rerender.value;


const Element = props.as;
const ItemElement = props.item;
const count = props.data.length;

const [startIndex, endIndex] = store._getRange();
Expand Down Expand Up @@ -150,12 +164,13 @@ export const WindowVirtualizer = /*#__PURE__*/ defineComponent({
_hide={store._isUnmeasuredItem(i)}
_children={e}
_isHorizontal={isHorizontal}
_as={ItemElement}
/>
);
}

return (
<div
<Element
ref={containerRef}
style={{
// contain: "content",
Expand All @@ -169,7 +184,7 @@ export const WindowVirtualizer = /*#__PURE__*/ defineComponent({
}}
>
{items}
</div>
</Element>
);
};
},
Expand Down
Loading