UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

77 lines (76 loc) 3.07 kB
import { defineComponent, computed, createBlock, createElementBlock, openBlock, unref, withCtx, createVNode, createElementVNode, toDisplayString } from "vue"; import { ScalarListbox, ScalarButton } from "@scalar/components"; import { ScalarIconCaretDown } from "@scalar/icons"; const _hoisted_1 = { class: "overflow-x-auto" }; const _hoisted_2 = { key: 1, class: "text-c-1 flex h-auto w-full items-center gap-0.75 rounded-b-lg px-3 py-1.5 text-base leading-[20px] whitespace-nowrap" }; const _hoisted_3 = { class: "overflow-x-auto" }; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "Selector", props: { selectedServer: {}, servers: {}, target: {} }, emits: ["update:modelValue"], setup(__props, { expose: __expose, emit: __emit }) { const emit = __emit; const serverOptions = computed( () => __props.servers.map((server) => ({ id: server.url, label: server.url })) ); const serverUrlWithoutTrailingSlash = computed( () => __props.selectedServer?.url?.replace(/\/$/, "") || "" ); const selectedServerOption = computed( () => serverOptions.value.find((opt) => opt.id === __props.selectedServer?.url) ); __expose({ servers: __props.servers, serverUrlWithoutTrailingSlash, serverOptions, selectedServer: __props.selectedServer }); return (_ctx, _cache) => { return serverOptions.value.length > 1 ? (openBlock(), createBlock(unref(ScalarListbox), { key: 0, ref: "elem", class: "group", modelValue: selectedServerOption.value, options: serverOptions.value, placement: "bottom-start", resize: "", target: __props.target, "onUpdate:modelValue": _cache[0] || (_cache[0] = (e) => emit("update:modelValue", e.id)) }, { default: withCtx(() => [ createVNode(unref(ScalarButton), { class: "bg-b-1 text-c-1 h-auto w-full justify-start gap-1.5 overflow-x-auto rounded-t-none rounded-b-lg px-3 py-1.5 text-base font-normal whitespace-nowrap -outline-offset-1", variant: "ghost" }, { default: withCtx(() => [ _cache[1] || (_cache[1] = createElementVNode("span", { class: "sr-only" }, "Server:", -1)), createElementVNode("span", _hoisted_1, toDisplayString(serverUrlWithoutTrailingSlash.value || "Select a server"), 1), createVNode(unref(ScalarIconCaretDown), { class: "text-c-2 ui-open:rotate-180 mt-0.25 size-3 transition-transform duration-100", weight: "bold" }) ]), _: 1 }) ]), _: 1 }, 8, ["modelValue", "options", "target"])) : (openBlock(), createElementBlock("div", _hoisted_2, [ _cache[2] || (_cache[2] = createElementVNode("span", { class: "sr-only" }, "Server:", -1)), createElementVNode("span", _hoisted_3, toDisplayString(serverUrlWithoutTrailingSlash.value), 1) ])); }; } }); export { _sfc_main as default };