UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

49 lines (48 loc) 1.6 kB
import { defineComponent, ref, onMounted, onUnmounted, createElementBlock, openBlock, normalizeClass, renderSlot } from "vue"; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "LinkList", setup(__props) { const containerRef = ref(); const needsScroll = ref(false); const checkScrollability = () => { if (!containerRef.value) { return; } const { scrollWidth, clientWidth } = containerRef.value; needsScroll.value = scrollWidth > clientWidth; }; let mutationObserver = null; onMounted(() => { checkScrollability(); window.addEventListener("resize", checkScrollability); if (containerRef.value) { mutationObserver = new MutationObserver(() => { checkScrollability(); }); mutationObserver.observe(containerRef.value, { childList: true, subtree: true }); } }); onUnmounted(() => { window.removeEventListener("resize", checkScrollability); if (mutationObserver) { mutationObserver.disconnect(); mutationObserver = null; } }); return (_ctx, _cache) => { return openBlock(), createElementBlock("div", { ref_key: "containerRef", ref: containerRef, class: normalizeClass([{ "icons-only": needsScroll.value }, "custom-scroll mb-3 flex h-auto min-h-8 max-w-full items-center gap-2 overflow-x-auto text-xs whitespace-nowrap xl:mb-1.5"]) }, [ renderSlot(_ctx.$slots, "default", {}, void 0, true) ], 2); }; } }); export { _sfc_main as default };