28 lines
803 B
Vue
28 lines
803 B
Vue
<script lang="ts">
|
|
import { defineComponent, h, Fragment, useAttrs, type PropType } from "vue";
|
|
|
|
/**
|
|
* Declarative items renderer for rows. Use the default scoped slot with
|
|
* each item, matching the upstream Table.Collection API.
|
|
*/
|
|
export default defineComponent({
|
|
name: "TableCollection",
|
|
inheritAttrs: false,
|
|
props: {
|
|
items: { type: Array as PropType<unknown[]>, default: () => [] },
|
|
as: { type: String, default: undefined },
|
|
},
|
|
setup(props, { slots }) {
|
|
const attrs = useAttrs();
|
|
return () => {
|
|
const children = (props.items ?? []).map((item, index) =>
|
|
slots.default?.({ item, index }),
|
|
);
|
|
return props.as
|
|
? h(props.as, { ...attrs, "data-slot": "table-collection" }, children)
|
|
: h(Fragment, children);
|
|
};
|
|
},
|
|
});
|
|
</script>
|