UNPKG

reka-ui

Version:

Vue port for Radix UI Primitives.

72 lines (69 loc) 2.44 kB
import { useForwardExpose } from "../shared/useForwardExpose.js"; import { Primitive } from "../Primitive/Primitive.js"; import { valueComparator } from "./utils.js"; import { injectSelectRootContext } from "./SelectRoot.js"; import { computed, createBlock, createTextVNode, defineComponent, onMounted, openBlock, renderSlot, toDisplayString, unref, withCtx } from "vue"; //#region src/Select/SelectValue.vue?vue&type=script&setup=true&lang.ts var SelectValue_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({ __name: "SelectValue", props: { placeholder: { type: String, required: false, default: "" }, asChild: { type: Boolean, required: false }, as: { type: null, required: false, default: "span" } }, setup(__props) { const props = __props; const { forwardRef, currentElement } = useForwardExpose(); const rootContext = injectSelectRootContext(); onMounted(() => { rootContext.valueElement = currentElement; }); const selectedLabel = computed(() => { let list = []; const options = Array.from(rootContext.optionsSet.value); const getOption = (value) => options.find((option) => valueComparator(value, option.value, rootContext.by)); if (Array.isArray(rootContext.modelValue.value)) list = rootContext.modelValue.value.map((value) => getOption(value)?.textContent ?? ""); else list = [getOption(rootContext.modelValue.value)?.textContent ?? ""]; return list.filter(Boolean); }); const slotText = computed(() => { return selectedLabel.value.length ? selectedLabel.value.join(", ") : props.placeholder; }); return (_ctx, _cache) => { return openBlock(), createBlock(unref(Primitive), { ref: unref(forwardRef), as: _ctx.as, "as-child": _ctx.asChild, style: { pointerEvents: "none" }, "data-placeholder": selectedLabel.value.length ? void 0 : props.placeholder }, { default: withCtx(() => [renderSlot(_ctx.$slots, "default", { selectedLabel: selectedLabel.value, modelValue: unref(rootContext).modelValue.value }, () => [createTextVNode(toDisplayString(slotText.value), 1)])]), _: 3 }, 8, [ "as", "as-child", "data-placeholder" ]); }; } }); //#endregion //#region src/Select/SelectValue.vue var SelectValue_default = SelectValue_vue_vue_type_script_setup_true_lang_default; //#endregion export { SelectValue_default }; //# sourceMappingURL=SelectValue.js.map