var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name2 in all) __defProp(target, name2, { get: all[name2], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var stdin_exports = {}; __export(stdin_exports, { default: () => stdin_default }); module.exports = __toCommonJS(stdin_exports); var import_vue = require("vue"); var import_vue2 = require("vue"); var import_utils = require("../utils"); var import_DropdownMenu = require("../dropdown-menu/DropdownMenu"); var import_use = require("@vant/use"); var import_use_expose = require("../composables/use-expose"); var import_cell = require("../cell"); var import_icon = require("../icon"); var import_popup = require("../popup"); const [name, bem] = (0, import_utils.createNamespace)("dropdown-item"); const dropdownItemProps = { title: String, options: (0, import_utils.makeArrayProp)(), disabled: Boolean, teleport: [String, Object], lazyRender: import_utils.truthProp, modelValue: import_utils.unknownProp, titleClass: import_utils.unknownProp }; var stdin_default = (0, import_vue2.defineComponent)({ name, props: dropdownItemProps, emits: ["open", "opened", "close", "closed", "change", "update:modelValue"], setup(props, { emit, slots }) { const state = (0, import_vue2.reactive)({ showPopup: false, transition: true, showWrapper: false }); const { parent, index } = (0, import_use.useParent)(import_DropdownMenu.DROPDOWN_KEY); if (!parent) { if (process.env.NODE_ENV !== "production") { console.error("[Vant] must be a child component of ."); } return; } const getEmitter = (name2) => () => emit(name2); const onOpen = getEmitter("open"); const onClose = getEmitter("close"); const onOpened = getEmitter("opened"); const onClosed = () => { state.showWrapper = false; emit("closed"); }; const onClickWrapper = (event) => { if (props.teleport) { event.stopPropagation(); } }; const toggle = (show = !state.showPopup, options = {}) => { if (show === state.showPopup) { return; } state.showPopup = show; state.transition = !options.immediate; if (show) { state.showWrapper = true; } }; const renderTitle = () => { if (slots.title) { return slots.title(); } if (props.title) { return props.title; } const match = props.options.find((option) => option.value === props.modelValue); return match ? match.text : ""; }; const renderOption = (option) => { const { activeColor } = parent.props; const active = option.value === props.modelValue; const onClick = () => { state.showPopup = false; if (option.value !== props.modelValue) { emit("update:modelValue", option.value); emit("change", option.value); } }; const renderIcon = () => { if (active) { return (0, import_vue.createVNode)(import_icon.Icon, { "class": bem("icon"), "color": activeColor, "name": "success" }, null); } }; return (0, import_vue.createVNode)(import_cell.Cell, { "role": "menuitem", "key": option.value, "icon": option.icon, "title": option.text, "class": bem("option", { active }), "style": { color: active ? activeColor : "" }, "tabindex": active ? 0 : -1, "clickable": true, "onClick": onClick }, { value: renderIcon }); }; const renderContent = () => { const { offset } = parent; const { zIndex, overlay, duration, direction, closeOnClickOverlay } = parent.props; const style = (0, import_utils.getZIndexStyle)(zIndex); if (direction === "down") { style.top = `${offset.value}px`; } else { style.bottom = `${offset.value}px`; } return (0, import_vue.withDirectives)((0, import_vue.createVNode)("div", { "style": style, "class": bem([direction]), "onClick": onClickWrapper }, [(0, import_vue.createVNode)(import_popup.Popup, { "show": state.showPopup, "onUpdate:show": ($event) => state.showPopup = $event, "role": "menu", "class": bem("content"), "overlay": overlay, "position": direction === "down" ? "top" : "bottom", "duration": state.transition ? duration : 0, "lazyRender": props.lazyRender, "overlayStyle": { position: "absolute" }, "aria-labelledby": `${parent.id}-${index.value}`, "closeOnClickOverlay": closeOnClickOverlay, "onOpen": onOpen, "onClose": onClose, "onOpened": onOpened, "onClosed": onClosed }, { default: () => { var _a; return [props.options.map(renderOption), (_a = slots.default) == null ? void 0 : _a.call(slots)]; } })]), [[import_vue.vShow, state.showWrapper]]); }; (0, import_use_expose.useExpose)({ state, toggle, renderTitle }); return () => { if (props.teleport) { return (0, import_vue.createVNode)(import_vue2.Teleport, { "to": props.teleport }, { default: () => [renderContent()] }); } return renderContent(); }; } });